akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; ///4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};///8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};///Knight Direction
//int dx[]={2,1,-1,-2,-1,1};int dy[]={0,1,1,0,-1,-1}; ///Hexagonal Direction

inline int in() { int x; scanf("%d", &x); return x; }
inline ll inl() { ll x;scanf("%I64d",&x); return x;}
inline double ind() { double x;scanf("%lf",&x);return x;}

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

int gcd(int a,int b) { return b==0 ? a:gcd(b,a%b);}
int power( int x, int n)
{
    if(n==0)return 1;
    else if(n%2==0)
    {
        int y=power(x,n/2);
        return y*y;
    }
    else
        return x*power(x,n-1);
}
//abcdefghijklmnopqrstuvwxyz//
int pa[100010];
int findpa(int x)
{
    if(x==pa[x]) return x;
    return pa[x]=findpa(pa[x]);
}


main()
{
    #ifdef CP
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif // CP
    int n=in(),m=in(),a,b;
    for(int i=1;i<=n;i++) pa[i]=i;
    int conn=n;
    for(int i=0;i<m;i++)
    {
        a=in(),b=in();
        if(findpa(a)==findpa(b)) continue;
        if(a>b) swap(a,b);
        pa[findpa(b)]=findpa(a);
        conn--;
    }
    printf("%d\n",conn-1);
}



Measured memory_bytes: 4212
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll mod = 1e9 +7;
const ll MAXN = 1e6 + 5;

char s[MAXN];
ll dp[MAXN][2];


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	s[0]='0';
	cin>>s+1;
	int n=strlen(s+1);
	int k=s[n]-'0';
	dp[n][0]=k;//拿该位的个数 
	dp[n][1]=10-k;//找(10-该位) 拿该位上一个的个数 
	for(int i=n-1;i>=0;i--) {
		k=s[i]-'0';
		dp[i][0]=min(dp[i+1][0], dp[i+1][1]+1)+k;
		dp[i][1]=min(dp[i+1][0], dp[i+1][1]-1)+10-k;
	}
	cout<<min(dp[0][0], dp[0][1]) ;
	return 0;
}


Measured memory_bytes: 16896
import math
a,b,x = map(int,input().split())
if a * a * b / 2 >= x:
  dx = 2 * x / a / b
  sha = math.sqrt(b * b + dx * dx)
  co = b / sha
  print(90 - math.degrees(math.acos(co)))
else:
  dx = 2 * (a * a * b - x) / a / a
  sha = math.sqrt(a * a + dx * dx)
  co = a / sha
  print(math.degrees(math.acos(co)))

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
  int h[100],w[100];
  int i=0;
  while(1){
    cin>>h[i]>>w[i];
    if(h[i]==0&&w[i]==0){
      break;
    }
    i++;
  }
  for(int j=0;j<i;j++){
    for(int k=0;k<h[j];k++){
      for(int l=0;l<w[j];l++){
	cout<<'#';
      }
      cout<<endl;
    }
    cout<<endl;
  }
  return(0);
}

Measured memory_bytes: 3096
import scala.io.StdIn._

object Main extends App {


  val Array(a,b) = readLine().split(" ").map(_.toLong)

  def solve() = {
    calcLCM(a,b)
  }

  // Greatest Common Divisor
  def calcGCD(x: Long, y: Long): Long = {
    if(y == 0) x
    else calcGCD(y, x % y)
  }

  // Least Common Multiple
  def calcLCM(x: Long, y: Long): Long = {
    (x * y) / calcGCD(x, y)
  }

  println(solve())

}



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

int main() {
  int n;
  cin >> n;
  int f[n + 1] = {0};
  for (int x = 1; x <= sqrt(n); x++)
    for (int y = 1; y <= sqrt(n - x * x); y++)
      for (int z = 1; z <= sqrt(n - x * x - y * y); z++) {
        int tmp = x * x + y * y + z * z + x * y + y * z + z * x;
        if (tmp > n)
          continue;
        f[tmp]++;
      }
  for (int i = 1; i <= n; i++)
    cout << f[i] << endl;
  return 0;
}

Measured memory_bytes: 3504
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;



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

  ll N;
  cin >> N;
  vector<ll> d(N);
  REP(i,N){ cin >> d[i]; }

  ll ans = 0;
  REP(i,N){
    REP3(j,i+1,N){
      ans += d[i]*d[j];
    }
  }

  cout << ans << "\n";
  return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	map<char, ll> m;

	rep(i, s.size()){
		m[s[i]]++;
	}

	if (m.size() != 2){
		cout << "No\n";
		return 0;
	}

	ITR(itr, m){
		if (itr->se != 2){
			cout << "No\n";
			return 0;
		}
	}

	cout << "Yes\n";

	return 0;
}

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

int main(){
    int N;cin>>N;
    string S;
    vector<ll> count(5);
    for(int i=0;i<N;i++){
        cin>>S;
        if(S.at(0)=='M')count.at(0)++;
        else if(S.at(0)=='A')count.at(1)++;
        else if(S.at(0)=='R')count.at(2)++;
        else if(S.at(0)=='C')count.at(3)++;
        else if(S.at(0)=='H')count.at(4)++;
    }
    int flag=0;
    for(int i=0;i<5;i++)if(count.at(i))flag++;
    ll ans=0;
    if(flag<3)ans=0;
    else{
        for(int i=0;i<3;i++){
            for(int j=i+1;j<4;j++){
                for(int k=j+1;k<5;k++){
                    ans+=count.at(i)*count.at(j)*count.at(k);
                }
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  while(1){
    int r,w,c,rr;
    cin >> r >> w >> c >> rr;
    if(r==0&&w==0&&c==0&&rr==0)break;
    int co=0;
    while(1){
      if(r/w<c){
	r+=rr;
	co++;
      }
      else break;
    }
    cout << co << endl;

  }
  return 0;
}

Measured memory_bytes: 3076
"""
1 selectionSort(A, N) // N個の要素を含む0-オリジンの配列A
2   for i が 0 から N-1 まで
3     minj = i
4     for j が i から N-1 まで
5       if A[j] < A[minj]
6         minj = j
7     A[i] と A[minj] を交換
"""
def selectionSort(A, N):
    count = 0
    B = []
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        out = A[i]
        A[i] = A[minj]
        A[minj] = out
        if(A[i]!=A[minj]):
            count += 1
            
    print(' '.join(map(str, A)))
    print(str(count))
    
if __name__ == '__main__':
    N = int(input()) #1行目のNを取得する
    M = list(map(int,input().split()))
    selectionSort(M, N)


Measured memory_bytes: 5612
#include<iostream>
#include<algorithm>
using namespace std;
#define rep(i, n) for (int i = 1; i < (int)(n); i++)
int main()
{
    int a,b,c;
    int D;
    cin >> a >> b >> c >> D;
    if(abs(a - c) <= D)
    {
        cout << "Yes";
    }
    else if(abs(b - a) <= D && abs(c - b <= D))
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace V0100{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            int n;
            while((n = sr.Next<int>()) != 0){
                var result = sr.Next<long>(n, 3)
                    .GroupBy(x => x[0])
                    .Where(g => g.Sum(x => x[1] * x[2]) >= 1000000)
                    .Select(g => g.Key.ToString())
                    .ToArray();

                Console.WriteLine(result.Length == 0 ? "NA" : string.Join("\n", result));
            }
            //---------------------------------
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = Console.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var result = new T[x];
            for(var i = 0; i < x; ++i) result[i] = Next<T>();
            return result;
        }

        public T[][] Next<T>(int y, int x){
            var result = new T[y][];
            for(var i = 0; i < y; ++i) result[i] = Next<T>(x);
            return result;
        }
    }
}

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

using namespace std;
int n;
long long a[200000];
int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    if (a[n] != 2) {
        cout << "-1\n";
        return 0;
    }
    long long l = 2, r = 3;
    for (int i = n - 1; i >= 1; i--) {
        //a[i] * k
        l = l + (a[i] - (l % a[i])) % a[i];
        r = r - (r % a[i]);
        if (l > r) {
            cout << "-1\n";
            return 0;
        }
        r += a[i] - 1;

    }
    cout << l << " " << r << "\n";
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;
long long cnt;
int A[1000005];
vector<int> G;
void insertionSort(int A[], int n, int g);
void shellSort(int A[], int n);

int main()
{
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    scanf("%d", &A[i]);
  }
  cnt = 0;
  shellSort(A, n);
  cout << G.size() << endl;
  for (int i = G.size() - 1; i >= 0; i--)
  {
    printf("%d", G[i]);
    if (i)
    {
      printf(" ");
    }
  }
  printf("\n");
  printf("%lld\n", cnt);
  for (int i = 0; i < n; i++)
  {
    printf("%d\n", A[i]);
  }
  return 0;
}

void insertionSort(int A[], int n, int g)
{
  for (int i = g; i < n; i++)
  {
    int j = i;
    while (j - g >= 0 && A[j] < A[j - g])
    {
      int temp = A[j];
      A[j] = A[j - g];
      A[j - g] = temp;
      j -= g;
      cnt++;
    }
  }
}

void shellSort(int A[], int n)
{
  for (int h = 1;;)
  {
    if (h > n)
    {
      break;
    }
    G.push_back(h);
    h = 3 * h + 1;
  }

  for (int i = G.size() - 1; i >= 0; i--)
  {
    insertionSort(A, n, G[i]);
  }
}



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

using namespace std;
#define ll long long
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
const ll mod = 1e9 + 7;
typedef pair<int,int>           P;
typedef vector<P>               vip; 
typedef vector<int>             vi;
typedef vector<vi>              vvi;






int main (){
	int n, m;
	cin >> n >> m;
	vector<pair<ll,ll> > shop(n+1);
	REPS(i,n){
		cin >> shop.at(i).first >> shop.at(i).second;
	}

	sort(shop.begin(),shop.end());
	ll ans = 0;
	ll drink = 0;
	REPS(i,n){
		drink += shop.at(i).second;
		if(drink >= m){
			ll sa = drink - m;
			ans += shop.at(i).first *(shop.at(i).second - sa);
			break;
		}
		ans += shop.at(i).first * shop.at(i).second;
	}

	cout << ans << endl;





    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
    std::vector<std::string> candidates = {"dream", "dreamer", "erase", "eraser"};
    for (auto &c : candidates)
    {
        std::reverse(c.begin(), c.end());
    }

    std::string S;
    std::cin >> S;
    std::reverse(S.begin(), S.end());

    while (0 < S.size())
    {
        bool canReplace = false;
        // 一致する文字列を探す
        for (auto &c : candidates)
        {
            auto str = S.substr(0, c.size());
            if (str == c)
            {
                S = S.substr(c.size(), S.size());
                canReplace = true;
                continue;
            }
        }

        if (!canReplace)
        {
            std::cout << "NO";
            return 0;
        }
    }

    std::cout << "YES";
}

Measured memory_bytes: 512
use proconio::{fastout, input};

fn main() {
    input! {
        n: i64,
    };
    let max: i64 = (n as f64).sqrt().ceil() as i64;
    let mut f_vec: Vec<usize> = vec![0; n as usize];
    for x in 1..=max {
        for y in x..=max {
            for z in y..=max {
                let temp = (x + y + z) * (x + y + z) - x * y - y * z - z * x;
                if temp > n {
                    continue;
                }
                if x == y && x == z {
                    f_vec[temp as usize - 1] += 1;
                } else if x == y || y == z {
                    f_vec[temp as usize - 1] += 3;
                } else {
                    f_vec[temp as usize - 1] += 6;
                }
            }
        }
    }
    f_vec.iter().for_each(|f| println!("{}", f));
}


Measured memory_bytes: 2672
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define sc second
#define ve vector
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define ea(i, n) for(auto&& i: n)
#define so(n) sort(n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// abs 絶対値, rtsq ルート, pow(a, n) aのn乗

int main() {
  int A, B;
  ci(A, B);
  repi(i, 1, 1009) {
    if((int)(i * 0.08) == A && (int)(i * 0.10) == B) {
      co(i);
      return 0;
    }
  }
  co(-1);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

void print(const std::vector<int>& v)
{
  std::for_each(v.begin(), v.end(), [](int x) {
    std::cout << x << " ";
  });
  std::cout << std::endl;
}

int main ()
{
    int X,Y,Z;
    int K;
    cin>>X>>Y>>Z;
    cin>>K;
    vector<ll> A(X),B(Y),C(Z);
    for(int i = 0; i < X; i++)  cin>>A[i];
    for(int i = 0; i < Y; i++)  cin>>B[i];
    for(int i = 0; i < Z; i++)  cin>>C[i];

    vector<ll> AB;
    REP(i,X){
        REP(j,Y){
            AB.push_back(A[i]+B[j]);
        }
    }
    sort(AB.begin(),AB.end(),greater<ll>());
    vector<ll> ABC;
   for(int i =0;i<min(K,(int)AB.size());i++){
       for(int j = 0; j < Z; j++)
       {
           ABC.push_back(AB[i]+C[j]);
       }
   }
   sort(ABC.begin(),ABC.end(),greater<ll>());
    REP(i,K){
        cout<<ABC[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 43240
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() { 
    int k,s;cin >> k >> s;
    int count = 0;
    rep(i, k+1) {
        rep(j, k+1) {
            if(0<=s-i-j&&s-i-j<=k) count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3568
/*input
abracadabra
avadakedavra
*/
 
// author - Madhav Thakker
 
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace std;
 
#define ll long long
#define ld long double
#define int ll
#define endl '\n'

typedef pair<int, int> pii; 
typedef pair<ld, ld> pdd;
 
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FileIn(file) freopen(file, "r", stdin)
#define FileOut(file) freopen(file, "w", stdout)
#define all(c) c.begin(), c.end() 
#define tr(container, it )\
for(__typeof__(container.begin()) it = container.begin(); it != container.end(); it++) 
#define present(container, element) (container.find(element) != container.end())  //map, set
#define cpresent(container, element) (find(aint(container),element) != container.end()) //vector
#define what_is(x) cout << #x << " is " << x << endl; 
#define all(c) c.begin(), c.end() 
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
const int MOD = 1e9+7;
 
 
int fast_pow(int a, int b){
	int res = a, ret = 1;
	while(b>0){
		if(b%2)
			ret = (ret*res)%MOD;
		res = (res*res)%MOD;b/=2;
	}
	return ret;
}
 
// --
// -- 
// -- 
// std::cout << std::fixed;
// std::cout << std::setprecision(26) << f << '\n';
// str = to_string(n)
// stoi , stoll, stol
// sort(arr, arr+n, greater<int>());
// fill(prefix.begin(), prefix.end(), 0);
// 
// 
 
 
 
////
const int maxN = 1e5+700;
string a, b;
int dp[3007][3007];
////


signed main(){
 
	fastio;
	time_t time_t1, time_t2;
	time_t1 = clock();
 
	////////////////////////////////

	int t = 1;
	// cin >> t ;

	while(t--){

		cin >> a >> b;

		memset(dp, 0, sizeof dp);
		for (int i = 1; i <= a.size(); i++){
			for (int j = 1; j <= b.size() ; ++j){
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
				if(a[i-1]==b[j-1]){
					dp[i][j] = 1 + dp[i-1][j-1];
				}
			}
		}
		std::vector<char> ans;
		// cout << dp[a.size()][b.size()] << endl;
		for (int i = a.size(), j = b.size(); i > 0 and j>0; ){
			if(a[i-1] == b[j-1]){
				ans.push_back(a[i-1]);
				i--;
				j--;
			}
			else if(dp[i-1][j] > dp[i][j-1]){
				i--;
			}
			else{
				j--;
			}
		}
		reverse(all(ans));
		for(char x:ans){
			cout << x;
		}
		cout << endl;



	}
 	
	///////////////////////////////
	// 
 
	time_t2 = clock();
	// cerr << "time taken :" << time_t2 - time_t1 << endl;
 
	return 0;
}


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

int main(){
    string s;
    cin >> s;
    int n;
    n = s.size();
    bool check = true;
    for(int i = 0; i < n; i++){
        if(i % 2 == 0){
            if(s[i]=='L') check = false;
        }else{
            if(s[i]=='R') check = false;
        }
    }
    if(check){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
     if(a==1&&b==2) printf("%d",3);
     if(a==1&&b==3) printf("%d",2);
     if(a==2&&b==1) printf("%d",3);
     if(a==3&&b==1) printf("%d",2);
     if(a==2&&b==3) printf("%d",1);
     if(a==3&&b==2) printf("%d",1);
}




Measured memory_bytes: 128
import numpy as np
n = int(input())
count = 0
val_list = np.array(list(map(int, input().split())))

while True:
    # 偶数の数算出
    even_cnt = len(list(filter(lambda x:x % 2 == 0, val_list)))
    
    # 配列の値の偶数判定
    if n == even_cnt:
        # 配列の割り算
        val_list = val_list/2
        # 上記繰り返しの回数保存
        count += 1
    else:
        break
print(count)

Measured memory_bytes: 12484
#include <bits/stdc++.h>
using namespace std;
typedef priority_queue <int> pqi;

int main() {
	int n, m;
	cin >> n >> m;
	pqi a;
	a.push(n * 2 - 1);
	a.push(m * 2 - 1);
	a.push(m + n);
	cout << a.top() << endl;
	return 0;
}


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

int main() {
  string str, a, b, c, d;
  cin >> str;
  a = str.substr(0,1);
  b = str.substr(1,1);
  c = str.substr(2,1);
  d = str.substr(3,1) ; 
    
  if ((a == b && b == c) || (b == c && c == d)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
long long longpow(long long n, long long a, long long mod) {
  if (a == 0) return 1;
  if (a == 1) return n % mod;
  if (a % 2 == 1) return (n * longpow(n, a - 1, mod)) % mod;
  ll t = longpow(n, a / 2, mod) % mod;
  return (t * t) % mod;
}
int main() {
  ll N;
  cin >> N;
  int mx = 1;
  for (int i = 2; i <= N; i++) {
    for (int j = 2; longpow(i, j, MOD) <= N; j++) {
      mx = max<ll>(mx, longpow(i, j, MOD));
    }
  }
  cout << mx << endl;
}

Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

class Main {

	public static void main(final String[] args) throws Exception {

		try {

			final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			final String[] inputString = br.readLine().split(" ");

			final List<Integer> candyPackCountList = Arrays.asList(inputString).stream().map(s -> Integer.parseInt(s))
					.sorted((i1, i2) -> i2 - i1).collect(Collectors.toList());

			final boolean isPossible = getPossible(candyPackCountList);

			String result;

			if (isPossible) {
				result = "Yes";
			} else {
				result = "No";
			}

			System.out.println(result);

		} catch (IOException | NumberFormatException e) {
			e.printStackTrace();
			System.exit(0);
		} catch (final Exception e) {
			e.printStackTrace();
			System.exit(0);
		}

	}

	public static boolean getPossible(final List<Integer> candyPackCountList) {
		return candyPackCountList.get(0) == candyPackCountList.get(1) + candyPackCountList.get(2);
	}
}

Measured memory_bytes: 26708
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e9)
using namespace std;
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B,C;
    cin >> A >> B >> C;
    bool ans = false;
    rep(i,A, A*B+1){
        if(i % A != 0) continue;
        if(i % B == C) ans = true;
    }
    if(ans){
        print("YES");
    }else{
        print("NO");
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
 
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define F first
#define S second
#define MP make_pair
#define PB push_back
 
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)
int main(){
	int a,b;
	cin>>a>>b;
	int ct=0;
	int temp=1;
	int time=a;
	while(b>temp){
		temp+=a-1;
		ct++;
	}
	//int ans=ceil((b-1)/(a-1));
	wd(ct);
	NL;
	return 0;
}

Measured memory_bytes: 256
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll ans = 0;
    rep(i,0,n){
        ll a; cin >> a;
        while(a % 2 == 0){
            a /= 2;
            ans++;
        }
    }

    cout << ans << "\n";
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    string s, t;
    cin >> s >> t;
    int ns = s.length(), nt = t.length();
    int ans = INF;
    for(int i = 0; i + nt <= ns; ++i){
        int count = 0;
        for(int j = 0; j < nt; ++j){
            if(s[i + j] != t[j])    ++count;
        }
        chmin(ans, count);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <ctype.h>

int main(){

    char a[10],b[10],c[10];
    scanf("%s %s %s",a,b,c);

    a[0]=toupper(a[0]);
    b[0]=toupper(b[0]);
    c[0]=toupper(c[0]);

    printf("%c%c%c\n",a[0],b[0],c[0]);

    

    return 0;
}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main{

	double EPS = 1e-9;
	
	class P implements Comparable<P>{
		double x, y;
		boolean me, up;
		public P(double x, double y, boolean me, boolean up) {
			this.x = x;
			this.y = y;
			this.me = me;
			this.up = up;
		}
		public int compareTo(P o) {
			if(Math.abs(x-o.x)<EPS)return (int) Math.signum(x-o.x);
			else return (int) Math.signum(y-o.y);
		}
	}
	
	boolean cross(P a, P b, P s, P t){
		if(ex(a, b, s)*ex(a, b, t)>0)return false;
		if(ex(b, a, s)*ex(b, a, t)>0)return false;
		if(ex(t, s, a)*ex(t, s, b)>0)return false;
		return ex(s, t, a)*ex(s, t, b)<EPS;
	}
	double ex(P s, P t, P r){
		double x1 = t.x-s.x, y1 = t.y-s.y, x2 = r.x-s.x, y2 = r.y-s.y;
		return x1*y2-x2*y1;
	}
	double dist(P a, P b, P p){
		double x1 = b.x-a.x, y1 = b.y-a.y, x2 = p.x-a.x, y2 = p.y-a.y;
		return Math.abs((x1*y2-x2*y1))/Math.hypot(x1, y1);
	}
	P cp(P a, P b, P s, P t, boolean m, boolean u){
		double ds = dist(a, b, s), dt = dist(a, b, t);
		double k = ds/(ds+dt);
		double dx = t.x-s.x, dy = t.y-s.y;
		return new P(s.x+k*dx, s.y+k*dy, m, u);
	}
	boolean on(P a, P b, P p){
		if(Math.abs(a.x-b.x)<EPS)return Math.min(a.y, b.y)<=p.y&&p.y<=Math.max(a.y, b.y);
		double alpha = (b.y-a.y)/(b.x-a.x);
		double beta = a.y-alpha*a.x;
		if(Math.abs(p.y-(alpha*p.x+beta))>EPS)return false;
		return Math.min(a.x, b.x)<=p.x&&p.x<=Math.max(a.x, b.x);
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		while(T--!=0){
			P A = new P(sc.nextDouble(), sc.nextDouble(), true, true), B = new P(sc.nextDouble(), sc.nextDouble(), true, true);
			int n = sc.nextInt();
			P[][] line = new P[n][2];
			for(int i=0;i<n;i++){
				double x1 = sc.nextDouble(), y1 = sc.nextDouble(), x2 = sc.nextDouble(), y2 = sc.nextDouble();
				boolean m = sc.nextInt()==1, u = sc.nextInt()==1;
				line[i][0] = new P(x1, y1, m, u);
				line[i][1] = new P(x2, y2, m, u);
			}
			List<P> l = new ArrayList<P>();
			for(int i=0;i<n;i++){
				P s = line[i][0], t = line[i][1];
				double x1 = B.x-A.x, y1 = B.y-A.y, x2 = t.x-s.x, y2 = t.y-s.y;
				if(Math.abs(x1*y2-x2*y1)<EPS){
					if(on(A, B, s))l.add(s);
					if(on(A, B, t))l.add(t);
				}
				else 
					if(cross(A, B, s, t))l.add(cp(A, B, s, t, s.me, s.up));
			}
			Collections.sort(l);
			int res = 0;
			if(l.size()>0){
				P h = l.get(0);
				boolean u = h.me?h.up:!h.up;
				for(int i=1;i<l.size();i++){
					h = l.get(i);
					if(h.me){
						if(h.up!=u){
							res++; u=!u;
						}
					}
					else{
						if(h.up==u){
							res++; u=!u;
						}
					}
				}
			}
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

typedef long long ll;
int main()
{
	int t=1;
	// cin >> t ;

	while(t--)
	{
		int n,k;
		cin>>n>>k;

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

		vector<int> ans(n,1e9);
		
		ans[n-1]=0;

		
		for(int i=n-2; i>=0; i--)
		{
			for(int j=1; j<=k; j++)
			{	
				if(i+j<n)
					ans[i] = min(ans[i], abs(h[i+j]-h[i]) + ans[i+j]);
			}
		}		
		cout<<ans[0]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using Matrix = vector<vector<int>>;

int	main()
{
	int n, m, l;
	cin >> n >> m >> l;
	Matrix	a(n, vector<int>(m)), b(m, vector<int>(l));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j)
			cin >> a.at(i).at(j);
	}
	for (int j = 0; j < m; ++j) {
		for (int k = 0; k < l; ++k)
			cin >> b.at(j).at(k);
	}
	for (int i = 0; i < n; ++i) {
		for (int k = 0; k < l; ++k) {
			int64_t	val = 0;
			for (int j = 0; j < m; ++j)
				val += a.at(i).at(j) * b.at(j).at(k);
			if (k == 0)
				cout << val;
			else
				cout << " " << val;
		}
		cout << endl;
	}
}

	
	



Measured memory_bytes: 3244
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		int a;
		String op;
		int b;
		int result = 0;
		boolean flag = true;
		Scanner sc = new Scanner(System.in);
		while(flag){
			a = sc.nextInt(); 
			op = sc.next();
			b = sc.nextInt();
			if(op.equals("?")){
				//flag = false;
				break;
			}
			switch(op){
				case "+":
					System.out.println(a + b);
					break;
				case "-":
					System.out.println(a - b);
					break;
				case "*":
					System.out.println(a * b);
					break;
				case "/":
					System.out.println(a / b);
					break;
				case "?":
					flag = false;
					break;
			}
			
		}
	}
}
			


Measured memory_bytes: 25984
N,K= map(int, input().split())
A = [int(i) for i in input().split()]

XX=0
YY=0
for x in range(0,N-1):
    for y in range(x+1,N):
        if A[x]>A[y]:
            XX=XX+1
for x in range(0,N):
    for y in range(0,N):
        if A[x]>A[y]:
            YY=YY+1
S=XX*K+YY*(K**2-K)//2
S=S%(10**9+7)
print(S)


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

int main() {
	int n, k, ans;
	cin >> n >> k;

	/*使わない
	int a[1000];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	*/
	
	ans = (n - 1) / (k - 1);
	if ((n - 1) % (k - 1) != 0) {
		ans++;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long n, a, b; cin >> n >> a >> b;
	if((a&1) == (b&1)) cout << (b - a)/2 << endl;
	else {
		long long ans = 1ll<<60;
		{
			long long na = 1, nb = b - (a - 1), r = a - 1;
			while((na & 1) != (nb & 1)){
				na = 1;
				nb--;
				r++;
			}
			r += (nb - na) / 2;
			ans = min(ans, r);
		}
		{
			long long na = a + (n - b), nb = n, r = n - b;
			while((na & 1) != (nb & 1)){
				na++;
				nb = n;
				r++;
			}
			r += (nb - na) / 2;
			ans = min(ans, r);
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[3][3];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>a[i][j];
    }
  }
  int N;
  cin>>N;
  int b[N];
  for(int i=0;i<N;i++){
    cin>>b[i];
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(a[j][k]==b[i]){
          a[j][k]=10000;
        }
      }
    }
  }
  bool ans=false;
  if(a[0][0]==a[0][1]&&a[0][0]==a[0][2]||a[1][0]==a[1][1]&&a[1][0]==a[1][2]||a[2][0]==a[2][1]&&a[2][0]==a[2][2]){
    ans=true;
  }
  else if(a[0][0]==a[1][0]&&a[0][0]==a[2][0]||a[0][1]==a[1][1]&&a[0][1]==a[2][1]||a[0][2]==a[1][2]&&a[0][2]==a[2][2]){
    ans=true;
  }
  else if(a[0][0]==a[1][1]&&a[0][0]==a[2][2]||a[0][2]==a[1][1]&&a[0][2]==a[2][0]){
    ans=true;
  }
  
  if(ans){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>

using namespace std;

/*相手の駒と接触したら、あとは相手を壁側に追い詰めることができるので、勝ちである。
接触するということは、距離1になるということ。結局、自分の手番で距離が偶数で回ってきたら勝ちである。
*/

int main() {
	int N, A, B;

	scanf("%d %d %d", &N, &A, &B);

	if ((A - B) % 2 == 0) { printf("Alice\n"); }
	else { printf("Borys\n"); }

	return 0;

}

Measured memory_bytes: 128
n = int(input())
p = list(map(int, input().split()))

cnt = 1
min_p = p[0]

if n == 1:
    print(n)
else:
    for i in range(1, n):
        if p[i] < min_p:
            min_p = p[i]
            cnt += 1
    print(cnt)

Measured memory_bytes: 24744
#include <bits/stdc++.h>
using namespace std;
int main(){
 int h,w;
  cin >> h >> w;
  vector<vector<bool>> da(h,vector<bool>(w,false));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      int x;
      cin >> x;
      if(x%2)
        da[i][j]=true;
    }
  }
  int co=0;
  vector<vector<int>> ans(250000);
  for(int i=0;i<h;i++){
    for(int j=0;j<w-1;j++){
      if(da[i][j]){
        da[i][j]=false;
        da[i][j+1]=!da[i][j+1];
        ans[co]={i+1,j+1,i+1,j+2};
        co++;
      }
    }
  }
  for(int i=0;i<h-1;i++){
    if(da[i][w-1]){
      da[i][w-1]=false;
      da[i+1][w-1]=!da[i+1][w-1];
      ans[co]={i+1,w,i+2,w};
      co++;
    }
  }
  cout << co << endl;
  for(int i=0;i<co;i++){
    cout << ans[i][0] << ' ' << ans[i][1] << ' ' << ans[i][2] << ' ' << ans[i][3] << endl;
  }
  /*for(int i=0;i<h;i++){
    for(int j=0;j<w;j++)
      cout << da[i][j] << ' ';
    cout << endl;
  }*/
}


Measured memory_bytes: 11904
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

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

#define v vector
#define ALL(x) x.begin(),x.end()
#define rALL(x) x.rbegin(),x.rend()
#define DEBUG

template<typename T> void DBG(const char* name, T&& H) {
	cerr << name << " = " << H << ')' << endl;
}

template<typename T, typename... Args> void DBG(const char* names, T&& H, Args&&... args) {
	const char* NEXT = strchr(names+1, ',');
	cerr.write(names, NEXT-names) << " = " << H << " |";
	DBG(NEXT+1, args...);
}

#ifdef DEBUG
	#define dbg(...) cerr << __FUNCTION__ << ' ' <<__LINE__ << " : (", DBG(#__VA_ARGS__, __VA_ARGS__)
#else
	#define dbg(...)
#endif

using ll = long long;
using ld = long double;

const long long mod = 1e9+7;
const long double PI = acos(-1.0);
const long long INF = 1e18;
const int maxN = 2e5+1;

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

bool can(int x, int y) {
	return ((x >= 0) && (y >= 0) && (x < 500) && (y < 500));
}

vector<long long> Sieve(int N) {
	vector<long long> primes;
	vector<bool> isPrime(N+1, 0);
	for(int i = 2; i < N+1; i ++) {
		if(isPrime[i] == 0) {
			primes.push_back(i);
			for(int j = i+i; j < N+1; j += i) {
				isPrime[j] = 1;
			}
		}
	}
	return primes; 
}

void Solve() {
	vector<long long> p = Sieve(int(1e5));
	vector<vector<long long>> mat(500, vector<long long>(500, 1));
	vector<pair<int, int>> start;
	int ptr = -1;
	for(int i = 0; i < 500; i += 2) {
		ptr ++;
		int x = 0, y = i;
		while((x < 500) && (y < 500)) {
			mat[x][y] *= p[ptr];
			x ++, y ++;
		}
		if(i == 0) continue;
		ptr ++;
		x = i, y = 0;
		while((x < 500) && (y < 500)) {
			mat[x][y] *= p[ptr];
			x ++, y ++;
		}
	}
	for(int i = 0; i < 500; i += 2) {
		ptr ++;
		int x = i, y = 0;
		while((x >= 0) && (y < 500)) {
			mat[x][y] *= p[ptr];
			x --, y ++;
		}
		ptr ++;
		x = 499, y = i+1;
		while((x >= 0) && (y < 500)) {
			mat[x][y] *= p[ptr];
			x --, y ++;
		}
	}
	for(int i = 0; i < 500; i ++) {
		for(int j = 0; j < 500; j ++) {
			if(mat[i][j] != 1) continue;
			long long LCM = 1;
			for(int k = 0; k < 4; k ++) {
				int x = i+dx[k], y = j+dy[k];
				if(can(x, y)) {
					long long other = mat[x][y];
					long long GCD = __gcd(LCM, other);
					other /= GCD;
					LCM *= other;
				}
			}
			mat[i][j] = LCM+1;
		}
	}
	int N;
	cin >> N;
	for(int i = 0; i < N; i ++) {
		for(int j = 0; j < N; j ++) {
			cout << mat[i][j] << " ";
		}
		cout << endl;
	}
}

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

	int tt = 1; 
	for(int i = 1; i <= tt; i ++) {
		Solve();
	}
	
	return 0;
}

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

int main()
{
    int N;
    cin >> N;
    
    vector<int> order = vector<int>(N, 0);
    
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        order[x-1] = i+1;
    }
    
    for (int i = 0; i < N; i++) {
        cout << order[i];
        if (i < N) {
            cout << " ";
        }
    }
    
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 1280
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    Main() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            int num = sc.nextInt() - 1;
            a[i] = num;
        }
        int p = 0;
        int np;
        int cnt = 0;
        while (true) {
            cnt++;
            np = a[p];
            if (np == -1) {
                System.out.println(-1);
                return;
            } else if (np == 1) {
                System.out.println(cnt);
                return;
            }
            a[p] = -1;
            p = np;
        }
    }

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


Measured memory_bytes: 49528
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <numeric>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

typedef unsigned long long ull;

int main()
{
  int n, s = 0;
  cin>>n;
  
  int hoge = n;
  do {
  	s += hoge % 10;
    hoge /= 10;
  } while (hoge);
  
  if (n%s == 0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int inf = 1e18;

signed main() {

  int a, b, q;
  cin >> a >> b >> q;
  vector<int> s(a + 2), t(b + 2), x(q);

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

  for (int i = 1; i <= b; i++) {
    cin >> t[i];
  }
  s[0] = t[0] = -1 * inf;
  s[a + 1] = t[b + 1] = inf;
  for (auto &&w : x) {
    cin >> w;
  }

  for (auto &&w : x) {
    int res = inf;
    int sr = *lower_bound(s.begin(), s.end(), w);
    int sl = *(lower_bound(s.begin(), s.end(), w) - 1);
    int tr = *lower_bound(t.begin(), t.end(), w);
    int tl = *(lower_bound(t.begin(), t.end(), w) - 1);
    for (int s0 : {sl, sr})
      for (int t0 : {tl, tr}) {
        res = min(res, abs(w - s0) + abs(s0 - t0));
        res = min(res, abs(w - t0) + abs(s0 - t0));
      }
    cout << res << endl;
  }
}


Measured memory_bytes: 3712
#include <iostream>
#include <algorithm>

using namespace std;

#define N 100000

int main(void){
    int n;
    int nums[N];
    
    cin >> n;
    for(int j = 0;j < n;++j){
        cin >> nums[j];
    }
    // 末端
    int x = nums[n - 1];
    int i = 0;
    for(int j = 0;j < n - 1;++j){
        if(nums[j] <= x){
            swap(nums[i],nums[j]);
            ++i;
        }
    }
    swap(nums[i],nums[n - 1]);
    
    // 表示
    for(int j = 0;j < n;++j){
        if(j == i){
            cout << "[" << nums[j] << "]";
        }else{
            cout << nums[j];
        }
        
        if(j + 1 < n){
            cout << " ";
        }
    }
    cout << endl;
}



Measured memory_bytes: 3468
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
int fg(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
signed main(){
 int a;
  cin>>a;
 vector<int> vec(a);
  rep(i,a){
  cin>>vec[i];
  }
  sort(all(vec));
  reverse(all(vec));
  int p=a/2;
  int q=a%2;
  int p1=p-1;
  int sum=0;
  rep(j,p1){
   sum+=vec[j+1];
  }
  cout<<vec[0]+sum*2+q*vec[p1+1];
}   

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  ll n, m, p, y;
  cin >> n >> m;
  vector<P> a(m);
  map<P, int> ump;
  map<int, map<int, P> > mp;
  for(int i = 0; i < m; ++i)
  {
    cin >> p >> y;
    P ind = P(p, y);
    a[i] = ind;
    ump[ind] = i;
    mp[p][y] = ind;
  }

  for(const auto& ip : mp)
  {
    int ind = 1;
    for(const auto& im : ip.second)
    {
      a[ump[im.second]].second = ind;
      ind++;
    }
  }

  for(const auto& city : a)
  {
    cout << setfill('0') << right << setw(6) << city.first << setw(6) << city.second << endl;
  }

}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 26636
import Data.List

f x@([d,v]:_) =
  sum $ g $ sortBy s x
  where
    s [a0,a1] [b0,b1] =
      let c0 = compare a0 b0
          c1 = compare b1 a1
      in
        if c0 /= EQ then c0 else c1
    g [] = []
    g ([d,v]:x) =
      let r = dropWhile (\ [d',v'] -> d == d' ) x
      in
        v:(g r)
        

ans ([0,0]:_) = []
ans ([n,m]:x) =
  let d = take n x
      r = drop n x
      a = f d
  in
    a:(ans r)

main = do
  c <- getContents
  let i = map (map read) $ map words $ lines c :: [[Int]]
      o = ans i
  mapM_ print o
      



Measured memory_bytes: 5328