akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main(){
    double t, x; cin >> t >> x;
    cout << fixed << setprecision(10) << t/x << endl;
}

Measured memory_bytes: 256
import sys
from collections import Counter
table = [Counter(), Counter()]
i = 0
for s in sys.stdin.readlines():
    s = s.rstrip()
    if not s:
        i+=1
        continue
    table[i][int(s.split(",")[0])] += 1
for n in sorted(set(table[0])&set(table[1])):
    print(n, table[0][n]+table[1][n])


Measured memory_bytes: 5992
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int main() {
	int N;
	int b;
	cin >> N;
	int a[N];
	long long int ans = 0;
	for (int i = 0;i < N;i++) {
		cin >> a[i];
		a[i] = a[i] - i - 1;
	}
	sort(a,a+N);
	b = a[N/2];
	for (int i = 0;i < N;i++) {
		ans += abs(a[i]-b);
	}
	cout << ans;
}

Measured memory_bytes: 1024
A, B, C = map(int, input().split())

if A % 2 == 1 and B % 2 == 1 and C % 2 == 1:
    print(0)
    exit()
elif A == B and B == C:
    print('-1')
    exit()
else:
    ans = 0
    while A % 2 != 1 and B % 2 != 1 and C % 2 != 1:
        a = B//2+C//2
        b = C//2+A//2
        c = A//2+B//2
        A, B, C = a, b, c
        ans += 1
print(ans)


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

using namespace std;

const int MAX = 1001;
const int MOD = (int)1e9 + 7;

typedef long long ll;

ll H, W, dp[MAX][MAX]; //dp[i][j] returns number of ways to get to (i, j) from (0, 0)

char grid[MAX][MAX];
int main()
{
    cin >> H >> W;
    for(int i=0; i<H; i++)
    {
        for(int j=0; j<W; j++)
        {
            cin >> grid[i][j];
        }
    }

    //dp[i][j] = dp[i-1][j] + dp[i][j-1]

    dp[0][0] = 1;
    for(int i=0; i<H; i++)
    {
        for(int j=0; j<W; j++)
        {
            if(grid[i][j] != '#')
            {
                if(i>0)
                {
                    dp[i][j] = (dp[i-1][j] + dp[i][j])%MOD;
                }
                if(j>0)
                {
                    dp[i][j] = (dp[i][j-1] + dp[i][j])%MOD;
                }
            }
        }
    }
    cout << dp[H-1][W-1];
    return 0;
}


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




int main(){
    string s;
    int Q;
    int len_s;
    int list_f[200001];
    char list_c[200001];
    int list_t[200001];
    list<char> lst;
    cin >>s>>Q;
    len_s=s.length();
    rep(i,len_s){
        lst.push_back(s[i]);
    }
    
    bool muki=true;
    bool top=true;
    for(int i=1;i<=Q;i++){
        cin>>list_t[i];
        if(list_t[i]==1) muki= !muki;
        else{
            cin>>list_f[i]>>list_c[i];
            top = (list_f[i]==2) ? true : false;
            if(muki^top)lst.push_front(list_c[i]);
            else lst.push_back(list_c[i]);
        }
    }

    if(muki){
        for(auto itr = lst.begin(); itr != lst.end(); ++itr) {
        cout << *itr;
        }cout<<endl;
    }
    else{
       for(auto itr = lst.rbegin(); itr != lst.rend(); ++itr) {
        cout << *itr;
        }cout<<endl;
    } 
    
            
    return 0;
    
}

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

using namespace std;

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

    int N, M;
    cin >> N >> M;
    priority_queue<int> q;
    for(int i=0; i<N; i++){
        int a; cin >> a; q.push(a);
    }
    while(M--){
        q.push(q.top()/2);
        q.pop();
    }

    long long ans = 0;
    while(!q.empty()){
        ans += q.top();
        q.pop();
    }

    cout << ans;
}

Measured memory_bytes: 892
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long
const int MAXN=200005;
const long long ONE=1;
const long long INF=1e13;
int N;long long K;
int A[MAXN],B[MAXN];
int Check(LL p){
	LL ret=0;
	for(int i=1;i<=N;i++){
		int j=N-i+1;
		LL t=p/B[j];
		LL cnt=max(0*ONE,A[i]-t);
		ret+=cnt;
	}
	return ret<=K;
}
int main(){
	scanf("%d%lld",&N,&K);
	for(int i=1;i<=N;i++)scanf("%d",&A[i]);
	for(int i=1;i<=N;i++)scanf("%d",&B[i]);
	sort(A+1,A+N+1);sort(B+1,B+N+1);
	LL l=-1,r=INF;
	while(l+1<r){
		LL mid=(l+r)/2;
		if(Check(mid))r=mid;
		else l=mid;
	}
	printf("%lld\n",r);
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <queue>
#include <functional>

#define out(t) cout << (t) << "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;

void swap(int &a, int &b) {
    a ^= b;
    b ^= a;
    a ^= b;
}

uint tzcnt(uint x) {
    x = ~x & (x - 1);
    x -= x >> 1 & 0x55555555;
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = x + (x >> 4) & 0x0F0F0F0F;
    return x * 0x01010101 >> 24;
}

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

    int n, y;

    cin >> n >> y;

    int a = -1, b = -1, c = -1;
    for (int i = 0; i <= n; ++i) {
        int sol = 10000 * i;
        for (int j = 0; j <= n - i; ++j) {
            if (sol + 5000 * j + 1000 * (n - i - j) == y) {
                a = i;
                b = j;
                c = n - i - j;

                goto solved;
            }
        }
    }

    solved:

    cout << a << " " << b << " " << c << "\n";

    int ttttttt;
    cin >> ttttttt;
}

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

int main() {
    int64_t N, ans = 0;
    cin >> N;
    vector<int64_t> A(N);
    map<int64_t, int64_t> num;
    for (int64_t i = 0; i < N; i++) {
        cin >> A[i];
        if (num.count(A[i])) {
            num[A[i]] += 1;
            ans += (num[A[i]] - (num[A[i]] - 2)) * (num[A[i]] - 1) / 2;
        } else {
            num[A[i]] = 1;
        }
    }

    for (int64_t i = 0; i < N; i++) {
        if (num.count(A[i])) {
            if (num[A[i]] > 1) {
                cout << ans - (num[A[i]] - (num[A[i]] - 2)) * (num[A[i]] - 1) / 2 << endl;
            } else {
                cout << ans << endl;
            }
        } else {
            cout << ans << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 12672
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random  # randome is not available at Codeforces
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=lambda: sys.stdin.readline().rstrip()
import sys
sys.setrecursionlimit(10**7)

show_flg=False
show_flg=True


n,m=LI()
a=LI()
g=[[] for _ in range(n)]
ans=0
cmp=0
for i in range(m):
    x,y=LI()
    g[x].append(y)
    g[y].append(x)

rest=[]
q=[]
v=[-1]*n

for i in range(n):
    if v[i]!=-1:
        continue
    p=[]
    cost=[]
    p.append(i)
    heappush(cost,a[i])
    while p:
        c=p.pop()
        v[c]=a[c]
        for nb in g[c]:
            if v[nb]==-1:
                p.append(nb)
                v[nb]=a[nb]
                heappush(cost,a[nb])
    ans+=heappop(cost)
    cmp+=1
    while cost:
        heappush(rest,heappop(cost))

if cmp==1:
    ans=0
elif len(rest)<cmp-2:
    ans="Impossible"
else:# cmp=n-m, n-m-1 edges needed, 2n-2m-2 vers, 2n-2m-2-cmp=n-m-2=cmp-2
    for i in range(cmp-2):
        ans+=heappop(rest)

print(ans)


Measured memory_bytes: 96832
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> V;
typedef pair<int,int> P;
typedef vector<vector<int>> Graph;

struct Edge {
    int to ,id;
};

vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v, int c=-1, int p=-1){
    int k=1;
    rep(i,g[v].size()){
        int u = g[v][i].to, ei = g[v][i].id;
        if(u==p) continue;
        if(k == c) ++k;
        ans[ei] = k; k++;
        dfs(u,ans[ei],v);
    }
}

int main() {
    int n;
    cin >> n;
    g.resize(n);
    ans = vector<int>(n-1);
    rep(i,n-1) {
        int a,b;
        cin >> a >> b;
        --a;--b;
        g[a].push_back((Edge){b,i});
        g[b].push_back((Edge){a,i});
    }
    dfs(0);
    int mx =0;
    rep(i,n) mx = max(mx,int(g[i].size()));
    cout << mx << endl;
    rep(i,n-1){
        cout << ans[i] << endl;
    }
}

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

typedef long long int lli;
#define int lli
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<lli> vli;
typedef vector<pii> vii;

const int MOD   = 1e9 + 7;
const double PI = acos(-1.0);
const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};
const int INF   = 1e18;

#define fastio            ios_base::sync_with_stdio(false);cin.tie(0)
#define sz(a) int((a).size())
#define rsz resize
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define f first
#define s second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define endl "\n"
#define spc " "
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }

void solve(){

    int n;
    cin >> n;

    vi a(n);
    rep(i, n){
        cin >> a[i];
    }
    vi b(n);
    rep(i, n){
        cin >> b[i];
    }
    reverse(all(b));

    int c = -1;
    int l = n + 1;
    int r = -1;

    rep(i, n){
        if(a[i] == b[i]){
            c = a[i];
            l = min(l, i);
            r = max(r, i);
        }
    }

    int pos = true;

    if(c != -1){
        vb mark(n);
        rep(i, n){
            if(a[i] != c && b[i] != c){
                mark[i] = true;
            }
        }

        int st = l;
        rep(i, n){
            if(mark[i]){
                swap(b[i], b[st++]);
                if(st > r) break;
            }
        }

        if(st <= r) pos = false;
    }

    if(pos){
        cout << "Yes" << endl;
        rep(i, n) cout << b[i] << spc;
        cout << endl;
    }else{
        cout << "No" << endl;
    }

}

signed main(){
    fastio;

    solve();

    return 0;
}


Measured memory_bytes: 6320
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds;
using namespace std;

typedef long long int lli;
#define int lli
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef vector<pii> vii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OrderedSet;

const int MOD	= 1e9 + 7;
const double PI = acos(-1.0);

#define fastio			ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto &i : c)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define fill(a)  memset(a, 0, sizeof (a))
#define error(x) cerr << #x << " = " << (x) << endl
#define errorp(p) cerr << #p << " = " << (p.first) << ", " << (p.second) << endl

template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }
int mul(int a, int b, int c){lli res=(lli)a*b;return (int)(res>=c?res%c:res);}
template<typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
template <class T>  inline void smax(T &x,T y){ x = max((x), (y));}
template <class T>  inline void smin(T &x,T y){ x = min((x), (y));}


signed main(){
    // #ifndef ONLINE_JUDGE
	// 	freopen("test", "r", stdin);
	// #endif
    fastio;
    
    int N, K;
    cin >> N >> K;

    // lli ans = power((lli)10, (lli)100, MOD);
    // ans = mul(ans, K, MOD);

    int ways = 0;
    repA(k, K, N + 1){
        int min = ((k) * (k - 1)) / 2;
        int max = (N * k)  - min;
        ways += max - min + 1;
        ways %= MOD;
    }

    cout << ways << endl;


    return 0;
}


Measured memory_bytes: 3656
<?php
fscanf(STDIN, "%d", $N);
$H = explode(" ", trim(fgets(STDIN)));
$mmax = 0;
$ans = 0;
for ($i = 0; $i < $N; $i++) {
    if ($mmax <= $H[$i]) {
        $mmax = $H[$i];
        $ans++;
    }
}
echo $ans;


Measured memory_bytes: 4604
N = int(input())
v = map(int, input().split())
c = map(int, input().split())
V = []
C = []
test = []
ans = 0
for i in v:
    V.append(i)
for i in c:
    C.append(i)
for i in range(N):
    test.append(V[i] - C[i])
    if test[i] > 0:
        ans += test[i]
print(ans)

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

int main(){
    int n;
    bool ans = false;
    cin >> n;
    int div_2 = 0, div_4 = 0, others = 0;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        if(a%4 == 0) div_4++;
        else if(a%2 == 0) div_2++;
        else others++;
    }

    if(others == 0) ans = true;
    else if(div_4 >= others) ans = true;
    else if(div_4+1 == others && div_2 == 0) ans = true;

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
/** 
 *                                                                   
 *   |    |                        ,   .              ,--.,--.,--.,--.
 *   |    |    ,---..    ,,---.    |   |,---..   .      -||  ||  ||  |
 *   |    |    |   | \  / |---'    `---'|   ||   |       ||  ||  ||  |
 *   `    `---'`---'  `'  `---'      |  `---'`---'    `--'`--'`--'`--'
 *                                   `                                
**/
#include <bits/stdc++.h>
using namespace std;

int n, w, wei[105], val[105];
long long dp[105][100005];

long long solve(int id, int sisa) {
	if (id == n) return 0;
	if (dp[id][sisa] != -1) return dp[id][sisa];

	long long res = solve(id + 1, sisa);
	if (sisa - wei[id] >= 0) res = max(res, solve(id + 1, sisa - wei[id]) + val[id]);

	return dp[id][sisa] = res;
}

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

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	cin >> n >> w;
	for (int i = 0; i < n; i++) {
		cin >> wei[i] >> val[i];
	}

	memset(dp, -1, sizeof(dp));
	cout << solve(0, w) << '\n';

	return 0;
}

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

int main() {
  int N,M,C;
  cin >>N>>M>>C;
  int B[M];
  for(int i=0;i<M;i++){
    cin >>B[i];
  }
  vector<vector<int>> data(N,vector<int>(M));
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      cin >>data.at(i).at(j);
    }
  }
  int ans=0;
  for(int i=0;i<N;i++){
    int sum=C;
    for(int j=0;j<M;j++){
      sum+=data.at(i).at(j)*B[j];      
    }
    if(sum>0){
      ans++;
    }
  }
  cout <<ans<<endl;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll n;cin >>n;
    vector<ll> h(n);
    ll mx=0,mint=INF;
    bool flg=true;
    ll ans=0;
    for(int i=0;i<n;i++){
        cin >>h[i];
        if(flg&&h[i]<mx){
            flg=false;
            ans+=mx;
            mx=0;
            mint=INF;
        }
        if(!flg&&h[i]>mint){
            flg=true;
            ans-=mint;
            mint=INF;
            mx=0;
        }
        mint=min(mint,h[i]);
        mx=max(mx,h[i]);
    }
    if(n==1||(n>2&&h[n-2]<=h[n-1]))ans+=h[n-1];
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

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

  int n,m;
  cin >> n >> m;
  
  if(n % 3 == 0 || m % 3 == 0){
    cout << 0 << endl;
    return 0;
  }
  
  ll ans = min(m,n);  // 縦横同じ方向に３分割した最小の差
  
  FOR(i,1,n){
    ll size = max(abs(i*m -(n-i)*(m/2)),abs(i*m -(n-i)*(m-m/2)));
    ans = min(ans,size);
  }
  
  FOR(i,1,m){
    ll size = max(abs(i*n -(m-i)*(n/2)),abs(i*n -(m-i)*(n-n/2)));
    ans = min(ans,size);
  }   

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ff first
#define ss second
#define pb push_back
#define I insert
int main()
{
  
  ll K,X;
  cin>>K>>X;
  if(K*500>=X)
    cout<<"Yes"<<"\n";
  else
    cout<<"No"<<"\n";
  
  
  
  
  
  
}

Measured memory_bytes: 256
n, m, k = map(int,input().split())
if not m+k-1 <= n <= m*k:
    print(-1)
    exit()

streak = [1]*k
streak[0] = m
i = 1
for increment in range(n-m-k+1):
    if streak[i] == m: i+= 1
    streak[i]+= 1
seq = list(range(n, 0, -1))

i = 0
for s in streak:
    subseq = seq[i:i+s]
    seq[i:i+s] = subseq[::-1]
    i+= s
print(*seq)

Measured memory_bytes: 23204
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,T;
  cin>>N>>T;
  vector<pair<int, int> > pairs(N);
  for(int i=0;i<N;i++){
        int a;
        int b;
        cin >> a >> b;
        pairs[i] = make_pair(b, a);
    }
  sort(pairs.begin(),pairs.end());
  int ans=1000000000;
  for(int i=0;i<N;i++){
    if(pairs[i].first<=T)
      ans=min(ans,pairs[i].second);
    else
      break;
  }
  if(ans==1000000000)
    cout<<"TLE"<<endl;
  else
    cout<<ans<<endl;
}
  

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

char in[120];
pair<pair<string, int>, int> p[110];

int main()
{
    int N;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int t;
        scanf("%s%d", in, &t);
        string tmp = in;
        p[i] = make_pair(make_pair(in, -t), i);
    }
    std::sort(p, p + N);
    for (int i = 0; i < N; i++)
    {
        printf("%d\n", p[i].second + 1);
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    int a[100], b[100], c[100], d[105];
    int i;
    for (i = 0; i < n; i++)
        scanf("%d %d", &a[i], &b[i]);
    for (i = 0; i < n; i++)
        scanf("%d %d", &c[i], &d[i]);
    int ans = 0;
    int x;
    for (i = 0; i < n - 1; i++)
    {
        if (a[i] < a[i + 1])
        {
            x = a[i];
            a[i] = a[i + 1];
            a[i + 1] = x;
            x = b[i];
            b[i] = b[i + 1];
            b[i + 1] = x;
            if (i != 0)
                i -= 2;
        }
        if (a[i] == a[i + 1])
        {
            if (b[i] < b[i + 1])
            {
                x = a[i];
                a[i] = a[i + 1];
                a[i + 1] = x;
                x = b[i];
                b[i] = b[i + 1];
                b[i + 1] = x;
                if (i != 0)
                    i -= 2;
            }
        }
    }
    for (i = 0; i < n - 1; i++)
    {
        if (c[i] < c[i + 1])
        {
            x = c[i];
            c[i] = c[i + 1];
            c[i + 1] = x;
            x = d[i];
            d[i] = d[i + 1];
            d[i + 1] = x;
            if (i != 0)
                i -= 2;
            continue;
        }
        if (c[i] == c[i + 1])
        {
            if (d[i] < d[i + 1])
            {
                x = c[i];
                c[i] = c[i + 1];
                c[i + 1] = x;
                x = d[i];
                d[i] = d[i + 1];
                d[i + 1] = x;
                if (i != 0)
                    i -= 2;
            }
        }
    }
    int j;
    int y;
    d[103] = 9999;
    for (i = 0; i < n; i++)
    {
        y = 103;
        for (j = 0; j < n; j++)
        {
            if (a[i] < c[j] && b[i] < d[j])
            {
                if (d[y] > d[j])
                    y = j;
            }
        }
        if (y != 103)
        {
            ans++;
            c[y] = d[y] = 0;
        }
    }
    printf("%d\n", ans);
    return 0;
}

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

int main() {
    //
    int h, w, num;
    int tmp;
    cin >> h >> w >> num;

    if (h >= w){
        tmp = num / h;
        if (num % h != 0) tmp++;
        cout << tmp;
    } else {
        tmp = num / w;
        if (num % w != 0) tmp++;
        cout << tmp;
    }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;

// 插入此處

void solve_sum(int cut, int idx, vector<string>& M, vector<int>& acc, int& ma) {
    // cout << "solve_sum cut " << cut << " idx " << idx << " ma " << ma << endl;
    // for (int i = 0; i < acc.size(); ++i) {
    //     cout << acc[i] << ' ';
    // }
    // cout << endl;
    int ptr = 0;
    for (int i = 0; i < M.size(); ++i) {
        // cout << "ma " << ma << " ptr " << ptr << endl;
        if (i == 0) {
            acc[ptr] += (M[i][idx] == '1' ? 1 : 0);
            ma = max(ma, acc[ptr]);
            continue;
        } else {
            if (cut & (1 << (i - 1)))  ++ptr;
        }
        acc[ptr] += (M[i][idx] == '1' ? 1 : 0);
        ma = max(ma, acc[ptr]);
        // cout << "ma " << ma << " ptr " << ptr << endl;
    }
    // cout << "solve_sum cut " << cut << " idx " << idx << " ma " << ma << " ptr " << ptr << endl;
    // for (int i = 0; i < acc.size(); ++i) {
    //     cout << acc[i] << ' ';
    // }
    // cout << endl;
}

int count_bit(int n) {
    int ret = 0;
    while (n) {
        ret += (n & 1);
        n >>= 1;
    }
    return ret;
}

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int H, W, K; cin >> H >> W >> K;
    vector<string> M(H); 
    for (int i = 0; i < H; ++i) {
        cin >> M[i];
    }
    int ans = H + W;
    for (int i = 0; i < (1 << (H - 1)); ++i) {
        // cout << "i " << i << endl;
        vector<int> acc(count_bit(i) + 1, 0);
        int res = 0;
        // cout << "i " << i << endl;
        bool double_fail = false;
        for (int j = 0; j < W; ++j) {
            // cout << "j " << j << endl;
            int ma = 0;
            solve_sum(i, j, M, acc, ma);
            if (ma > K) {
                if (double_fail)  break;
                ++res;
                --j;
                for (int k = 0; k < count_bit(i) + 1; ++k) {
                    acc[k] = 0;
                }
                double_fail = true;
            } else {
                double_fail = false;
            }
        }
        if (double_fail)  continue;
        // cout << "i " << i << endl;
        int tmp = i;
        while (tmp) {
            res += (tmp & 1);
            tmp >>= 1;
        }
        ans = min(ans, res);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
S = input()
for i, s in enumerate(S):
    if i % 2 == 0:
        if s not in ("R", "U", "D"):
            print("No")
            import sys
            sys.exit(0)
    else:
        if s not in ("L", "U", "D"):
            print("No")
            import sys
            sys.exit(0)
print("Yes")


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

func main() {
     sc := bufio.NewScanner(os.Stdin)
     sc.Split(bufio.ScanWords)

     var a, b, c int
     if sc.Scan() {a, _ = strconv.Atoi(sc.Text()) }
     if sc.Scan() {b, _ = strconv.Atoi(sc.Text()) }
     if sc.Scan() {c, _ = strconv.Atoi(sc.Text()) }

     if a < b && b < c {
     	fmt.Println("Yes")
     } else {
	fmt.Println("No")
     }
}


Measured memory_bytes: 1104
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
typedef long long int ll;
using namespace std;
bool G[10][10]={false};

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

int N,M;
cin>>N>>M;
rep(i,M){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G[a][b]=G[b][a]=true;
}

vector<int> ord(N);
rep(i,N)ord[i]=i;
int res=0;
do{
    if(ord[0]!=0) break;

    bool ok=true;
    rep(i,N-1){
        int from=ord[i];
        int to=ord[i+1];
        if(!G[from][to]) ok = false;
    }
    if(ok) res++;
}while(next_permutation(ord.begin(),ord.end()));
cout<<res<<endl;
//system("pause");
return 0;
}

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

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

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

int main() {
	multimap<int,string> words;
	string str;
	string maxstr="";
	for(;cin>>str;){
		if(maxstr.size()<str.size())maxstr=str;
		multimap<int,string>::iterator it;
		bool nw=true;
		for(it=words.begin();it!=words.end();it++){
			if(it->second==str){
				words.insert(map<int,string>::value_type(it->first-1,str));
				nw=false;
break;
			}
		}
		if(nw)words.insert(map<int,string>::value_type(-1,str));
		/*for(it=words.begin();it!=words.end();it++){
			cout<<it->second<<endl;
			cout<<1<<endl;
		}*/
		//cout<<str<<endl;
	}
	cout<<words.begin()->second<<" "<<maxstr<<endl;
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int MAX = 1e6 + 10;
const int MOD = 1e9 + 7;
const int oo = 1e9;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	#define endl '\n'
	int x, y, z;
	cin >> x >>y >> z;
	cout << z << " "<< x << " " << y << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    char _a,_b,_c,_d;cin >> _a >> _b >> _c >> _d;
    int a = _a-'0';
    int b = _b - '0';
    int c = _c -'0';
    int d = _d - '0';
    if(a+b+c+d == 7)cout << a << "+" << b << "+" << c << "+" << d <<"=7"<<endl;
    else if(a+b+c-d == 7)cout << a << "+" << b << "+" << c << "-" << d <<"=7"<<endl;
    else if(a+b-c-d == 7)cout << a << "+" << b << "-" << c << "-" << d <<"=7"<<endl;
    else if(a-b-c-d == 7)cout << a << "-" << b << "-" << c << "-" << d <<"=7"<<endl;
    else if(a-b+c-d == 7)cout << a << "-" << b << "+" << c << "-" << d <<"=7"<<endl;
    else if(a+b-c+d == 7)cout << a << "+" << b << "-" << c << "+" << d <<"=7"<<endl;
    else if(a-b-c+d == 7)cout << a << "-" << b << "-" << c << "+" << d <<"=7"<<endl;
    else if(a-b+c+d == 7)cout << a << "-" << b << "+" << c << "+" << d <<"=7"<<endl;
    
}




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

template <int MOD_>
struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");
 
private:
	using ll = long long;
 
	int v;
 
	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}
 
public:
 
	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }
 
	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }
 
	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
 
	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}
 
	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}
 
	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
using num = modnum<int(1e9) + 7>;

const int MAXN = 2e5;
int N;
int A[MAXN];
int last[MAXN];

num fact[MAXN];
num ifact[MAXN];

void precomp() {
	fact[0] = 1;
	for (int i = 1; i < MAXN; i++) {
		fact[i] = fact[i-1] * i;
	}
	ifact[MAXN-1] = num(1) / fact[MAXN-1];
	for (int i = MAXN-2; i >= 0; i--) {
		ifact[i] = ifact[i+1] * (i+1);
	}
}

num choose(int n, int r) {
	if (r < 0 || n < r) {
		return 0;
	} else {
		return fact[n] * ifact[r] * ifact[n-r];
	}
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	precomp();

	cin >> N;
	int cnt = 0;
	for (int i = 1; i <= N+1; i++) {
		int a; cin >> a;
		if (last[a]) {
			cnt = N - i + last[a];
		} else {
			last[a] = i;
		}
	}

	for (int k = 1; k <= N+1; k++) {
		num res = choose(N+1, k) - choose(cnt, k-1);
		cout << res << '\n';
	}

	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define f first
#define s second
#define pr(x) cout<<x<<endl;
#define pr2(x,y) cout<<x<<" "<<y<<endl;
#define pr3(x,y,z) cout<<x<<" "<<y<<endl;
#define prv(v) for(auto x:v) cout<<x<<" ";
#define ffs fflush(stdout);
#define int ll
using namespace std;
 
const ll N =(2e5+5);
const ll MOD = 1e9+7;
const ll INF = LLONG_MAX;
const ll LOG = 29;
#define PI 3.141592653589793238 


long long binpow(long long a, long long b) {
    a%=MOD;    
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%MOD;
        a = (a * a)%MOD;
 
        
        b >>= 1;
    }
    res%=MOD;
    return res;
}
void solve(){
    ll x;
    cin>>x;
    for(ll a = -1000;a<=1000;a++){
        for(ll b = -1000;b<=1000;b++){
            //if(a==0||b==0)continue;
            ll gg = pow(a,5);
            ll gg2 = pow(b,5);
            //cout<<a<<" "<<b<<" "<<gg<<" "<<gg2<<endl;
            if((gg-gg2) == x){

          //  cout<<gg<<" "<<gg2<<endl;
                cout<<a<<" "<<b<<endl;
                return; 
            }
        }
    }
}   
 
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     
    ll t=1;
    while(t--){
        solve();
    }    
}

Measured memory_bytes: 4080
x = int(input())

def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return n != 1

ans = x
while True:
    if is_prime(x):
        print(x)
        break
    else:
        x += 1

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

int main()
{
    string s;
    while (cin >> s)
    {
        if (s == "EOF")
            return 0;
        int a = 0, b = 0;
        for (int i = 0; i + 2 < s.size(); i++)
        {
            if (s.substr(i, 3) == "JOI")
                a++;
            if (s.substr(i, 3) == "IOI")
                b++;
        }
        cout << a << endl;
        cout << b << endl;
    }
}


Measured memory_bytes: 3172
MOD = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))


def main():
    SUM = []
    now = 0
    ans = 0
    for i in range(N):
        now += A[i]
        SUM.append(now)
    
    for i in range(N):
        ans += A[i] * (SUM[-1] - SUM[i])
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 102016
def main():
    abck = list(map(int, input().split()))
    count = abck[3]
    r = 0
    
    r += min(abck[0], count)
    count -= min(abck[0], count)
    count -= min(abck[1], count)
    r -= min(abck[2], count)
    count -= min(abck[2], count)

    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9072
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001

#define F first
#define S second

#define Pii pair<SINT32,SINT32>
#define Pll pair<SINT64,SINT64>


using namespace std;

int main() {

	SINT32 N = 0;
	SINT32 ans = INF * -1;
	cin >> N;

	vector<vector<SINT32>> data01(N,vector<SINT32>(10));
	vector<vector<SINT32>> dataR(N,vector<SINT32>(11));
	vector<SINT32> DATA(N);
	
	rep(i,0,N) {
		rep(j,0,10) {
			cin >> data01[i][j];
		}
	}
	rep(i,0,N) {
		rep(j,0,11) {
			cin >> dataR[i][j];
		}
	}

	rep(i,1,1024) {
		SINT32 buf = 0;
		rep(j,0,N) {
			SINT32 cnt = 0;
			rep(k,0,10) {
				if ((data01[j][k] == 1) && (((i>>k) & 1) == 1)) {
					cnt++;
				}
			}
			buf += dataR[j][cnt];
		}
		ans = MAX(ans,buf);
	}

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

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());	//ソート後に使用

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));	//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();	//key以上を探す
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/
/* 文字列合成
	string N,M;
	cin >> N >> M;
	SINT64 ans = 0;
	ans = stoi(N+M);
*/



/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

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

using namespace std;
 
typedef long long ll;


int main()
{
    ll x,d,k;
    cin>>x>>k>>d;
    x=abs(x);
    ll ans1,ans2,ans;
    ans1 = x%d;
    ans2 = abs((x%d)-d);
    if(k<=x/d){
        cout<<x-k*d;
    }
    else{
        ll rem = k-x/d;
        if(rem%2==0){
            cout<<ans1;
        }
        else{
            cout<<ans2;
        }
    }
}
 

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007

vector<long long>v[2005];
long long vis[2005],dst[2005];
map<pair<long long ,long long>,long long>m1;
long long sum=0;

void bfs(long long src)
{
    queue<long long>q;
    vis[src]=1;
    q.push(src);
    dst[src]=0;
    
    while(!q.empty())
    {
        int curr=q.front();
        q.pop();
        for(int i=0;i<v[curr].size();i++)
        {
            if(vis[v[curr][i]]==0)
            {
                q.push(v[curr][i]);
                vis[v[curr][i]]=1;
                dst[v[curr][i]]=dst[curr]+1;
                m1[{src,v[curr][i]}]=dst[v[curr][i]];
            }
        }
    }
}
int main() {
    
      long long n,i,k,j,ans=0,m,w,mx=0,l,r,x,y,r1,c1,r2,c2;
      cin>>n>>x>>y;
      long long c[n]={0};
      for(i=0;i<(n-1);i++)
      {
          v[i].push_back(i+1);
          v[i+1].push_back(i);
      }
      v[x-1].push_back(y-1);
      v[y-1].push_back(x-1);
      
      for(i=0;i<n;i++)
      {
          for(j=0;j<n;j++)
          vis[j]=0;
          bfs(i);
      }
      for(i=0;i<n-1;i++)
      {
          for(j=i+1;j<n;j++)
          c[m1[{i,j}]]++;
      }
      for(i=1;i<n;i++)
      cout<<c[i]<<endl;
}


Measured memory_bytes: 251264
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef vector<vector<ll>> matrix;

map<int, int> minDP[2001];
map<int, int> maxDP[2001];
int l[2000];
int n;

int getMin(int idx, int a, int b);
int getMax(int idx, int a, int b);

int getMin(int idx, int a, int b) {
  if(idx == n) return abs(a-b);
  if(minDP[idx].count(a)) return minDP[idx][a];
  int ret = 1e9;
  for(int i = idx; i < n; i++) {
    ret = min(ret, getMax(i+1, a, l[i]));
  }
  minDP[idx][a] = ret;
  return ret;
}

int getMax(int idx, int a, int b) {
  if(idx == n) return abs(a-b);
  if(maxDP[idx].count(b)) return maxDP[idx][b];
  int ret = 0;
  for(int i = idx; i < n; i++) {
    ret = max(ret, getMin(i+1, l[i], b));
  }
  maxDP[idx][b] = ret;
  return ret;
}

void solve() {
  cin >> n;
  int z, w;
  cin >> z >> w;
  for(int i = 0; i < n; i++) cin >> l[i];
  cout << getMax(0, z, w) << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define ld long double
#define MOD 1000000007
#define nl cout << bl
#define rt ll Q[100005] = {0}
#define mp make_pair
#define test() \
    ull t;     \
    cin >> t;  \
    while (t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define s(ar, n) sort(ar, ar + n)
#define rs(ar, n) sort(ar, ar + n, greater<ll>())
#define oa(a, n)               \
    for (ll i = 0; i < n; i++) \
        cout << a[i] << " ";
#define cn(a, n)               \
    for (ll i = 0; i < n; i++) \
        cin >> a[i];
#define ov(a, n)                    \
    for (ll i = n - 1; i >= 0; i--) \
        cout << a[i] << " ";        \
    nl
#define ovp(a, n)              \
    for (ll i = 0; i < n; i++) \
        cout << a[i].ff << " " << a[i].ss << bl;
#define maxa(ar, N) *max_element(ar, ar + N)
#define mina(ar, N) *min_element(ar, ar + N)
#define present(c, x) ((c).find(x) != (c).end())
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
typedef pair<int, int> pii;
ll fast_exp(ll base, ll exp)
{
    ll res = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
            res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return res % MOD;
}
ll fib(ll n)
{
    if (n < 2)
        return n;
    ll a = 0, b = 1, pre;
    int i = 1;
    while (i < n)
    {
        pre = (a + b) % MOD;
        a = b;
        b = pre;
        i++;
    }
    return pre;
}
ll fac(ll n)
{
    if (n % 2 == 0)
        return 2;

    for (ll i = 3; i * i <= n; i += 2)
    {
        if (n % i == 0)
            return i;
    }

    return n;
}
ll fact(ll n)
{
    if (n > 1)
        return n * fact(n - 1);
    else
        return 1;
}
bool sortbysec(const tuple<int, int, int> &a,
               const tuple<int, int, int> &b)
{
    return (get<1>(a) < get<1>(b));
}
int last_digit(int n)
{
    int ans = 0;
    while (n != 0)
    {
        ans = n % 10;
        n /= 10;
    }
    return ans;
}
int main()
{
    string s;
    cin >> s;
    int rem = 0;
    for (int i = 0; i < s.length(); i++)
    {
        rem += (s[i] - '0');
        rem %= 9;
    }
    if (rem == 0)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}


Measured memory_bytes: 3748
use std::collections::BTreeSet;

fn main() {
    let s = read_string();
    let mut sc = Scanner::new(&s);

    let s: String = sc.next();
    let k: usize = sc.next();

    let mut set = BTreeSet::new();

    for i in 0..s.len() {
        for j in 1..6 {
            if i+j<=s.len() {
                set.insert(&s[i..i+j]);
            }
        }
    }

    println!("{}", set.iter().nth(k-1).unwrap());
}

// 以下、たなこふ先生からぱくったやつ (´･_･`)

struct Scanner<'a> {
    iter: std::str::SplitWhitespace<'a>,
}

impl<'a> Scanner<'a> {
    fn new(s: &str) -> Scanner {
        Scanner {
            iter: s.split_whitespace(),
        }
    }

    fn next<T>(&mut self) -> T
        where T: std::str::FromStr,
              <T as std::str::FromStr>::Err: std::fmt::Debug,
    {
        let s = self.iter.next().unwrap();
        s.parse().unwrap()
    }
}

fn read_string() -> String {
    use std::io::Read;

    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    buf
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
using namespace std;
const int INF = 1000000;
int bu(int a, int b) {
  int an = 0;
  if (a % b) an ++;
  an += a / b;
  return an;
}
int main () {
  int D;
  long long G;
  cin >> D >> G;
  int p[11];
  int c[11];
  for (int i = 0; i < D; i ++) cin >> p[i] >> c[i];
  int bi[11];
  bi[0] = 1;
  for (int i = 0; i < 10; i ++) bi[i + 1] = bi[i] * 2;
  vector<int>ans(bi[D], 0);
  for (int i_ = 0; i_ < bi[D]; i_ ++) {
    int i = i_;
    long long score = 0;
    int f;
    for (int j = 0; j < D; j ++) {
      if (i % 2) {
        score += (long long) 100 * (j + 1) * p[j] + c[j];
        ans[i_] += p[j];
      }
      else f = j + 1;
      i /= 2;
    }
    if (score < G) {
      int g = (int) (G - score) / 100;
      int k = bu(g, f);
      if (k >= p[--f]) ans[i_] = INF;
      else ans[i_] += k;
    }
  }
  int jun = ans[0];
  for (int i = 1; i < bi[D]; i ++) {
    if (jun > ans[i]) {
      jun = ans[i];
    }
  }
  cout << jun << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = k; i < (int)(n); i++)
const int maxN = int(1e5 + 10);
int e[maxN] = {}, o[maxN] = {};
int num[maxN] = {};
using ll = long long;

int main() {
    int n, t, a;
    cin >> n >> t >> a;
    double diff, ans;
    int h[1010];
    rep(i, n) cin >> h[i];
    diff = abs(a - (t - h[0] * 0.006));
    ans = 1;
    rep(i, n) {
        double tdiff = abs(a - (t - h[i] * 0.006));
        if(tdiff < diff) {
            diff = tdiff;
            ans = i + 1;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18

long n, k, h[200005];

int main(){
    scanf("%ld%ld", &n, &k);
    for(int i = 0; i < n; i++){
        scanf("%ld", h+i);
    }
    std::sort(h, h+n);
    long ans = 0;
    for(int i = 0; i < n-k; i++){
        ans += h[i];
    }
    printf("%ld\n", ans);
}


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


int main(void) {
    using namespace std;

    constexpr long MOD = 1e9 + 7;
    auto inv = [&](long a) {
        long r = 1;
        long b = MOD - 2;
        while(b) {
            if(b&1) r *= a, r %= MOD;
            a *= a, a %= MOD;;
            b >>= 1;
        }
        return r;
    };
    auto comb = [&](long a, long b) {
        long r = 1;
        for(long i=0; i<b; i++)
            r *= a - i, r %= MOD;
        for(long i=0; i<b; i++)
            r *= inv(i+1), r %= MOD;
        return r;
    };

    long x, y;
    cin >> x >> y;

    long n = (x + y) / 3;

    if((x + y) % 3 > 0) {
        cout << 0 << endl;
        return 0;
    }

    // 1s + 2(n-s) == x
    // 2n - s == x
    // s == 2n - x
    // t == 2n - y

    // (s+t)! / s!t!
    if(2*n - x < 0 || 2*n - y < 0) {
        cout << 0 << endl;
        return 0;
    }
    cout << comb(4*n-x-y, 2*n-y) << endl;
}


Measured memory_bytes: 256