akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void)
{
	int a, b, c;
	int kazu = 0;
	
	scanf("%d %d %d", &a, &b, &c); 
	while (b >= a){
			if (c % b == 0){
				++kazu;	
			}
		
		--b;
	}
	
	printf("%d\n", kazu);
	return 0;
}

Measured memory_bytes: 596
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,w,z;
    char ca,cb,cc;
    cin>>n;
    if(n<1000){
cout<<"ABC"<<endl;
    }else{
        cout<<"ABD"<<endl;
    }
    return 0;
}


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

int main(){
  int a, b, h;
  cin >> a >> b >> h;
  
  cout << (a+b)*h/2 << endl;
}

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

using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;

int N;
Graph G;

vector<int> res;

void dfs(int v, int p, int c) {
	res[v] = c;
	for (auto nv : G[v]) {
		if (nv.first == p) continue;
		if (nv.second & 1) dfs(nv.first, v, 1 - c);
		else dfs(nv.first, v, c);
	}
}

int main()
{



	cin >> N;
	G.assign(N, vector<Edge>());
	for (int i = 0; i < N - 1; ++i)
	{
		int u, v, w; cin >> u >> v >> w;
		--u, --v;
		G[u].push_back(Edge(v, w));
		G[v].push_back(Edge(u, w));
	}
	res.assign(N, 0);
	dfs(0, -1, 1);
	for (auto v : res) cout << v << endl;
	return 0;

}

Measured memory_bytes: 8960
import java.util.*;

public class Main {
  static long[] dp;
  static ArrayList[] edge;
  static ArrayList[] cost;
  //static HashMap<int[], Long> cost;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    dp = new long[n];
    edge = new ArrayList[n];
    cost = new ArrayList[n];
    for(int i = 0; i < n; i++) {
      edge[i] = new ArrayList<Integer>();
      cost[i] = new ArrayList<Long>();
    }
    for(int i = 0; i < n - 1; i++) {
      int a = sc.nextInt() - 1;
      int b = sc.nextInt() - 1;
      long c = sc.nextLong();
      cost[a].add(c);
      cost[b].add(c);
      edge[a].add(b);
      edge[b].add(a);
    }
    int Q = sc.nextInt();
    int K = sc.nextInt() - 1;
    dfs(K, -1);
    for(int i = 0; i < Q; i++) {
      int x = sc.nextInt() - 1;
      int y = sc.nextInt() - 1;
      System.out.println(dp[x] + dp[y]);
    }
  }

  public static void dfs(int v, int parent) {
    ArrayList<Integer> e = edge[v];
    ArrayList<Long> c = cost[v];
    if((parent >= 0) && (e.size() == 1)) {
      
    } else {
      for(int i = 0; i < e.size(); i++) {
        int u = e.get(i);
        if(u != parent) {
          long ct = c.get(i);
          dp[u] = dp[v] + ct;
          dfs(u, v);
        }
      }
    }
  }
}

class Edge {
  int u;
  int v;
  Edge(int u, int v) {
    this.u = u;
    this.v = v;
  }
}

Measured memory_bytes: 202144
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <functional>
#define fs first
#define se second

#ifdef imeimi
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...)
#endif

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
typedef pair<ld, ld> pdd;

pii operator+(pii a, pii b) {
    return pii(min(a.fs, b.fs), max(a.se, b.se));
}

int n, k;
int P[200001];

pii seg[1 << 19];

void init(int i, int s, int e) {
    if (s == e) {
        seg[i] = pii(P[s], P[e]);
        return;
    }
    int m = (s + e) / 2;
    init(i << 1, s, m);
    init(i << 1 | 1, m + 1, e);
    seg[i] = seg[i << 1] + seg[i << 1 | 1];
}

pii query(int i, int s, int e, int x, int y) {
    if (e < x || y < s) return pii(n + 1, -1);
    if (x <= s && e <= y) return seg[i];
    int m = (s + e) / 2;
    return query(i << 1, s, m, x, y) + query(i << 1 | 1, m + 1, e, x, y);
}
int inc[200001];
bool sorted[200001];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) cin >> P[i];
    int ans = 1;
    init(1, 1, n);
    for (int i = 1; i < n; ++i) {
        inc[i] = P[i] < P[i + 1];
    }
    for (int i = 1; i < n; ++i) {
        inc[i + 1] += inc[i];
    }
    for (int i = 0; i + k <= n; ++i) {
        sorted[i] = (inc[i + k - 1] - inc[i]) == k - 1;
    }
    bool S = sorted[0];
    for (int i = 1; i + k <= n; ++i) {
        if (sorted[i]) {
            if (S) continue;
            S = 1;
            ++ans;
            continue;
        }
        int s = i;
        int e = i + k;
        pii p = query(1, 1, n, s + 1, e - 1);
        if (P[s] < p.fs && p.se < P[e]);
        else ++ans;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 6144
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = {105, 135, 165, 189, 195};
		for (int i = 0; i < a.length; i++) {
			if (n >= 195) {
				System.out.println(5);
				return;
			}
			if (n < a[i]) {
				System.out.println(i);
				return;
			}
		}
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;
inline int toInt(string s){int v;istringstream i(s);i>>v;return v;}
template<class T> inline string toString(T x){ostringstream o;o<<x;return o.str();}
template<class T> void pv(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}
const int INF = 1000000000;
const double PI = acos(-1.0), EPS = 1e-10;

bool field[410][410];

void on(int x, int y) {
	field[x + 200][y + 200] = true;
}

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

int px[400];
int py[400];

int main() {
	for(int N; cin >> N, N;) {
		memset(field, 0, sizeof field);
		on(0, 0);
		px[0] = 0;
		py[0] = 0;
		for(int i = 1; i < N ; i++) {
			int n, d;
			cin >> n >> d;
			int nx = px[n] + dx[d];
			int ny = py[n] + dy[d];
			px[i] = nx;
			py[i] = ny;
			on(nx, ny);
		}
#if 0
		for(int x = 0; x < 410; x++)
			for(int y = 0; y < 410; y++)
				if(field[x][y])
					cout << x << ":" << y << endl;
#endif
		int top = -INF;
		int bottom = INF;
		int right = -INF;
		int left = INF;
		for(int x = 0; x < 410; x++)
			for(int y = 0; y < 410; y++) {
				if(field[x][y]) {
					int nx = x - 200;
					int ny = y - 200;
					top = max(top, ny);
					bottom = min(bottom, ny);
					right = max(right, nx);
					left = min(left, nx);
				}
			}
		
		cout << (right - left + 1) << " " << (top - bottom + 1) << endl;
	}
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

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

template <int mod>
struct ModInt {
  int x;
  ModInt(): x(0) {}
  ModInt(long long a) { x = a % mod; if (x < 0) x += mod; }
  ModInt &operator+=(ModInt that) { x = (x + that.x) % mod; return *this; }
  ModInt &operator-=(ModInt that) { x = (x + mod - that.x) % mod; return *this; }
  ModInt &operator*=(ModInt that) { x = (long long) x * that.x % mod; return *this; }
  ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
  ModInt inverse() {
    int a = x, b = mod, u = 1, v = 0;
    while (b) { int t = a / b; a -= t * b; u -= t * v; swap(a, b); swap(u, v); }
    return ModInt(u);
  }
  #define op(o, p) ModInt operator o(ModInt that) { return ModInt(*this) p that; }
    op(+, +=) op(-, -=) op(*, *=) op(/, /=)
  #undef op
  friend ostream& operator<<(ostream &os, ModInt m) { return os << m.x; }
};

using mint = ModInt<998244353>;

void solve() {
  int n, s;
  cin >> n >> s;
  vi32 a(n);
  cin >> a;
  using vm = vector<mint>;
  vector<vm> dp(n + 1, vm(s + 1));
  dp[0][0] = exp((mint) 2, n);
  mint div = (mint) 1 / 2;
  rep(i, n) repc(j, s) {
    dp[i + 1][j] += dp[i][j];
    if (j + a[i] <= s) dp[i + 1][j + a[i]] += dp[i][j] * div;
  }
  cout << dp[n][s] << endl;
}


Measured memory_bytes: 38576
#!python3

import numpy as np

LI = lambda: list(map(float, input().split()))

# input
N = int(input())
P = LI()


def main():
    dp = np.zeros((N + 1, N + 1))
    dp[0][0] = 1
    for i in range(1, N + 1):
        p = P[i - 1]
        bac = dp[i - 1][:i] * (1 - p)
        hos = dp[i - 1][:i] * p
        dp[i][:i] += bac
        dp[i][1 : i + 1] += hos
    ans = sum(dp[N][(N + 1) // 2:])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 72784
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 string S;
  cin>>S;
  for(ll i=0;i<4;i++) {
    ll count=0;
for(ll j=0;j<4;j++) {
  if(S[i]==S[j]) {
count++;
  }
}

    if(count!=2) {
      cout<<"No"<<endl;
      return 0;
    }
  }


  cout<<"Yes"<<endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define pb push_back
const int mod=1e9+7;

int main(){
	ll n;
	while(cin >> n){
		int cont[n+5] = {};
		multiset<int>st;
		f(n){
			cin >> cont[i];
			st.insert(cont[i]);
		}
		f(n){
			st.erase(st.lower_bound(cont[i]));
			cout<<*(--st.end())<<'\n';
			st.insert(cont[i]);
		}
	}

}

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

int main(){
	string s;
	cin >> s;
	ll Q;
	cin >> Q;
	int count = 0;//何回反転するか
	
	string pre;
	string suf;
	
	rep(i,Q){
		int t;
		cin >> t;
		//文字列を反転
		if(t == 1){
			count++;
		}
		if(t == 2){
			int f;
			cin >> f;
			if(f == 1){
				char c;
				cin >> c;
				if(count%2 == 0){
					pre.push_back(c);
				}else{
					suf.push_back(c);
				}
			}
			if(f == 2){
				char c;
				cin >> c;
				if(count % 2 == 0){
					suf.push_back(c);
				}else{
					pre.push_back(c);
				}
			}
		}
	}
	
	if(count % 2 == 1){
		reverse(s.begin(),s.end());
	}
	
	
	
	if(count % 2 == 0){
		reverse(pre.begin(),pre.end());
		cout << pre + s + suf << endl;
	}else{
		reverse(suf.begin(),suf.end());
		cout << suf + s + pre << endl;
	}
	
    return 0;
}



Measured memory_bytes: 1348
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>
#include <cmath>
#include <iomanip>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////


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

    int N, M, X;

    cin >> N >> M >> X;

    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M));
    
    for (int i = 0; i < N; i++) {
        cin >> C[i];
        for (int j = 0; j < M; j++) {
            cin >> A[i][j];
        }
    }

    int bst = (1<<30);

    for (int msk = 1; msk < (1<<N); msk++) {
        int cost = 0;

        vector<int> level(M);

        for (int i = 0; i < N; i++) {
            if ((msk >> i) & 1) {
                cost += C[i];

                for (int j = 0; j < M; j++)
                    level[j] += A[i][j];
            }
        }

        bool ok = true;
        for (int j = 0; j < M; j++)
            if (level[j] < X)
                ok = false;

        if (ok) {
            bst = min(bst, cost);
        }
    }

    cout << (bst != (1<<30) ? bst : -1) << "\n";

    return 0;
}


Measured memory_bytes: 3624
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class ABC179E
    {
        // https://atcoder.jp/contests/abc179/tasks/abc179_e

        static void Main(string[] args)
        {
            var items = Console.ReadLine().Split();
            long N = Int64.Parse(items[0]);
            long X = Int64.Parse(items[1]);
            long M = Int64.Parse(items[2]);

            long sum = X;
            long Ai = X;

            if (X < 1)
            {
                Console.WriteLine(0);
                return;
            }

            long[] mo = new long[M];
            long[] Si = new long[M];
            mo[Ai] = 1;
            Si[1] = Ai;

            for (int i = 2; i <= N; i++)
            {
                Ai = Ai * Ai % M;

                if (mo[Ai] > 0)
                {
                    long loopSize = i - mo[Ai];

                    if ((N - i + 1) % loopSize == 0)
                    {
                        long loopCount = (N - i + 1) / loopSize;
                        long loopSum = Si[i - 1] - Si[mo[Ai] - 1];
                        sum += loopSum * loopCount;

                        Console.WriteLine(sum);
                        return;
                    }
                }

                mo[Ai] = i;
                sum += Ai;
                Si[i] = sum;
            }

            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 28696
#include <iostream>
using namespace std;
int main(void){
    long long N,T,x,xx,ans=0;
    cin >> N >> T >> x;
    ans += T;
    for(int i = 0;i<N-1;i++){
        cin >> xx;
        if(xx-x >= T) ans += T;
        else ans += xx- x;
        x = xx;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    int x;
    scanf("%d",&x);
    if(x==1)
    {
        printf("1");
        return 0;
    }
    int w=1000,s,i,j;
    for(i=2;i<=10;i++)
        for(j=2;j<40;j++)
        {
            if(pow(j,i)>x)
                break;
            s=x-pow(j,i);
            if(s<w)
                w=s;
        }
        printf("%d",x-w);
    return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

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

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

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

	for (int i = 0; i < s.size(); i++){
		cout<<"x";
	}
	cout<<endl;


	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define mid (low+high)/2
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 300004

using namespace std;

ll n,m,s,t,a,b,c,mod=1e9+7;
vector < pi > graph[N];
ll dist[N][2],ways[N][2];
vector < pair < pi,ll > > edges;

void dijkstra(ll root,ll id)
{
    rep(i,0,n+1)
    {
        dist[i][id] = -1;
        ways[i][id] = 0;
    }

    dist[root][id] = 0;
    ways[root][id] = 1;

    priority_queue < pi > pq;
    pq.push(mp(0,root));

    while(!pq.empty())
    {
        pi cur = pq.top();
        pq.pop();

        if(-cur.first > dist[cur.second][id])
            continue;

        rep(i,0,graph[cur.second].size())
        {
            ll v = graph[cur.second][i].first;
            c = graph[cur.second][i].second;

            if(dist[v][id] == -1 || dist[v][id] > dist[cur.second][id] + c)
            {
                dist[v][id] = dist[cur.second][id] + c;
                ways[v][id] = ways[cur.second][id];
                pq.push(mp(-dist[v][id],v));
            }
            else if(dist[v][id] == dist[cur.second][id]+c)
                ways[v][id] = (ways[v][id] + ways[cur.second][id])%mod;
        }
    }

    return;
}

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

    cin >> n >> m;
    cin >> s >> t;

    rep(i,0,m)
    {
        cin >> a >> b >> c;
        graph[a].push_back(mp(b,c));
        graph[b].push_back(mp(a,c));
        edges.push_back(mp(mp(a,b),c));
    }

    dijkstra(s,0);
    dijkstra(t,1);

    ll ans = (ways[t][0]*ways[s][1])%mod;
    ll S = dist[t][0];

    // meet at vertex

    rep(i,1,n+1)
    {
        if(dist[i][0] == dist[i][1] && dist[i][0] + dist[i][1] == S)
        {
            ll paths = (ways[i][0]*ways[i][1])%mod;

            ans = (ans - (paths*paths)%mod + mod)%mod;
        }
    }

    // meet at edge

    rep(i,0,m)
    {
        ll u = edges[i].first.first;
        ll v = edges[i].first.second;
        c = edges[i].second;

        if(dist[u][0] + dist[v][1] + c == S)
        {
            if(dist[u][0] < S/2.0 && dist[v][0] > S/2.0)
            {
                //cout << "meet from " << u << " to " << v << endl;
                ll paths = (ways[u][0]*ways[v][1])%mod;
                ans = (ans - (paths*paths)%mod + mod)%mod;
            }
        }
        if(dist[v][0] + dist[u][1] + c == S)
        {
            if(dist[v][0] < S/2.0 && dist[u][0] > S/2.0)
            {
               // cout << "meet from " << v << " to " << u << endl;
                ll paths = (ways[u][1]*ways[v][0])%mod;
                ans = (ans - (paths*paths)%mod + mod)%mod;
            }
        }
    }

    cout << ans;

    return 0;
}

/*
5 6
1 5
1 2 1
1 3 1
2 4 1
3 4 1
4 5 1
1 5 100

5 7
1 5
1 2 1
1 3 1
3 4 1
3 5 2
5 2 2
5 4 1
2 4 1

6 7
1 5
1 2 1
1 3 1
2 4 1
3 4 1
4 5 2
5 6 1
6 4 1

7 8
1 5
1 2 1
1 3 1
2 4 1
3 4 1
7 4 1
7 6 1
6 5 1
7 5 2

*/


Measured memory_bytes: 33060
#include <iostream>
#include <string.h>
#include <cstdio>
#include <algorithm>
using namespace std;

const int INF = 1e+8;
int DP[10010];
int M, N, P[10001], C[501], E[501];

int main() {
	for(int i = 0; i < 10010; ++i)
		DP[i] = INF;
	
	int Psum[10001] = {0};
	cin >> M >> N; 
	for(int i = 0; i < M; ++i)
		scanf("%d", &P[i]);
	for(int i = 0; i < N; ++i)
		scanf("%d %d", &C[i], &E[i]);
	
	sort(P, P + M, greater<int>());	
	Psum[0] = 0;
	for(int i = 1; i <= M; ++i)
		Psum[i] = Psum[i - 1] + P[i - 1];
	
	DP[0] = 0;
	for(int i = 0; i < N; ++i){
		for(int j = M; j >= 0; --j){
			DP[j] = min(DP[j], DP[max(j - C[i], 0)] + E[i]);
		}
	}
	/*cout << DP[4] << endl;
	cout << Psum[4] << endl;*/
	int ans = 0;
	for(int i = 1; i <= M; ++i)
		ans = max(ans, Psum[i] - DP[i]);
	
	cout << ans << endl;
	return 0;
}

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

int main(){
  long long A,B,K; cin >> A >> B >> K;
  if(A>0){
    if(A<=K){
      K-=A;
      A=0;
    }else{
      A-=K;
      K=0;
    }
  }
  if(B>0){
    if(B<=K){
      K-=B;
      B=0;
    }else{
      B-=K;
      K=0;
    }
  }
  cout << A << " " << B << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する


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

    int H, W, K;
    cin >> H >> W >> K;
    vector<string> A;
    rep(i, 0, H) {
        string s;
        cin >> s;
        A.push_back(s);
    }

    int sx, sy;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (A[i][j] == 'S') {
                sx = i;
                sy = j;
            }
        }
    }

    using Pxy = pair<int, int>; //座標
    using V = pair<Pxy, int>; //あるへん


    set<Pxy> grids; //最初に行ける座標たち
    set<Pxy> used; // 使用済み
    queue<V> que;
    que.push(V(Pxy(sx, sy), 0));
    used.emplace(sx, sy);

    while (!que.empty()) {
        V top = que.front();
        que.pop();
        if (top.second <= K) {
            grids.insert(top.first);
            int dx[] = {-1, 0, 1, 0};
            int dy[] = {0, -1, 0, 1};
            for (int k = 0; k < 4; ++k) {
                int h = top.first.first + dx[k];
                int w = top.first.second + dy[k];

                if (h >= 0 && h < H && w >= 0 && w < W) {
                    if (A[h][w] == '.' && !used.count(Pxy(h, w))) {
                        que.push(V(Pxy(h, w), top.second + 1));
                        used.insert(Pxy(h, w));
                    }
                }
            }

        }
    }

    int ans = INF;
    for (auto e : grids) {
        int h = e.first;
        int w = e.second;

        vector<int> kouho;
        kouho.push_back(h);
        kouho.push_back(H - 1 - h);
        kouho.push_back(w);
        kouho.push_back(W - 1 - w);
        sort(all(kouho));
        int dist = kouho[0] / K + (kouho[0] % K != 0) + 1;

        chmin(ans, dist);
    }

    cout << ans << endl;

    return 0;
}


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

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fr(i,k) for(i=0;i<k;i++)
#define ALL(c) (c).begin(),(c).end()
#define deb(x) cerr<<#x<<"  = "<<x<<endl;
#define SZ(x) (x).size();
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define em emplace_back
#define ulli unsigned long long int
#define INF 1e18
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> ii;
void solve();

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main() {
	fastio;
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/

	int t;
	t=1;

    //cin>>t;
	while (t--)
	{
		solve();
	}
	return 0;
}

void solve()
{
	ll n,i,ans=0;
	cin>>n;

	ll a[n];

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

    vector<ll> suf(n);
    suf[n-1]=a[n-1];

    for(i=n-2;i>=0;i--)
    {
        suf[i]= (suf[i+1]%MOD+a[i])%MOD;
    }

    for(i=0;i<n-1;i++)
    {
        ans = (MOD+ans + ((a[i]%MOD)*(suf[i+1])%MOD)%MOD)%MOD;
    }

    cout<<ans<<endl;

}


Measured memory_bytes: 6332
#include <algorithm>
#include <iostream>
#include <map>

int main()
{
    long long h, w, n;
    std::cin >> h >> w >> n;
    std::map<std::pair<long long, long long>, long long> grid;
    for(std::size_t i = 0; i != n; ++i)
    {
        long long a, b;
        std::cin >> a >> b;
        for(long long x = std::max(1LL, a - 1 - 1);
            x != std::min(a - 1 + 1 + 1, h - 1); ++x)
            for(long long y = std::max(1LL, b - 1 - 1);
                y != std::min(b - 1 + 1 + 1, w - 1); ++y)
                grid[{x, y}]++;
    }
    std::cout << (h - 2) * (w - 2) - grid.size() << std::endl;
    for(unsigned long long i = 1; i != 10; ++i)
        std::cout << std::count_if(
                         grid.begin(), grid.end(),
                         [i](const auto &pair) { return pair.second == i; })
                  << std::endl;
    return 0;
}


Measured memory_bytes: 56448
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());
        int y = Integer.parseInt(sc.next());
        long ans = 0;
        int min = Math.min(x, y);
        if (a + b > c * 2) {
            ans += c * 2 * min;
        } else {
            ans += min * a + min * b;
        }
        int sub = Math.abs(x - y);
        if (sub != 0) {
            if (x > y) {
                if (a > c * 2) {
                    ans += c * 2 * sub;
                } else {
                    ans += a * sub;
                }
            } else {
                if (b > c * 2) {
                    ans += c * 2 * sub;
                } else {
                    ans += b * sub;
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#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 rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    ll res=0;
    for(int i=1;i<=n;i++){
        if(i%3==0)continue;
        if(i%5==0)continue;
        else res += i;
    }
    
    cout<<res<<endl;
}


Measured memory_bytes: 3632
#include<iostream>

using namespace std;

int main(){
    int a, b, c;

    cin >> a >> b >> c;

    if(a<=b){
        if(b<=c){
            cout << a+b;
        }else{
            cout << a+c;
        }
    }else{
        if(a<=c){
            cout << a+b;
        }else{
            cout << b+c;
        }
    }
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int l = sc.nextInt();
    String[] line = new String[n + 1];
    for (int cnt = 0; cnt < n + 1; cnt++) {
      line[cnt] = sc.nextLine();
    }
    Arrays.sort(line);
    for (int cnt = 0; cnt < n + 1; cnt++) {
      System.out.print(line[cnt]);
    }
    sc.close();
  }
}

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

using namespace std;

typedef long long ll;

const int N = 1e5 + 5;
const int mod = (int) 1e9 + 7;

int n, a[N];

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

        sort (a + 1, a + n + 1, greater<int> ());

        int f = n, x = 0;
        for (int i = 1; i <= n; i++)
            if (a[i] < i)
            {
                    f = i - 1;
                    break;
            }
        for (int i = 1; i <= n; i++)
            if (a[i] >= f)
                x ++;

        puts (((x - f) | (a[f] - f)) % 2 ? "First" : "Second");
}


Measured memory_bytes: 640
//デバッグ用オプション：-fsanitize=undefined,address

//コンパイラ最適化
#pragma GCC optimize("Ofast")

//インクルードなど
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
//FORAは範囲for文(使いにくかったら消す)
#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 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 FORA(i,I) for(const auto& i:I)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

signed main(){
    //入力の高速化用のコード
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
  int N=0,d=0,s=0;
  cin >> N;
  vector<int> D;
  for (int i=0; i<N;i++) {
    cin >> d;
    D.push_back(d);
  }
  if(N<3){
    cout << 0;
  }else{
    for(int i=0; i<N-1;i++){
      for(int j=i+1;j<N;j++){
        if(D[i]==D[j]){
          continue;
        }else{
          for(int k=j+1;k<N+1;k++){
            if(D[k]==D[i] || D[k]==D[j]){
              continue;
            }else{
              if( (D[i]+D[j]>D[k]) && (D[i]+D[k]>D[j]) && (D[k]+D[j]>D[i]) ){
              	s++;
              }
            }
          }
        }
      }
    }
    cout << s;
  }
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define ll long long
#define lli long long int
#define endl "\n"
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dump(a) for (auto a: v) cout << a << " "
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define precision(x, y) cout << fixed << setprecision(y) << x << endl
#define PI 3.1415926535897932384626
#define MOD 1e9+7
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pl;
typedef vector<int>     vi;
typedef vector<ll>      vl;
typedef vector<pii>     vpii;
typedef vector<pl>      vpl;
typedef vector<vi>      vvi;
typedef vector<vl>      vvl;

void solve() {
    char c;
    cin >> c;

    bool is_upper = false;
    if (c >= 'A' && c <= 'Z') {
        is_upper = true;
    }
    if (is_upper) cout << 'A' << endl;
    else cout << 'a' << endl;
}

int main() {
    fastio;
    // int t; cin >> t;
    // while (t--)
    solve();
    return 0;
}


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

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

	int n; cin >> n;
	n /= 200;
	n -= 2;
	int a[] = {8,7,6,5,4,3,2,1};
	cout << a[n] << endl;
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const double pi=3.1415926536;
#define fo(i,n) for( ll int i=0;i<n;++i)
#define fos(j,i,n) for(ll int j=i;j<n;++j)
#define N 100004
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define abs(x) ((x)<0?(-(x)):(x))
#define dis(k) cout << k << endl
#define forr(i,n) for( ll int i= n-1;i>=0;--i)
#define dbg(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define ve vector
#define fi first
#define se second
#define setzero(a) memset(a,0,sizeof(a))
#define setinf(a) memset(a,0x7F,sizeof(a))
typedef ve< ll > vi;
typedef ve< vi > vvi;
typedef pair< ll ,ll > ii;



/*Don't just sit and hope that God will solve this
fucking do something, try to observe or solve it a different way.
Use that pen and paper.
If nothing works take a deep breath and start again.*/


void solve(){
	ll n,k;
	cin >> n >> k;
	vi a(n);
	vi dp(n,INF);
	dp[0]=0;
	fo(i,n) cin >> a[i];
	fo(i,n) {
		for(ll j=i-1;j>=max(i-k,0ll);--j)
			dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
	}
	dis(dp[n-1]);
	
}

int main(){
	fast;
	int t=1;
	int tt=1;
	//cin >> t;

	while(t--){
		//cout << "Case #" << tt << ": " ;
		tt++;
		solve();
	}
	return 0;
}

Measured memory_bytes: 4752
from collections import deque
# リストの両端の要素に対する編集が必要
# 同一方向に進むときは移動回数が増えないためリストのの先頭に挿入
# この仕組みを実装するためdequeを読み込み

H, W, K = map(int, input().split())
# HとWとKの値それぞれを取得

x1, y1, x2, y2 = map(int, input().split())
x1 -= 1
y1 -= 1
x2 -= 1
y2 -= 1
# リストの先頭要素は0番目として数えられる
# 座標のそれぞれの値から1を引いて取得

grid = [input() for _ in range(H)]
# グリッド部分をH行にわたって取得

INF = float('inf')
path = [[[(INF, INF)] * 4 for _ in range(W)] for _ in range(H)]
# 無限大の浮動小数点を管理

D = [(-1, 0), (0, 1), (1, 0), (0, -1)]
# 進行方向を座標で管理

q = deque()
for d in range(4):
	path[x1][y1][d] = (1, 0)
	# スタート地点を(1, 0)に設定
	q.append((x1, y1, d, 1, 0))
	# (x, y, 進行方向, 移動回数, 進行済マス数)を要素に追加

while q:
	x, y, d, c, k = q.popleft()
	#要素の削除
	
	# nx, ny: 次の座標
	# nd: 次の進行方向
	# nc: 次の移動回数
	# nk: 次の進行済マス数
	
	for nd in range(4):
		if nd == d:
			dx, dy = D[nd]
			nk = 1 if k == K else k + 1
			nc = c + 1 if k == K else c
		else:
			dx, dy = 0, 0
			nk = 0
			nc = c + 1
		nx = x + dx; ny = y + dy
		if 0 <= nx < H and 0 <= ny < W and grid[nx][ny] == '.' and path[nx][ny][nd] > (nc, nk):
			path[nx][ny][nd] = (nc), (nk)
			if nc == c:
				q.appendleft((nx, ny, nd, nc, nk))
			else:
				q.append((nx, ny, nd, nc, nk))
				
# コストの算出
ans = INF
for d in range(4):
	ans = min(ans, path[x2][y2][d][0])
ans = -1 if ans == INF else ans

print(ans)


Measured memory_bytes: 399668
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i64,
        b: i64,
        k: i64,
    }
    for (i, x) in (a..b+1).enumerate() {
        let i = i as i64;
        if i < k {
            println!("{}", x);
            continue;
        }
        if i > b - a - k {
            println!("{}", x);
        }
    }
}


Measured memory_bytes: 4352
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
prev = -10
for one in A:
    ans+=B[one-1]
    if one==prev+1:
        ans+=C[prev-1]
    prev = one
print(ans)

Measured memory_bytes: 38256
#!/usr/bin/env python
# coding: utf-8

import fractions

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    la = rli()
    checkpoints = [0]
    cur = la[0]
    for i in range(1, n):
        if la[i] >= cur:
            cur = la[i]
            continue
        if la[i] + cur*2 >= cur:
            cur = la[i] + cur*2
            continue
        checkpoints.append(i)
        cur = la[i]
    # print(checkpoints)
    ll = checkpoints[-1]
    op = []
    for c in checkpoints[::-1]:
        if c > ll:
            continue
        l = c
        cur = la[l]
        while l > 0:
            if la[l-1] <= cur:
                break
            op.append((l, l-1))
            op.append((l, l-1))
            cur = la[l-1] + cur * 2
            l -= 1
        ll = l-1
    cur = la[checkpoints[-1]]
    for i in range(checkpoints[-1], n-1):
        if la[i+1] >= cur:
            cur  = la[i+1]
        else:
            op.append((i, i+1))
            op.append((i, i+1))
            cur = la[i+1]+cur*2
    print(len(op))
    for o in op:
        print(o[0]+1, o[1]+1)



if __name__ == '__main__':
    main()


Measured memory_bytes: 5204
n=int(input())
s_rev=""
while n!=0:
    #s_rev+=str(-(n%(-2)))
    #n=-(n//(-2))
    s_rev+=str(n%2)
    n=n//(-2)+n%2
    #print(n)
s=""
for i in range(len(s_rev)):
    s+=s_rev[len(s_rev)-i-1]
if s=="":
    print("0")
else:
    print(s)


Measured memory_bytes: 3316
// Ref. Official editorial

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

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

ll N, A;

template <typename T>
T expt(T a, T n, T mod = std::numeric_limits<T>::max()){
    T res = 1;
    while(n){
        if(a >= N){return N;}
        if(n & 1){res = res * a % mod;}
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

    std::cin >> N >> A;

    assert((1ll << 50) > expt(10, 12));
    ll res = numeric_limits<ll>::max();
    for(int i=0;i<=50;++i){
        ll lb = expt(10ll, 12ll), ub = 0;
        
        while(std::abs(ub - lb) > 1){
            ll mid = (lb + ub) / 2; 
            
            if(expt((int128_t)mid, (int128_t)(i+1)) >= N){
                lb = mid;
            }else{
                ub = mid;
            }
        }
        // std::cout << lb << std::endl;

        // j: lb-1, i+1-j: lb
        for(int j=0;j<=i+1;++j){
            if(expt((int128_t)lb, (int128_t)(i+1-j)) * expt((int128_t)(lb-1), (int128_t)j) >= N){
                // std::cout << i << ", " << j << std::endl;
                res = min(res, A * i + (lb - 1) * j + lb * (i + 1 - j));
            }
        }
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

vector<string> seq;

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>S;
    cin>>k;

    n = strlen(S);

    string cur;

    for(int i=0;i<n;i++){
        cur.clear();
        for(int j=i;j<min(i+k,n);j++){
            cur = cur+S[j];
            seq.push_back(cur);
        }
    }

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

    seq.erase(unique(seq.begin(),seq.end()),seq.end());

    cout<<seq[k-1]<<"\n";

    return 0;
}


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

int main(){
    ll H, W;
    cin >> H >> W;
    vector<string> a(H);
    vector<bool> valH(H, false), valW(W, false);
    rep(h, 0, H) cin >> a[h];
    rep(h, 0, H){
        bool f = false;
        rep(w, 0, W){
            if(a[h][w] == '#') f = true;
        }
        if(f) valH[h] = true;
    }
    rep(w, 0, W){
        bool f = false;
        rep(h, 0, H){
            if(a[h][w] == '#') f = true;
        }
        if(f) valW[w] = true;
    }
    rep(h, 0, H){
        if(!valH[h]) continue;
        rep(w, 0, W){
            if(!valW[w]) continue;
            cout << a[h][w];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from collections import deque
s=input()
q=int(input())
#反転操作はまとめてする
#2の操作が入れ替わるだけ
check=True
d=deque(list(s))
for i in range(q):
    x=input().split()
    if len(x)==1:
        check=(not check)
    else:
        t,f,c=x
        f=int(f)
        if check:
            if f==1:
                d.appendleft(c)
                #s=c+s
            else:
                d.append(c)
                #s=s+c
        else:
            if f==2:
                d.appendleft(c)
                #s=c+s
            else:
                d.append(c)
                #s=s+c

if check:
    print("".join(list(d)))
else:
    print("".join(list(d)[::-1]))

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

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

ll n;

const int maxn = 105;

vector<int> f(ll X){
    if(X == 1){
        return vector<int>(0);
    }
    if(X & 1){
        vector<int> b = f(X - 1);
        vector<int> a(0);
        a.push_back(b.size() + 1);
        for(auto v : b){
            a.push_back(v);
        }
        return a;
    }else{
        vector<int> b = f(X / 2);
        b.push_back(b.size() + 1);
        return b;
    }
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    vector<int> a = f(n + 1);
    cout << a.size() * 2 << endl;
    for(int i = 0;i < (int)a.size();i++){
        cout << a[i] << " ";
    }
    for(int i = 0;i < (int)a.size();i++){
        cout << i + 1 << " ";
        //cout << i + 1 << (i == a.size() - 1 ? '\n' : ' ');
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
struct points {
	double x;
	double y;
};
int main(void) {
	
	
	struct points eigenvector;
	int p1x, p1y, p2x, p2y, px, py; 
	double length;
	int q;
	int i;
		scanf("%d%d%d%d",&p1x,&p1y,&p2x,&p2y);
		struct points p1, p2;
		p1.x = p1x;
		p1.y = p1y;
		
		p2.x = p2x;
		p2.y = p2y;
	 length = sqrt((p1.x - p2.x)*(p1.x - p2.x)+ (p1.y - p2.y)*(p1.y - p2.y));
		eigenvector.x = (p2.x - p1.x) / length;
		eigenvector.y = (p2.y - p1.y) / length;
		
		scanf("%d",&q);
		
		for ( i = 0; i < q; ++i) {
			scanf("%d%d", &px, &py);
			//double  returnqx, returnqy;
			double length1 = (px - p1.x)*eigenvector.x + (py - p1.y)*eigenvector.y;
			printf("%.10f %.10f\n", p1.x+ length1*eigenvector.x, p1.y + length1*eigenvector.y);

		}

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<bitset>
#include<random>
#include<time.h>

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code

int main()
{
  int a, b, v, d;
  cin>>a>>b>>v>>d;
  int l = a+b;
  int r = v+d;
  if(l < r) puts("Right");
  else if(l > r) puts("Left");
  else puts("Balanced");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int A, B; cin >> A >> B;
    cout << max({A + B, A - B, A * B}) << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int T = sc.nextInt();
		long total = 0;
		int t = sc.nextInt();
		int tmp=0;
		int tmp2;
		for(int i = 1;i<N;i++){
			tmp2=sc.nextInt();
			if(T>tmp2-tmp){
				total += tmp2-tmp;
			}
			else{
				total +=T;
			}
			tmp=tmp2;
		}
		if(N==1){
			total=T;
		}
		else{
			total +=T;
		}

		System.out.println(total);
	}


}


Measured memory_bytes: 61388