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

#define fastio {\
    ios::sync_with_stdio(0);\
    cin.tie(0);\
}

#define file {\
    freopen("io\\in.txt", "r", stdin);\
    freopen("io\\out.txt", "w", stdout);\
    freopen("io\\err.txt", "w", stderr);\
}

#ifdef LOCAL
#define debug(args...) {\
    string _s(#args);\
    replace(_s.begin(), _s.end(), ',', ' ');\
    stringstream _ss(_s);\
    istream_iterator<string> _it(_ss);\
    debug1(_it, args);\
}

#pragma GCC diagnostic ignored "-Wunused-parameter"
void debug1(istream_iterator<string> it) {
    cerr << endl;
}
#pragma GCC diagnostic pop

template<class T, class... Args>
void debug1(istream_iterator<string> it, T a, Args... args) {
    cerr << '>' << *it << " = " << a << "; ";
    debug1(++it, args...);
}
#else
#define debug(args...)
#define cerr if (false) cerr
#endif

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, n)   for (int i = 0; i < n; i++)
#define dotc()      int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)       (int)x.size()
#define eb          emplace_back
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define all(x)      x.begin(), x.end()
#define rall(x)     x.rbegin(), x.rend()
#define fi          first
#define se          second

const int inf(0x3fffffff);
const int mod(1000000007);
const double pi(acos(-1.0));

signed main() {
    fastio;
#ifdef LOCAL
    file;
#endif

    string st;
    cin >> st;
    deque<char> s(all(st));
    bool t = false;
    int q;
    cin >> q;
    while (q--) {
        int x;
        cin >> x;
        if (x == 1) t ^= 1;
        else {
            int i;
            char j;
            cin >> i >> j;
            i--;
            if ((t ^ i) == 0) s.push_front(j);
            else s.pb(j);
        }
    }

    cout << (t ? string(rall(s)) : string(all(s)));

    return 0;
}


Measured memory_bytes: 4044
b = int(input())

a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(a[b-1])


Measured memory_bytes: 38384
use proconio::input;
use proconio::fastout;

#[fastout]
fn main(){

    input!{
        n: i32,
        x: i32,
        t: i32,
    }

    let ans = if n%x == 0 {
       n/x * t
    }else{
         (n / x + 1) * t 
    };

    println!("{}",ans);


}

Measured memory_bytes: 2172
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
    // 頂点数と辺数
    int N, M; cin >> N >> M;

    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    // BFS のためのデータ構造
    vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;
    vector<int> ans(N, 0);

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(0); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.push(nv);
            ans[nv] = v+1;
        }
    }

    // 結果出力 (各頂点の頂点 0 からの距離を見る)
    for (int v = 1; v < N; ++v){
      if(ans[v] == 0){
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
    for (int v = 1; v < N; ++v) cout << ans[v] << endl;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    double r;
    cin >> r;
    cout << setprecision(10) << 2 * r * M_PI << endl;
    return 0;
}

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

const ll SIZE = 100001;
ll dp[SIZE];

int main() {
    ll H, N;
    cin >> H >> N;
    vector<ll> A(N), B(N);

    for(ll i = 0; i < N; i++){
        cin >> A[i] >> B[i];
    }

    dp[0] = 0;
    for(ll i = 1; i <= H; i++){
        dp[i] = 100000000;
    }

    for(ll i = 0; i < N; i++){
        ll a = A[i], b = B[i];
        for(ll j = 0; j < H; j++){
            ll next_j = j + a;
            next_j = min(next_j, H);
            dp[next_j] = min(dp[next_j], dp[j] + b);
        }
    }

    cout << dp[H] << endl;
}

Measured memory_bytes: 384
/*input
10 2
8 5
10 8
6 5
1 5
4 8
2 10
3 6
9 2
1 7
*/
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll INF64=4e18;
const int INF=1e6+1;
 ll MOD=1e9+7;
const ld PI=2*acos(0);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
int add(int a,int b){
    return (a+b)%MOD;
}
int mult(int a,int b){
    return (ll)a*b%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}

// default code end
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
vector<int> v[maxn],pref[maxn],suff[maxn];
vector<int> child[maxn],val[maxn];
int down[maxn],up[maxn];
void dfs(int u,int par){
    down[u]=0;
    for(auto x:v[u]){
        if(x!=par){
            dfs(x,u);
            child[u].pb(x);
            down[u]=add(down[u],mult((1+down[u]),down[x]));
            val[u].pb(down[x]);
        }
    }
    down[u]++;
    down[u]%=MOD;
}
void dfs2(int u){
    REP(i,sz(child[u])){
        int x=child[u][i];
        int cur=0;
        if(i!=0){
            cur=add(cur,mult(1+cur,pref[u][i-1]));
        }
        if(i!=sz(child[u])-1){
            cur=add(cur,mult(1+cur,suff[u][i+1]));
        }
        if(u) cur=add(cur,mult(1+cur,up[u]));
        up[x]=(cur+1)%MOD;
        dfs2(x);
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n>>MOD;
    REP(i,n-1){
        int a,b;
        cin>>a>>b;
        --a;
        --b;
        v[a].pb(b);
        v[b].pb(a);
    }
    dfs(0,-1);
    REP(i,n){
        int cur=0;
        REP(j,sz(val[i])){
            cur=add(cur,mult(1+cur,val[i][j]));
            pref[i].pb(cur);
        }
        cur=0;
        for(int j=sz(val[i])-1;j>=0;j--){
            cur=add(cur,mult(1+cur,val[i][j]));
            suff[i].pb(cur);            
        }
        reverse(ALL(suff[i]));
    }
    dfs2(0);
    REP(i,n){
        int cur=0;
        if(i) cur=add(cur,mult(1+cur,up[i]));

        if(sz(child[i])){
            cur=add(cur,mult(1+cur,pref[i].back()));
        }
        cout<<(cur+1)%MOD<<'\n';
    }
}

Measured memory_bytes: 34560
import sys
input = sys.stdin.readline

a, b = map(int, input().split())
if a <= 0:
    if b >= 0:
        ans = 'Zero'
    elif b < 0 and (b-a)%2 == 0:
        ans = 'Negative'
    else:
        ans = 'Positive'
else:
    ans = 'Positive'
print(ans)

Measured memory_bytes: 2940
n , m = map(int , input().split())
ans = []
total = 0
for i in range(n):
  a = list(map(int , input().split()))
  ans.append(a)
ans = sorted(ans, key=lambda x:x[0])
j = 0
while m > 0:
  small = min(ans[j][1] , m)
  total += ans[j][0] * small
  m -= small
  j += 1
print(total)

Measured memory_bytes: 29788
#import sys
#sys.setrecursionlimit(1000000000)

from collections import deque

def main():
    k = int(input())
    lst = []
    bfs("",k,lst)
    print(lst[k-1])


def bfs(s,k,lst=[]):
    d = deque()
    for c in "0123456789":
        d.append(c)
    while d:
        if len(lst) > k:
            return
        now = d.popleft()
        if now=="0":
            continue
        lst.append(now)
        for nxt in [int(now[-1])-1,int(now[-1]),int(now[-1])+1]:
            if nxt < 0 or nxt > 9:
                continue
            d.append(now+str(nxt))



if __name__ == '__main__':
    main()


Measured memory_bytes: 24044
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

ll A, B, C, K;

int main() {
    cin >> A >> B >> C >> K;
    ll x = A - B;
    if (abs(x) >= 1000000000000000000LL) {
        cout << "Unfair" << endl;
        return 0;
    }
    if (K % 2 == 1) x *= -1;
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String t = sc.next();
    char[] s_array = s.toCharArray();
    char[] t_array = t.toCharArray();
    Arrays.sort(s_array);
    Arrays.sort(t_array);
    t = reverse_array(t_array);
    t_array = t.toCharArray();
    int s_len = s_array.length;
    int t_len = t_array.length;
    boolean judge = true;
    if(s_len < t_len) {
      for(int i = 0; i < s_len; i++) {
        if(s_array[i] > t_array[i]) {
          judge = false;
          break;
        } else if(s_array[i] < t_array[i]) {
          judge = true;
          break;
        }
      }
    } else {
      for(int i = 0; i < t_len; i++) {
        if(s_array[i] > t_array[i]) {
          judge = false;
          break;
        } else if(s_array[i] < t_array[i]) {
          judge = true;
          break;
        } else {
          judge = false;
        }
      }
    }
    if(judge == true) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }

  public static String reverse_array(char[] array) {
    int len = array.length;
    char[] new_array = new char[len];
    int count = len - 1;
    for(int i = 0; i < len; i++) {
      new_array[i] = array[count];
      count--;
    }
    String s = String.valueOf(new_array);
    return s;
  }
}


Measured memory_bytes: 23764
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    static int[] w = new int[100010];
    static int[] v = new int[100010];
    static int[][] dp = new int[110][100010];
    static int k;

    static int chmin(int a, int b) {
        if (a > b) {
            a = b;
            return a;
        }
        return a;
    }

    static int chmax(int a, int b) {
        if (a < b) {
            a = b;
            return a;
        }
        return a;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        
        if (n > 8 || k > 8) {
            System.out.println(":(");
        } else {
            System.out.println("Yay!");
        }
    }
}


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

using namespace std;

const int SIZE = 1e5 + 10;
vector<int> adj[SIZE];
vector<int> par(SIZE);

const long long mod = 1e9 + 7;

inline long long multiply(long long a, long long b) {
	return ((a % mod) * (b % mod)) % mod;
}

void bfs(int s) {
	vector<bool> vis(SIZE);
	queue<int> q;
	q.push(s);
	vis[s] = true;
	while(!q.empty()) {
		s = q.front();
		q.pop();
		for(auto i : adj[s]) {
			if(!vis[i]) {
				par[i] = s;
				vis[i] = true;
				q.push(i);
			}
		}
	}
}

int main() { 

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

	int n;
	long long k;
	
	cin >> n >> k;

	int u, v;

	for(int i = 1; i < n; i++) {
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	bfs(1);

	vector<long long> val(n + 1);

	vector<int> child[n + 1];

	for(int i = 2; i <= n; i++) {
		child[par[i]].push_back(i);
	}
	val[1] = k;
	long long x = k - 1;
	for(auto j : child[1]) {
		val[j] = x--;
	}

	for(int i = 2; i <= n; i++) {
		x = k - 2;
		for(auto j : child[i]) {
			val[j] = x--;
		}
	}
	long long ans = 1;
	for(int i = 1; i <= n; i++) {
		ans = multiply(ans, val[i]);
	}
	cout << ans;

	return 0; 
}

Measured memory_bytes: 12416
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<vector<double> > vvd;
typedef vector<double> vd;

#define debugone(x) cerr << #x << " " << x << "\n"; cerr.flush();
#define debugtwo(x) cerr << #x << "-------------" << "\n";for(auto &it: x) cerr << it << " ";cerr << "\n"; cerr.flush();
#define debugthree(x_, i_, j_) cerr << #x_ << "------------" << "\n";cerr << "from " << i_ << " to " << j_ << "\n";for(ll k_=i_; k_<=j_; k_++) cerr << x_[k_] << " ";cerr << "\n"; cerr.flush();
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#define all(x) x.begin(), x.end()
#define INF 1000000009
#define MOD 1000000007

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

	int n, k;
	cin >> k >> n;
	vi a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vi dist(n);
	for (int i = 0; i < n - 1; i++) {
		dist[i] = a[i + 1] - a[i];
	}
	dist[n - 1] = k - a[n - 1] + a[0];
	sort(all(dist));
	cout << k - dist.back() << endl; 
}

Measured memory_bytes: 1792
//Two Abbreviations

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<ll,string> p;
using g = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n,m;cin>>n>>m;
    string s,t;cin>>s>>t;
    map<int,char>q{};
    int g = lcm(n,m);
    rep(i,0,n)q[(g/n)*i]=s[i];
    rep(i,0,m){
        if('a'<=q[(g/m)*i]&&'z'>=q[(g/m)*i]&&q[(g/m)*i]!=t[i]){
            cout<<-1<<nnn;
            return 0;
        }
    }        
    cout<<g<<nnn;
    return 0;
}

Measured memory_bytes: 10880
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
 
fn main() {
    input! {
        n: usize,
        p: [i64; n],
    }
 
    let mut p = p;
    p.sort();
    p.reverse();
 
    p[0] /= 2;
 
    let ans = p.iter().sum::<i64>();
 
    println!("{}", ans);
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define vec(type) vector<type>

int main() {
	int n;
	string a, b, c;
	cin >> n >> a >> b >> c;

	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (a[i]==b[i] && b[i]==c[i] && c[i]==a[i]) continue;
		else if (a[i]==b[i] || b[i]==c[i] || c[i]==a[i]) ans++;
		else ans += 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3624
//#include<bits/stdc++.h>
#include"bits/stdc++.h"
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n; cin >> n;
  vector<int> q(n),x(n);
  for(int i = 0; i < n; i++){
    cin >> q[i] >> x[i];
  }
  reverse(q.begin(),q.end());
  reverse(x.begin(),x.end());

  int a = 0,b = 1;
  for(int i = 0; i < n; i++){
    if(q[i] == 1){
      b *= x[i];
    }
    else {
      if(q[i] == 2) a -= x[i] * b;
      else a += x[i] * b;
    }
  }
  cout << a << " " << b << endl;

  return 0;
}



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

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

int main(){
  int N;
  cin>>N;
  int ans=0;
  if(N%2==0)
    N=N-1;
  rep(i,N){
    int count=0;
    for(int j=1;j<i+1;j++){
      if(i%j==0)
	count++;
    }
    if(count==8)
      ans++;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define llint long long

using namespace std;

llint N, K;
llint a[5005];
bool dp[5005][5005];

bool check(llint m)
{
	if(m > N) return true;
	if(m <= 0) return false;
	
	for(llint i = 0; i <= N; i++){
		for(llint j = 0; j < K; j++){
			dp[i][j] = false;
		}
	}
	dp[0][0] = true;
	
	for(llint i = 1; i <= N; i++){
		for(llint j = 0; j < K; j++){
			dp[i][j] = dp[i-1][j];
			if(i == m) continue;
			if(j - a[i] >= 0 && dp[i-1][j-a[i]]) dp[i][j] = true;
		}
	}
	
	for(llint i = max(0LL, K - a[m]); i < K; i++){
		if(dp[N][i]) return true;
	}
	return false;
}

int main(void)
{
	cin >> N >> K;
	for(llint i = 1; i <= N; i++) cin >> a[i];
	sort(a+1, a+N+1);
	
	llint ub = N+1, lb = 0, mid;
	while(ub - lb > 1){
		mid = (ub + lb) / 2;
		if(check(mid)) ub = mid;
		else lb = mid;
	}
	
	cout << lb << endl;
	return 0;
}

Measured memory_bytes: 24704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

vector<pair<ll, ll>> factorize(ll n) {
    vector<pair<ll, ll>> res;
    for (ll i = 2; (i * i) <= n; i++) {
        if (n % i) continue;
        res.emplace_back(i, 0);
        while((n % i) == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1);
    return res;
}

struct BinomialCoefficient  {
    BinomialCoefficient() {
        
    }
    
    BinomialCoefficient(int n) : fac(n + 2), finv(n + 2), inv(n + 2) {
        initialize(n, false);
    }
    
    void initialize(int n, bool resize = true) {
        if (resize) {
            fac.resize(n + 2);
            finv.resize(n + 2);
            inv.resize(n + 2);
        }
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i <= n; i++) {
            fac[i] = fac[i - 1] * i % mod;
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }
    
    ll factorial(int n) {
        return fac[n];
    }
    
    ll combination(int n, int r) {
        if ((n < r) || (n < 0) || (r < 0)) return 0;
        return fac[n] * (finv[r] * finv[n - r] % mod) % mod;
    }
    
    ll permutation(int n, int r) {
        if ((n < r) || (n < 0) || (r < 0)) return 0;
        return fac[n] * finv[n - r] % mod;
    }
    
private:
    int mod = 1e9 + 7;
    vector<ll> fac, finv, inv;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    const ll mod = 1e9 + 7;
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> fac = factorize(m);
    ll ans = 1, cnt = 0;
    rep(i, sz(fac)) cnt = max(cnt, fac[i].second);
    BinomialCoefficient bc(n + cnt);
    rep(i, sz(fac)) {
        ans = (ans * bc.combination(n + fac[i].second - 1, fac[i].second)) % mod;
    }
    cout << ans << endl;
    return 0;
}


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

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

#define forn(i, a, n) for (int i = a; i < n; ++i)
#define ford(i, a, n) for (int i = n - 1; i >= a; --i)
#define fore(i, a, n) for (int i = a; i <= n; ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    forn(i, 0, n) cin >> a[i];
    vector<ll> pos(n), neg(n);
    forn(i, 0, n) {
        if (i) {
            pos[i] = pos[i - 1];
            neg[i] = neg[i - 1];
        }
        (a[i] >= 0 ? pos : neg)[i] += a[i];
    }
    ll ans = 0;
    for (int i = 0; i + k <= n; ++i) {
        ll x1 = i ? pos[i - 1] : 0;
        ll x2 = pos[n - 1] - pos[i + k - 1];
        ll x3 = pos[i + k - 1] + neg[i + k - 1] - (i ? pos[i - 1] + neg[i - 1] : 0);
        if (x3 < 0) x3 = 0;
        ans = max(ans, x1 + x2 + x3);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 2304
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

int main(void){
  int now;
  double num[100];
  int i,j,k;
  char str[100],c;
  
  now=0;
  while(scanf("%s%c",str,&c)>0){
    if(strlen(str)!=1 || isdigit(str[0])){
      num[now++]=(double)strtol(str,NULL,10);
    }else{
      now--;
      switch(str[0]){
        case '+':
          num[now-1]+=num[now];
          break;
        case '-':
          num[now-1]-=num[now];
          break;
        case '*':
          num[now-1]*=num[now];
          break;
        case '/':
          num[now-1]/=num[now];
          break;
      }
    }
    if(c=='\n'){
      printf("%f\n",num[0]);
      memset(num,0,sizeof(num));
      now=0;
    }
  }
  return 0;
}

Measured memory_bytes: 592
# d = [[0]*3] * 3

a = [[i for i in map(int, input().split())] for j in range(3)]
n = int(input())

# a = [[66, 85, 92], [56, 37, 86], [7, 52, 23]]
# n = 9
# B = [30, 85, 52, 48,89, 92, 26, 5, 67]

d = [[0] * 3 for i in range(3)]
for i  in range(n):
    b = int(input())
    # b = B[i]
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                d[j][k] = 1
# if ans[0][0] + ans[0][1] + ans[0][2] == 3 or ans[1][0] + ans[1][1] + ans[1][2] == 3 or ans[2][0] + ans[2][1] + ans[2][2] == 3 or ans[0][0] + ans[1][0] + ans[2][0] == 3 or ans[0][1] + ans[1][1] + ans[2][1] == 3 or ans[0][2] + ans[1][2] + ans[2][2] == 3 or ans[0][0] + ans[1][1] + ans[2][2] == 3 or ans[0][2] + ans[1][1] + ans[2][0] == 3:
flag = False
for i in range(3):
    cnt = 0
    for j in range(3):
        cnt += d[i][j]
    if cnt == 3:
        flag = True

for i in range(3):
    cnt = 0
    for j in range(3):
        cnt += d[j][i]
    if cnt == 3:
        flag = True

cnt = 0
for i in range(3):
    cnt += d[i][i]
    if cnt == 3:
        flag = True

cnt = 0
for i in range(3):
    cnt += d[i][2-i]
    if cnt == 3:
        flag = True
print("Yes") if flag == True else print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<string> S(N);
	for (auto& x : S) cin >> x;
	vector<int> b(26, 1<<30);
	for (auto x : S) {
		vector<int> a(26);
		for (auto c : x) ++ a[c-'a'];
		for (int i = 0; i < 26; ++ i) b[i] = min(b[i], a[i]);
	}
	string r;
	for (int i = 0; i < 26; ++ i) {
		for (int j = 0; j < b[i]; ++ j) r += 'a' + i;
	}
	cout << r << endl;
}


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

int main(){
  int h, w, white = 0;  cin >> h >> w;
  char s[55][55];
  for(int i=1; i<=h; i++)
    for(int j=1; j<=w; j++){
      cin >> s[i][j];
      if(s[i][j] == '.')  white++;
    }
  
  int cost[55][55] = {0}, d[] = {1, 0, -1, 0, 1};
  cost[1][1] = 1;
  queue<pair<int, int>> que;
  que.push({1, 1});
  while(!que.empty()){
    int nowh = que.front().first, noww = que.front().second;
    que.pop();
    for(int i=0; i<4; i++){
      int nexh = nowh + d[i], nexw = noww + d[i+1];
      if(s[nexh][nexw]=='.' && !cost[nexh][nexw]){
	que.push({nexh, nexw});
	cost[nexh][nexw] = cost[nowh][noww] + 1;
      }
    }
  }

  int ans =  white - cost[h][w];
  if(!cost[h][w])  ans = -1;

  cout << ans << endl;

  return 0;
}


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

int main() {
  string n;
  cin >> n;
  rep(i, 3) {
    if(n[i] == '9') n[i] = '1';
    else if(n[i] == '1') n[i] = '9';
  }
  rep(i, 3) cout << n[i];
  cout << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

int main() {
    string s;
    cin >> s;
    int l=s.length();
    int ans=0;
    for(int i=0;i<l;++i) {
        int sum=0;
        while(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T') {
            ++sum;
            ++i;
        }
        ans=max(ans, sum);
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
 
int main()
{
	int N;
	std::cin >> N;
	std::string C;
	std::cin >> C;
 
	int r = std::count(C.begin(), C.end(), 'R');
 
	int ans = 0;
	for (int i = 0; i < r; i++)
		if (C[i] == 'W')
			ans++;
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include <algorithm>

#define Range(x, y, w, h) ((0<=x)&&(x<w)&&(0<=y)&&(y<h))

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

int map_size;

int kiten_size;
int kiten_n[30];
int kiten_x[30];
int kiten_y[30];
int kiten_pnt;

bool result;

using namespace std;

void search(int map[][width], int mx, int my, int cnt) {
	for(int dd=0; dd < 4 && !result; dd++) {
		int nx = mx + dx[dd];
		int ny = my + dy[dd];
		if(Range(nx, ny, map_size, map_size) && (map[ny][nx] != 0)){
			int tmp = map[ny][nx];
			if((tmp+cnt) == kiten_n[kiten_pnt]) {
				map[ny][nx] = 0;
				if(++kiten_pnt >= kiten_size) {
					result = true;
					map[ny][nx] = tmp;
					return;
				}
				else {
					search(map, kiten_x[kiten_pnt], kiten_y[kiten_pnt], 0);
					kiten_pnt--;
					map[ny][nx] = tmp;
				}
			}
			else if((tmp+cnt) < kiten_n[kiten_pnt]){
				map[ny][nx] = 0;
				search(map, nx, ny, (tmp+cnt));
				map[ny][nx] = tmp;
			}
		}
	}
}

int main(void)
{
	int n;
	int sum;
	int map[height][width];
	int tmp;

	while(cin >> n, n) // input n
	{
		sum = kiten_size = 0;
		for(int y=0; y < n; y++) for(int x=0; x < n; x++) {
			cin >> tmp; map[y][x] = tmp; // input map[y][x]
			sum += tmp;
			if(tmp < 0) { // check point
				kiten_n[kiten_size] = -tmp;
				kiten_x[kiten_size] = x;
				kiten_y[kiten_size++] = y;
				map[y][x] = 0;
			}
		}
		if(sum) { // not zero
			printf("NO\n");
			continue;
		}
		map_size = n; kiten_pnt = 0; result = false;
		search(map, kiten_x[kiten_pnt], kiten_y[kiten_pnt], 0);
		if(result)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 0
def main():
    N = int(input())
    *A, = map(int, input().split())

    ans = f(N, A)
    print(ans)


try:
    # 最大公約数: greatest common divisor
    # py3.5+
    from math import gcd
except ImportError:
    from fractions import gcd


def f(N, A):
    """
    はじめ、モンスター iの体力は Ai
    以降、体力が1以上のモンスターを生きているモンスターと呼びます。
    生きているモンスターが 1体になるまで以下を繰り返します。

    ランダムに 1体の生きているモンスターがランダムに別の生きているモンスターに攻撃します。
    その結果、攻撃されたモンスターの体力を攻撃したモンスターの体力と同じ値だけ減らします。

    最後に生き残ったモンスターの最終的な体力の最小値を求めてください。

    成約
        入力は全て整数である。
        2 ≤ N  ≤ 10^5
        1 ≤ Ai ≤ 10^9

    どれだけ体力を減らせるか
    1のモンスターがいたら1
    一番少ない体力のモンスターが最低限の体力
    その体力で他のモンスターを攻撃し続けると Amax % Amin が最小になる
        ただし0になったらだめ
    多いモンスターは他に攻撃してもらう

    なんとなく最小公倍数・最大公約数が浮かんだ
    他のモンスターの体力で割り切れてしまうなら
        約数なら、他のモンスターが最小
        6と3
        6と4なら2残る
        9と2なら1残る
    """
    ans = A[0]
    for a in A[1:]:
        ans = gcd(ans, a)

    return ans


if __name__ == '__main__':
    main()


Measured memory_bytes: 16240
n, m, x = [int(v) for v in input().split()]

c = [0] * n
a = [[] * m for i in range(n)]
for i in range(n):
    line = [int(v) for v in input().split()]
    c[i] = line[0]
    a[i] = line[1:]

ans = sum(c)
can = False
for i in range(1, 2 ** n):
    sumv = [0] * m
    sumc = 0
    for j in range(n):
        has_bought = i & 1
        if has_bought:
            sumc += c[j]
            for k in range(m):
                sumv[k] += a[j][k]
        i = i >> 1
    can = True
    for k in range(m):
        if sumv[k] < x:
            can = False
            break
    if can:
        ans = min(ans, sumc)

if can:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 9248
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat

int main(int argc, char const *argv[])
{
	sync;
	string a, b;
	cin >> a ;
	if(a.compare("ABC")==0){
		cout << "ARC" << endl;
	}else
	{
		cout << "ABC" << endl;
	}
	return 0;
}


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

int main(){
   int k;
   string str,ans;
   cin>>k>>str;
   if(str.size()<=k) cout<<str;
   else{
      for(int i=0;i<k;i++)
         ans.push_back(str[i]);
      ans+="...";
      cout<<ans;
   }
}


Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <utility>
#include <unordered_map>
#include <numeric>
using namespace std;
#define fol(i,n) for (int i=0;i<n;i++)
int main(){
    string N,M;
    cin >>N;
    fol(i,N.size()){
        if (N[i]=='0') M +='0';
        else if (N[i]=='1') M +='1';
        else  if (M.size())M.pop_back();
    }
    cout << M<<endl;
}

Measured memory_bytes: 256
//#pragma GCC optimize ('O3')
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 3e5 + 5;
const int M = 5e5 + 5;
const int OO = 1e9;
const int mod = 1e9 + 7;

int t,n,a[N],freq[N],cum[N];

void init() {



}

bool f(int m, int k) {
    if(m==n) return 0;
    return cum[m]/(m-n+k) >= freq[m+1];
}

int main() {

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

    cin >> n;

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

    sort(freq+1, freq+1+n);

    for (int i = 1; i <= n; ++i) {
        cum[i] = cum[i-1] + freq[i];
    }

    for (int k = 1; k <= n; ++k) {

        int s = n-k+1, e = n;

        while (s<e) {

            int m = (s+e)/2;

            if(f(m, k)) {
                s = m + 1;
            } else {
                e = m;
            }

        }

        cout << cum[e]/(e-(n-k)) << '\n';

    }

    return 0;
}

Measured memory_bytes: 7136
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 60;

template<typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

double dp[3010][3010];

int main() {
  int n; cin>>n;
  dp[0][0] = 1;
  rep(i, n) {
    double p; cin>>p;
    rep(j, 3010) {
      dp[i+1][j] += dp[i][j] * (1-p);
      dp[i+1][j+1] += dp[i][j] * p;
    }
  }
  double ans = 0;
  rep(i, 3010) if (i >= (float)n/2) ans += dp[n][i];
  cout << setprecision(15);
  print(ans);
  return 0;
}


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

int main(){
    vector <int> so(50,1);
    int k;
    so[0]=0;
    so[1]=0;
    rep(i,25){
        k=2;
        if(so[i+2]==1){
        while(k*(i+2)<49){
            so[k*(i+2)]=0;
            ++k;
        }
        }
    }

    int n,s;
    cin >> n;
    vector <int> nn(50,0);
    rep(i,n){
        k=2;
        s=i+1;
        while(s!=1){
            while(s%k==0){
                s/=k;;
                ++nn[k];
            }
            ++k;
        }
    }

    

    int y2=0,y4=0,y14=0,y24=0,y74=0;
    rep(i,50){
        if(nn[i]>=2){
            ++y2;
        }
        if(nn[i]>=4){
            ++y4;
        }
        if(nn[i]>=14){
            ++y14;
        }
        if(nn[i]>=24){
            ++y24;
        }
        if(nn[i]>=74){
            ++y74;
        }
        //cout << i << " " << nn[i] << endl;
    }

    ll ans=0;
    ans+=y24*(y2-1);
    ans+=y14*(y4-1);
    ans+=(y4*(y4-1)/2)*(y2-2);
    ans+=y74;

    cout << ans << endl;
    

    

    return 0;
}

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

public class Main {

  static class Restaurant implements Comparable<Restaurant> {
    public int id;
    public String city;
    public int rating;

    public Restaurant(int id, String city, int rating) {
      this.id = id;
      this.city = city;
      this.rating = rating;
    }

    @Override
    public int compareTo(Restaurant r) {
      if (city.equals(r.city)) {
        if (rating == r.rating)
          return 0;
        else if (rating < r.rating)
          return 1;
        else
          return -1;
      }
      return city.compareTo(r.city);
    }
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();

    Restaurant[] rs = new Restaurant[n];

    for (int i = 0; i < n; ++i) {
      String s = sc.next();
      int p = sc.nextInt();
      rs[i] = new Restaurant(i + 1, s, p);
    }

    Arrays.sort(rs);

    for (Restaurant r : rs)
      System.out.println(r.id);
  }
}


Measured memory_bytes: 21844
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main() {
	int i,j,k,num,n,cards[4][13];
	char s;

	for ( i = 0; i < 4; i++){
		for ( j = 0; j < 13; j++){
			cards[i][j] = 0;
		}

	}

	scanf("%d\n", &n);
	for (i = 0; i <  n; i++) {
		scanf("%c %d\n", &s, &num);
		switch (s) {
		case 'S': j = 0; break;
		case 'H': j = 1; break;
		case 'C': j = 2; break;
		case 'D': j = 3; break;
		default:
			break;
		}
		cards[j][num - 1] = 1;
	}

	for (i = 0; i < 4; i++) {
		for (j = 0; j < 13; j++) {
			switch (i){
			case 0: s = 'S'; break;
			case 1: s = 'H'; break;
			case 2: s = 'C'; break;
			case 3: s = 'D'; break;
			default:
				break;
			}
			if (cards[i][j] == 0) {
				printf("%c %d\n", s, j + 1);
			}
				
		}
	}
}

Measured memory_bytes: 1860
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
typedef long long ll;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int n,m,id[N],st[N],top=0;
ll a[N],ans[N],k;
bool vis[N];
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) a[i]=gi(),id[i]=i;
    for(int i=n;i;i--) a[i]-=a[i-1];
    cin>>m>>k;
    for(int i=1,x;i<=m;i++) x=gi(),swap(id[x],id[x+1]);
    for(int i=1;i<=n;i++)
        if(!vis[i]) {
            top=0;
            for(int j=i;!vis[j];j=id[j]) st[++top]=j,vis[j]=1;
            for(int j=1;j<=top;j++) ans[st[j]]=a[st[(k+j-1)%top+1]];
        }
    for(int i=1;i<=n;i++) ans[i]+=ans[i-1],printf("%lld\n",ans[i]);
    return 0;
}
//orzgzy
//鸡贼明年进队超稳


Measured memory_bytes: 3712
#include <stdio.h>

int main()
{
	int no_a, no_b,no_c;
	scanf("%d %d %d", &no_a, &no_b,&no_c);
	if (no_a < no_b&&no_b<no_c)
		printf("Yes\n");
	else 
		printf("No\n");
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main(){
	int n, m; cin >> n >> m;
	set<pair<int, int> > s;
	string ans = "IMPOSSIBLE";

	REP(i, m){
		int a, b; cin >> a >> b;
		s.insert(make_pair(a, b));
	}

	FOR(i, 2, n){
		if( s.count(make_pair(1, i)) && s.count(make_pair(i, n)) ){
			ans = "POSSIBLE";
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 9600
from itertools import permutations

n = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

vec = [x for x in range(1,n+1)]
pmt = permutations(vec, n)
a = 0
b = 0
for i, v in enumerate(pmt):
    if list(v) == P:
        a = i + 1
    if list(v) == Q:
        b = i + 1

    if a > 0 and b > 0:
        break

print(abs(a - b))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
using ll = unsigned long long;
using namespace std;

int main(void) {
    int h,w;
    cin >> h >> w;
    vector<vector<char>> a(h, vector<char>(w));
    for(int hi = 0; hi < h ; ++hi) {
        for(int wi = 0; wi < w; ++wi) {
            cin >> a[hi][wi];
        }
    }

    // for(int hi = 0; hi < h ; ++hi) {
    //     for(int wi=0; wi < w; ++wi) {
    //         cout <<  a[hi][wi];
    //     }
    //     cout << endl;
    // }

    

    // solve

    vector<int> skiprows;

    for(int i = 0; i < h; ++i) {
        // if (accumulate(a[i].begin(), a[i].end(), 0) == 0) {
        bool skip = true;
        for(int wi = 0; wi < w; ++wi) {
            if (a[i][wi] != '.') {
                skip = false;
                break;
            }
        }
        if (skip) {
            skiprows.push_back(i);
        }
    }

    vector<int> skipcols;
    for(int i = 0; i < w; ++i) {

        bool skip = true;
        for(int j = 0; j < h; ++j){
            if (a[j][i] != '.') {
                skip = false;
                break;
            }
        }

        if (skip) {
            skipcols.push_back(i);
        }
    }

    // show
    for(int hi = 0; hi < h; ++hi) {
        if (find(skiprows.begin(), skiprows.end(), hi) != skiprows.end()) {
            continue;
        }

        bool need_lf = false;
        for(int wi = 0; wi < w;++wi) {
            if (find(skipcols.begin(), skipcols.end(), wi) != skipcols.end()) {
                continue;
            }

            cout << a[hi][wi];
            need_lf = true;
        }
        if (need_lf){
            cout << endl;
        }
    }

    return 0;
}

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

using namespace std;

typedef long long ll;

ll x;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> x;
    ll y = 100;
    ll ans = 0;
    while(y < x)
    {
        ans++;
        y += y / 100;
    }
    cout << ans << "\n";
    return 0;
}


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

int main(){
    string s;
    cin >>s;
    if(s=="Sunny") cout<<"Cloudy"<<endl;
    else if(s=="Cloudy") cout<<"Rainy"<<endl;
    else if(s=="Rainy") cout<<"Sunny"<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<stdlib.h>
#include<math.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef pair<int, char> pic;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int r, g, b, N;
int ans;

signed main(){
    cin >> r >> g >> b >> N;
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N; j++){
            int a = N - r * i - g * j;
            if(a >= 0){
                if(a % b == 0){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}
/*



*/


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

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    ll ab = a + b;
    ll q = n / ab;
    ll r = n % ab;
    cout << q * a + ((a < r) ? a : r) << endl;
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

struct seg {
	int l, r;
	bool operator< (const seg& b) const {
		return r < b.r;
	}

	seg operator* (const seg& b) const {
		return {max(l, b.l), min(r, b.r)};
	}

	int len() const {
		return max(0, r-l+1);
	}
};

int n;
seg a[100005];
seg suf[100005];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	cin >> n;
	for (int i=0; i<n; i++)
		cin >> a[i].l >> a[i].r;
	sort(a, a+n);

	sort(a+1, a+n, [](auto p, auto q) {
		return p.l < q.l;
	});

	suf[1] = a[n-1];
	for (int i=2; i<=n; i++)
		suf[i] = suf[i-1] * a[n-i];

	seg p = a[0];
	int sol = p.len() + suf[n-1].len();
	for (int i=1; i<n-1; i++) {
		p = p * a[i];
		sol = max(sol, p.len() + suf[n-1-i].len());
	}

	// najveci i presek svih ostalih?
	sort(a, a+n, [](auto p, auto q) {
		return p.len() > q.len();
	});

	p = a[1];
	for (int i=2; i<n; i++)
		p = p * a[i];

	sol = max(sol, a[0].len() + p.len());

	cout << sol << '\n';
}

Measured memory_bytes: 1792
#include<iostream>

using namespace std;

int main(){
    
    int n;
    int a;
    bool flag = false;

    cin >> n;
    cin >> a;

    if ((n % 500) <= a) {
        flag = true;
    }

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

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	// AtCoder Beginner Contest 136
	// https://atcoder.jp/contests/abc136/tasks
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if (b > a) { b = a; }
		if (c < (a - b)) {
			System.out.println("0");
		} else {
			System.out.println(c- (a -b));
		}
	}

	static class FastReader { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine()); 
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try{ 
                str = br.readLine(); 
            } catch (IOException e) { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}


Measured memory_bytes: 22612