akhauriyash/Code-Regression huggingface dataset:
/*
        ######## ##   ## #######          ##########
           ##    ##   ## ##                 ##    ##
           ##    ####### ######             ##    ##
           ##    ##   ## ##                 ##    ##
           ##    ##   ## ####### ######## ##########
    */
    #include<bits/stdc++.h>
    #include <iomanip>
    #define int         long long
    #define ll             long long
    #define pb          push_back
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define vii         std::vector<vector<int> > v;
    #define all(a)      (a).begin(),(a).end()
    #define F           first
    #define S           second
    #define sz(x)       (int)x.size()
    #define hell        1000000007
    #define rep(i,a,b)    for(int i=a;i<b;i++)
    #define lbnd        lower_bound
    #define ubnd        upper_bound
    #define bs          binary_search
    #define mp          make_pair
    #define maxc(v)     max_element(all(v))
    #define minc(v)     min_element(all(v))
    #define endl        "\n"
    using namespace std;
    #define N  100005
    //#define M  1000003
    #define rn return
    #define B 100000000
    int modularExponentiation(int x,int n,int M = hell)
	{
    	if(n==0)
        	return 1;
    	else if(n%2 == 0)
        	return modularExponentiation((x*x)%M,n/2,M);
    	else
        	return (x*modularExponentiation((x*x)%M,(n-1)/2,M))%M;

	}
	int abs(int a, int b){
        if(a>b) return a-b;
        else return b-a;
    }
    void solve();
    signed main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int TESTS=1;
        //cin>>TESTS;
        while(TESTS--)
        {
            solve();
        }
        return 0;
    }
    void solve(){
    	string s,t;
    	cin>>s>>t;
    	int n = s.size(), m = t.size();
    	int dp[n+1][m+1];
    	rep(i,0,n+1){
    		rep(j,0,m+1){
    			if(i==0 || j==0) dp[i][j] = 0;
    			else{
    				if(s[i-1]==t[j-1]) dp[i][j] = dp[i-1][j-1]+1;
    				else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
    			}
    		}
    	}
    	int l = dp[n][m];
    	char v[l+1];
    	v[l] = '\0';
    	int i = n, j = m;
    	while (i > 0 && j > 0) 
   { 
      // If current character in X[] and Y are same, then 
      // current character is part of LCS 
      if (s[i-1] == t[j-1]) 
      { 
          v[l-1] = s[i-1]; // Put current character in result 
          i--; j--; l--;     // reduce values of i, j and index 
      } 
  
      // If not same, then find the larger of two and 
      // go in the direction of larger value 
      else if (dp[i-1][j] > dp[i][j-1]) 
         i--; 
      else
         j--; 
   }
    	//rep(i,0,dp[n][m]) cout<<v[i];
    	cout<<v<<endl;
    }

Measured memory_bytes: 70656
N,X,Y = map(int,input().split())
g = [[] for _ in range(N+1)]
for i in range(1,N+1):
    if i != 1:
        g[i].append(i-1)
    if i != N:
        g[i].append(i+1)
g[X].append(Y)
g[Y].append(X)
from collections import deque
answer = [0]*(N+1)
for i in range(1,N+1):
    q = deque([i])
    d = [None]*(N+1)
    d[i] = 0
    while q:
        p = q.popleft()
        for j in g[p]:
            if d[j] == None:
                d[j] = d[p]+1
                q.append(j)
    for k in d[1:]:
        answer[k] += 1
for l in answer[1:-1]:
    print(l//2)

Measured memory_bytes: 77136
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
#define ll long long
#define re register
#define pb push_back
#define fi first
#define se second
const int N=1e6+10;
const int M=1e6;
const int mod7=1e9+7;
const int mod=1e9+7;
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
void read(ll &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
ll quickmod(ll x,ll y)
{
    ll res=1,base=x;
    while(y)
    {
        if(y&1) res=res*base%mod;
        base=base*base%mod;
        y>>=1;
    }
    return res;
}
int prim[N],cnt;
ll phi[N];
bool vis[N];
void init()
{
    phi[1]=1;
    for(re int i=2;i<=M;i++)
    {
        if(!vis[i]) prim[++cnt]=i,phi[i]=i-1;
        for(re int j=1;j<=cnt&&i*prim[j]<=M;j++)
        {
            vis[i*prim[j]]=1;
            if(i%prim[j]==0)
            {
                phi[i*prim[j]]=phi[i]*prim[j];
                break;
            }
            phi[i*prim[j]]=phi[i]*(prim[j]-1);
        }
    }
    for(re int i=1;i<=M;i++) phi[i]+=phi[i-1],phi[i];
}
ll solve(int n,int k)
{
    ll res=0;
    for(re int l=1,r;l<=n;l=r+1)
    {
        r=min(n/(n/l),n);
        res+=1ll*(phi[r]-phi[l-1])*quickmod(n/l,k);
        res%=mod;
    }
    return res;
}
int main()
{
    init();
    int n,k;read(n),read(k);
    printf("%lld",solve(k,n));
    return 0;
}

Measured memory_bytes: 12848
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

int gcd(int x, int y) {
  if (x < y) swap(x, y);
  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}

/*迷路
const int INF = 50;

typedef pair<int,int> P;
char field[52][52];
int d[51][51];
int r,c;
int sx,sy;
int gx,gy;

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

int bfs(){
    queue<P> que;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            d[i+1][j+1] = INF;
        }
    }
    que.push(P(sy,sx));
    d[sy][sx]=0;
while(que.size()){
    P p=que.front();
    que.pop();
    if(p.second==gx&&p.first==gy) break;
    for(int i=0;i<4;i++){
        int nx=p.second+dx[i];
        int ny=p.first+dy[i];

        if(1<=nx&&nx<=c&&1<=ny&&ny<=r&&field[ny][nx]!='#'&&d[ny][nx]==INF){
            que.push(P(ny,nx));
            d[ny][nx] = d[p.first][p.second] + 1;
        }
    }
}
return d[gy][gx];
}
*/

int main(){
  int n; cin>>n;
  ll xx; cin>>xx;
  ll x[n+1];
  x[0] = xx;
  for(int i = 0; i<n; i++) cin>>x[i+1];
  sort(x,x+n+1);
  ll d[n];
  for(int i = 0; i<n; i++){
    d[i] = x[i+1] - x[i];
  }
  ll z;
  z = d[0];
  for(int i = 1; i<n; i++){
    z = gcd(z,d[i]);
  }
cout<<z<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, M;
string S[50];
int D[50][50];

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


void solve() {
	cin >> N >> M;
	int cnt = 0;
	rep(i, 0, N) {
		cin >> S[i];
		rep(j, 0, M) {
			if(S[i][j] == '#') cnt++;
		}
	}
	rep(i, 0, N) 
		rep(j, 0, M) D[i][j] = inf;

	D[0][0] = 1;
	queue<pi> que;
	que.push(pi(0, 0));

	while(!que.empty()) {
		pi p = que.front(); que.pop();
		int x = p.fst, y = p.sec;
		rep(i, 0, 4) {
			int nx = dx[i] + x, ny = dy[i] + y;
			if(nx < 0 || nx >= N || ny < 0 || ny >= M) continue;
			if(S[nx][ny] == '.' && D[nx][ny] == inf) {
				D[nx][ny] = D[x][y] + 1;
				que.push(pi(nx, ny));
			}
		}
	}
	if(D[N - 1][M - 1] == inf) {
		cout << -1 << "\n";
	}
	else cout << N * M - cnt - D[N - 1][M - 1] << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#include <memory.h>
#include <algorithm>
#define case        printf("Case %d: ",++tc);
#define read        freopen("tst.txt","r",stdin)
#define write       freopen("out.txt","w",stdout)
typedef long long ll;
using namespace std;
#define pi acos(-1)
int ara[4],ar[30];
bool check(int a,int b,int c){
    ara[0] = a;
    ara[1] = b;
    ara[2] = c;
    sort(ara,ara+3);
    return ara[1]==a;
}


main(){
int t,tc = 0;
int n;
cin>>n;
for(int i = 0; i<n; i++)    cin>>ar[i];

int ans = 0;


for(int i = 1; i<n-1; i++){
    if(check(ar[i],ar[i-1],ar[i+1]))    ans++;
}
/*
if(check(ar[0],ar[1],ar[2]))    ans++;
if(check(ar[n-1],ar[n-2],ar[n-3]))   ans++;
*/
cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 256
def bubble_sort(a)
  i = 0
  n = a.length
  flag = true
  sw = 0
  while flag do
    flag = false
    j = n - 1
    while j > i do
      if a[j] < a[j - 1]
        t = a[j]
        a[j] = a[j - 1]
        a[j - 1] = t
        flag = true
        sw += 1
      end
      j -= 1
    end
    i += 1
  end
  i = 0
  while i < n do
    print " " if i > 0
    print a[i]
    i += 1
  end
  puts ""
  puts sw
end

n = gets.to_i
a = gets.split.map(&:to_i)

bubble_sort(a)



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

struct UnionFind {
	int sz;
	vector<int> par;
	UnionFind(int a) : sz(a), par(sz, -1) {}
	int root(int x) { return par[x] < 0 ? x : par[x] = root(par[x]);}
	bool same(int x, int y) { return root(x) == root(y);}
	bool unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (size(x) < size(y)) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}
	int size(int x) { return -par[root(x)];}
	int size() { return sz;}
};

int main() {
    int n, m, q; cin >> n >> m;
    UnionFind U(n+1);
    while (m--) {
        int a, b; cin >> a >> b;
        U.unite(a, b);
    }
    cin >> q;
    while (q--) {
        int a, b; cin >> a >> b;
        if (U.same(a, b)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define N 15
#define ll long long
int n,cnt[N][N];ll ans;
int main()
{
	scanf("%d",&n);
	for(int i=1,x,y;i<=n;++i)
	{
		y=i%10;for(int j=i;j;j/=10) x=j;
		++cnt[x][y];
	}
	for(int i=1;i<=9;++i) for(int j=1;j<=9;++j)
		ans+=1ll*cnt[i][j]*cnt[j][i];
	printf("%lld\n",ans);return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

N, M = map(int, readline().split())
H = list(map(int, readline().split()))
AB = [tuple(map(int, readline().split())) for i in range(M)]

edges = [[] for i in range(N)]
for a,b in AB:
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)

a = [None] * N

def test(n):
    for t in edges[n]:
        if H[t] > H[n]:
            a[n] = False
            return
        elif H[t] == H[n]:
            a[t] = a[n] = False
            return
        else:
            a[t] = False
    a[n] = True
    return

for i in range(N):
    if a[i] is None:
        test(i)

print(a.count(True))

Measured memory_bytes: 43792
# abc151_a.py
# https://atcoder.jp/contests/abc151/tasks/abc151_a

# A - Next Alphabet /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# z でない英小文字 Cが与えられます。アルファベット順で Cの次の文字を出力してください。

# 制約
#     Cは z でない英小文字

# 入力
# 入力は以下の形式で標準入力から与えられる。
# C

# 出力
# アルファベット順で Cの次の文字を出力せよ。

# 入力例 1
# a

# 出力例 1
# b

# a の次は b です。

# 入力例 2
# y

# 出力例 2
# z

# y の次は z です。


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    C = lines[0]
    # N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))
    alp = 'abcdefghijklmnopqrstuvwxyz'

    for i in range(25):
        if alp[i] == C:
            result = alp[i+1]

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['a']
        lines_export = ['b']
    if pattern == 2:
        lines_input = ['y']
        lines_export = ['z']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9012
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    Map<String,String> map = new HashMap<>();
    String[] input = sc.next().split("");
    for(String c : input){
      if(map.get(c)!=null ){
        System.out.println("no");
        return;
      }else{
        map.put(c,"add");
      }
    }
    System.out.println("yes");
  }
}

Measured memory_bytes: 21844
#include<stdio.h>
int main(){
  int n,cnt=0,swap=0;
  scanf("%d",&n);
  int i,p[n+10];
  for(i=1;i<=n;i++)
    scanf("%d",&p[i]);
  for(i=1;i<=n;i++){
    if(p[i]==i)
      continue;
    else{
      cnt++;
      if(p[p[i]]==i)
        swap++;
    }
  }
  if(swap >2){
    printf("NO\n");
    return 0;
  }

  if(swap==cnt)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include<limits.h>
#include<stdio.h>
#include<cstring>
#include<string>
using namespace  std;
typedef long long ll;
typedef long double ld;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define fi first
#define se second
#define rsz(a,n) a.resize(n)
#define test(t) ll t;cin>>t;while(t--)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define fillv(a,k) memset(a,k,sizeof(a))
#define leadzero(a) __builtin_clz(a) //count leading zeros
#define trailzero(a) __builtin_ctz(a) //count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout<<endl
#define sp cout<<" "
#define spaceprint(a,i,s,n) {forsn(i,s,n) { cout<<a[i]; sp;}}
#define lineprint(a,i,s,n) {forsn(i,s,n) {cout<<a[i]; ln;}}
#define maxe(a) *max_element(a.begin(),a.end())
#define maxi(a) max_element(a.begin(),a.end())-a.begin()
#define mine(a) *min_element(a.begin(),a.end())
#define mini(a) min_element(a.begin(),a.end())-a.begin()
#define all(c) c.begin(),c.end()
#define trav(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element)  (find(all(container),element) != container.end())// check the presence of element
//copy(from_begin, from_end, to_begin); copy function
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<string> vs;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
typedef map<ll,ll> m64;
const int LIM = 1e5+5, MOD =  1e9+7;
#define sumv(v) accumulate(all(v),ll(0))
#define productv(v) accumulate(all(v), ll(1), multiplies< ll >())
ll gcd(ll a, ll b) { if(b == 0) return a; return gcd(b, a % b); }
ll fastpowMOD(ll a, ll p,ll MOD){ if(p==0) return 1; ll z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }
bool seive[100005];
ll dp[10005][105];
void SieveOfEratosthenes(ll n)
{ memset(seive, true, sizeof(seive)); for (ll p=2; p*p<=n; p++) if (seive[p] == true) for (ll i=p*p; i<=n; i += p) seive[i] = false; }
int main()
{
    fast;
    ll h,w,i,k,n;
    cin>>h>>w>>n;
    if(h>w)
        swap(h,w);
    ll l=0;
    ll r=w;
    while(l<r)
    {
        ll mid=(l+r)/2;
        ll k=mid*(h+w)-mid*mid;
        if(k>=n)
        {
            r=mid;
        }
        else
        {
            l=mid+1;
        }
    }
    ll k1=(n+w-1)/w;
    cout<<min(2*l,k1);

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int cnt[1000006];
int vis[1000006];
int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    int gc=0;
    bool chk=0;
    int cnt1=0;
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        gc=__gcd(gc,x);
        cnt[x]++;
        if(cnt[x]>1 && x!=1)
        {
            chk=1;
        }
        if(x%2==0)
            cnt1++;
        if(cnt1>1)
            chk=1;
    }
    if(chk==0)
    {
        for(int i=2; i<=1e6; i+=2)
        {
            vis[i]=1;
        }
        for(int i=3; i<=1e6; i+=2)
        {
            int ase=0;
            for(int j=i; j<=1e6; j+=i)
            {
                ase += cnt[j];
                vis[j]=1;
            }
            if(ase>1)
            {
                chk=1;
                break;
            }
        }
    }
    if(gc!=1)
    {
        cout<<"not coprime\n";
    }
    else
    {
        if(chk==0)
        {
            cout<<"pairwise coprime\n";
        }
        else
        {
            cout<<"setwise coprime\n";
        }
    }
    return 0;
}


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

const int MAXN = 100 + 5;

int N, mx;
int A[MAXN], cnt[MAXN];

class noSolution: std::exception
{

};

void findSolution()
{
	if (mx & 1)
	{
		int loBound = mx - mx / 2;

		for (int i = loBound; i <= mx; i++)
		{
			cnt[i] -= 2;
			if (cnt[i] < 0)
				throw noSolution();
		}
		for (int i = loBound; i > 0; i--)
			if (cnt[i])
				throw noSolution();
	}
	else
	{
		int half = mx / 2;
		if (!cnt[half])
			throw noSolution();
		cnt[half] --;

		for (int i = half + 1; i <= mx; i++)
		{
			cnt[i] -= 2;
			if (cnt[i] < 0)
				throw noSolution();
		}
		for (int i = half; i > 0; i--)
			if (cnt[i])
				throw noSolution();

	}
}

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

	cin >> N;
	for (int i = 1; i <= N; i++)
		cin >> A[i], mx = max(mx, A[i]), cnt[A[i]]++;

	try
	{
		findSolution();
	}
	catch(noSolution &x)
	{
		cout << "Impossible" << endl ;
		return 0;
	}
	cout << "Possible" << endl ;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const long long INF = 1LL << 60;
const double PI = 3.14159265358979323846;
typedef long long ll;

int main(void) {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  sort(A.begin(), A.end());
  int aMax = A[N - 1];
  vector<bool> dp(aMax + 1);
  for (int i = 1; i <= aMax; i++) dp[i] = true;
  for (int i = 0; i < N; i++) {
    int x = A[i];
    if (A[i] == A[i + 1]) dp[A[i]] = false;
    while (x + A[i] <= aMax) {
      x += A[i];
      dp[x] = false;
    }
    while (A[i] == A[i + 1]) i++;
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (dp[A[i]]) ans++;
  }
  cout << ans << endl;
  return 0;
}

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


using namespace std;



int main()
{
    
    int cat,x,num;

    scanf("%d%d%d",&cat,&x,&num);

    int maximum = cat+x;

    if(num>=cat && num<=maximum)
        printf("YES\n");

     else
        printf("NO\n");

 

   return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if (s.equals("Sunny")) System.out.println("Cloudy");
        if (s.equals("Cloudy")) System.out.println("Rainy");
        if (s.equals("Rainy")) System.out.println("Sunny");
    }
}

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

int main()
{
    int N, M;
    cin >> N >> M;

    vector<int> H(N + 1, 0);
    for (int i = 1; i <= N; i++) cin >> H[i];

    Graph G(N + 1);
    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }


    int cnt = 0;
    for (int i = 1; i <= N; i++)
    {
        int flag = 1;
        for (auto n : G[i])
        {
            if (H[n] >= H[i])
                flag = 0;
        }
        if (flag == 1)
            cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 8780
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String[] P = new String[N];
		String[] Q = new String[N];
		for(int i = 0; i < N; i++) {
			P[i] = sc.next();
		}
		for(int i = 0; i < N; i++) {
			Q[i] = sc.next();
		}
		sc.close();
		String[] data = new String[N];
		for(int i = 0; i < N; i++) {
			data[i] = String.valueOf(i + 1);
		}
		// 順列の作成
		List<List<String>> perm = get(data);
		// 検索
		int p = perm.indexOf(Arrays.asList(P)) + 1;
		int q = perm.indexOf(Arrays.asList(Q)) + 1;
		System.out.println(Math.abs(p - q));
	}

	static List<List<String>> get(String[] data) {
		return permutation(data);
	}

    // static void print(String[] data) {
    //     int number = 0;
    //     for (List<String> comb : permutation(data)) {
    //         System.out.println("#" + ++number + " " + Arrays.asList(comb));
    //     }
	// }
	
    static <T> List<List<T>> permutation(T[] data) {
        List<List<T>> result = new ArrayList<List<T>>();
		// 候補の配列
		List<T> candidate = new ArrayList<>(Arrays.asList(data));
		// 順列の配列
		List<T> perm = new ArrayList<>();
		permutation(candidate, perm, result);
        return result;
    }
	
    static <T> void permutation(List<T> candidate, List<T> perm, List<List<T>> result) {
		if(candidate.size() == 0) {
			// System.out.println("##" + perm.toString());
			result.add(perm);
		}
		for(int i = 0; i < candidate.size(); i++) {
			List<T> p = new ArrayList<>(perm);
			List<T> c = new ArrayList<>(candidate);
			p.add(c.get(i));
			c.remove(i);
			permutation(c, p, result);
		}
	}
}

Measured memory_bytes: 44896
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin>>a>>b;
    cout<<6-a-b<<endl;
}

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

using namespace std;

void Main() {
    string S;
    long long K;
    cin >> S;
    cin >> K;

    long long num1st1 = 0;
    long long the1stNon1 = 0;
    for (int i = 0; i < S.size(); ++i) {
        if (S[i] == '1') {
            ++num1st1;
        }
        else {
            the1stNon1 = S[i] - '0';
            break;
        }
    }

    if (K <= num1st1) {
        cout << 1 << endl;
    }
    else {
        cout << the1stNon1 << endl;
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int num[N];
  for(int i=0;i<N;i++){
    cin >> num[i];
  }
  int j=0;
  bool flag=true;
  while(flag){
    for(int i=0;i<N;i++){
      if(num[i]%2==0){
        num[i]/=2;
      }
      else{
        flag=false;
      }
    }
    j++;
  }
  cout << j-1 << endl;
}


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

using Graph = vector<vector<int>>;

void dfs(Graph &G, int v, int N, vector<bool> visited, int &ans) {
  visited[v] = true;
  
  for (int next_v : G[v]) {
    if (visited[next_v]) continue;
    dfs(G, next_v, N, visited, ans);
  }
  
  bool all_visited = true;
  for (int i = 0; i < N; i++) {
    if (!visited[i]) all_visited = false;
  }
  
  if (all_visited) ans++;
}
  
int main() {
  int N, M; cin >> N >> M;
  Graph G(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    G[a-1].push_back(b-1);
    G[b-1].push_back(a-1);
  }
  int ans = 0;
  vector<bool> visited(N, false);
  dfs(G, 0, N, visited, ans);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int A,B;cin>>A  >>B;
  int cnt = 0;
  for(int i = 1; i <= N; i++){
  	const string s = to_string(i);
    const int sum = accumulate(s.begin(),s.end(),0)-'0'*s.size();
    cnt += (A<= sum and sum <= B?i:0);
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
import sys

class Node():
    #key = ตัว z เอง และตัวด้านซ้ายด้านขวา
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left, self.right = None, None
        
    def __str__(self):
        return self.key

root = None
#z คือรับเลขเข้ามาว่าจะ insert ค่าไหน
def insert(z):
    global root
    x, y = root, None
    #ทำการ update ค่า y ว่าตัวไหนเป็น root ต่อไป โดยมาเทียบกับ root ว่าจะลงซ้ายหรือขวา
    while x:
        y = x
        if z < x.key:
            x = x.left
        else:
            x = x.right
    
    if y == None:
       #ทำการ update ค่า y ให้ อีกที ว่าอะไรเป็น left เป็น right 
        root = Node(z)
    elif z < y.key:
        y.left = Node(z)
    else:
        y.right = Node(z)
        
#root->left->right        
def preorder(x):
    return f" {x.key}" + preorder(x.left) + preorder(x.right) if x else ""
#left-root-right
def inorder(x):
    return inorder(x.left) + f" {x.key}" + inorder(x.right) if x else ""
        
input()
#รับค่าทีละบรรทัด
node = {}
for s in sys.stdin:
    if s[0] == "p":
        #ถ้าเป็น p ก็ print ถ้าไม่เป็น p ดู ตน. 7 คือ ตัวเลข
        pass
        print(inorder(root))
        print(preorder(root))
    else:
        insert(int(s[7:]))



Measured memory_bytes: 63544
#include<bits/stdc++.h>  
    using namespace std;  
    const int maxn=1e5+10;  
    int n,ans[maxn];  
    char ch[maxn];  
    bool check()  
    {  
        if (!ans[n])  
        {  
            if (ch[n]=='o'&&ans[n-1]!=ans[1]) return 0;  
            if (ch[n]=='x'&&ans[n-1]==ans[1]) return 0;  
        }  
        else  
        {  
            if (ch[n]=='x'&&ans[n-1]!=ans[1]) return 0;  
            if (ch[n]=='o'&&ans[n-1]==ans[1]) return 0;  
        }  
        if (!ans[1])  
        {  
            if (ch[1]=='o'&&ans[n]!=ans[2]) return 0;  
            if (ch[1]=='x'&&ans[n]==ans[2]) return 0;  
        }  
        else  
        {  
            if (ch[1]=='x'&&ans[n]!=ans[2]) return 0;  
            if (ch[1]=='o'&&ans[n]==ans[2]) return 0;  
        }  
        return 1;  
    }  
    int main()  
    {  
        scanf("%d%s",&n,ch+1);  
        for (int S=0;S<4;S++)  
        {  
            ans[1]=S&1;  
            ans[2]=(S>>1)&1;  
            for (int i=3;i<=n;i++)  
                if (!ans[i-1])  
                {  
                    if (ch[i-1]=='o') ans[i]=ans[i-2];  
                    else ans[i]=ans[i-2]^1;  
                }  
                else  
                {  
                    if (ch[i-1]=='x') ans[i]=ans[i-2];  
                    else ans[i]=ans[i-2]^1;  
                }  
            if (check())  
            {  
                for (int i=1;i<=n;i++)  
                    if (!ans[i]) printf("S");  
                    else printf("W");  
                return 0;  
            }  
        }  
        cout<<"-1";  
        return 0;  
    }  

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

int main() {
  int n, m, x;
  cin >> n >> m >> x;

  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  rep(i, n) {
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }

  int initial = 1'000'000'000;
  int ans = initial;
  for (int s = 0; s < (1 << n); s++) {
    int cost = 0;
    vector<int> r(m);
    for (int i = 0; i < n; i++) {
      if (s >> i & 1) {
        cost += c[i];
        rep(j, m) r[j] += a[i][j];
      }
    }
    bool f = true;
    rep(j, m) {
      if (r[j] < x) f = false;
    }

    if (f) ans = min(ans, cost);
  }

  if (ans == initial)
    cout << -1 << endl;
  else
    cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){

int a,b;
cin>>a>>b;

if(a>=b){
    for(int i=0;i<a;i++){
        cout<<b;
    }
}
else if(a<b){
    for(int i=0;i<b;i++){
        cout<<a;
    }
}
cout<<endl;
return 0;
}

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

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    string S;
    cin >> N >> S;
    int ret = 0;
    FOR(i, 0, N)
        if (i + 3 <= N && S.substr(i, 3) == "ABC")
            ret++;
    cout << ret << endl;
    return 0;
};

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

int main(){
  char S[101];
  size_t N, N2, N4;
  int flag;
  
  scanf("%s",S);
  N = strlen(S);
  N2 = (N-1)/2;

  flag = 0;
  
  for(int i=0; i<N2; i++)
    if(S[i] != S[N-1-i])
      flag++;

  for(int i=0; i<N2/2; i++)
    if(S[i] != S[N2-1-i])
      flag++;

  for(int i=0; i<N2/2; i++)
    if(S[N2+i+1] != S[N-1-i])
      flag++;

  if(flag)
    printf("No\n");
  else
    printf("Yes\n");

  return 0;
}


Measured memory_bytes: 128
n, m = gets.split.map(&:to_i)
disignation = []
ans = '-1'
flag = false
m.times do
  disignation << gets.split.map(&:to_i)
end
model = '1' + '0' * (n - 1)

digits = []
disignation.each do |d|
  if digits.include?(d[0]) && model[d[0] - 1] != d[1].to_s
    flag = true
    break
  else
    model[d[0] - 1] = d[1].to_s
  end
  digits << d[0]
end

unless flag
  ans = model
end

if n != 1 && model[0] == '0'
  ans = '-1'
end

if m == 0 && n == 1
  ans = '0'
end

puts ans

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define For1(i, n) for(int i = 1; i <= (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, k, t);
    Cins(int, t, a);
    
    int ans = 0;
    int prei = -1;
    Rep(k){
        int mini = -1;
        For(i, t){
            if(i == prei) continue;
            if(i != -1 && a[i] > a[mini]) mini = i;
        }
        if(mini == -1) mini = prei, ans ++;
        a[mini] --;
        prei = mini;
    }
    Cout(ans);
}





Measured memory_bytes: 256
a,b,c=[int(i) for i in input().split()]
n=int(input())
flag=0
e=0
while(a>=b):
    b=b*2
    e=e+1
while(e<n and c<=b):
    c=c*2
    e=e+1
if(b>a and c>b and e<=n):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 61960
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned int ui;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
#define All(v) (v).begin(),(v).end()
#define Rep(i,n) for(int i = 0; i < (int)n; i++)
#define Reps(i,n) for(int i = 1; i <= (int)n; i++)
#define For(i,m,n) for(int i = m; i < n; i++)
#define Fors(i,m,n) for(int i = m; i <= n; i++)
#define Inf 2e9
#define F first
#define S second
#define pb push_back
#define mp make_pair
struct speed{speed(){cin.tie(); ios::sync_with_stdio(false); cout << fixed << setprecision(18);}}speed;

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

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

ll lcm(ll a, ll b){
    return a*b/gcd(a,b);
}


int main (){
    string s;
    cin >> s;
    int maru = 0;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'o') maru++;
    }
    if(15-s.length()+maru >= 8) cout << "YES" << "\n";
    else cout << "NO" << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 200005
#define MOD 998244353
#define INF 10000000000

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

bool cmp(ll x, ll y){
    return x > y;
}
void solve(){
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    ll d1[a], d2[b], d3[c];
    for(ll i = 0; i < a; i++) cin >> d1[i];
    for(ll i = 0; i < b; i++) cin >> d2[i];
    for(ll i = 0; i < c; i++) cin >> d3[i];
    sort(d1, d1+a, cmp);
    sort(d2, d2+b, cmp);
    sort(d3, d3+c, cmp);
    vector <ll> v;
    for(ll i = 0; i  < x; i++) v.push_back(d1[i]);
    for(ll i = 0; i  < y; i++) v.push_back(d2[i]);
    for(ll i = 0; i  < c; i++) v.push_back(d3[i]);
    sort(v.rbegin(), v.rend());
    ll k = 0, ans = 0;
    for(auto xx : v){
        ans += xx;
        k++;
        if(k == x+y) break;
    }
    cout<< ans;

}

int main()
{
    fast();
    int t= 1; //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 8560
#include <cassert>
#include <cstdio>
#define SIZE 244140625

int Hash(const char* c)
{
    int Hash = 0;
    while(1){
        Hash *= 5;
        switch(*c){
        case 'A':
            Hash += 1; break;
        case 'C':
            Hash += 2; break;
        case 'G':
            Hash += 3; break;
        case 'T':
            Hash += 4; break;
        default:
            return Hash;
        }
        ++c;
    }
}
int main()
{
    bool* dic = new bool[SIZE];
    int n;
    std::scanf("%d", &n);
    char command[7];
    char str[13];
    for(int i = 0; i < n; ++i){
        std::scanf("%s %s", command, str);
        if(command[0] == 'i'){
            dic[Hash(str)] = true;
        }else{
            std::puts((dic[Hash(str)] ? "yes" : "no"));
        }
    }
    return 0;
 }

Measured memory_bytes: 50480
#pragma GCC optimize("O3")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define mp make_pair
#define all(c) (c).begin() , (c).end()
#define sz(c) ((long long)((c).size()))
#define phb push_back
#define ppb pop_back
#define phf push_front
#define ppf pop_front

using namespace __gnu_pbds;
using namespace std;

#define int ll

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

template
<
    class key,
    class val=null_type,
    class comp=less<key>
>
using ord_set=tree
<
    key,
    val,
    comp,
    rb_tree_tag,
    tree_order_statistics_node_update
>;

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

    int a,b;
    cin>>a>>b;
    cout<<(b-1+a-1-1)/(a-1);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int sum = 0;
		int N = scan.nextInt();
		int K = scan.nextInt();
		int[] x = new int[N];
		for(int i = 0; i < N; i++) {
			x[i] = scan.nextInt();
			sum += (Math.min(K - x[i], x[i]) * 2);
		}
		System.out.println(sum);
		scan.close();

	}

}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

const int MAX_N = 212345;
ll h[MAX_N];
ll dp[MAX_N];

struct Line {
  ll a, b;
  ll f(ll x) {
    return a*x + b;
  }
};

bool check(Line l1, Line l2, Line l3) {
  return (l1.a - l2.a)*(l3.b - l2.b) <= (l2.b - l1.b)*(l2.a - l3.a);
}

int main2() {
  int N; cin >> N;
  ll C; cin >> C;
  REP(i, N) cin >> h[i+1];

  deque<Line> deq;
  dp[1] = 0;
  for (int i = 2; i <= N; i++) {
    Line line = (Line){-2 * h[i-1], (h[i-1] * h[i-1] + dp[i-1])};
    while (deq.size() >= 2 && check(deq[deq.size()-2], deq[deq.size()-1], line)) deq.pop_back();
    deq.push_back(line);
    while (deq.size() >= 2 && deq[0].f(h[i]) >= deq[1].f(h[i])) deq.pop_front();
    ll res = deq[0].f(h[i]);
    res += h[i] * h[i] + C;
    dp[i] = res;
  }
  cout << dp[N] << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

int main() {
    cin.tie(NULL); cout.tie(NULL);
    ios_base::sync_with_stdio(false);
    int t; t=1;
while(t--){
string s; cin>>s;
long long int n=s.size();	
if(s[n-1]=='s'){
	s+="es";
}
else{s+="s";
}
cout<<s;
}
   
	return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
	int n;
	cin >> n;
	std::vector<int> p(n);
	rep(i,n) cin >> p[i];

	std::vector<int> q(n);
	rep(i,n) q[i] = p[i];
	sort(ALL(q));

	int ct = 0;
	rep(i,n){
		if(p[i] != q[i]){
			ct++;
		}
		if(ct > 2){
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" <<  endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<long long> vll, vLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    ll ans = 0;
    if(n>=k){
        ll tmp = (n-k)/k+1;
        ans = tmp*tmp*tmp;
    }
    if(k%2==0){
        ll k2 = k/2;
        if(n>=k2){
            ll tmp = (n-k2)/k+1;
            ans += tmp*tmp*tmp;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
let () =
  let open Queue in
  let (n:int),(quantum:int) = Scanf.scanf "%d %d\n" (fun a b -> a,b) in
  let (q:(string * int) t) = create () in
  for i=1 to n do
    add (Scanf.scanf "%s %d\n" (fun a b -> a,b)) q
  done;
  let (sum:int ref) = ref 0 in
  while not (is_empty q) do
    match take q with
      p,t when t <= quantum ->
      sum := !sum + t;
      Printf.printf "%s %d\n" p !sum
    | p,t ->
      add (p,t-quantum) q;
      sum := !sum+quantum
  done

Measured memory_bytes: 12680
#include<bits/stdc++.h>
using namespace std;
main() {
	int L, M, N;
	while( cin >> L && L ) {
		int t = 0, S = 0;
		for ( int i = 1; i <= 12; i++ ) {
			cin >> M >> N;
			S += M - N;
			if ( S >= L && t == 0 ) t = i;
		}
		if ( S < L ) cout << "NA" << endl;
		else cout << t << endl;
	}
}

Measured memory_bytes: 3072
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<deque>
using namespace std;
typedef long long ll;

const ll MOD_CONST = 1000000007;



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

	deque<char> deq;
	for (int i = 0; i < s.length(); i++) {
		deq.emplace_back(s[i]);
	}

	bool isStartFirst = true;

	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int t;
		cin >> t;
		if (t == 1) {
			isStartFirst = 1 ^ isStartFirst;
		}
		else {
			int f;
			char c;
			cin >> f >> c;
			if (f + isStartFirst == 2) {
				deq.emplace_front(c);
			}
			else {
				deq.emplace_back(c);
			}
		}
	}

	while (!deq.empty()) {
		if (isStartFirst) {
			cout << deq.front();
			deq.pop_front();
		}
		else {
			cout << deq.back();
			deq.pop_back();
		}
	}

}  



Measured memory_bytes: 896
import sys

input = sys.stdin.readline

N, M = map(int, input().split())
s = []
for _ in range(N):
    a, b = map(int, input().split())
    s.append((a, b))

g = []
for _ in range(M):
    c, d = map(int, input().split())
    g.append((c, d))

ans = []
for i in range(N):
    a, b = s[i]
    i_ans = -1
    tmp = float("inf")
    for j in range(M):
        c, d = g[j]
        dist = abs(c-a) + abs(d-b)
        # print(i, j, dist)
        if dist < tmp:
            i_ans = j
            tmp = dist
    ans.append(i_ans)

for a in ans:
    print(a+1)

Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int solve(int i)
{
  int a,b,c,d;
  a = i%10;
  b = i/10000 % 10;
  c = i/10%10;
  d = i/1000%10;
  if(a == b && c == d){
    return 1;
  }
  return 0;
}

int main()
{
  int a, b, ans = 0;
  cin >> a >> b;
  for(int i = a; i <= b; i++){
    ans += solve(i);
  }
  cout << ans << endl;
  system("pause");
}


Measured memory_bytes: 504