akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=1000007;
const long long INF=1000000009;
long long A[N],D[N];
int main(){
  int n,k;
  cin>>n>>k;
  for(int i=1;i<=n;++i)
    cin>>A[i],D[i]=INF;
  D[1]=0;
  for(int i=1;i<=n;++i){
    for(int j=i;j<=i+k;++j){
        D[j]=min(D[j],D[i]+abs(A[i]-A[j]));
    }
  }
  cout<<D[n];
}


Measured memory_bytes: 5120
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <regex>
#include <stack>
#include <queue>
#include <vector>
#define MAX_N 100
#define INF 10000000

using namespace std;


int n;
string s;
int a[200000];

void solve() {
	for (int i = 0; i < 4; i++) {
		cout << s[i];
	}
	cout << ' ';
	for (int i = 4; i < 12; i++) {
		cout << s[i];
	}
	cout << endl;

}

int main() {
	cin >> s;
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 8e4+5;
int n, m;
queue<int> q;
vector<int>g[200005];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i = 0; i < g[1].size(); i++){
        q.push(g[1][i]);
    }
    while(!q.empty()){
        int t = q.front();
        q.pop();
        for(int i = 0; i < g[t].size(); i++){
            if(g[t][i] == n) {
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 12400
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;

struct ret{
    string name;
    int score;
    int id;
};

bool cmp(ret a,ret b){
    if(a.name!=b.name){
        return a.name < b.name;
    }else{
        return a.score > b. score;
    }
}

ret v[101];


int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        v[i].id = i + 1;
        cin >> v[i].name >> v[i].score;

    }
    sort(v, v + n, cmp);
    for (int i = 0; i < n;i++){
        cout << v[i].id << endl;
    }
    return 0;
}

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

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) begin(v), end(v)

const int N = 1e5 + 5;

int n, X, Y, Z;
struct pt {
  int a, b, c;
  bool operator < (const pt& o) const {
    return a - b > o.a - o.b;
  }
} a[N];

int main(int argc, char const *argv[])
{
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  cin >> X >> Y >> Z;
  n = X + Y + Z;
  for(int i = 1; i <= n; ++i) {
    cin >> a[i].a >> a[i].b >> a[i].c;
  }
  sort(a+1, a+1+n);
  set<ii> goldc, silverc;
  set<int> silveridx;
  ll ans = 0;
  for(int i = 1; i <= X; ++i) {
    goldc.insert(ii(a[i].c - a[i].a, i));
    ans += a[i].a;
  }
  for(int i = X+1; i <= n; ++i) {
    silverc.insert(ii(a[i].c - a[i].b, i));
    silveridx.insert(i);
    ans += a[i].b;
  }
  while(Z--) {
    int first_silver = *silveridx.begin();
    int delta = a[first_silver].a - a[first_silver].b;
    int gold_optimal = goldc.rbegin() -> first + delta;
    int silver_optimal = silverc.rbegin() -> first;
    if(gold_optimal > silver_optimal) {
      int take_gold = goldc.rbegin() -> second;
      ans += goldc.rbegin() -> first + delta;
      goldc.erase(--goldc.end());
      goldc.insert(ii(a[first_silver].c - a[first_silver].a, first_silver));
      silverc.erase(ii(a[first_silver].c - a[first_silver].b, first_silver));
      silveridx.erase(first_silver);
    } else {
      int take_silver = silverc.rbegin() -> second;
      ans += silverc.rbegin() -> first;
      silverc.erase(--silverc.end());
      silveridx.erase(take_silver);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 10752
N = int(input())
a = [int(i) for i in input().split()]
result = 1
delta = 0
for i in range(1,N) :
    if a[i-1] < a[i]:
        ndelta = 1
    elif a[i-1] > a[i]:
        ndelta = -1
    else:
        ndelta = 0
        
    if delta and ndelta and delta != ndelta:
        result += 1
        delta = 0
    elif not delta:
        delta = ndelta
    
print(result)
    
            

Measured memory_bytes: 62832
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<deque>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
template<class T> inline bool chmax(T&a , T b){
    if(a<b){
        a=b; return true;
    }else{
        return false;
    }
}
template<class T> inline bool chmin(T&a , T b){
    if(a>b){
        a=b; return true;
    }else{
        return false;
    }
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll dp[3005][3005];

int main(){
    int n;
    cin >> n;
    int a[3005];
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }

    for(int i=1;i<=n;i++) dp[i][i] = a[i];

    int cnt=1;
    
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n-cnt;j++){
            dp[j][j+cnt] = max(a[j]-dp[j+1][j+cnt], a[j+cnt]-dp[j][j+cnt-1]);
        }
        cnt++;
    }

    cout << dp[1][n] << endl;


}

Measured memory_bytes: 70016
#!/usr/bin/env python
N, M = map(int, input().split())
m = 10**9+7
F = [0]*N
for _ in range(M):
    F[int(input())-1] = 1

a, b = 0, 1
for n in range(N):
    if F[n]:
        a, b = b, 0
    else:
        a, b = b, (a+b) % m
print(b)

Measured memory_bytes: 3828
#include <iostream>
#include <string>
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int K,N,num,temp,t;
int sum = 0;
int counter = 1;
void solve()
{
    temp=K-1;
    sum += K;
    while(sum<N)
    {
        counter++;
        sum += temp;
    }
}
int main()
{
    cin >> N >> K;
    int A[N];
    for(int i=0;i<N;i++)
    {
        cin >> A[i];
    }

    solve();
    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

struct MinimumCostFlow {
	using Flow = int;
	using Cost = int;
	struct Edge {
		int to, rev;
		Flow cap;
		Cost cost;
		Edge() {}
		Edge(int to, int rev, Flow cap, Cost cost) :to(to), rev(rev), cap(cap), cost(cost) {}
	};
	int n;
	vector<vector<Edge>> g;
	vector<int> dist;
	vector<int> prevv, preve;
	MinimumCostFlow(int n) :n(n), g(n), dist(n), prevv(n), preve(n) {}
	void addArc(int from, int to, Flow cap, Cost cost) {
		g[from].emplace_back(to, (int)g[to].size(), cap, cost);
		g[to].emplace_back(from, (int)g[from].size() - 1, 0, -cost);
	}
	// s??????t????????????f???????°??????¨???
	// ??????????????´?????? -1
	Cost minimumCostFlow(int s, int t, Flow f) {
		Cost total = 0;
		while (f > 0) {
			// Bellman-Ford
			fill(dist.begin(), dist.end(), INF);
			dist[s] = 0;
			bool update = true;
			while (update) {
				update = false;
				for (int v = 0; v < n; v++) {
					if (dist[v] == INF)continue;
					for (int i = 0; i < g[v].size(); i++) {
						Edge &e = g[v][i];
						if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
							dist[e.to] = dist[v] + e.cost;
							prevv[e.to] = v;
							preve[e.to] = i;
							update = true;
						}
					}
				}
			}
			// ????????\???????????????
			if (dist[t] == INF)
				return -1;
			// ?????????????????£??????????????????
			int d = f;
			for (int v = t; v != s; v = prevv[v])
				d = min(d, g[prevv[v]][preve[v]].cap);
			f -= d;
			total += d*dist[t];
			for (int v = t; v != s; v = prevv[v]) {
				Edge &e = g[prevv[v]][preve[v]];
				e.cap -= d;
				g[v][e.rev].cap += d;
			}
		}
		return total;
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int N; cin >> N&&N;) {
		;
		vector<int> x(N), y(N), z(N); rep(i, 0, N) {
			cin >> x[i] >> y[i] >> z[i];
		}
		MinimumCostFlow mcf(N + N + 2);
		int s = N + N, t = s + 1;
		rep(i, 0, N) {
			mcf.addArc(s, i, 1, 0);
			mcf.addArc(i + N, t, 1, 0);
		}
		rep(i, 0, N)rep(j, 0, N) {
			if (i == j) {
				mcf.addArc(i, t, 1, x[i] * y[i] * z[i]);
			}
			else {
				vector<int> I{ x[i],y[i],z[i] }, J{ x[j],y[j],z[j] };
				sort(all(I)); sort(all(J));
				if (I[0] < J[0] && I[1] < J[1] && I[2] < J[2]) {
					mcf.addArc(i, N + j, 1, 0);
				}
			}
		}
		cout << mcf.minimumCostFlow(s, t, N) << endl;
	}
	return 0;
}

Measured memory_bytes: 3320
import copy
import sys

N, K = map(int, input().split())
A = list(map(int, input().split()))

def dfs(bitstring):
  if len(bitstring) == N:
    if sum(bitstring) == K:
      cost = 0
      B = copy.deepcopy(A)
      for i in range(1, N):
        if bitstring[i]:
          previousMax = max(B[0:i])
          if previousMax < B[i]:
            continue
          else:
            cost += previousMax - B[i] + 1
            B[i] = previousMax + 1
      return cost
    else:
      return sys.maxsize
  else:
    return min(dfs(bitstring + [False]), dfs(bitstring + [True]))

print(dfs([1]))

Measured memory_bytes: 56792
#include <iostream>

using namespace std;

int main()
{
    int N,i,j,sum=0,k;


    cin>>N;
    int a[N];
    for(k=0;k<N;k++)
    {
        cin>>a[k];
    }
    for(i=0;i<N-1;i++)
    {
        for(j=i+1;j<=N-1;j++)
        {
            sum=sum+(a[i]*a[j]);
        }
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int H,W,h,w;
  while(1){
scanf("%d %d",&H,&W);
 for(h=1;h<=H;h++){
      if(h==1){ 
	for(w=1;w<=W;w++){
	  if(w<W){
	printf("#");
      }
      else if(w==W){
	printf("#\n");
      }
	}}
      else if(h>0&&h<H){
	for(w=1;w<=W;w++){
	  if(w==1){
	  printf("#");
	}
	else if(w>0&&w<W){
	  printf(".");
	}
	else if(w==W){
	  printf("#\n");
	}
      }}
      else if(h==H){
	for(w=1;w<=W;w++){
if(w<W){
	  printf("#");
	}
	else if(w==W){
	  printf("#\n");
	}
      }
      }}
    if(H!=0){
      if(h=H+1){
   printf("\n");
 }
    }
    if(H==0&&W==0){
    break;
    }
 }

  return 0;
}

Measured memory_bytes: 1016
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;

int main(){
    long long n;
    cin >> n;
    vector<long long> a(n);
    for(int i = 0; i < n; ++i) cin >> a[i];
    long long c = 1;
    multiset<long long> s;
    s.insert(a[n - 1]);
    for(int i = n - 2; i >= 0; --i){
        auto now = s.upper_bound(a[i]);
        if(now == s.end()){
            c++;
            s.insert(a[i]);
        }
        else{
 
            s.erase(now);
            s.insert(a[i]);
        }
    }
    cout << c;
}

Measured memory_bytes: 5760
import sys
input = sys.stdin.readline
import numpy as np

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
wv = np.array(wv)
V = max(wv[:, 1])
dp = np.array([float('inf')]*(N*V+1))

dp[0] = 0
for i in range(N):
    w, v = wv[i]
    dp[v:] = np.minimum(dp[v:], dp[:-v]+w)
print(max(np.where(dp<=W)[0]))

Measured memory_bytes: 14800
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
signed main()
{
    int a,b,x;
    double f,result,y;
    cin>>a>>b>>x;
    if(2*x<=a*a*b)
    {
        f=(double)(2*x)/(a*b);
        result= atan(b/f);
        cout<<fixed<<setprecision(7)<<result*180/3.14159265359;
    }
    else
    {
        y=(double)(2*x)/(a*a);
        y=(double)2*b-y;
        result= atan(y/a);
        cout<<fixed<<setprecision(7)<<result*180/3.14159265359;
    }
}

Measured memory_bytes: 256
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
a,b=gsmi

puts a.lcm(b)

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

int main(){
    int N;
    int Alice=0, Bob=0;
    cin >> N;
    vector<int> a(N);
    for (int i=0; i<N; i++) cin >> a.at(i);

    sort(a.begin(), a.end(), greater<int>());

    for (int i=0; i<N; i=i+2){
        Alice += a.at(i);
        if (i!=N-1) Bob += a.at(i+1);
    }

    cout << Alice-Bob << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define ic_a int a;cin>>a;
#define ic_b int b;cin>>b;
#define ic_s string s;cin>>s;
#define Rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000

using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


int main(void) {
	Rapid_pleaseAC_fast;

	int n;
	cin >> n;
	vint l(n), r(n);
	rep(i, n) {
		cin >> l[i] >> r[i];
	}
	int ans = 0;
	rep(i, n) {
		ans += r[i] - l[i] + 1;
	}
	cout << ans << rt;

	please AC;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		if ("+".equalsIgnoreCase(operator)) {
			System.out.println(a + b);
		} else {
			System.out.println(a - b);
		}
		sc.close();
	}
}

Measured memory_bytes: 23380
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

#include <bits/stdc++.h>
using namespace std;

#define NIL -1
#define MAX 25


struct Node{int p,l,r;};
Node A[MAX];
int n;

void Preorder(int u){
  if(u==NIL) return;
  cout<<" "<<u;
  Preorder(A[u].l);
  Preorder(A[u].r);
}

void Inorder(int u){
  if(u==NIL) return;
  Inorder(A[u].l);
  cout<<" "<<u;
  Inorder(A[u].r);
}

void Postorder(int u){
  if(u==NIL) return;
  Postorder(A[u].l);
  Postorder(A[u].r);
  cout<<" "<<u;
} 

int main() {
  cin>>n;
  
  rep(i,n) A[i].p=NIL;
  rep(i,n){
    int a,b,c;
    cin>>a>>b>>c;
    A[a].l=b;
    A[a].r=c;
    A[b].p=a;
    A[c].p=a;
  }
  int root;
  rep(i,n){
    if(A[i].p==NIL) root=i;
  }
  
  cout<<"Preorder"<<endl;
  Preorder(root);
  cout<<endl;
  cout<<"Inorder"<<endl;
  Inorder(root);
  cout<<endl;
  cout<<"Postorder"<<endl;
  Postorder(root);
  cout<<endl;
  
  return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = 3;
  if(a == b) ans--;
  if(b == c) ans--;
  if(a == c) ans--;
  if(ans == 0) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    REP(i, N)cin >> p[i];

    int ans = 0;
    FOR(i, 1, N - 1) {
        if (p[i - 1] <= p[i] && p[i] <= p[i + 1]) {
            ans++;
        }
        else if (p[i - 1] >= p[i] && p[i] >= p[i + 1]) {
            ans++;
        }
    }

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

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, q, last, cnt, sum, ans, d[10000000][2],leng[1000000][2],a[2000000], b[2000000];
string str;
bool f;
double Ans;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 } ,{ 0,-1 } };
struct Edge { LL to, cost; };
vector<Edge>vec[1000000];
vector<Pll>v;
map<string, LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


int main() {
	cin >> n;
	cin >> str;
	rep(i, n) {
		if (str[i] == ')') {
			if (sum == 0) {
				cnt++;
			}
			else
				sum--;
		}
		else {
			sum++;
		}
	}
	rep(i, cnt)
		cout << "(";
	cout << str;
	rep(i, sum)
		cout << ")";
	cout << endl;
	return 0;
}

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

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
	int H, W;
	while (true)
	{
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		REP(h, H)
		{
			REP(w, W)
			{
				if ((h + w) % 2 == 1)
				{
					cout << '.';
				}
				else
				{
					cout << '#';
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


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

template <typename T>
class imos2 {
	int n, m;
	vector<vector<T>> v;
public:
	imos2(int n_, int m_) : n(n_), m(m_), v(n + 1, vector<T>(m + 1)) {}
	T& val(int i, int j) { assert(0 <= i && i < n && 0 <= j && j < m); return v[i + 1][j + 1]; }
	void add(int li, int lj, int ri, int rj, T x) {
		assert(0 <= li && li <= ri && ri <= n);
		assert(0 <= lj && lj <= rj && rj <= m);
		val(li, lj) += x;
		if (ri < n) val(ri, lj) -= x;
		if (rj < m) val(li, rj) -= x;
		if (ri < n && rj < m) val(ri, rj) += x;
	}
	void build() {
		for (int i = 1; i <= n; i++) for (int j = 0; j <= m; j++) v[i][j] += v[i - 1][j];
		for (int i = 0; i <= n; i++) for (int j = 1; j <= m; j++) v[i][j] += v[i][j - 1];
	}
	T sum(int li, int lj, int ri, int rj) {
		assert(0 <= li && li <= ri && ri <= n);
		assert(0 <= lj && lj <= rj && rj <= m);
		return v[ri][rj] - v[ri][lj] - v[li][rj] + v[li][lj];
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N, D;
	cin >> N >> D;
	vector<vector<int>> cnt(D, vector<int>(D));
	for (int i = 0; i < N; i++) {
		int x, y;
		cin >> x >> y;
		cnt[x % D][y % D]++;
	}
	int ma = 0;
	for (int i = 0; i < D; i++) {
		for (int j = 0; j < D; j++) {
			ma = max(ma, cnt[i][j]);
		}
	}
	int x = 0;
	while ((x + 1) * (x + 1) < ma) ++x;
	imos2<int> all1(D * 2, D * 2), all2(D * 2, D * 2);
	for (int i = 0; i < D * 2; i++) {
		for (int j = 0; j < D * 2; j++) {
			all1.val(i, j) = cnt[i % D][j % D] > x * x && cnt[i % D][j % D] <= x * (x + 1);
			all2.val(i, j) = cnt[i % D][j % D] > x * (x + 1);
		}
	}
	all1.build();
	all2.build();
	int sum2 = all2.sum(0, 0, D, D);
	int mi = D - 1;
	for (int i = 0; i < D; i++) {
		for (int j = 0; j < D; j++) {
			int lb = 0, ub = D;
			while (ub - lb > 1) {
				int c = (lb + ub) >> 1;
				if (all2.sum(i, j, i + c, j + c) == sum2
					&& all1.sum(i + c, j + c, i + D, j + D) == 0) {
					ub = c;
				}
				else {
					lb = c;
				}
			}
			mi = min(mi, lb);
		}
	}
	cout << x * D + mi << endl;
	return 0;
}


Measured memory_bytes: 35584
N, W = gets.split.map(&:to_i)

h = Hash.new(0)
h[0] = 0
N.times do 
    f = h.clone
    w, v = gets.split.map(&:to_i)

    h.each do |key, sum|
        if key + w <= W && f[key + w] < sum + v
            f[key + w] = sum + v
        end
    end

    h = f
end

puts h.values.max

Measured memory_bytes: 107356
#include <iostream>

int main()
{

    int a, b;
    std::cin >> a >> b;


    if (a < b){
    std::cout << "a < b\n";
    }else if (a > b){
    std::cout << "a > b\n";
    }else if (a == b){
    std::cout << "a == b\n";
    }
    return 0;
}



Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
	int n,i,a[100000],b[100000];
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
		b[a[i]]=i;
	}
	for(i=1;i<=n;i++){
		printf("%d ",b[i]);
	}
	return 0;
}

Measured memory_bytes: 2444
#include <bits/stdc++.h>
#define N 50001
#define M 100011
#define f first
#define s second
#define INF (1e9)
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
int n,m,T;
vector<PP> G[M]; // to,cost
vector<int> g[M]; 
vector<P> D[M];

priority_queue<PP,vector<PP>,greater<PP> >Q;  
P dijkstra(int a,int b){
  while(!Q.empty()){
    PP t=Q.top();Q.pop();
    int cost=t.f.f,cnt=t.f.s;
    int y=t.s.f, x=t.s.s;
    int pos=g[y][x];
    if(D[y][x]<t.f) continue;
    if(pos==b) return t.f;
    for(int i=0;i<G[pos].size();i++){
      PP e=G[pos][i];
      int ncost=cost+e.f.s,ncnt=cnt;
      int ny=e.s.f,nx=e.s.s;
      if(pos!=a&&(ny!=y||abs(x-nx)!=1)) ncost+=T,ncnt++;
      if(D[ny][nx]>P(ncost,ncnt))
	D[ny][nx]=P(ncost,ncnt),Q.push(PP(D[ny][nx],P(ny,nx)));
    }
  }
  return P(-1,-1);
}

int main(){
  string s,t;
  cin>>m>>T>>s>>t;
  map<string,int> mp;
  mp[s]=n++;
  mp[t]=n++;

  for(int i=0,a;i<m;i++){
    cin>>a;
    D[i].resize(a,P(INF,INF));
    for(int j=0;j<a;j++){
      string str;
      cin>>str;
      if(!mp.count(str))mp[str]=n++;
      if(str==s)D[i][j]=P(0,0);
      if(str==s&&Q.empty())Q.push(PP(P(0,0),P(i,j)));
      g[i].push_back(mp[str]);
    }

    for(int j=0,pre=g[i][0],cost;j<a-1;j++){
      cin>>cost;
      int pos=g[i][j+1];
      G[pre].push_back(PP(P(pos,cost),P(i,j+1)));
      G[pos].push_back(PP(P(pre,cost),P(i,j)));
      pre=pos;
    }
  }

  P ans=dijkstra(0,1);
  if(ans==P(-1,-1)) cout<<-1<<endl;
  else cout<<ans.f<<" "<<ans.s<<endl;
  return 0;
}

Measured memory_bytes: 23408
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;//KIHBR
char a[110],b[110];
int pd(int cd)
{
	if(cd!=5)return 0;
	if(b[0]!='K')return 0;
	if(b[1]!='I')return 0;
	if(b[2]!='H')return 0;
	if(b[3]!='B')return 0;
	if(b[4]!='R')return 0;
	return 1;	
}
int main()
{
	int i=0,anm=0,j=0;
	char t;
	scanf("%s",&a);
	int acd=strlen(a);
	for(int k=0;k<acd;k++)
	{
		if(a[k]!='A')
		{
			b[j++]=a[k];
		}
		else
		{
			int qwertyuiop=k-anm;
			if(qwertyuiop!=0&&qwertyuiop!=3&&qwertyuiop!=4&&qwertyuiop!=5)
			{
				printf("NO");
				return 0;
			}
			if(a[k+1]=='A')
			{
				printf("NO");
				return 0;
			}
			anm++;
		}
	}
	if(pd(j)==0||anm>4)
	{
		printf("NO");
		return 0;
	}
	printf("YES");
	return 0;
}
//0  3
//012345678{...}
//KIHBR
// KIH B R {...}
//AKIHABARA{...}
//AAKIHBR


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define MOD 1000000007
#define f(i,a,n) for(lli i = a; i < n; i++)
#define pb push_back
#define mp make_pair

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

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    int n;
    cin>>n;
    int m;
    cin>>m;
    int arr[n+2];
    for(int i=0;i<=n+1;i++)
    	arr[i]=0;
    for(int i=0;i<m;i++)
    {
    	int a,b;
    	cin>>a>>b;
    	arr[a]+=1;
    	arr[b+1]-=1;
    }
    for(int i=1;i<=n+1;i++)
    {
    	arr[i]=arr[i-1]+arr[i];
    }
    int count = 0;
    for(int i=0;i<n+2;i++)
    {
    	if(arr[i]==m)
    		count++;
    }
    cout<<count;
return 0;
}

Measured memory_bytes: 640
#include <chrono>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

set<int> ok;

int n;

void check(int k) {
    if (k == 1) return;
    int cur = n;
    while (cur % k == 0) cur /= k;
    if (cur % k == 1) ok.insert(k);
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
    #else
//        freopen("capitals.in", "r", stdin);
//        freopen("capitals.out", "w", stdout);
    #endif
    cin >> n;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            check(i);
            check(n / i);
        }
    }
    for (int i = 1; i * i <= (n - 1); i++) {
        if ((n - 1) % i == 0) {
            check(i);
            check((n - 1) / i);
        }
    }
    check(n);
    check(n - 1);
    cout << ok.size();
//    cout << "\n";
//    for (auto k : ok) cout << k << " ";
}
/*
*/


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

int main() {
 int a;cin >>a;
  if(a<1000){
    cout << "ABC" << endl;
  }else{
    cout << "ABD" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int a,b;
    char op;
    cin>>a>>op>>b;
    if(op=='+') cout<<a+b<<endl;
    else cout<<a-b<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int DP[11][1030][331];

int search(int n,int limit,int bits,int sum){
  int i,res = 0;
  if(sum < 0 || limit > 10 || sum > 331){return 0;}
  
  if(DP[n][bits][sum] >= 0){
    return DP[n][bits][sum];
  }
  
  if(n == limit){
    if((sum / n) < 10 && (sum%n) == 0 && (bits & (1U << sum/n)) == 0){
      res = 1;
    }
  }else{
    for(i = 0; i < 10; i++){
      if((bits & (1U << i)) == 0){
	res += search(n+1,limit,bits | (1U << i),sum - i*n);
      }
    }
  }
  
  DP[n][bits][sum] = res;
  return res;
}

int main(int argc,char* argv[]){
  int n,s,bn = -1;
  int x,y,z;
  
  while(scanf("%d %d",&n,&s) != EOF){
    if(n != bn){
      for(x=0;x<11;x++){
	for(y=0;y<1030;y++){
	  for(z=0;z<331;z++){
	    DP[x][y][z]=-1;
	  }
	}
      }
    }
    printf("%d\n",search(1,n,0,s));
    bn = n;
  }
  
  return 0;
  
}

Measured memory_bytes: 0
#include<stdio.h>


    int main()
    {
        int a,b,c,x,y,z;

        scanf("%d %d %d",&a,&b,&c);

        x=a;
        y=b;
        z=c;

        a=z;
        b=x;
        c=y;

        printf("%d %d %d\n",a,b,c);



    }

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


int main() {
 int N;
 cin >> N;
  int x=0;
  int num;
  for (int i=1; i < N; i++){
  num = (N-1)/i;
    x = x + num;
  } 
    cout << x << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
 
#define cinsc ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOR(i,k,n)  for(int64 i=k;i<(int64)n;i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define FOREACHr(it, l) for (auto it = l.rbegin(); it != l.rend(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define SQ(x) ((x)*(x))
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
 
//ONLINE_JUDGE   LOCAL
 
int64 powr(int64 x,int64 y,int64 p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0){   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
} 
 
void  in_o(){
#ifndef LOCAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	cinsc;
}


int main(){
//	in_o();
	int n;
	cin>>n;
	deque <int> q;

	FOR(i,0,n){
		int x;
		cin>>x;
		if(i%2)
			q.push_front(x);
		else
			q.push_back(x);
	}
	if(!(n%2))
		FOREACH(it,q){
			cout<<*it<<" ";
		}
	else
		FOREACHr(it,q){
			cout<<*it<<" ";
		}
	return 0;
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  ll H, W;
  cin >> H >> W;

  ll total = H * W;

  if(H == 1 || W == 1){
    cout << 1 << endl;
  }else{
    cout << (total + 1) / 2 << endl;
  }


  return 0;
}


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

using namespace std;

long H2T(long h, long T) {
    return T - h * 0.006;
}

int main()
{
    long N, T, A;
    long min = LONG_MAX, opp, h, index;
    
    cin >> N >> T >> A;
    
    opp = (T-A) / 0.006;
    
    for (long i = 1; i < N+1; i++) {
        cin >> h;
       if (min > abs(opp - h)) {
           min = abs(opp - h);
           index = i;
       }
    }

    cout << index << endl;
    
    return 0;   
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
using namespace std;
 
 template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
const double EPS=0.00001;


int main(){
    int N;cin>>N;
    vector<LL>a(N);
    REP(i,N)cin>>a[i];
    LL res=LONG_LONG_MAX;
    FOR(i,-100,101){
        LL tmp=0;
        REP(j,N)tmp+=(i-a[j])*(i-a[j]);
        res=min(res,tmp);
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
import math

n,m = map(int,input().split())
ans = 0
for i in range(1,int(math.sqrt(m))+1):
    if m%i == 0 and i <= m/n:
        if ans < i:
            ans = i
    k = m//i
    if m%k == 0 and k <= m/n:
        if ans < k:
            ans = k

print(ans)

Measured memory_bytes: 39024
import java.util.Scanner;

class Main {

    int n, k;
    long[] x, y;

    void solve() {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        k = in.nextInt();
        x = new long[n];
        y = new long[n];
        for(int i = 0; i < n; i++) {
            x[i] = in.nextInt();
            y[i] = in.nextInt();
        }
        long ans = Long.MAX_VALUE;
        for(int a = 0; a < n; a++) {
            for(int b = 0; b < n; b++) {
                for(int c = 0; c < n; c++) {
                    for(int d = 0; d < n; d++) {
                        long mx = Math.min(Math.min(x[a], x[b]), Math.min(x[c], x[d]));
                        long my = Math.min(Math.min(y[a], y[b]), Math.min(y[c], y[d]));
                        long Mx = Math.max(Math.max(x[a], x[b]), Math.max(x[c], x[d]));
                        long My = Math.max(Math.max(y[a], y[b]), Math.max(y[c], y[d]));
                        if(count(mx, my, Mx, My) >= k) {
                            ans = Math.min((Mx - mx) * (My - my), ans);
                        }
                    }
                }
            }
        }
        System.out.println(ans);
    }
    int count(long mx, long my, long Mx, long My) {
        int c = 0;
        for(int i = 0; i < n; i++) {
            if(mx <= x[i] && x[i] <= Mx && my <= y[i] && y[i] <= My) {
                c++;
            }
        }
        return c;
    }

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


Measured memory_bytes: 25044
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>

using namespace std;
typedef long long ll;

int main()
{

    ll a;
    cin >> a;

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

    sort(b, b + a);

    for (int i = 0; i < (a - 1); i++)
    {
        b[i + 1] = (b[i] + b[i + 1]) / 2;
    }

    // cout << fixed;
    // cout << setprecision(14);
    cout << b[a - 1] << endl;
}

Measured memory_bytes: 256
int main(){
  int n, i, j, tem;
  scanf("%d",&n);
  int A[n];
  for(i = 0; i < n; i++) scanf("%d", &A[i]);
  for(j = 0; j < n; j++){
    if(j == n-1) printf("%d",A[j]);
    else printf("%d ",A[j]);
  }
  printf("\n");
  for(i = 1; i < n; i++){
    tem = A[i];
    j = i-1;
    while(j >= 0 && A[j] >tem){
    A[j+1] = A[j];
      j--;
    }
    A[j+1] = tem;
    for(j = 0; j < n; j++){
      if(j == n-1) printf("%d",A[j]);
      else printf("%d ",A[j]);
    }
    printf("\n");
  }
  return 0;
}



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


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

    string s;
    cin>>s;
    string yaki="YAKI";
    if(s.size()<4){
        cout<<"No"<<endl;
        return 0;
    }
    bool ok=true;
    for(int i=0;i<4;i++){
        if(s[i]!=yaki[i]) ok=false;
    }
    if(ok){
        cout<<"Yes"<<endl;
        return 0;
    }
    else cout<<"No"<<endl;
    
    
}

Measured memory_bytes: 256
import itertools

N = int(input())
N_data = [ i for i in range(1,1+ N) ]
P = tuple(map(int,input().split(" ")))
Q = tuple(map(int,input().split(" ")))

permutation_list = list(itertools.permutations(N_data,N))

def cal(data):
    for i in range(len(permutation_list)):
        if data  == permutation_list[i]:
            return i + 1

a = cal(P)
b = cal(Q)

print(abs(a-b))


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

int main() {
  long long N, a = 26, k = 1;
  cin >> N;
  while(N > a) {
    N -= a;
    a *= 26;
    k++;
  }
  N--;
  for(int i = 0;i < k;i++) {
    a /= 26;
    int b = N / a;
    cout << (char)('a' + b);
    N %= a;
  }
  cout << endl;
}

Measured memory_bytes: 3648
#include<cstdio>
long n,k,m,j,p,i,f[333][333][333];main(){scanf("%d%d%d",&n,&k,&m);for(f[i=0][1][0]=1;i<=n;++i)for(j=0;k/++j;)for(p=i;~p;--p)(f[i+1][j][p]+=f[i][j][p]*(p+1))%=m,((p?f[i][j][p-1]:f[i][j+1][i])+=f[i][j][p])%=m;printf("%d",f[n][k+1][n]);}

Measured memory_bytes: 262144
#include<bits/stdc++.h>
#define f first
#define s second
#define inf 999999999999
#define N  500009
#define M  (L+R)/2
#define ll long long
#define pb push_back
using namespace std;

ll a,b;

int main()
{

	ios::sync_with_stdio(0);
	
	cin>>a>>b;
	
	if(b%a==0)cout<<a+b<<endl;
	else
	cout<<b-a<<endl;

return 0;
}






Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i,n) FOR(i,0,n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main(void){
	ll dp[4][2001];
	fill_n(*dp, 4*2001, 0);
	//????????????
	rep(i, 1001)dp[0][i] = 1;

	for(int i = 1; i <= 3; i++)
		for(int j = 2000; j >= 0; j--)
			for(int k = 0; k <= 1000; k++){
				if(j-k < 0)break;
				dp[i][j] += dp[i - 1][j - k];
			}

	int n;
	while(cin >> n){
		if(n > 2000)n -= 4000;
		FIN(dp[3][abs(n)]);
	}

	return 0;
}

Measured memory_bytes: 1220
def main():
    import sys,bisect
    input = sys.stdin.readline

    n = int(input())
    s = input()
    q = int(input())
    k_list = tuple(map(int,input().split()))
    
    for k in k_list:
        res = 0
        p = 0
        cnt = 0
        q = 0
        for i in range(n):
            if i >= k:
                if s[i-k] == 'D':
                    cnt -= 1
                    p -= q
                elif s[i-k] == 'M':
                    q -= 1

            if s[i] == 'D':
                cnt += 1
            elif s[i] == 'M':
                p += cnt
                q += 1
            elif s[i] == 'C':
                res += p
        print(res)



if __name__ == '__main__':
    main()

Measured memory_bytes: 59628
def main():
    N, M, X = map(int,input().split())
    book = [list(map(int,input().split())) for _ in range(N)]

    skill = [0]*M
    get_skill = [0]*M
    money = 0

    ans = 99999999
    back = []

    for i in range(2**N):
        #bit全探索
        for j in range(N):
            if ( (i>>j)&1 ):
                back.append(book[j])
        #print(back)

        for A in back:
            #print(A)
            money += A[0]
            for j in range(1,M+1):
                skill[j-1] += A[j]

        #print(skill)

        for k in range(M):
            if skill[k] >= X:
                get_skill[k] += 1

        if 0 not in get_skill:
            if money < ans:
                ans = money

        skill = [0]*M
        get_skill = [0]*M
        money = 0
        back = []

    if ans == 99999999:
        ans = -1
        return ans
    else:
        return ans

print(main())


Measured memory_bytes: 9236
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<'YES'<<endl;}else{cout<<'NO'<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

vector<string> v;

int main() {
	int n;
	float r=0;
	cin>>n;
	float a[n];
	rep(i,n)cin>>a[i];
	sort(a,a+n);
	rep(i,n-1){
		a[i+1]=(a[i]+a[i+1])/2;
	}
	printf("%.9f",a[n-1]);
	return 0;
}


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

#define MX 100050
#define INF 0x7f7f7f7f7f7f7f7fll
typedef long long ll;
struct edge {
	int v; ll w;
	edge(int v = 0, ll w = 0) : v(v), w(w) {}
	bool operator < (const edge& rhs) const { return w > rhs.w; }
};

vector<edge> g[MX];
ll d[MX];
bool vis[MX];

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i = 2; i <= n; i++) g[i].push_back(edge(i - 1, 0));
	while(m--) {
		int l, r, c;
		scanf("%d%d%d", &l, &r, &c);
		g[l].push_back(edge(r, c));
	}
	priority_queue<edge> pq;
	pq.push(edge(1, 0));
	for(int i = 2; i <= n; i++) d[i] = INF;
	
	while(pq.size()) {
		edge e = pq.top(); pq.pop();
		int u = e.v;
		if(vis[u]) continue;
		vis[u] = true;
		
		for(auto e : g[u])
			if(d[e.v] > d[u] + e.w) {
				d[e.v] = d[u] + e.w;
				pq.push(edge(e.v, d[e.v]));
			}
	}
	if(d[n] == INF) puts("-1");
	else printf("%lld\n", d[n]);
	return 0;
}


Measured memory_bytes: 10232
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

inline int read() {
    int x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while('0' <= c && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

int main() {
    int x = read();
    int a = (x / 500) * 1000;
    x %= 500;
    int b = (x / 5) * 5;
    cout << a + b << endl;
    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define ll long long int
#define sp ' '
#define intmax 2147483647
#define intmin –2147483648
#define llmax 9223372036854775807
#define llmin -9223372036854775808
using namespace std;

int n;
int A[100000];
ll a,b;

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	ll g = gcd(x, y);
	return x / g * y;
}

int main(){
	cin >> n;
	lp(n)
		cin >> A[i];
	sort(A, A + n);
	a = b = 0;
	lp(n-1){
		if (A[i] == A[i + 1]) {
			a = b;
			b = A[i];
			i++;
		}	
	}
	cout << a*b << endl;
}

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

int main(){
  int i,o=0;
  string s;
  cin>>s;
  for(i=0;i<s.size();i++){
    if(s[i]=='o') o++;
  }
  if((15-s.size())+o>=8) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}

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

using namespace std;

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

int main(){
	int num, a, b, c; cin >> a >> b >> c;
	num = 100 * a + 10 * b + c;
	if(num % 4) cout << "NO" << endl;
	else cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int n = scan.nextInt();
		HashSet<Integer> set = new HashSet<>();
		for(int i = 0;i < n; ++i){
			set.add(scan.nextInt());
		}
		int diff = 99999;
		int ans  = x;
		for(int i = 0;i <= 101; ++i){
			if(!set.contains(i)){
				if(Math.abs(i-x) < diff){
					ans = i;
					diff = Math.abs(i-x);
				}
			}
		}
		System.out.print(ans);
	}
}


Measured memory_bytes: 35736
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[211],ans=0;
	cin>>n;
	for(int i=0;i<2*n;i++)
		cin>>a[i];
	sort(a,a+(2*n));
	for(int i=0;i<2*n;i+=2)
		ans+=min(a[i],a[i+1]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;
int main(){ 
   int ans=0;
   int x;
   cin>>x;
   for(int i=1;i<=x;i++){
      for(int j=2;j<=1000;j++){
         int m=pow(i,j);
         if(m<=x){ 
            ans=max(ans,m);
            
         }
         else{
            break;
         }
      }
   }
   cout<<ans;

   

   
      return 0;
}

Measured memory_bytes: 256