akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
typedef complex<double> Point;
const double EPS = 1e-8;

struct Line : public vector<Point> {
    Line(const Point& a, const Point& b) {
        push_back(a); push_back(b);
    }
    Point vector() const {
        return back() - front();
    }
};
double cross(Point a, Point b){
    return imag(conj(a) * b);
}
double distanceLP(Line l, Point p){
    // return abs(p - projection(l, p));
    return abs(cross(l.vector(), p - l[0])) / abs(l.vector());
}

Point incenter(Point p1, Point p2, Point p3){
    double a = abs(p2 - p3);
    double b = abs(p3 - p1);
    double c = abs(p1 - p2);
    return (a * p1 + b * p2 + c * p3) / (a + b + c);
}

Point find_point(Point a, double r, Point p, Point c, Line l){
    double lb = 0, ub = 1;
    REP(iter, 50){
        double mid = (lb + ub) / 2;
        Point q = p * (1 - mid) + c * mid;
        double s = distanceLP(l, q);
        if(abs(a - q) < r + s){ // too near
            ub = mid;
        }else{ // come closer
            lb = mid;
        }
    }
    return p * (1 - lb) + c * lb;
}

int main(){
    while(true){
        Point tri[3];
        REP(i, 3){
            double x, y;
            cin >> x >> y;
            tri[i] = Point(x, y);
        }
        if(tri[0] == tri[1]) break;
        Point c = incenter(tri[0], tri[1], tri[2]);
        double lb = 0, ub = 1;
        REP(iter, 50){
            double mid = (lb + ub) / 2;
            Point p0 = (tri[0] * (1 - mid) + c * mid);
            double r0 = distanceLP(Line(tri[0], tri[1]), p0);
            //cout << "mid : " << mid << endl;
            //cout << "p0 : " << p0 << " r0 : " << r0 << endl;

            Line l(tri[1], tri[2]);
            Point p1 = find_point(p0, r0, tri[1], c, l);
            double r1 = distanceLP(l, p1);
            //cout << "p1 : " << p1 << " r1 : " << r1 << endl;
            Point p2 = find_point(p0, r0, tri[2], c, l);
            double r2 = distanceLP(l, p2);
            //cout << "p2 : " << p2 << " r2 : " << r2 << endl;
            if(abs(p1 - p2) < r1 + r2){ // come closer
                //cout << "lb update" << endl;
                lb = mid;
            }else{
                //cout << "ub update" << endl;
                ub = mid;
            }
        }

        Point p0 = (tri[0] * (1 - lb) + c * lb);
        double r0 = distanceLP(Line(tri[0], tri[1]), p0);
        Line l(tri[1], tri[2]);
        Point p1 = find_point(p0, r0, tri[1], c, l);
        double r1 = distanceLP(l, p1);
        Point p2 = find_point(p0, r0, tri[2], c, l);
        double r2 = distanceLP(l, p2);
        printf("%.6f %.6f %.6f\n", r0, r1, r2);
    }
    return 0;
}

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

struct UF {
    vector<int> v;
    UF(int n) : v(n,-1) {;}
    int root(int x) { return (v[x] < 0) ? x : v[x] = root(v[x]); }
    bool same(int v,int u) { return root(v) == root(u); }
    bool unite(int x,int y) {
        x = root(x); y = root(y);
        if(x != y) {
            if(v[y] < v[x]) swap(x,y);
            v[x] += v[y]; v[y] = x;
        }
        return x != y;
    }
};

const int MAXH = 1000;
int w,h;
string in[MAXH];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

inline int idx(int x,int y) { return y*w+x; }
inline bool ok(int x,int y) { return x >= 0 && x < w && y >= 0 && y < h; }

int main() {
    cin>>w>>h;
    for(int i=0; i<h; ++i) cin>>in[i];
    UF uf(w*h);

    int tx,ty;
    for(int i=0; i<h; ++i)
        for(int j=0; j<w; ++j) {
            if(in[i][j] == 't') tx=j, ty=i;
            if(in[i][j] != '#') {
                for(int k=0; k<4; ++k)
                    if(ok(j+dx[k],i+dy[k]) && in[i+dy[k]][j+dx[k]] != '#')
                        uf.unite(idx(j,i),idx(j+dx[k],i+dy[k]));
            }
        }

    int n = 0,ans=1<<29,x,y;
    cin>>n;
    for(int i=0; i<n; ++i) {
        if(uf.same(idx(0,0),idx(tx,ty))) ans = min(ans,i);
        cin>>x>>y;
        if(in[y][x] == '#') {
            for(int k=0; k<4; ++k)
                if(ok(x+dx[k],y+dy[k]) && in[y+dy[k]][x+dx[k]] != '#')
                    uf.unite(idx(x,y),idx(x+dx[k],y+dy[k]));
            in[y][x] = '.';
        }
    }

    if(uf.same(idx(0,0),idx(tx,ty))) ans = min(ans, n);
    if(ans == 1<<29) ans = -1;
    cout<<ans<<endl;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
typedef long long LL;
using namespace std;
const int N=1e5+5;
int n,m,fa[N],p[N];
LL sum[N],f[N],a[N],b[N];
int head[N],ce;
bool vis[N];
struct edge{int to,nxt;} e[N<<1];
bool cmp(int x,int y) {return a[x]<a[y];}
void adde(int x,int y) {e[++ce].to=y,e[ce].nxt=head[x],head[x]=ce;}
int find(int x)
{
	if(x==fa[x]) return x;
	return fa[x]=find(fa[x]);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)
	{
		scanf("%lld%lld",&a[i],&b[i]);
		a[i]=max(a[i]-b[i],0ll);
		p[i]=fa[i]=i,f[i]=a[i],sum[i]=b[i];
	}
	for(int i=1;i<=m;++i)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		adde(x,y); adde(y,x);
	}
	sort(p+1,p+n+1,cmp);
	for(int i=1;i<=n;++i)
	{
		int u=p[i]; vis[u]=1;
		for(int j=head[u];j;j=e[j].nxt)
		{
			int v=e[j].to;
			if(!vis[v]) continue;
			int x=find(u),y=find(v);
			if(x!=y)
			{
				fa[y]=x,sum[x]+=sum[y];
				f[x]=min(f[x],max(f[y],a[x]-sum[y]));
			}
		}
	}
	printf("%lld",f[find(1)]+sum[find(1)]);
	return 0;
}

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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n)
    {
        if(n & 1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return result;
}



int32_t main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    IOS

    int k;
    cin>>k;
    string s="";
    for(int i=0;i<k;i++)
    	s+="ACL";
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 3656
n = int(input())

if n <= 1000:
    print(1000-n)
elif 1000< n <=2000:
    print(2000-n) 
elif 2000< n <=3000:
    print(3000-n)
elif 3000< n <=4000:
    print(4000-n)
elif 4000< n <=5000:
    print(5000-n)
elif 5000< n <=6000:
    print(6000-n)
elif 6000< n <=7000:
    print(7000-n)
elif 7000< n <=8000:
    print(8000-n)
elif 8000< n <=9000:
    print(9000-n)
elif 9000< n <=10000:
    print(10000-n)

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  if (a + b <= 2*c) {
    cout << x * a + y * b << '\n';
  }
  else {
    if (x < y) {
      cout << min(2 * y * c, (y-x) * b + x*2*c) << '\n';
    }
    else {
      cout << min(2 * x * c, (x-y) * a + y * 2 * c) << '\n';
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

signed main() {
  ll Q;
  cin >> Q;

  ll N = 100009;
  ll sosu[N];
  rep(i, N) {
    sosu[i] = 1;
  }
  sosu[0] = 0;
  sosu[1] = 0;
  rep(i, N) {
    if (sosu[i] == 1) {
      rep2(j, i + 1, N) {
        if (sosu[j] == 1 && j % i == 0) {
          sosu[j] = 0;
        }
      }
    }
  }

  ll like2017[N];
  rep(i, N) {
    if (sosu[i] == 1 && sosu[(i + 1) / 2] == 1) {
      like2017[i] = 1;
    } else {
      like2017[i] = 0;
    }
    // debug(like2017[i]);
  }

  ll wa[N];
  rep(i, N) {
    if (i == 0) {
      wa[i] = 0;
      continue;
    }
    wa[i] = wa[i - 1] + +like2017[i];
    // debug(wa[i]);
  }

  rep(i, Q) {
    ll a, b;
    cin >> a >> b;
    COUT(wa[b] - wa[a - 1]);
  }

  // ll before = 0;
  // rep(i, N) {
  //   if (!f[i] && !f[(i + 1) / 2]) {
  //     wa[i] = before + 1;
  //     before = before + 1;
  //   } else {
  //     wa[i] = before;
  //   }
  // }

  // rep(i, Q) {
  //   ll a, b;
  //   cin >> a >> b;
  //   // debug(a);
  //   // debug(b);
  //   // debug(wa[a]);
  //   // debug(wa[b]);
  //   if (a == b && !f[a]) {
  //     COUT(1);
  //   } else {
  //     ll ans = wa[b] - wa[a];
  //     if (!f[a] && !f[(a + 1) / 2]) {
  //       COUT(ans + 1);
  //     } else {
  //       COUT(ans);
  //     }
  //   }
  // }

  return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

// 期待値算出
double e_value(double p){
    return (1+p) / 2;
}

int main(){
    // 入力
    int N, K; cin >> N >> K;
    double p[N],sum_p[N];
    for(int i = 0; i < N; i++){
        cin >> p[i];
        sum_p[i] = e_value(p[i]); 
    }

    for(int i = 1; i < N; i++){
        sum_p[i] += sum_p[i-1];  // 累積和配列
    }

    // 最大部分計算
    int head = 0, tail = K-1;
    int final_head,final_tail;
    double final_total = 0, now_total = 0;

    while(tail < N){
        now_total = sum_p[tail] - sum_p[head-1];

        if(now_total > final_total){ // 累積和更新
            final_total = now_total;
            final_head = head; final_tail = tail; 
        }

        head++;
        tail++;
    }


    cout << fixed << setprecision(12) << final_total << endl;
    
}

Measured memory_bytes: 3328
import sys
sys.setrecursionlimit(100000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *

a, b = map(int, input().split())
if abs(a-b) % 2:
    print('IMPOSSIBLE')
else:
    print((a+b)//2)

Measured memory_bytes: 3444
#include <iostream>
using namespace std;
int main(void){
    int a[3], k, tmp;
    
    cin >> a[0] >> a[1] >> a[2];
    cin >> k;
    
    for(int i=0; i<2; i++){
        if(a[i]>a[i+1]){
            tmp = a[i];
            a[i] = a[i+1];
            a[i+1] = tmp;
            
        }
    }
    
    for(int i=0; i<k; i++){
        a[2]*=2;
    }
    
    cout << a[0] + a[1] + a[2] << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    int x,a,b; cin >>x>>a>>b;

    if (abs(x - a) > abs(x - b)) {
        cout << "B" << endl;
    } else {
        cout << "A" << endl;
    } 
    
    return 0;
}



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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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



int main(void){

	long long A, B, C; cin >> A >> B >> C;
	if(A%2 == 0 or B%2 == 0 or C%2 == 0)  cout << 0 << endl;
	else{
		cout << min(A*B, min(B*C, C*A)) << endl;
	}

	return 0;

}


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

#define pb push_back
#define pf push_front
#define pp pop_back
#define sz(a) (int)(a.size())
#define mp make_pair
#define F first
#define S second
#define next _next
#define prev _prev
#define left _left
#define right _right
#define y1 _y1
#define all(x) x.begin(), x.end()
#define what_is(x) #x << " is " << (x)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = (int)1e6 + 123;
const ll INF = (ll)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;

void megaRandom() {
	unsigned int FOR;
 	asm("rdtsc" : "=A"(FOR));
  srand(FOR);
}

string s;
bool have[256];

int main() {
	megaRandom();
	cin >> s;
	for(int i = 0; i < sz(s); i ++) {
		have[s[i]] = 1;
	}
	if((have['N'] + have['S']) % 2 != 0 || (have['W'] + have['E']) % 2 != 0)
		puts("No");
	else
		puts("Yes");
	return 0;  
}


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

const int N = 81;
int n, k, a[N];
int main()
{
	cin >> n;
	for(int i = 0; i < n; ++i) cin >> a[i];
	long long num = 0;
	long long s = 1000;
	for(int i = 0; i < n; ++i)
		if(num && (i == n - 1 || a[i] > a[i+1]))
		{
			s += num * a[i];
			num = 0;
		}
		else if(!num && i < n - 1 && a[i] < a[i+1])
		{
			num = s / a[i];
			s -= num * a[i];
		}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    int K, X;
    cin >> K >> X;
    if (K * 500 >= X) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,tgt;
int ord[500005];
int cnt[500005];

void dfs(int v){
	if(v==(1<<(n+1))){
		bool flag=true;
		for(int i=0;i<v;i++){
			for(int j=i+1;j<v;j++){
				if(ord[i]==ord[j]){
					int su=0;
					for(int k=i+1;k<j;k++){
						su^=ord[k];
					}
					if(su!=tgt)flag=false;
				}
			}
		}
		if(flag){
			for(int i=0;i<v;i++){
				printf("%d ",ord[i]);
			}
			printf("\n");
		}
	}else{
		for(int j=0;j<(1<<n);j++){
			if(cnt[j]<=1){
				cnt[j]++;
				ord[v]=j;
				dfs(v+1);
				cnt[j]--;
			}
		}
	}
}

int main(void){
	scanf("%d%d",&n,&tgt);
	//dfs(0);
	if(tgt>=(1<<n)){
		printf("-1\n");
		return 0;
	}else if(n==1 && tgt==1){
		printf("-1\n");
		return 0;
	}else if(n>=1 && tgt>=1){
		ord[0]=0;
		ord[1]=tgt;
		ord[2]=0;
		int sz=3;
		for(int i=(1<<n)-1;i>=1;i--){
			if(i==tgt)continue;
			ord[sz++]=i;
		}
		ord[sz++]=tgt;
		for(int i=1;i<=(1<<n)-1;i++){
			if(i==tgt)continue;
			ord[sz++]=i;
		}
		for(int i=0;i<sz;i++){
			printf("%d%c",ord[i],i+1==sz?'\n':' ');
		}
	}else if(n>=1){
		for(int i=0;i<(1<<n);i++){
			if(i>0)printf(" ");
			printf("%d %d",i,i);
		}
		printf("\n");
	}else{
		if(tgt>0){
			printf("-1\n");
			return 0;
		}else{
			printf("0 0\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2816
#include<stdio.h>
#define N 100

int main(){
  int n,i,j,minj,via,count = 0,A[N];

  scanf("%d",&n);

  for(i = 0;i < n;i++) scanf("%d",&A[i]);

  for(i = 0;i < n;i++){
    minj = i;
    for(j = i;j < n;j++){
      if(A[j] < A[minj]) minj = j;
    }
    if(A[i] != A[minj]) count++;
    via = A[i];
    A[i]  = A[minj];
    A[minj] = via;
  }
  for(i = 0;i < n;i++){
    printf("%d",A[i]);
    if(i == n-1) break;
    printf(" ");
  } printf("\n");
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
bool is_prime(int x){
    for(int i = 2; i*i <= x; i++){
        if(x % i == 0) return false;
    }
    return true;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int x;
    cin >> x;

    while(!is_prime(x)) x++;
    cout << x << "\n";
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
 
static const int INF = 1000000000;
int N, M, P;
 
struct Edge{
  int src, dest;
  int weight;
  Edge(int src, int dest, int weight):src(src),dest(dest),weight(weight){}
};
bool operator>(const Edge& a, const Edge& b){return (a.weight>b.weight);}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
 
 
bool bellmanford(const Graph& g, int start, vector<int>& costs){
  int n=g.size();
  vector<int> trace(n,-2);
  costs[start]=0;
  trace[start]=-1;
  rep(k,n) rep(a,n) if(costs[a]!=INF) FOR(it,g[a]){
    int b=it->dest;
    int w=costs[a]+it->weight;
    if(w<costs[b]){
      costs[b]=w;
      trace[b]=a;
    }
  }
  rep(a,n) FOR(it,g[a])
    if(costs[a]+it->weight<costs[it->dest]) return false;
  return true;
}
 
bool can_visit[2505];
bool can_goal[2505];
 
void can_check(const Graph& g, const Graph& revg, int st, int ed){
  can_visit[st] = true;
  {
    queue<int> que;
    que.push(st);
    while(!que.empty()){
      int x = que.front(); que.pop();
      can_visit[x] = true;
      FOR(it,g[x]){
        if(can_visit[it->dest]) continue;
        can_visit[it->dest] = true;
        que.push(it->dest);
      }
    }
  }
  can_goal[ed] = true;
  {
    queue<int> que;
    que.push(ed);
    while(!que.empty()){
      int x = que.front(); que.pop();
      can_goal[x] = true;
      FOR(it,revg[x]){
        if(can_goal[it->dest]) continue;
        can_goal[it->dest] = true;
        que.push(it->dest);
      }
    }
  }
}
 
 
int main(){
  int N, M, P;
  cin >> N >> M >> P;
  Graph g(N), revg(N);
  rep(i,M){
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    g[a].emplace_back(a,b,-c + P);
    revg[b].emplace_back(b,a,0);
  }
  can_check(g, revg, 0, N-1);
  /*
  rep(i,N){
    cout << can_visit[i] << " ";
  }
  cout << endl;
  rep(i,N){
    cout << can_goal[i] << " ";
  }
  cout << endl;
   */
  Graph newg(N+1);
  rep(i,N){
    FOR(it,g[i]){
      int a = it->src;
      int b = it->dest;
      int c = it->weight;
      if(can_visit[a] && can_goal[a] && can_visit[b] && can_goal[b]){
        newg[a].emplace_back(a,b,c);
      }
    }
  }
  newg[N-1].emplace_back(N-1,N,0);
  
  vector<int> costs(newg.size(),INF);
  bool cycle_check = bellmanford(newg, 0, costs);
 
  /*
  cout << (cycle_check?1:0) << endl;
  rep(i,N){
    cout << costs[i] << endl;
  }
   */
  
  if(!cycle_check){
    cout << -1 << endl;
  }else{
    cout << max(0, -costs[N]) << endl;
  }
  
  return 0;
}
 

Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] numstr = str.split(" ", 5);
		int[] num = new int[5];
		for (int i = 0; i < 5; i++) {
			num[i] = Integer.parseInt(numstr[i]);
		}
		for (int i = 0; i < 4; i++) {
			for (int j = i + 1; j < 5; j++) {
				if (num[i] < num[j]) {
					int temporary = num[i];
					num[i] = num[j];
					num[j] = temporary;
				}
			}
		}
		for (int i = 0; i < 5; i++) {
			System.out.print(num[i]);
			if (i != 4) {
				System.out.print(" ");
			} else {
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 24264
#include <iostream>
#include <algorithm>
#include <string>

#define int long long

signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
 
    std::string input;
    std::getline(std::cin, input);
    for(const auto& c : input){
        if(c>='a' && c<='z') std::cout << static_cast<char>(c+'A'-'a');
        else if(c>='A' && c<='Z') std::cout << static_cast<char>(c+'a'-'A');
        else std::cout << c;
    }
    std::cout << "\n";
    return 0;
}

Measured memory_bytes: 3196
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <bitset>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <cmath>

using namespace std;

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

#ifdef WIN32
#define LLIO "%I64d"
#else
#define LLIO "%lld"
#endif

struct FastIO {
    inline FastIO& operator >> (int& x) {
        x = 0; char f = 0, ch = getchar();
        while(ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
        while(ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
        return x = (f ? -x : x), *this;
    }
    inline FastIO& operator >> (long long& x) {
        x = 0; char f = 0, ch = getchar();
        while(ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
        while(ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
        return x = (f ? -x : x), *this;
    }
    inline FastIO& operator >> (double& x) {
        x = 0; char f = 0, ch = getchar();
        double d = 0.1;
        while(ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
        while(ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
        if(ch == '.') {
            ch = getchar();
            while(ch <= '9' && ch >= '0') x += d * (ch ^ 48), d *= 0.1, ch = getchar();
        }
        return x = (f ? -x : x), *this;
    }
}rin;
bool vis[2500];
//const int mod = 998244353;
const int mod = 924844033;
ll f[2500][2500][2][2];
ll jc[2500], a[2500];
int main() {
	jc[0] = 1;
	for(int i = 1 ; i <= 2400 ; ++ i) jc[i] = jc[i - 1] * i % mod;
	int n, k; rin >> n >> k;
	int tot = 0;
	for(int i = 1 ; i <= n ; ++ i) if(!vis[i]) for(int j = i ; j <= n ; j += k) vis[j] = 1, a[++ tot] = j;
	f[0][0][0][0] = 1;
	a[0] = -(1 << 30);
	for(int i = 1 ; i <= n ; ++ i) {
		f[i][0][0][0] = 1;
		for(int j = 1 ; j <= i ; ++ j) {
			f[i][j][0][0] = ((a[i] - a[i - 1] == k) * (f[i - 1][j - 1][0][0]) + f[i - 1][j][1][0] + f[i - 1][j][0][0]) % mod;
			f[i][j][1][0] = ((a[i] - a[i - 1] == k) * (f[i - 1][j - 1][0][1]) + f[i - 1][j][0][1] + f[i - 1][j][1][1]) % mod;
			f[i][j][0][1] = (a[i + 1] - a[i] == k) * (f[i - 1][j - 1][1][0] + f[i - 1][j - 1][0][0]) % mod;
			f[i][j][1][1] = (a[i + 1] - a[i] == k) * (f[i - 1][j - 1][0][1] + f[i - 1][j - 1][1][1]) % mod;
		}
	}
	ll ans = 0;
	for(int i = 0 ; i <= n ; ++ i) {
		ll sum = (f[n][i][0][0] + f[n][i][1][0]) % mod;
		if(i & 1) ans = ((ans - sum * jc[n - i] % mod) % mod + mod) % mod;
		else ans = (ans + sum * jc[n - i] % mod) % mod;
	}
	printf(LLIO "\n", ans);
	return 0;
}


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

using namespace std;

const int m = 1000000 + 1;

int main() {
    int n;
    cin >> n;
    int tmp;
    priority_queue<int, vector<int>, greater<int>> a;
    for(int i = 0; i < n; i++) {
        cin >> tmp;
        a.push(tmp);
    }

    bool note[m];
    for(int i = 0; i < m; i++) {
        note[i] = true;
    }

    int counter = 0;
    while(!a.empty()) {
        int x = a.top();
        a.pop();
        if(!a.empty() && (x == a.top())) {
            while(!a.empty() && (x == a.top())) a.pop();
        }else if(note[x]) {
            counter++;
        }
        for(int y = 2*x; y < m; y += x) {
            note[y] = false;
        }
    }

    cout << counter << endl;
}

Measured memory_bytes: 5076
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
int main(){
	const int MAX=100001;
	ll N;
	cin>>N;
	ll a[3*MAX];
	for(int i=0;i<3*N;i++)
		cin>>a[i];
	//sort
	sort(a,a+3*N,greater<ll>());
	ll sum=0;
	for(int i=0;i<2*N;i++){
		//cout<<a[i]<<endl;
		if(i%2)
			sum+=a[i];
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 1e9+9;

signed main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, W;
	cin>>n>>W;
	vector<int> dp(1e5+5, inf); 
	//dp[i] is the minimum weight thru which we can reach sigma(v) == i
	dp[0]=0;
	for(int i=1; i<=n; ++i)
	{
		int v, w;
		cin>>w>>v;

		for(int sumv=1e5; sumv>=0; --sumv)
		{
			if(sumv-v>=0 and dp[sumv-v]+w < dp[sumv] and dp[sumv-v]+w<=W)
			{
				
				dp[sumv] = dp[sumv-v]+w;
			}
		}
	}
	int ans=0;
	for(int i=0; i<=1e5; ++i)
	{
		if(dp[i]!=inf)
		{
			ans=i;
		}
	}
	cout<<ans;

	return 0;	
}

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

int main() {
  int N, n, tmp, sum;
  cin >> N;
  
  sum = 0;
  tmp = 1e7;
  
  for(int i=0; i<N-1; i++) {
    cin >> n;
    sum += min(n, tmp);
    tmp = n;
  }
  
  cin >> n;
  sum += n;
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    string s;
    cin>>s;
    string y="YAKI";
    int n=s.size();
    if(s.substr(0,4)==y){cout<<"Yes"<<endl; return 0;}
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
//misosoupさんの写経
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i = 0 ; i<(a) ; i++)
const ll MOD = 1e9 +7;

int color[101010]; 
vector<vector<pair<int,int>>> G(101010);//辺と辺の長さ

void solve(int v,int P, int c){//頂点、P、色
	color[v] = c;
	for(auto p:G[v]){
		if(p.first == P) continue;
		solve(p.first,v,(c+p.second)%2);
	}
}

int main(){
	int N; 
	cin >> N; 
	rep(i,N-1){
		int a,b,w;
		cin >> a>>b>>w;
		a--;b--;
		G[a].push_back({b,w});
		G[b].push_back({a,w});
	}
	solve(0,-1,0);
	rep(i,N) cout << color[i] << endl;
	return 0 ;
}


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

using namespace std;


#define MAXN 101
int main() {
    int n, f[MAXN][10], p[MAXN][11];
    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 10; ++j) {
            cin >> f[i][j];
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= 10; ++j) {
            cin >> p[i][j];
        }
    }
    int ans = -1e9-1;
    for (int i = 1; i < (1<<10); ++i) {
        int profit = 0;
        for (int j = 0; j < n; ++j) {
            int cnt = 0;
            for (int k = 0; k < 10; ++k) {
                cnt += (i>>k)&1 && f[j][k];
            }
            profit += p[j][cnt];
        }
        ans = max(ans, profit);
    }
    cout << ans << endl;
    return 0;
}


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

#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back

const int maxm = 1000000000 + 7;

using namespace std;

int in[100007];
long long arr[100007];

int main() {

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

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

	int n;
	cin >> n;
	loop(i, n) {
		cin >> in[i];
	}
	arr[0] = 0;
	arr[1] = abs(in[1] - in[0]);
	for (int j = 2; j < n; j++) {
		arr[j] = min(arr[j - 1] + abs(in[j] - in[j - 1]), arr[j - 2] + abs(in[j] - in[j - 2]));
	}
	cout << arr[n - 1];

}

Measured memory_bytes: 4740
#include <iostream>
#include <algorithm>
using namespace std;
const int INF = 1 << 25;

int cost[100][100];
int tmin[100][100];

int main() {
	int n, m, query;
	while (cin >> n >> m , n) {
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < m; j++) {
				cost[i][j] = (i == j) ? 0 : INF;
				tmin[i][j] = (i == j) ? 0 : INF;
			}
		}

		while (n--) {
			int a, b, c, t;
			cin >> a >> b >> c >> t;
			cost[a - 1][b - 1] = cost[b - 1][a - 1] = c;
			tmin[a - 1][b - 1] = tmin[b - 1][a - 1] = t;
		}

		for (int k = 0; k < m; k++) {
			for (int i = 0; i < m; i++) {
				for (int j = 0; j < m; j++) {
					cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
					tmin[i][j] = min(tmin[i][j], tmin[i][k] + tmin[k][j]);
				}
			}
		}

		cin >> query;
		while (query--) {
			int p, q, r;
			cin >> p >> q >> r;
			if (r == 0) {
				cout << cost[p - 1][q - 1] << endl;
			}
			else {
				cout << tmin[p - 1][q - 1] << endl;
			}
		}
	}
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#include <atcoder/all>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int n,q;
  cin >> n >> q;
  atcoder::dsu uf(n);
  rep(i,q) {
    int t;
    cin >> t;
    int a,b;
    cin >> a >> b;
    if(t) {
      cout << uf.same(a,b) << endl;
    } else {
      uf.merge(a,b);
    }
  }
  return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> d(n);
	rep(i, n) cin >> d.at(i);
	
	sort(d.begin(), d.end());

	int diff = d.at(n/2) - d.at(n/2-1);
	cout << diff << endl;

	return 0;
}


Measured memory_bytes: 640
"""    Arnab Chanda    """

from collections import defaultdict, deque
from itertools import permutations
from sys import stdin,stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
import heapq

int_input=lambda : int(stdin.readline())
string_input=lambda : stdin.readline().split()
multi_int_input =lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input=lambda : list(map(int,stdin.readline().split()))
string_list_input=lambda: list(string_input())
MOD = pow(10,9)+7


import itertools

n, m, k = multi_int_input()

stuff = [x for x in range(0, n)]

a = []

for i in range(n):
    b = list_input()
    a.append(b)

ans = 9999999999999999

def calculate(arr):
    ax = [0 for i in range(m+1)]
    cost = 0
    for j in arr:
        for i in range(1,m+1):
            ax[i] += a[j][i]
        cost+= a[j][0]
    for j in range(1, m+1):
        if ax[j] < k:
            return 9999999999999999
    return cost

for L in range(0, len(stuff)+1):
    for subset in itertools.combinations(stuff, L):
        
        ans = min(ans, calculate(subset))
        # print(subset, ans)

if ans == 9999999999999999:
    ans = -1

print(ans)



Measured memory_bytes: 9636
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	int dp[n];
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++)
	{
		int a=abs(arr[i]-arr[i-1])+dp[i-1];
		int b=abs(arr[i]-arr[i-2])+dp[i-2];

		dp[i]=min(a,b);
	}
  if(n<=0)
    cout<<0<<endl;
	cout<<dp[n-1]<<endl;

}


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

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

#define MOO(i, a, b) for (int i=a; i<b; i++)
#define M00(i, a) for (int i=0; i<a; i++)
#define MOOd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define M00d(i,a) for (int i = (a)-1; i >= 0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _<< " _ " <<

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ld,ld> pd;
typedef vector<ll,ll> vll;
typedef pair<ll,ll> pll;

const ll MOD = 1e9+7;
int n;
//# ways first i ppl can be paired with bitmask mask
ll DP[1 << 21];
vector<vi> adj(21, vi (21));

ll solve(int mask) {
	if(DP[mask] != -1) return DP[mask];
	int men = __builtin_popcount(mask);
	DP[mask] = 0;
	M00(i, n) {
		if(adj[men-1][i] && ((1 << i) & mask)) {
			DP[mask] += solve(mask ^ (1 << i));
		}
	}
	DP[mask] %= MOD;
	return DP[mask];
}


int main() { FAST
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	cin >> n;
	M00(i, 1 << 21) DP[i] = -1;
	M00(i, n) M00(j, n) cin >> adj[i][j];

	DP[0] = 1;
	//M00(i, n) if(adj[0][i]) DP[1 << i] = 1;

	for(int mask = 1; mask < 1 << n; mask++) {
		int men = __builtin_popcount(mask);
		DP[mask] = 0;
		M00(i, n) {
			if(adj[men-1][i] && ((1 << i) & mask)) {
				DP[mask] += DP[mask ^ (1 << i)];
			}
		}
		DP[mask] %= MOD;
	}

	finish(solve((1 << n) - 1));
}


Measured memory_bytes: 16640
import collections
n,k,q=map(int,input().split())
a = [int(input()) for i in range(q)]
c = collections.Counter(a)

if k-q>0:
    for i in range(n):
        print('Yes')
else:
    r=[k-q]*n
    for i in range(n):
        r[i]+=c[i+1]

    for l in r:
        if l<=0:
            print('No')
        else:
            print('Yes')

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

bitset<2000 * 2000 + 10> b;

int main() {
    int n, x, s = 0;
    cin >> n; b.set(0);
    while (n--) {
        cin >> x; b |= (b << x), s += x;
    }
    for (int i = (s + 1) / 2; ; i++) {
        if (b.test(i)) printf("%d\n", i), exit(0);
    }
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
    int L, A, B, C, D;
    int k, s;
    scanf("%d%d%d%d%d", &L, &A, &B, &C, &D);
    
    k = L - (A + C - 1) / C;
    s = L - (B + D - 1) / D;
    
    if (k < s){
        printf("%d\n", k);
    }
    else {
        printf("%d\n", s);
    }
    
    return (0);
}

Measured memory_bytes: 596
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-12;

	int[] is;
	String line;

	void run(){
		line=sc.next();
		solve();
	}

	void solve(){
		is=new int[24];
		for(int i=0; i<24; i++){
			is[i]=i/4;
		}
//		debug(is);
		for(char c : line.toCharArray()){
			switch(c){
			case 'U':
				up();
				break;
			case 'F':
				front();
				break;
			case 'R':
				right();
				break;
			case 'D':
				down();
				break;
			case 'B':
				back();
				break;
			case 'L':
				left();
				break;
			default:
				break;
			}
		}
		// debug(is);
		int[][] tab={{-1, -1, 0, 1, -1, -1, -1, -1},
				{-1, -1, 3, 2, -1, -1, -1, -1}, {4, 5, 8, 9, 12, 13, 16, 17},
				{7, 6, 11, 10, 15, 14, 19, 18},
				{-1, -1, 20, 21, -1, -1, -1, -1},
				{-1, -1, 23, 22, -1, -1, -1, -1},};
		for(int j=0; j<tab.length; j++){
			for(int i=0; i<tab[j].length; i++){
				print(tab[j][i]==-1?".":"rgybwo".charAt(is[tab[j][i]])+"");
			}
			println("");
		}
	}

	void up(){
		swap(0, 1, 2, 3);
		swap(4, 16, 12, 8);
		swap(5, 17, 13, 9);
	}

	void front(){
		swap(8, 9, 10, 11);
		swap(2, 15, 20, 5);
		swap(3, 12, 21, 6);
	}

	void right(){
		swap(12, 13, 14, 15);
		swap(2, 16, 22, 10);
		swap(1, 19, 21, 9);
	}

	void down(){
		swap(20, 21, 22, 23);
		swap(11, 15, 19, 7);
		swap(10, 14, 18, 6);
	}

	void back(){
		swap(16, 17, 18, 19);
		swap(13, 0, 7, 22);
		swap(14, 1, 4, 23);
	}

	void left(){
		swap(4, 5, 6, 7);
		swap(0, 8, 20, 18);
		swap(3, 11, 23, 17);
	}

	void swap(int a, int b, int c, int d){
		int t=is[d];
		is[d]=is[c];
		is[c]=is[b];
		is[b]=is[a];
		is[a]=t;
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 17328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;



int main(){
    int h,w;
    cin >> h >> w;

    int sx,sy,gx,gy;
    cin >> sy >> sx >> gy >> gx;
    sx--;sy--;gx--;gy--;

    pair<int,int> s = make_pair(sx,sy), g = make_pair(gx,gy); 
    vector<vector<int>> ans(h,vector<int>(w,mod));
    string sur[h];

    for(int i = 0; i < h; i++) cin >> sur[i];

    auto inout = [&](int x,int y){
        if(0 <= x && x < w && 0 <= y && y < h) return true;
        else return false;
    };

    auto add = [&](pair<int,int> now,int dx,int dy){
        pair<int,int> ret = make_pair(now.first+dx,now.second+dy);
        return ret;
    };

    auto answer = [&](pair<int,int> now){
        if(now == g){
            cout << ans[now.second][now.first] << endl;
            return true;
        } else return false;
    };

    queue<pair<int,int>> p,q;

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

    p.push(s);
    ans[s.second][s.first] = 0;

    int can = 0;

    while(!p.empty()){
        while(!p.empty()){
            pair<int,int> now = p.front();
            p.pop();
            bool first = true;
            for(int i = 0; i < 4; i++){
                pair<int,int> nxt = add(now,dx[i],dy[i]);
                if(inout(nxt.first,nxt.second)){
                    if(sur[nxt.second][nxt.first] == '.'){
                        ans[nxt.second][nxt.first] = can;
                        if(answer(nxt)) return 0;
                        p.push(nxt);
                        sur[nxt.second][nxt.first] = '#';
                    } else if(sur[nxt.second][nxt.first] == '#' && first){
                        q.push(now);
                        first = false;
                    }
                }
            }
        }
        can++;
        while(!q.empty()){
            pair<int,int> now = q.front();
            q.pop();
            for(int i = -2; i < 3; i++){
                for(int j = -2; j < 3; j++){
                    pair<int,int> nxt = make_pair(now.first+i,now.second+j);
                    if(inout(nxt.first,nxt.second)){
                        if(sur[nxt.second][nxt.first] == '.'){
                            ans[nxt.second][nxt.first] = can;
                            p.push(nxt);
                            sur[nxt.second][nxt.first] = '#';
                            if(answer(nxt)) return 0;
                        }
                    }
                }
            }
        }
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 9504
#include <iostream>
#include <vector>

using namespace std;

int main() 
{
    string s;
    cin >> s;
    int len, end;
    vector<int> start;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'A') {
            start.push_back(i);
            }   
        if (s[i] == 'Z' && i > end) {
            end = i;
        }   
    }   
        len = end - start[0] + 1;
        cout << len << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>                   // below comment for pbds
#include<ext/pb_ds/assoc_container.hpp>   // to use it make ordered_set
#include<ext/pb_ds/tree_policy.hpp>       // all set fnct + = 1. order_of_key(x); //number 
#define ll long long                      //of element strictly smaller than it;
#define ld long double                    // 2. find_by_order(x),pointer el at x pos after 
using namespace std;                      // sort use as s.f();
using namespace __gnu_pbds;



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);		
	cout.flush();
	ll t=1;
	//cin>>t;
	while(t--)
	{
		ll a,b,c;
		cin>>a>>b>>c;
	 cout<<c<<" "<<a<<" "<<b<<endl;  
	
	}
	
return 0;
}


Measured memory_bytes: 256
H, N = map(int, input().split())
A_list = []
B_list = []
for i in range(N):
    A, B = map(int, input().split())
    A_list.append(A)
    B_list.append(B)

dp = [[10**8+1]*(H) for _ in range(N+1)] # DPテーブルの作成

for i in range(N):
    for j in range(H):
        if j < A_list[i]: # 選ばない時
            #dp[i+1][j] = dp[i][j]
            dp[i+1][j] = min(dp[i][j],B_list[i])
        else: # 選ぶ時
            dp[i+1][j] = min(dp[i][j],dp[i+1][j-A_list[i]]+B_list[i])
        #print(i,j,dp[i+1]) #debug

#print(dp[N])
print(dp[N][H-1])

Measured memory_bytes: 147264
#include<bits/stdc++.h>
using namespace std;
const int N=4000;
const double PI=acos(-1);
typedef complex<double>C;
C sum1,sum2,ans;
int n,L;
int main(){
	cin>>n>>L;
	for(int i=1;i<=n;++i){
		int x;cin>>x;C a(cos(x*PI/L),sin(x*PI/L));
		ans+=sum1*a+sum2*C(n-2*i)*a;
		sum1+=C(2*i,0)*a;sum2+=a;
	}
	long long count=1ll*n*(n-1)*(n-2)/6;
	cout<<setprecision(15)<<ans.real()/count<<' '<<ans.imag()/count<<endl;
	return 0;
}

Measured memory_bytes: 512
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/dp/tasks/dp_t
//参考：
//https://emtubasa.hateblo.jp/entry/2019/03/16/000319

//例えば文字列<><が与えられたとき

//前から1文字目まで見たとき p1<p2 より 
//(1,2)の1通り

//前から2文字目まで見たとき p1<p2,p3<p2より
//(1,3,2),(2,3,1)の2通り

//前から3文字目まで見たとき p1<p2,p3<p2,p3<p4より
//(1,3,2,4),(1,4,2,3),(2,3,1,4),(2,4,1,3),(3,4,1,2)の5通り

//ポイント：
//できている順列の、一番最後についている数をdpのキーにしてみる

//Sのi文字目が<の時：
//新たにpi,pi+1間に大小関係が導入されても、
//p0~piの大小関係については影響を及ぼさないことに注目

//Sのi文字目が>の時：

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

struct mint {
  LL x; 
  mint(LL x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(LL t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
 
struct combination {
  vector<mint> fact, ifact;//factに階乗を計算、ifactはその各々に対する逆元
  combination(LL n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (LL i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (LL i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(LL n,LL k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int N,K;
LL A[100000];

mint ans = 0;
 
void solve(){
	if(K==1) return;
	sort(A,A+N);
	//A[0]~A[i-1]の累積和をaccum_A[i]とおく
	vector<mint> accum_A(N+1,0);
	for(int i=0;i<N;i++) accum_A[i+1] = accum_A[i] + mint(A[i]);

	combination c(((LL)N));
	for(int i=K;i<=N;i++){
		mint a = accum_A[N]-accum_A[i-1];
		mint b = accum_A[N-i+1];
		ans += (a-b)*c(i-2,K-2);
	}
}
 
int main(){
    cin >> N >> K;
    for(int i=0;i<N;i++){
    	cin >> A[i];
    }
 
    solve();
 
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
using namespace std;
int main(){
	int a,b;
	char f;
	cin>>a>>f>>b;
	if(f=='-') cout<<a-b<<endl;
	else cout<<a+b<<endl; 
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N; cin >> N;
	int a[N];
	rep(i, N) cin >> a[i];
	sort(a, a + N);
	if (a[N - 1] - a[0] > 1) {
		cout << "No" << endl;
		return 0;
	}
	else if (a[N - 1] == a[0]) {
		if (N % a[0] == 0 || N - 1 == a[0]) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
		return 0;
	}
	int mincnt = 0;
	int maxcnt = 0;
	rep(i, N) {
		if (a[i] == a[0]) mincnt++;
		else maxcnt++;
	}
	if (mincnt + 1 <= a[N - 1] && a[N - 1] <= mincnt + (maxcnt / 2)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


    return 0;
}


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

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

	int[] A = new int[N];

	for(int i = 0 ; i < N ; i++){
		A[i] = sc.nextInt();
	}
	sc.close();


	Arrays.sort(A);

	int p = 0;
	if(A[N-1]%2 == 1){
		p = (A[N-1]/2)+1;
	}
	else{
		p = (A[N-1]/2);
	}

	int min = 1000000000;
	int aa = 0;
	for(int i = 0 ; i < N ; i++){
		if(min > Math.abs(p-A[i])){
			min = Math.abs(p-A[i]);
			aa = i;
		}
	}
	System.out.println(A[N-1] + " " + A[aa]);
	}
}


Measured memory_bytes: 49576
#include <stdio.h>
#include <math.h>
int a[10],i,n,s;
int summing(int n,int s){
    int ans=0,i,max=0,min=0,m;
    if(n==1){if(s<10 && a[s]==1)return 1; else return 0;}
    else{
        for(i=0,m=n;m>0 && i<10;i++){if(a[i]==1){min+=m*i;m--;if(s<min)return 0;}}
        for(i=9,m=n;m>0 && i>=0;i--){if(a[i]==1){max+=m*i;m--;if(s<=max)break;}}
		if(s>max)return 0;
        for(i=0;i<10;i++){
            if(a[i]==1 && n*i<=s){
                if(n==2){
                    m=s-i*2;
                    if(m>=0 && m<10 && i!=m && a[m]==1)ans++;
                }
                else{
                    a[i]=0;
                    ans+=summing(n-1,s-n*i);
                    a[i]=1;
                }
            }
        }
        return ans;
    }
}
int main(void){
    for(i=0;i<10;i++)a[i]=1;
    while(scanf("%d %d",&n,&s)!=EOF){printf("%d\n",summing(n,s));}
    return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
#define N 200050
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
using namespace std;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n; cin>>n;
    int ans = n/500;
    ans *= 1000;
    n =  n%500;
    int h = n/5; h*=5;
    ans += h;
    cout<<ans;
    
        return 0;
}


Measured memory_bytes: 256