akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <functional>
#include <vector>
#include <math.h>

using namespace std;
int main()
{
	long long a[101];
	int N;

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

	sort(a, a + N);

	cout << a[N - 1] - a[0];

	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define li long
#define pb push_back
#define mem(arr,x) memset(arr,x,sizeof(arr))

ll n,W;
ll w[101],v[101];
ll dp[101][100010];
ll totalV=0;

ll minWeight(ll end, ll Val)
{
  if(Val<=0)
  return 0;
  if(end==0)
  // return 1000000010;
  return INT_MAX;
  // 2147483647
  if(dp[end][Val]!=1000000010)
  return dp[end][Val];
  if(v[end-1]>Val)
  return dp[end][Val]=minWeight(end-1,Val);
  else
  return dp[end][Val]=min(w[end-1]+minWeight(end-1,Val-v[end-1]), minWeight(end-1,Val));
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i,j;
    cin>>n>>W;
    for(i=0;i<n;i++)
    {
      cin>>w[i]>>v[i];
      totalV+=v[i];
    }

    for(i=0;i<=n;i++)
      for(j=0;j<=totalV;j++)
        dp[i][j]=1000000010;

    for(i=totalV;i>=1;i--)
    {
      if(minWeight(n,i)<=W)
      break;
    }
    cout<<i;
    return 0;
}

Measured memory_bytes: 82356
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(vec) vec.begin(), vec.end()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define repc(bit, k, n) for (ll bit = (1 << k) - 1; bit < (1 << n); bit = next_combination(bit))
#define repi(itr, vec) for (auto itr = vec.begin(); itr != vec.end(); ++itr)
using namespace std;
using ppi = pair<pair<int, int>, int>;
struct UnionFind
{
  //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
  //そうでなければ親のid
  vector<int> r;

  UnionFind(int N)
  {
    r = vector<int>(N, -1);
  }

  int root(int x)
  {
    if (r[x] < 0)
      return x;
    return r[x] = root(r[x]);
  }

  bool unite(int x, int y)
  {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (r[x] > r[y])
      swap(x, y);
    r[x] += r[y];
    r[y] = x;
    return true;
  }

  int size(int x)
  {
    return -r[root(x)];
  }
};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<ppi> town(n);
  rep(i, n)
  {
    int a, b;
    cin >> a >> b;
    town[i] = make_pair(make_pair(a, b), i);
  }
  UnionFind closed(n);
  priority_queue<pair<int, pair<int, int>>> road;
  sort(ALL(town), [](const ppi &a, const ppi &b) { return a.first.first < b.first.first; });
  rep(i, n - 1)
  {
    road.push(make_pair(-min(abs(town[i].first.first - town[i + 1].first.first), abs(town[i].first.second - town[i + 1].first.second)), make_pair(town[i].second, town[i + 1].second)));
  }
  sort(ALL(town), [](const ppi &a, const ppi &b) { return a.first.second < b.first.second; });
  rep(i, n - 1)
  {
    road.push(make_pair(-min(abs(town[i].first.first - town[i + 1].first.first), abs(town[i].first.second - town[i + 1].first.second)), make_pair(town[i].second, town[i + 1].second)));
  }
  int ans = 0;
  while (!road.empty())
  {
    auto top = road.top();
    road.pop();
    int cost = -top.first;
    int i = top.second.first;
    int j = top.second.second;
    if (closed.root(i) == closed.root(j))
      continue;
    closed.unite(i, j);
    ans += cost;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 7928
using System;
using System.Collections.Generic;

public class CSharp
{
    public static void Main()
    {
        Kyopuro chokudai = new Kyopuro();
        chokudai.AtCoder();
    }
}

public class Kyopuro
{

    int n, m, k;

    public void AtCoder()
    {
        string[] input;
        input = Console.ReadLine().Split(' ');
        string s = input[0];
        var c = new List<char>();
        int x = 1;
        bool f = false;
        bool g = false;
        c.Add(s[0]);
        for(int i=1; i<4; i++)
        {
            g = false;
            for(int j=0; j<c.Count; j++)
            {
                if(s[i] == c[j])
                {
                    g = true;                   
                }                
            }
            if (!g)
            {
                x++;
                c.Add(s[i]);
            }
        }
        if (x == 2)
        {
            x = 0;
            for(int i=1; i<4; i++)
            {
                if (s[0] == s[i]) x++;
            }
            if (x == 1) f = true;
        }

        if (f) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
    public static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); }
}


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


int main(){
  string S;
  cin >> S;
  bool flag=false;
  int sum=0, sum2=0;
  for(int i=2; S[i+1]!='\0'; i++){
    if(S[0] == 'A' && S[i]=='C'){
      flag=true;
    }
  }
  

  for(int i=0; S[i]!='\0'; i++){
    if(S[i]=='C')
      sum++;
    if(S[i]>='A' && S[i]<='Z')
      sum2++;

  }


  
  if(sum>=2 || sum2>=3)
    flag=false;

  if(flag==true)
    cout<<"AC"<<endl;
  else
    cout<<"WA"<<endl;
    
}



Measured memory_bytes: 256
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Main
int main() {
    int n;
    cin >> n;
    vector<vector<char>> s(n, vector<char>(n));
    rep(i, n) rep(j, n) cin >> s[i][j];
    
    int ans = 0;
    rep(i, n) {
        vector<int> vec(n, -1);
        queue<int> q;
        vec[i] = 0;
        q.push(i);
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            rep(j, n) {
                if (s[v][j] == '0') continue;
                if (vec[j] == -1) {
                    vec[j] = vec[v] + 1;
                    q.push(j);
                } else {
                    if (vec[j] != vec[v] - 1 && vec[j] != vec[v] + 1) {
                        cout << "-1\n";
                        return 0;
                    }
                }
            }
        }
        chmax(ans, *max_element(all(vec)) + 1);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3668
#include <iostream>

using namespace std;

int main() {
    int y, m, d;
    scanf("%d/%d/%d", &y, &m, &d);
    if (y > 2019 || m > 4) {
        cout << "TBD" << endl;
    }
    else {
        cout << "Heisei" << endl;
    }
}

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

using namespace std;

int main() {
	int arr[3];
	for (int i = 0; i < 3; i++)
		cin >> arr[i];
	
	sort(arr, arr + 3);

	cout << arr[0] << " " << arr[2] << endl;
}




Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr double INF{1e9};
constexpr int MAGIC_PRIME{1000000000 + 7};
constexpr array<int, 4> dy{-1, 1, 0, 0};
constexpr array<int, 4> dx{0, 0, -1, 1};
constexpr int div_ru(int a, int b)
{
    return (a - b + 1) / b;
}
ll pow_mod(ll b, ll e, ll m)
{ // https://atcoder.jp/contests/atc002/tasks/atc002_b
    ll r = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            r = (r * b) % m;
        b = (b * b) % m;
    }
    return r;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    cout << (n - 2) * 180 << endl;
}
// 　　　　　　_......_
// 　　　　 , ´　 <＊y　♪
// 　　　　 i,（i ﾉﾉﾊ）_）
// 　　　　ﾉ_iﾊﾟ ヮﾟﾉﾊ
// 　　　 　 ,´i'_ｿﾉj,〈つ　))
// 　　　　〈_,ﾉ＾＾＾ヽ.´
// 　　　　 .＾＾i_ｿ_ｿ^´
// 　　　　 ￣￣ ￣　


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
using namespace std;

queue <int> qt;

int w,h;
int ydata[40][40];
int tdata[40][40];
bool fflag[40][40];
int tesuu[40][40];

void check(int px,int py){
  int dx[4]={-1,0,1,0};
  int dy[4]={0,-1,0,1};
  for(int i=0;i<4;i++){
    int nx=px+dx[i];
    int ny=py+dy[i];
    if((nx>-1)&&(ny>-1)&&(nx<h)&&(ny<w)){
      if(i==0){//up
        if((fflag[nx][ny]==false)&&(tdata[nx][ny]==0)){
          qt.push(100*nx+ny);
          fflag[nx][ny]=true;		
          tesuu[nx][ny]=tesuu[px][py]+1;
        }

      }
      if(i==1){//left
        if((fflag[nx][ny]==false)&&(ydata[nx][ny]==0)){
          qt.push(100*nx+ny);
          fflag[nx][ny]=true;
          tesuu[nx][ny]=tesuu[px][py]+1;
        }
      }
      if(i==2){//down
        if((fflag[nx][ny]==false)&&(tdata[nx-1][ny]==0)){
          qt.push(100*nx+ny);
          fflag[nx][ny]=true;		
          tesuu[nx][ny]=tesuu[px][py]+1;
        }
      }
      if(i==3){//right
        if((fflag[nx][ny]==false)&&(ydata[nx][ny-1]==0)){
          qt.push(100*nx+ny);
          fflag[nx][ny]=true;
          tesuu[nx][ny]=tesuu[px][py]+1;
        }
      }
    }
  }
  if(!qt.empty()){
    int t=qt.front();
    qt.pop();
    check(t/100,t%100);
  }
}

int main(){
  while(1){
    for(int i=0;i<40;i++){
      for(int j=0;j<40;j++){
        fflag[i][j]=false;
        tesuu[i][j]=0;
      }
    }
      cin >> w >> h;
    if((w==0)&&(h==0)) return 0;
    for(int i=0;i<h*2-1;i++){
      if(i%2==0){
        for(int j=0;j<w-1;j++){
          cin >> ydata[i/2][j];
        }
      }else{
        for(int j=0;j<w;j++){
          cin >> tdata[i/2][j];
        }
      }
    }
    fflag[0][0]=true;
    tesuu[0][0]=1;
    check(0,0);
    cout << tesuu[h-1][w-1] << endl;

  }
  return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

using Graph = vector<vector<int>>;
int N;
Graph G;

void rec(int v, int p, int c, vector<int> &one, vector<int> &two) {
    if (c == 0) one.push_back(v);
    else two.push_back(v);
    for (auto ch : G[v]) {
        if (ch == p) continue;
        rec(ch, v, 1-c, one, two);
    }
}

vector<int> solve() {
    vector<int> one, two;
    rec(0, -1, 0, one, two);

    //COUT(one); COUT(two);

    int need_one = (N+2)/3;
    int need_two = (N+1)/3;
    int need_three = N/3;
    vector<int> res(N, -1);

    if (one.size() >= need_one && two.size() >= need_two) {
        for (int i = 0; i < one.size(); ++i) if (i < need_one) res[one[i]] = i*3+1;
        for (int i = 0; i < two.size(); ++i) if (i < need_two) res[two[i]] = i*3+2;
        int cur = 3;
        for (int i = 0; i < N; ++i) if (res[i] == -1) res[i] = cur, cur += 3;
        return res;
    }
    else {
        int num_one = 0, num_two = 0, num_three = 0;
        if (one.size() < need_one) {
            for (int i = 0; i < one.size(); ++i)
                res[one[i]] = (num_three++) * 3 + 3;
        }
        else {
            for (int i = 0; i < two.size(); ++i)
                res[two[i]] = (num_three++) * 3 + 3;
        }
        for (int i = 0; i < N; ++i) {
            if (res[i] != -1) continue;
            if (num_one < need_one) res[i] = (num_one++) * 3 + 1;
            else if (num_two < need_two) res[i] = (num_two++) * 3 + 2;
            else res[i] = (num_three++) * 3 + 3;
        }
        return res;
    }
}

int main() {
    while (cin >> N) {
        G.assign(N, vector<int>());
        for (int i = 0; i < N-1; ++i) {
            int a, b; cin >> a >> b; --a, --b;
            G[a].push_back(b), G[b].push_back(a);
        }
        const auto& res = solve();
        for (auto v : res) cout << v << " ";
        cout << endl;
    }
}


















Measured memory_bytes: 22300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int N; cin >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }

    vector<int> C(N+1, 0), CA(N+1, 0), CB(N+1, 0);
    for (int i = 0; i < N; i++) {
        CA[A[i]]++;
        CB[B[i]]++;
    }
    for (int i = 0; i < N+1; i++) {
        C[i] = CA[i] + CB[i];
    }
    vector<iint> D;
    for (int i = 0; i < N+1; i++) {
        if(C[i] > 0){
            D.push_back(make_pair(C[i], i));
        }
    }

    sort(ALL(D), greater<iint> ());
    if(D[0].first >= N+1){
        No();
        return 0;
    }

    Yes();
    int l = D.size();
    vector<iint> AB;
    for (int i = 0; i < l; i++) {
        for (int j = 0; j < CA[D[i].second]; j++) {
            AB.push_back(make_pair(D[i].second, 0));
        }
        for (int j = 0; j < CB[D[i].second]; j++) {
            AB.push_back(make_pair(D[i].second, 1));
        }
    }
    queue<int> a, b;
    for (int i = 0; i < N; i++) {
        if(AB[i].second == AB[i+N].second){
            if(AB[i].second == 0){
                a.push(i);
            }
            else{
                b.push(i);
            }
        }
    }
    while(!a.empty()){
        int v = a.front(); int w = b.front(); a.pop(); b.pop();
        swap(AB[v], AB[w]);
    }
    vector<iint> ans;
    for (int i = 0; i < N; i++) {
        if(AB[i].second == 0){
            ans.push_back(make_pair(AB[i].first, AB[i+N].first));
        }
        else{
            ans.push_back(make_pair(AB[i+N].first, AB[i].first));
        }
    }

    sort(ALL(ans));
    for (int i = 0; i < N; i++) {
        printf("%d ", ans[i].second);
    }
    cout << endl;

    


}

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

void swap(int &a, int &b);
void swap(int &a, int &b)
{
    if (a > b) {
        int tmp = a;
        a = b;
        b = tmp;
    }
}
int main() {
    int a, b, c;
    cin >> a >> b >> c;

    swap(a, b);
    swap(b, c);
    swap(a, b);
    cout << a <<" "<< b <<" "<< c<<endl;
    return 0;
}

Measured memory_bytes: 1164
import Control.Monad
import Data.Ratio ((%))

data Line = Vert Rational | Line { slope :: Rational
                               , interact :: Rational
                               } deriving Show

main = do
  n <- readLn
  replicateM_ n solve

solve :: IO ()
solve = do
  [x0,y0,x1,y1,x2,y2,x3,y3] <- fmap (map read.words) getLine
  let (l1,l2) = (corrLine (x0,y0) (x1,y1), corrLine (x2,y2) (x3,y3))
  putStrLn $ checkCrossAngle l1 l2

checkCrossAngle l1 l2
  | isParallel l1 l2 = "2"
  | isOrthogonal l1 l2 = "1"
  | otherwise = "0"

isVert :: Line -> Bool
isVert (Vert _) = True
isVert (Line _ _) = False

isParallel :: Line -> Line -> Bool
isParallel l1 l2
  | isVert l1 = isVert l2
  | isVert l2 = False
  | otherwise = slope l1 == slope l2

isOrthogonal :: Line -> Line -> Bool
isOrthogonal l1 l2
  | isVert l1 && isVert l2 = False
  | isVert l1 = slope l2 == 0
  | isVert l2 = slope l1 == 0
  | otherwise = slope l1 * slope l2 == -1

corrLine :: (Integer,Integer) -> (Integer, Integer) -> Line
corrLine (x1,y1) (x2,y2)
  | x1 == x2 = Vert (x1%1)
  | otherwise = Line a b
  where a = (y2 - y1) % (x2 - x1)
        b = (y1%1) - a*(x1%1)

Measured memory_bytes: 4156
var
s,s1,s2,s3,s4:string;
i,j,c,d,e,b:longint;
begin
read(s1);
s:='CODEFESTIVAL2016';
for i:=1 to length(s1) do
if s1[i]<>s[i] then inc(e);
write(e);
writeln;
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 10;
long long D[N], n, ans;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	for(int i = 1; i <= 1e7; ++i) {
		for(int j = i; j <= 1e7; j += i) {
			++D[j];
		}
	}
	cin >> n;
	for(int i = 1; i <= n; ++i)ans += D[i] * i;
	cout << ans << '\n';
}

Measured memory_bytes: 81780
n = int(input())
L = [['a','a']]
for i in range(1,n):
    new = []
    for j in range(len(L)):
        temp = L[j][0]
        cur = ord(L[j][1])-96
        for k in range(cur+1):
            ap = temp+chr(97+k)
            if chr(97+k) < L[j][1]:
                new.append([ap, L[j][1]])
            else:
                new.append([ap, chr(97+k)])
    L = new
L.sort()
for i in range(len(L)):
    print(L[i][0])

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();

    ll n, k ;
    cin >> n >> k ;
    vll pa ;
    vll ma ;
    pa.PB(0) ;
    ma.PB(0) ;
    REP(i,n){
        ll a ;
        cin >> a ;
        if(a==0){
            k-- ;
        }
        else if(a>0){
            pa.PB(a) ;
        }
        else{
            ma.PB(-a) ;
        }
    }
    sort(ALL(ma)) ;
    sort(ALL(pa)) ;
    ll sp = SZ(pa) ;
    ll sm = SZ(ma) ;

    ll ans = LINF ;

    for(ll i=0;i<=k;i++){
        ll tmp ;
        if(k-i<sm && i<sp){
            tmp = 2*min(pa[i],ma[k-i]) + max(pa[i],ma[k-i]) ;
            ans = min(ans,tmp) ;
        }
    }

    cout << ans <<endl;







    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}



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

int main() {
  int N,count;
  cin>>N;
  vector<int> vec(N,0);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  count=1;
  for(int i=0;i<N-1;i++){
    if(vec.at(i)<vec.at(i+1)){
      count+=1;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF (1<<28)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
signed main(){
  int n;
  cin>>n;
  vector<pair<string,pair<int,int> >> l;
  lp(i,n){
    string s;
    int a;
    cin>>s>>a;
    l.push_back({s,{-1*a,i}});
  }
  sort(l.begin(),l.end());
  lp(i,l.size()){
    cout<<l[i].second.second+1<<endl;
  }


  return 0;
}

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

string S, T;

int main() {
    cin >> S >> T;
    
    int start = -1;
    for (int i = S.length() - T.length(); i >= 0; i--) {
        bool f = true;
        for (int j = T.length() - 1; j >= 0; j--) {
            if (S[i+j] != T[j] && S[i+j] != '?') {
                f = false; 
                break;
            }
        }
        if (f) {
            start = i;
            break;
        }
    }

    if (start == -1) {
        cout << "UNRESTORABLE" << endl;
    }
    else {
        for (int i = 0; i < T.length(); i++) {
            S[start + i] = T[i];
        }

        for (int i = 0; i < S.length(); i++) {
            if (S[i] == '?') S[i] = 'a';
        }

        cout << S << endl;
    }
    
    return 0;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    vector a(n, vector(n, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }

    mcf_graph<int, int64_t> graph(2 * n + 2);
    const int s = 2 * n, t = 2 * n + 1;
    const int64_t m = 1000000000;
    graph.add_edge(s, t, n * k, m);
    for (int i = 0; i < n; i++) {
        graph.add_edge(s, i, k, 0);
        graph.add_edge(i + n, t, k, 0);
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            graph.add_edge(i, j + n, 1, m - a[i][j]);
        }
    }

    auto p = graph.flow(s, t, n * k);
    cout << n * k * m - p.second << endl;

    vector ans(n, vector(n, '.'));
    auto es = graph.edges();
    for (auto e : es) {
        if (e.from == s || e.to == t || e.flow == 0) continue;
        ans[e.from][e.to - n] = 'X';
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cout << ans[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3904
/*
 * じょえチャンネル
 * 高評価・チャンネル登録よろしくお願いします！
 * https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
 */

#include<bits/stdc++.h>

int main(){
    using namespace std;
    constexpr unsigned long MOD = 1000000007;
    unsigned long N, A, B;
    cin >> N >> A >> B;
    const auto& modpow = [](unsigned long a, unsigned long b = 1, unsigned long n = 1000000005) -> unsigned long {
        unsigned long r{b % MOD};
        a %= MOD;
        while(n){
            if(n & 1)(r *= a) %= MOD;
            (a *= a) %= MOD;
            n >>= 1;
        }
        return r;
    };
    const auto& comb = [&modpow](unsigned long a, unsigned long b) -> unsigned long {
        unsigned long d{1}, n{1};
        for(unsigned long i{0}; i < b; ++i){
            (n *= i + 1) %= MOD;
            (d *= a - i) %= MOD;
        }
        return modpow(n, d);
    };
    cout << (MOD * 2 + modpow(2, 1, N) - 1 - comb(N, A) - comb(N, B)) % MOD << endl;
    return 0;
}

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

typedef long long int llint;

int main(){
	llint N;
	cin >> N;
	llint minMove=-1;
	for(int n=1;n<=sqrt(N);n++){
		if(N%n==0){
			llint dx=N/n-1;
			llint dy=n-1;
			if(minMove==-1 || dx+dy<minMove){
				minMove=dx+dy;
			}
		}
	}
	cout << minMove << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int q;
  cin >> s >> q;
  deque<char> ds(s.size());
  for(int i=0;i<s.size();i++){
    ds[i]=s[i];
  }
  bool rev =false;
  int t,f;
  char c;
  for(int i=0;i<q;i++){
    cin >> t;
    if(t==1){
      if(rev){
        rev=false;
      }else{
        rev=true;
      }
    }else if(t==2){
      cin >> f >> c;
      if(rev){
        if(f==1){
          ds.push_back(c);
        }else{
          ds.push_front(c);
        }
      }else{
        if(f==1){
          ds.push_front(c);
        }else{
          ds.push_back(c);
        }
      }
    }
  }
  if(rev) reverse(ds.begin(),ds.end());
  for(int i=0;i<ds.size();i++){
    cout << ds[i];
  }
  cout << endl;
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#define all(c) (c).begin(),(c).end()
#define f first
#define s second

using namespace std;

typedef long long ll;

struct point{ll x,y,z;};

typedef pair<point,point> P;

int main(){
  ll n,k,x1,x2,y1,y2,z1,z2;
  vector<ll>x,y,z;

  cin >> n >> k;
  vector<P> p(n);

  for(int i=0;i<n;i++){
    cin >> p[i].f.x >> p[i].f.y >> p[i].f.z;
    cin >> p[i].s.x >> p[i].s.y >> p[i].s.z;

    x.push_back(p[i].f.x);
    x.push_back(p[i].s.x);
    y.push_back(p[i].f.y);
    y.push_back(p[i].s.y);
    z.push_back(p[i].f.z);
    z.push_back(p[i].s.z);
  }
  
  sort(all(x));
  sort(all(y));
  sort(all(z));

  map<ll,int>X,Y,Z;
  
  for(int i=0;i<x.size();i++)X[x[i]]=i;
  for(int i=0;i<y.size();i++)Y[y[i]]=i;
  for(int i=0;i<z.size();i++)Z[z[i]]=i;
  
  int board[101][101][101];
  for(int i=0;i<101;i++)
    for(int j=0;j<101;j++)
      for(int l=0;l<101;l++)board[i][j][l]=0;

  for(int i=0;i<n;i++)
    for(int xi=X[p[i].f.x];xi<X[p[i].s.x];xi++)
      for(int yi=Y[p[i].f.y];yi<Y[p[i].s.y];yi++)
	for(int zi=Z[p[i].f.z];zi<Z[p[i].s.z];zi++)
	  board[xi][yi][zi]++;

  ll ans=0;
  for(int i=0;i<x.size()-1;i++)
    for(int j=0;j<y.size()-1;j++)
      for(int l=0;l<z.size()-1;l++)
	if(board[i][j][l]>=k)
	  ans+=(x[i+1]-x[i])*(y[j+1]-y[j])*(z[l+1]-z[l]);
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5264
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	long long n, m, sum, small = 0, big;
	double ave;
	cin >> n >> m;
	vector<long long>l(m);
	vector<long long>r(m);
	for (long long i = 0; i < m; i++) {
		cin >> l[i] >> r[i];
	}
	big = r[0];

	for (long long i = 0; i < m; i++) {
		if (small < l[i]) {
			small = l[i];
		}
		if (big > r[i]) {
			big = r[i];
		}
	}
	if (big < small) {
		cout << "0" << endl;
	}
	else {
		cout << big - small + 1 << endl;

	}
}

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

struct S{
    string s;
    int n;
};

bool func(const S &a, const S &b){
    if(a.n > b.n) return true;
    else if(a.n < b.n) return false;
    else {
        if(a.s < b.s) return true;
        else return false;
    }
}

int main(){
    int n;
    cin >> n;
    string s[n];
    rep(i,n)cin>>s[i];

    map<string,int> mp;
    rep(i,n){
        mp[s[i]]++;
    }

    vector<S> d(n);
    int i = 0;
    auto begin = mp.begin(), end = mp.end();
    for(auto iter = begin; iter != end; iter++){
        d[i].s = iter->first;
        d[i].n = iter->second;
        i++;
    }

    sort(d.begin(), d.end(), func);

    int tmp = d[0].n;
    rep(i,n){
        if(tmp != d[i].n)break;
        cout << d[i].s << endl;
    }



    return 0;
    
}

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

using namespace std;

int N, X, Y, B, P;


int solve() {
	int b, p, currentSum, sum;

	sum = X*B + Y*P;
	b = max(0, 5 - B);
	p = max(0, 2 - P);
	currentSum = (X*(B + b) + Y*(P + p))*0.8;

	return min(currentSum, sum);
}

int main() {

	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> X >> Y >> B >> P;
		cout << solve() << endl;
	}

	return 0;
}



Measured memory_bytes: 3100
a = input()
n = len(a)
ar = []
br = []
for i in range(n//2):
    ar.append(a[i])
for i in range(n-1,n//2-1,-1):
    br.append(a[i])
count = 0
for i in range(n//2):
    if ar[i] != br[i]:
        count += 1
print(count)

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int N, M;
int x[1100], y[1100], z[1100];
int dp[1100][1100];
signed main() {
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> z[i];
    }
    int ans = 0;
    for (int i = 0; i < 8; i++) {
        int a = i % 2 * 2 - 1, b = i / 2 % 2 * 2 - 1, c = i / 4 % 2 * 2 - 1;
        for (int j = 0; j < 1100; j++) {
            for (int k = 0; k < 1100; k++) {
                dp[j][k] = -1e16;
            }
        }
        dp[0][0] = 0;
        for (int j = 1; j <= N; j++) {
            dp[j][0] = 0;
            for (int k = 1; k <= M; k++) {
                dp[j][k] = max(dp[j - 1][k], dp[j - 1][k - 1] + a * x[j - 1] + b * y[j - 1] + c * z[j - 1]);
            }
        }
        ans = max(ans, dp[N][M]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 9728
from collections import deque

n = int(input())
s = input()

l, que = 0, deque([])
for i in s:
    que.append(i)
    if i == '(':
        l += 1
    elif i == ')':
        if l == 0:
            que.appendleft('(')
            l += 1
        l -= 1
print(*que, ')' * l, sep='')


Measured memory_bytes: 65156
// 6/30 解き直し
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

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

    vector<vector<int>> A(N, vector<int>(N-1));
    rep(i, N) rep(j, N-1) {
        cin >> A[i][j];
        A[i][j]--;
    }

    vector<int> b(N, 0);
    int res = 0;
    int matches = 0;

    // 貪欲に解いてみる。
    while (true) {
        // ある日
        int add = 0;  // その日の試合数
        vector<bool> match(N, false);

        // printf("day %d\n", res);

        rep(i, N) {
            if (match[i]) continue;
            if (b[i] >= N-1) continue;

            int opponent = A[i][b[i]];

            if (A[opponent][b[opponent]] == i && match[opponent] != true) {
                // 相手も次の相手が自分だったらマッチ成立
                b[i]++;
                b[opponent]++;
                add++;

                match[i] = true;
                match[opponent] = true;

                // printf("(i, j) = %d, %d\n", i, opponent);
            }
        }

        if (add == 0) {
            cout << -1 << endl;
            return 0;
        } else {
            matches += add;
            res += 1;

            if (matches == N * (N-1) / 2) break;
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 7560
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int a = sc.nextInt(), b = sc.nextInt();
        if (a+b <= a*2-1 && b*2-1 <= a*2-1) {
            System.out.println(a*2-1);
        } else if (a*2-1 <= a+b && b*2-1 <= a+b) {
            System.out.println(a+b);
        } else {
            System.out.println(b*2-1);
        }
    }
}


Measured memory_bytes: 21844
import sys
from collections import deque

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def bfs(sy, sx):
    dist = [[-INF] * W for _ in range(H)]
    dist[sy][sx] = 0
    que = deque([(sy, sx)])
    popleft = que.popleft; append = que.append
    while que:
        y, x = popleft()
        cur = dist[y][x]
        for dy, dx in zip([0, 1, 0, -1], [1, 0, -1, 0]):            
            ny = y + dy
            nx = x + dx
            if 0 <= ny < H and 0 <= nx < W and \
                    grid[ny][nx] != '#' and dist[ny][nx] == -INF:
                dist[ny][nx] = cur + 1
                append((ny, nx))
    ret = max(max(x for x in di)for di in dist)
    return ret

INF = 10 ** 3
H, W = lr()
grid = [sr() for _ in range(H)]
answer = max(max(bfs(i, j) if grid[i][j] == '.' else 0 for j in range(W)) for i in range(H))
print(answer)
#

Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N; long long A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	bool ok = false;
	for (int i = 0; i <= N - 1; ++i) {
		long long la = A + i * C, ra = A + i * D;
		long long lb = B + (N - i - 1) * C, rb = B + (N - i - 1) * D;
		if (max(la, lb) <= min(ra, rb)) {
			ok = true;
		}
	}
	cout << (ok ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 172_A
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = a * a;
		int c = b * a;
		// 出力
		System.out.println(a+b+c);
	    // Scannerクラスのインスタンスをクローズ
		sc.close();
	}
}


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

using namespace std;

int main() {
    string s;
    int w;

    cin >> s >> w;
    string t;
    for (int i = 0; i < s.length(); i += w) {
        t += s[i];
    }
    cout << t << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    if ((A*B)%2 == 1) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 764
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.Exception;
import java.lang.Integer;
import java.lang.System;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] a) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(r.readLine());
        StringTokenizer st;

        int side[] = new int[3];
        for(int i = 0; i < n; i++) {
            st = new StringTokenizer(r.readLine());
            for(int j = 0; j < 3; j++) {
                side[j] = Integer.parseInt(st.nextToken());
            }
            Arrays.sort(side);
            if((side[0]*side[0] + side[1]*side[1]) == side[2]*side[2]) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }
}

Measured memory_bytes: 18436
#include <stdio.h>

int main(){
  int m1,m2;
  int d1,d2;
  int result=0;
  
  scanf("%d %d",&m1,&d1);
  scanf("%d %d",&m2,&d2);
  
  switch(m1){
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
      if(d1==31){
        result=1;
      }
      break;
    case 4:
    case 6:
    case 9:
    case 11:
      if(d1==30){
        result=1;
      }
      break;
    case 2:
      if(d1==28){
        result=1;
      }
  }
  
  printf("%d",result);
}
      

Measured memory_bytes: 128
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
 	
		int N = sc.nextInt();

		int a[] = new int[N];
		long sum[] = new long[N];
		
		a[0] = sc.nextInt();
		sum[0] = a[0];

		for(int i=1;i<N;i++){
			a[i] = sc.nextInt();
			sum[i] = sum[i-1] + a[i];
		}

		int rcut1 = 0;
		int rcut3 = 2;
		long rdiff = Long.MAX_VALUE;

		for(int cut2=1;cut2 < N-2;cut2++){

			long dev1diff = Long.MAX_VALUE;

			for(int cut1 = rcut1;cut1 < cut2;cut1++){

				long diff = Math.abs(sum[cut1] - (sum[cut2] - sum[cut1]));

				if(dev1diff >= diff) {
					dev1diff = diff;
					rcut1 = cut1;
				} else {
					break;
				}
			}
			

			long dev2diff = Long.MAX_VALUE;
			
			for(int cut3 = cut2 + 1 < rcut3 ? rcut3 : cut2 + 1;cut3 < N-1;cut3++){

				long diff = Math.abs((sum[cut3] - sum[cut2]) - (sum[N-1] - sum[cut3]));

				if(dev2diff >= diff){
					dev2diff = diff;
					rcut3 = cut3;
				}else{
					break;
				}
			}
			long a1 = sum[rcut1];
			long a2 = sum[cut2] - sum[rcut1];
			long a3 = sum[rcut3] - sum[cut2];
			long a4 = sum[N-1] - sum[rcut3];

			long max = Math.max(Math.max(a1,a2),Math.max(a3,a4));
			long min = Math.min(Math.min(a1,a2),Math.min(a3,a4));
			rdiff = rdiff < max - min?rdiff:max-min;

		}

		System.out.println(rdiff);

	}
 
}

Measured memory_bytes: 93332
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int n, h; cin >> n >> h;
    vector<int> a(n), b(n); repeat(i, n) cin >> a[i] >> b[i];
    
    vector<int> sa = a;
    vector<int> sb = b;
    
    sort(sa.begin(), sa.end(), greater<int>());
    sort(sb.begin(), sb.end(), greater<int>());
    
    int ans = 0;
    repeat (i, n) {
        if (sb[i] > sa[0]) {
            h -= sb[i];
            ++ans;
            
            if (h <= 0) {
                cout << ans << endl;
                return 0;
            }
            
        }
    }
    
    if (h % sa[0] == 0) {
        ans += (h / sa[0]);
    }
    else {
        ans += (h / sa[0]) + 1;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int D=365;
vector<int> c(26);
vector<vector<int>> s(365, vector<int>(26));

ll calc(const vector<int>& t, int d, int q){
  ll res = 0;
  vector<int> lst(26,-1);
  rep(i,D){
    if(i!=d){
      if(t[i]!=-1){
        res += s[i][t[i]];
        lst[t[i]] = i;
      }
    }
    else{
      res += s[i][q];
      lst[q]=i;
    }
    rep(j,26){
      res -= c[j]*(i-lst[j]);
    }
  }
  //cerr << res << '\n';
  return res;
}

ll calc2(const vector<int>& t, int d1, int d2){
  ll res = 0;
  vector<int> lst(26,-1);
  rep(i,D){
    if(i!=d1 && i!=d2){
      res += s[i][t[i]];
      lst[t[i]] = i;
    }
    else if(i==d1){
      res += s[i][t[d2]];
      lst[t[d2]]=i;
    }
    else if(i==d2){
      res += s[i][t[d1]];
      lst[t[d1]]=i;
    }
    rep(j,26){
      res -= c[j]*(i-lst[j]);
    }
  }
  //cerr << res << '\n';
  return res;
}

int main(){
  /*
  ifstream in("input.in");
  cin.rdbuf(in.rdbuf());
  ofstream ofs("output.txt");
  cout.rdbuf(ofs.rdbuf());
  //*/
  chrono::system_clock::time_point start, end;
  start = chrono::system_clock::now();
  mt19937 mt(184);
  cin >> D;
  rep(i,26) cin >> c[i];
  rep(y,D) rep(x,26) cin >> s[y][x];
  vector<int> t(D,-1);
  ll now = calc(t, -1, -1);
  rep(d,D){
    int k=-1;
    ll prenow=-1;
    rep(q,26){
      if(c[q]==0 && s[d][q]<10000) continue;
      ll pre = calc(t,d,q);
      if(now < pre){
        if(mt()&1 || mt()&1 || mt()&1) {
          now = pre;
          t[d] = q;
        }
        if(k==-1) {k=q; prenow = pre;}
      }
      if(chmax(now,calc(t,d,q))){
        t[d]=q;
      }
      end = chrono::system_clock::now();
      double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
      if(ela>1900) break;
    }
    if(t[d]==-1) {
      t[d]=k;
      now = prenow;
    }
    // timer
    end = chrono::system_clock::now();
    double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
    if(ela>1900) break;
  }
  while(1){
    int d1=mt()%365, d2=mt()%365;
    if(d1==d2) continue;
    if(chmax(now,calc2(t,d1,d2))){
      int tmp = t[d1];
      t[d1]=t[d2];
      t[d2]=tmp;
    }
    end = chrono::system_clock::now();
    double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
    if(ela>1970) break;
  }
  rep(i,D) cout << t[i]+1 << '\n';
  return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

std::string s;
int k;
int main(){
  std::cin>>s>>k;
  
  const auto size=s.size();
  std::vector<std::string> data;
  for(size_t i=0;i<size;++i)
    for(int j=1;j<=k;++j)
      data.emplace_back(s.substr(i,j));
  std::sort(data.begin(),data.end());
  data.erase(std::unique(data.begin(),data.end()),data.end());
  std::cout<<data[k-1]<<std::endl;
  return 0;
}


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

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int[] x = {s.nextInt(),s.nextInt(),s.nextInt()};
        Arrays.sort(x);
        String t = ""+x[2]+x[1];
        System.out.println(Integer.parseInt(t)+x[0]);
    }
}

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


void solve(long long N, std::vector<long long> P){
    vector<ll> num(N, 0);
    REP(i, N){
        ll pi = P.at(i);
        pi--;
        if(pi == 0){
            num.at(pi) = 1;
        }else{
            if(num.at(pi - 1) > 0){
                num.at(pi) = num.at(pi - 1) + 1;
            }else{
                num.at(pi) = 1;
            }
        }
    }
    cout << N - *max_element(num.begin(), num.end()) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> P(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&P[i]);
    }
    solve(N, std::move(P));
    return 0;
}


Measured memory_bytes: 3328
A,B,C,X,Y=map(int,input().split())
price_sum_1=A*X+B*Y
if min(X,Y)==X:
    price_sum_2=C*X*2+(Y-X)*B
else:
    price_sum_2=C*Y*2+(X-Y)*A

if max(X,Y)==X:
    price_sum_3=C*X*2
else:
    price_sum_3=C*Y*2
    
print(min(price_sum_1,price_sum_2,price_sum_3))

Measured memory_bytes: 3064
def main():
    X,N  = map(int, input().split()) 
    c=list(map(int, input().split()))
    XY = [True]*(104)

    for i in range(len(c)):
        XY[c[i]]=False

    ans = 0
    sa = 10000

    for i in range(-1,104):
        if i==-1 or XY[i]:
            if sa > abs(X-i) :
                ans = i
                sa = abs(X-i)
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

template<class T> inline int sgn(T n) { if (n > 0) return 1; else if (n < 0) return -1; else return 0; }

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

const int MAX_N = 1000;
int prime[MAX_N];
bool is_prime[MAX_N+1];

int sieve(int n) {
  int p = 0;
  for (int i = 0; i <= n; i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i<= n; i++) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2*i; j <= n; j += i) is_prime[j] = false;
    }
  }
  return p;
}

int main () {
  ll n;
  cin >> n;

  sieve(1000);

  map<int,int> mp;

  FOR(i,2,n+1) {
    int x = i;
    FOR(j,2,i+1) {
      if (!is_prime[j]) continue;
      while (x%j == 0) {
        x /= j;
        mp[j]++;
      }
    }
  }

  ll ans = 1;
  for (auto p : mp) {
    ans *= (1 + p.se);
    ans %= mod;
  }

  cout << ans << endl;
 }


Measured memory_bytes: 256
import collections
N = (int(input()))

ans = 0
counter_list = []

for _ in range(N):
    s = input()
    counter_list.append("".join(sorted(s)))

ans = 0
wordcount = {}
for word in counter_list:
    if word in wordcount:
        wordcount[word] += 1
        ans += (wordcount[word])
    else:
        wordcount[word] = 0

print(ans)

Measured memory_bytes: 66904
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(a[K-1])

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

typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

	ll a, b, c;
	cin >> a >> b >> c;
	if(c >= a+b && 4*a*b < (c-a-b)*(c-a-b)){
        cout << "Yes";
	}
	else cout << "No";
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, W, H):
    return (N-W+1)*(N-H+1)


def main():
    N = read_int()
    H = read_int()
    W = read_int()
    print(slv(N, W, H))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7776