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

int main(){
  int N,K;
  cin>>N>>K;
  int sum=0;
  for(int i=0;i<N;i++){
    int x;
    cin>>x;
    if(x<=(K-x)) sum+=2*x;
    else sum+=2*(K-x);
  }
  cout<<sum<<endl;
  
}

Measured memory_bytes: 3628
N=int(input())
A=list(map(int,input().split()))

c=0
for i in range(len(A)):
    for j in range(1,len(A)):
        if A[j] < A[j-1]:
            temp=A[j-1]
            A[j-1]=A[j]
            A[j]=temp
            c+=1
print(*A)
print(c)




Measured memory_bytes: 5604
#include <iostream>
#include <string>

using namespace std;

int main () {
   string S;
   cin>>S;
   int a=S.length(),x=0;
   for(int i=0;i<a;i++){
       if(S[i]!=S[a-i-1]){
           x++;
       }
   }
   x=(x-(x%2))/2;
   cout<<x;
   return 0;   }


Measured memory_bytes: 256
N, H, D = map(int, input().split())

MOD = 10**9 + 7

v = 1
w = 0
for i in range(1, N+1):
    v = v * i % MOD
    w += v
v %= MOD
w %= MOD

dp = [0]*(H+1)
dp[0] = v
s = 0
for i in range(H):
    s += dp[i] % MOD
    if i+1 < H:
        dp[i+1] = s * w % MOD
    else:
        dp[i+1] = s % MOD
    if i-D+1 >= 0:
        s -= dp[i-D+1] % MOD
print(dp[H])

Measured memory_bytes: 42544
import java.util.Scanner;

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

      int ans = a*b;

      //計算結果を出力をする
      if(ans % 2 == 0){
      System.out.println("Even");
        }else{
        System.out.println("Odd");
      }
    }
  }



Measured memory_bytes: 22608
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long a,sum = 0,max = -1000000, min = 1000000;
        long n = sc.nextLong();
        
        for(int i = 0; i < n; i++){
            a = sc.nextLong();
            if(a < min){
                min = a;
            }
            if(a > max){
                max = a;
            }
            sum+=a;
        }
        System.out.println(min + " " + max + " " + sum);
    }
}



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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

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


long long int n,cnt=0,ans=0,a[ohara],b[ohara],c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>n;
      rep(i,n)cin>>a[i]>>b[i];
      ll nowa=a[0],nowb=b[0];
      rrep(i,1,n){
      cmp=nowa/a[i];
      if(nowa%a[i]!=0)cmp++;
      cmpp=nowb/b[i];
      if(nowb%b[i]!=0)cmpp++;
      if(cmp>cmpp){
        nowa=a[i]*cmp;
        nowb=b[i]*cmp;
      }
      else{
        nowb=b[i]*cmpp;
        nowa=a[i]*cmpp;
      }
      }
      Cout(nowa+nowb);
     

       
return 0;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w,need;
  long long ans = 0;
  cin >> h >> w >> need;
  vector<string> s(h);
  for(int i = 0;i < h;i++){
    cin >> s[i];
  }
  for(int i = 0;i < (1 << h);i++){
    for(int j = 0;j < (1 << w);j++){
      int bl = 0;
      for(int k = 0;k < h;k++){
        for(int l = 0;l < w;l++){
          if(!(i & (1 << k)) && !(j & (1 << l)) && s[k][l] == '#')bl++;
        }
      }
      if(bl == need)ans++;
    }
  }
  cout << ans << endl;
}

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

#define MAX 100000

struct Node {
    int parent;
    int left;
    int right;
    int depth;
};

Node N[MAX];

void setDepth(Node& n, int depth) {
    Node* cur = &n;
    while (true) {
        cur->depth = depth;
        if (cur->left >= 0) {
            setDepth(N[cur->left], depth + 1);
        }
        if (cur->right < 0) break;
        cur = &N[cur->right];
    }
}

void print(Node n, int id) {
    std::string type;
    if (n.parent < 0) {
        type = "root";
    }
    else if (n.left < 0) {
        type = "leaf";
    }
    else {
        type = "internal node";
    }


    printf("node %d: parent = %d, depth = %d, %s, [", id, n.parent, n.depth, type.c_str());
    if (n.left >= 0) {
        printf("%d", n.left);
        Node cur = N[n.left];
        while (cur.right >= 0) {
            printf(", %d", cur.right);
            cur = N[cur.right];
        }
    }
    printf("]\n");
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        N[i].parent = -1;
        N[i].left = -1;
        N[i].right = -1;
    }

    for (int i = 0; i < n; ++i) {
        int id, k;
        scanf("%d", &id);
        scanf("%d", &k);

        if (k <= 0) continue;

        int left = -1;
        int C[k];
        for (int j = 0; j < k; ++j) {
            scanf("%d", &C[j]);
        }
        for (int j = 0; j < k; ++j) {
            N[C[j]].parent = id;
            N[C[j]].right = j < k-1 ? C[j+1] : -1;
        }
        N[id].left = C[0];
    }

    int root = -1;
    for (int i = 0; i < n; ++i) {
        if (N[i].parent == -1) {
            root = i;
            break;
        }
    }

    setDepth(N[root], 0);

    for (int i = 0; i < n; ++i) print(N[i], i);

}

Measured memory_bytes: 4752
from itertools import accumulate
n,q = map(int,input().split())
s = input()
a = [0] + [s[i-1:i+1] == 'AC' for i in range(1,n)]
acc = list(accumulate(a))

for i in range(q):
    l,r = map(int,input().split())
    print(acc[r-1] - acc[l-1])


Measured memory_bytes: 53864
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	string S;
	cin >> S;
	int count;
	count=0;
	for(int i=0;i<S.size();i++){
		if(S.at(i)=='x'){
			count++;		}
	}
	if(count>7){
		cout << "NO" << endl;
	}
	else{cout << "YES" << endl;}
	}

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

int main() {
    int cnt = 0, n = 0, s = 0;

    char N[20];
    for (int i = 0; i < 20; i++) {
        scanf("%c", &N[i]);
        if (N[i] == '\n') {
            break;
        }
        cnt++;
    }

    for (int i = 0; i < cnt; i++) {
        int x = (int)(N[i] - '0');
        n += x * pow(10, cnt - i - 1);
        s += x;
    }

    if (n % s == 0) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        words: [String; n],
    }
    let len0 = words.len();
    let mut procs = words.clone();
    procs.sort();
    procs.dedup();
    
    let is_valid = words.windows(2).all(|sib| {
        sib[1].starts_with(sib[0].chars().last().unwrap())
    });

    println!(
        "{}",
        if is_valid && (procs.len() == len0) {
            "Yes"
        } else {
            "No"
        });
}

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

int main() {

	long  double n, m, d;
	cin >> n >> m >> d;
	if (d == 0) {
		cout << setprecision(9) << ((m - 1.0) / n) << endl;
	}
	else {
		cout << setprecision(9) << 2.0*(((n - d)*((m - 1.0) / n))/n) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
a,b,c,d = gets.split(" ").map(&:to_i)
h = 0 #高い方
m = 0 #中間
l = 0 #高い方
if a < c then
  h = c
  l = a
else
  h = a
  l = c
end
if a < b && b < c || c < b && b < a then
  m = b
end
  
if h - l <= d then
  print "Yes"
elsif m - l <= d && h - m <= d then
  print "Yes"
else 
  print "No"
end

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

template<int mod>
struct ModInt{
	int x;
	ModInt () : x(0) {}
	ModInt (int64_t x) : x(x >= 0 ? x % mod : (mod - -x % mod) % mod) {}
	ModInt &operator += (const ModInt &p){
		if ((x += p.x) >= mod) x -= mod;
		return *this;
	}
	ModInt &operator -= (const ModInt &p) {
		if ((x += mod - p.x) >= mod) x -= mod;
		return *this;
	}
	ModInt &operator *= (const ModInt &p) {
		x = (int64_t) x * p.x % mod;
		return *this;
	}
	ModInt &operator /= (const ModInt &p) {
		*this *= p.inverse();
		return *this;
	}
	ModInt &operator ^= (int64_t p) {
		ModInt res = 1;
		for (; p; p >>= 1) {
			if (p & 1) res *= *this;
			*this *= *this;
		}
		return *this = res;
	}
	ModInt operator - () const { return ModInt(-x); }
	ModInt operator + (const ModInt &p) const { return ModInt(*this) += p; }
	ModInt operator - (const ModInt &p) const { return ModInt(*this) -= p; }
	ModInt operator * (const ModInt &p) const { return ModInt(*this) *= p; }
	ModInt operator / (const ModInt &p) const { return ModInt(*this) /= p; }
	ModInt operator ^ (int64_t p) const { return ModInt(*this) ^= p; }
	bool operator == (const ModInt &p) const { return x == p.x; }
	bool operator != (const ModInt &p) const { return x != p.x; }
	explicit operator int() const { return x; }
	ModInt &operator = (const int p) { x = p; return *this;}
	ModInt inverse() const {
		int a = x, b = mod, u = 1, v = 0, t;
		while (b > 0) {
			t = a / b;
			a -= t * b;
			std::swap(a, b);
			u -= t * v;
			std::swap(u, v);
		}
		return ModInt(u);
	}
	friend std::ostream & operator << (std::ostream &stream, const ModInt<mod> &p) {
		return stream << p.x;
	}
	friend std::istream & operator >> (std::istream &stream, ModInt<mod> &a) {
		int64_t x;
		stream >> x;
		a = ModInt<mod>(x);
		return stream;
	}
};

typedef ModInt<1000000007> mint;

template<int mod> struct MComb {
	using mint = ModInt<mod>;
	std::vector<mint> fact;
	std::vector<mint> inv;
	MComb (int n) { // O(n + log(mod))
		fact = std::vector<mint>(n + 1, 1);
		for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * mint(i);
		inv.resize(n + 1);
		inv[n] = fact[n] ^ (mod - 2);
		for (int i = n; i--; ) inv[i] = inv[i + 1] * mint(i + 1);
	}
	mint ncr(int n, int r) {
		return fact[n] * inv[r] * inv[n - r];
	}
	mint npr(int n, int r) {
		return fact[n] * inv[n - r];
	}
	mint nhr(int n, int r) {
		assert(n + r - 1 < (int) fact.size());
		return ncr(n + r - 1, r);
	}
};


int main() {
	int n = ri();
	mint res = mint(10) ^ n;
	res -= mint(9) ^ n;
	res -= mint(9) ^ n;
	res += mint(8) ^ n;
	std::cout << res << std::endl;
	return 0;
}


Measured memory_bytes: 3684
import sys
input = sys.stdin.readline
N, X = map(int, input().split())
A = list(map(int, input().split()))
B = [0]
cnt = 0

for i in range(N):
  B.append(B[i]+A[i])

for i in range(len(B)):
  if B[i] <= X:
    cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
#define MAX 2000000

int H, A[MAX+1];

void maxHeapify(int i) {
  int l, r, largest;
  l = 2 * i;
  r = 2 * i + 1;

  largest = i;
  if ( l <= H && A[l] > A[i] ) largest = l;
  if ( r <= H && A[r] > A[largest] ) largest = r;

  if ( largest != i ) {
    swap(A[i], A[largest]);
    maxHeapify(largest);
  }
}

int main() {
  cin >> H;

  for ( int i = 1; i <= H; i++ ) cin >> A[i];

  for ( int i = H / 2; i >= 1; i-- ) maxHeapify(i);

  for ( int i = 1; i <= H; i++ )
    cout << " " << A[i];
  cout << endl;

  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> idx(n);
    rep(i, n) cin >> a[i];
    rep(i, n) a[i]--;
    rep(i, n) idx[a[i]] = i;


    set<int> watchedNum;
    ll ans = 0;
    //a[x]:x番目の数字, idx[x]:xに大きい数字の順番(0始まり)
    for (int x = n - 1; x >= 0; x--)
    {
        int tmp = idx[x];
        watchedNum.insert(tmp);

        vector<int> l(2, -1);
        vector<int> r(2, n);
        {
            auto itr = watchedNum.find(tmp);
            for (int i = 0; i < 2; i++)
            {
                if (itr == watchedNum.begin()) break;
                itr--;
                l[i] = *itr;                
            }
        }
        {
            auto itr = watchedNum.find(tmp);
            for (int i = 0; i < 2; i++)
            {
                itr++;
                if (itr == watchedNum.end()) break;
                r[i] = *itr;
            }
        }
        vector<int> ls(2);
        vector<int> rs(2);
        ls[0] = tmp - l[0]; ls[1] = l[0] - l[1];
        rs[0] = r[0] - tmp; rs[1] = r[1] - r[0];
        ll c = (ll)(ls[0] * rs[1]) + (ll)(ls[1] * rs[0]);
        ans += c * (x + 1);   
    }

    cout << ans << endl;
}



Measured memory_bytes: 5760
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
  #include <atomic>
  #include <chrono>
  #include <condition_variable>
  #include <forward_list>
  #include <future>
  #include <initializer_list>
  #include <mutex>
  #include <random>
  #include <ratio>
  #include <regex>
  #include <scoped_allocator>
  #include <system_error>
  #include <thread>
  #include <tuple>
  #include <typeindex>
  #include <type_traits>
  #include <unordered_map>
  #include <unordered_set>
typedef long long int ll;
using namespace std;


int main() {
    ll A,B,C;
    cin >> A >> B >> C;
    ll D=C-A-B;
    if(D>0&&4*A*B<D*D){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int c[100010],v[100010];
int comp(const void*p,const void*q){
	if(v[*(int*)p]>v[*(int*)q])return -1;
	return 1;
}

int lim[100010];
int idx[100010];
int main(){
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<k;i++)scanf("%d",lim+i);
	for(int i=0;i<n;i++)scanf("%d%d",c+i,v+i),idx[i]=i;
	qsort(idx,n,sizeof(int),comp);
	long ans=0;
	for(int i=0;m>0&&i<n;i++)if(lim[c[idx[i]]-1]-->0)ans+=v[idx[i]],m--;
	printf("%ld\n",ans);
}


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

struct DisjointSet
{
    int g;
    vector<int> rank, p;
    DisjointSet(){}
    DisjointSet(int size){
        rank.resize(size, 0);
        p.resize(size, 0);
        rep(i, size) make_set(i);
    }
    void make_set(int x){
        p[x] = x;
        rank[x] = 0;
    }
    bool same(int x, int y){
        return find_set(x) == find_set(y);
    }
    int find_set(int x){
        if(x != p[x]) p[x] = find_set(p[x]);
        return p[x];
    }
    void unite(int x, int y){
        link(find_set(x), find_set(y));
    }
    void link(int x, int y){
        if(rank[x] > rank[y]) {
            p[y] = x;
        } else {
            p[x] = y;
            if(rank[x] == rank[y]) rank[y]++;
        }
    }
};

int main(){
    int n, m; cin >> n >> m;
    DisjointSet ds(n+1);
    rep(i, m) {
        int x, y, z; cin >> x >> y >> z;
        ds.unite(x, y);
    }

    int ans = 0;
    loop(i, 1, n+1) if(i == ds.p[i]) ans++;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cstring>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>
#include<cstdio>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
//#define INF ((LLONG_MAX) / (2))
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;
typedef pair<ll,ll> LL_LLP;
#define INF 1e9+7



int main(){


    double n,m,d,ans;
    cin >> n >> m >> d;
    if(d == 0){
        ans = (m-1)/n;
    }else{
        ans = 2*(m-1)*(n-d)/(n*n);
    }
    printf("%.12f\n",ans);
    return 0;
}

Measured memory_bytes: 256
str_t = input()
lis_t = [int(num) for num in str_t]
lis_op = ['','','']

def dfs(lis_op,cnt,s):
    if cnt == 3:
        return s == 7
    elif dfs(lis_op,cnt+1,s+lis_t[cnt+1]):
        lis_op[cnt] = '+'
        return True
    elif dfs(lis_op,cnt+1,s-lis_t[cnt+1]):
        lis_op[cnt] = '-'
        return True
    else:
        return False
    
if dfs(lis_op,0,lis_t[0]):
    print(str_t[0] + lis_op[0] + str_t[1] + lis_op[1] +str_t[2] + lis_op[2] + str_t[3] + "=7")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    string s; cin >> s;
    vector <string> ws = {"Sunny", "Cloudy", "Rainy"};
    REP(i, 3){
        if (s==ws[i]){
            cout << ws[(i+1)%3] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

int gcd(int x, int y) {
	return y == 0 ? x : gcd(y, x % y);
}

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int x;
	scanf("%d", &x);
	printf("%d\n", 360 / gcd(360, x));

	return 0;
}


Measured memory_bytes: 3220
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<string.h>
#include<cmath>
#include<vector>

#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#include <iomanip>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
#define MAX 100000


int N;
int K[32] = { 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 };




int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	cout << K[N - 1] << endl;;
	
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created by Harry on 4/1/20.
 */
//https://atcoder.jp/contests/dp/tasks/dp_f
public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String t = scanner.nextLine();

        int n = s.length();
        int m = t.length();
        int[][] dp = new int[n+1][m+1];
        for(int i=1; i<=n; i++){
            for(int j=1; j<=m; j++){
                if(s.charAt(i-1)==t.charAt(j-1)){
                    dp[i][j] = dp[i-1][j-1]+1;
                }
                else{
                    dp[i][j] = Math.max(dp[i][j-1], dp[i-1][j]);
                }
            }
        }
        char[] res = new char[dp[n][m]];
        int index = dp[n][m]-1;
        int i = n;
        int j = m;
        while(i>0 && j>0){
            if(s.charAt(i-1)==t.charAt(j-1)){
                res[index--] = s.charAt(i-1);
                i--;
                j--;
            }
            else if(dp[i-1][j]>dp[i][j-1]){
                i--;
            }
            else{
                j--;
            }
        }
        System.out.print(new String(res));
    }
}


Measured memory_bytes: 83140
#include<stdio.h>

 int w[100000];
 int P,n,truck;

 int count(int P){
          int i,sum;
          i=0;
          for(int j=0;j<truck;j++){
                          sum=0;
                          while(sum+w[i]<=P){
                                   sum+=w[i];
                                   i++;
                                   if(i==n)return n;
                                   }
                          }
          return i;
          }
          

 int solve(){
          int mid,right,left,v;
          left=0;
          right=100000*10000;

          while(right-left>1){
                   mid=(left+right)/2;
                   v=count(mid);
                   if(v>=n)right=mid;
                   else left=mid;
                   }
         return right;
         }
                  


 int main(){
       int i,ans;
       scanf("%d%d",&n,&truck);
       for(i=0;i<n;i++){
                  scanf("%d",&w[i]);
                  }
       ans=solve();
       printf("%d\n",ans);
       return 0;
       }
       


Measured memory_bytes: 2200
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

d_1 = 0
d_2 = 0
d_3 = 0
d_4 = []
for i in range(n):
    d_1 += abs(x[i] - y[i])
    d_2 += abs(x[i] - y[i]) ** 2
    d_3 += abs(x[i] - y[i]) ** 3
    d_4.append(abs(x[i] - y[i]))
print("{0:8f}".format(d_1))
print("{0:8f}".format(math.sqrt(d_2)))
print("{0:8f}".format(d_3 ** (1/3)))
print("{0:8f}".format(max(d_4)))

Measured memory_bytes: 5700
def gcd(a,b):
  if a<b:
    return gcd(b,a)
  if a%b==0:
    return b
  else:
    return gcd(b,a%b)

K = int(input())
ans=0
lst = [0]*201
for i in range(1,K+1):
  for j in range(1,K+1):
    lst[gcd(i,j)]+=1
for i in range(1,K+1):
  for j in range(1,K+1):
    ans += lst[i]*gcd(i,j)
print(ans)
    
    
  

Measured memory_bytes: 9204
#include<stdio.h>

#define min(a,b) ((a)<(b)?(a):(b))

int han(char a){
		if(a=='W')return 1;
		else return 0;
}

int main(){
		int n,i;scanf("%d",&n);
		char s[300000];scanf("%s",s);
		int wa[300000];
		if(s[0]=='W')wa[0]=1;
		else wa[0]=0;
		for(i=1;i<n;i++){
				if(s[i]=='W')wa[i]=wa[i-1]+1;
				else wa[i]=wa[i-1];
//				printf("%d,",wa[i]);
		}//puts("");
		int ans=2000000;
		for(i=0;i<n;i++){
				ans=min(ans,wa[i]+n-i-wa[n-1]+wa[i]-han(s[i]));
//				printf("%d,",wa[i]+n-i-wa[n-1]+wa[i]-han(s[i]));
		}//puts("");
		printf("%d\n",ans-1);
		return 0;
}


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

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int A[N];
	int max = 0;
	int mi;
	int pmax = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		if(A[i]>=max){
			mi = i;
			pmax = max;
			max = A[i];
		}else if(A[i]>pmax){
			pmax = A[i];
		}
	}

	for (int i = 0; i < N; i++)
	{
		int ans = (mi==i)? pmax : max;
		cout <<  ans << endl;	
	}
	
}

Measured memory_bytes: 2432
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("trapv")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
const ll mod = 7 * 17 * (1 << 23) + 1;
const ll inf = 1e18 + 69;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a < b || d < b) {
		cout << "No\n";
		return;
	};
	c = c - b + 1;
	if (c < 0) {
		ll x = __gcd(b, d);
		ll tc=c-(c%x)+(a%x);
		while(tc < c)
			tc+=x;
		while(tc-x >= c)
			tc-=x;
		c=tc;
		if (c < 0) {
			cout << "No\n";
			return;
		};
	}
	cout << "Yes\n";
}
int main() { //DINIC ORZ
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	cin >> t;
	while (t--)
		solve();
}


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

int main()
{
	int n,m;
	cin >> n >> m;
	vector<int> cnt(n),isac(n);

	ll ac=0,wa=0;

	for(int i = 0;i<m;i++)
	{
		int p;
		string s;
		cin >> p >> s;
		p--;
		if(isac[p])continue;
		else
		{
			if(s=="AC")
			{
				ac++;
				wa += cnt[p];
				isac[p]=1;
			}
			else
			{
				cnt[p]++;
			}
		}
	}
	cout << ac << ' '<< wa << endl;
}


Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

unordered_map<long long, int, custom_hash> safe_map;

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

    int r;
    cin>>r;
    cout<<(r*r);

    return 0;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define ld long double
#define mem(x,y) memset(x,y,sizeof x)

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
/*
 * Be careful of overflow
 * Array bounds
 * Assert a!=0 when performing x/a
 * Check base condition for recursion
 * Iterator -> O(1), Element -> O(log n) while using erase
 * 1LL<<x when x>32
 * Be sure of what you are going to code (exception dp)
 * Don't try fancy tricks during contest
 * You can always make a bad round to a good enough round
 */ 
ll a[200009];
int c[20][20];
void solve()
{
	int n,i;
	cin>>n;
	string s;
	ll mult=1e9;
	for(i=0;i<n;i++)
	{
		cin>>s;
		int j=0;
		ll val=0;
		while(j<L(s) && s[j]!='.')
		{
			val=val*10+s[j]-'0';
			j++;
		}
		j++;
		while(j<L(s))
		{
			val=val*10+s[j]-'0';
			j++;
			mult/=10;
		}
		a[i]=val*mult;
		mult=1e9;
	}
	ll ans=0;
	for(i=0;i<n;i++)
	{
		int twos=0,fives=0;
		while(a[i]%2==0)
		{
			a[i]/=2;
			twos++;
		}
		while(a[i]%5==0)
		{
			a[i]/=5;
			fives++;
		}
		twos=min(twos,18);
		fives=min(fives,18);

		int treq=18-twos,freq=18-fives;
		for(int j=treq;j<=18;j++)
		for(int k=freq;k<=18;k++)
		ans+=c[j][k];
		c[twos][fives]++;
	}
	cout<<ans<<'\n';
}

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


Measured memory_bytes: 5060
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<string>
using namespace std;

int a[5];

string S;

string poker(int p, int q, int r, int s, int t)
{
	if (p == q && q == r && r == s)
	{
		return "four card";
	}
	if (s == t && q == r && r == s)
	{
		return "four card";
	}
	if (p == q && q == r && s == t)
	{
		return "full house";
	}
	if (p == q && r == s && s == t)
	{
		return "full house";
	}
	if (p == q - 1 && q == r - 1 && r == s - 1 && s == t - 1)
	{
		return "straight";
	}
	if (p == 1 && q == 10 && r == 11 && s == 12 && t == 13)
	{
		return "straight";
	}
	if (p == q && q == r)
	{
		return "three card";
	}
	if (r == s && q == r)
	{
		return "three card";
	}
	if (r == s && s == t)
	{
		return "three card";
	}
	if (p == q && r == s)
	{
		return "two pair";
	}
	if (p == q && s == t)
	{
		return "two pair";
	}
	if (q == r && s == t)
	{
		return "two pair";
	}
	if (p == q)
	{
		return "one pair";
	}
	if (q == r)
	{
		return "one pair";
	}
	if (r == s)
	{
		return "one pair";
	}
	if (s == t)
	{
		return "one pair";
	}
	return "null";
}

int main() {
	while (cin >> S)
	{
		int cnt = 0;
		string U = "";
		S += ',';
		for (int i = 0; i < S.size(); i++)
		{
			if (S[i] == ',')
			{
				a[cnt] = stoi(U);
				U = "";
				cnt++;
			}
			else
			{
				U += S[i];
			}
		}
		sort(a, a + 5);
		cout << poker(a[0], a[1], a[2], a[3], a[4]) << endl;
	}
}

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

using namespace std;

using ll = int64_t;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = 2147483647;
constexpr ll L_INF = 9223372036854775807LL;

//===




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

	int num0 = N / K;
	ll ans = (ll)num0 * num0 * num0;

	if (K % 2 == 0) {
		N += K / 2;
		num0 = N / K;
		ans += (ll)num0 * num0 * num0;
	}

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

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

using namespace std;

int main() {
//	freopen("input.txt","r",stdin);
  int n;
  cin>>n;
  map<string,int> mp;
  mp["AC"]=0;
  mp["WA"]=0;
  mp["TLE"]=0;
  mp["RE"]=0;
  for(int i=0;i<n;i++) {
  	string s;
    cin>>s;
    mp[s]++;
  }
  cout<<"AC x "<<mp["AC"]<<endl;
  cout<<"WA x "<<mp["WA"]<<endl;
  cout<<"TLE x "<<mp["TLE"]<<endl;
  cout<<"RE x "<<mp["RE"]<<endl;
  return 0;
}

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

using namespace std;

int main() {
	string S;
	cin >> S;
	int cnt = 0;
	int tmp = 0;
	for (int i = 0; i < S.size(); i++)
	{
		if (S[i] == 'x') {
			cnt++;
		}
		else {
			tmp++;
		}
	}
	if (cnt >= 8) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import sys
from math import factorial

def ncr(n, r, p): 
    # initialize numerator 
    # and denominator 
    num = den = 1 
    for i in range(r): 
        num = (num * (n - i)) % p 
        den = (den * (i + 1)) % p 
    return (num * pow(den,  
            p - 2, p)) % p 

def check(x, y):
    if (x + y) % 3 == 0:
        return True
    else:
        return False
    

# Read
line = sys.stdin.readlines()[0]
X, Y = map(int,line.split(' '))

if not check(X, Y):
    print(0)
    exit(0)

m = int(1/3 * (2*Y - X))
n = int(Y - 2 * m)

if n < 0 or m < 0:
    print(0)
else:
    print(ncr(n+m, n, 10**9+7))


Measured memory_bytes: 3064
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define clr clear()
#define sqr(a) (a*a)
#define mk make_pair
#define pb push_back
string en="\n";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
#define srch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,c=0;
    while(cin>>x>>y)
    {
        n=0;
        if(y==100)
        {
            x=x*10+y/100;
            x=x*10+y%100;
            x=x*10+y%10;
        }
        else if(y>9)
        {
            x=x*10+y/10;
            x=x*10+y%10;
        }
        else x=x*10+y;
        n=sqrt(x);
        if(n*n==x) cout<<"Yes"<<en;
        else cout<<"No"<<en;
    }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define eps 1e-7
using namespace std;
int n,d1,d2,cnt=0;
bool f[1005][1005];
inline void solve(int d){
	int b=0;
	while(!(d%4))d>>=2,++b;
	if(d&1){
		for(int i=0;i<(n<<1);++i)
			for(int j=0;j<(n<<1);++j)
				if(((i>>b)+(j>>b))&1)f[i][j]=true;
		return;
	}
	for(int i=0;i<(n<<1);++i)
		for(int j=0;j<(n<<1);++j)
			if((i>>b)&1)f[i][j]=true;
}
int main(){
	scanf("%d%d%d",&n,&d1,&d2);
	solve(d1),solve(d2);
	for(int i=0;i<(n<<1);++i)
		for(int j=0;j<(n<<1);++j)
			if(cnt<n*n&&!f[i][j])printf("%d %d\n",i,j),++cnt;
	return 0;
}

Measured memory_bytes: 1536
#include "bits/stdc++.h"
using namespace std;
#define int long long
#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(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
void _OUT() {}; template<class H, class... T> void _OUT(H &h, T &... t) { cout<<' '<<h; _OUT(t...); };
template<class H, class... T> void _P(H &h, T &... t) { cout<<h; _OUT(t...); };
#define _PN(...) _P(__VA_ARGS__); cout << endl;

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 223450
#endif

int N,K;
vector<int> C(SIZE),Q;

void solve() {
    cin>>N>>K;
    int t,d;
    priority_queue<pair<int,int>> que;
    REP(i,N) {
        cin>>t>>d;
        que.push({d,t});
    }
    int ans = 0, cur = 0, s = 0;
    while(K--) {
        auto [d,t] = que.top();
        que.pop();
        cur += d;
        if (!C[t]) s++;
        else Q.push_back(d);
        C[t]=1;
    }
    chmax(ans, cur + s*s);
    while(que.size() && Q.size()) {
        auto [d,t] = que.top();
        que.pop();
        if (!C[t]) {
            s++;
            cur -= Q.back();
            cur += d;
            Q.pop_back();
            C[t]=1;
            chmax(ans, cur + s*s);
        }
    }
    _PN(ans);
}



Measured memory_bytes: 7164
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>




int main(void){
int n,k;
int count=0;
scanf("%d %d",&n,&k);

for(;;){
    if(n==0){printf("%d",count);break;}
    n=n/k;
    count++;
}
}


Measured memory_bytes: 128
#include <stdio.h>
#include <vector>
using namespace std;

int main()
{
	int n, min, ans=1;
	vector<int> p;
	
	scanf("%d", &n);
	p.resize(n);
	for (int i=0; i<n; i++){
		scanf("%d", &p[i]);
	}

	min = p[0];
	for (int i=1; i<n; i++){
		if (p[i] <= min){
		 	ans++;
			min = p[i];
		}
	}	
	
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1024
s = list(input())
q = int(input())
c = 0
s1 = []
s2 = []
for _ in range(q):
    t = input()
    if t != "1":
        t = t.split()
        if t[1] == "1":
            if c % 2 == 0:
                s1.append(t[2])
            else:
                s2.append(t[2])
        else:
            if c % 2 == 0:
                s2.append(t[2])
            else:
                s1.append(t[2])
    else:
        c += 1

if c % 2 == 0:
    s1.reverse()
    s = s1 + s + s2
else:
    s2.reverse()
    s3 = s
    s3.reverse()
    s = s2 + s3 + s1
print("".join(s))

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


const int p[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 
59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 
127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 
191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 
257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 
331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 
401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 
467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 
563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 
631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 
709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 
797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 
877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 
967, 971, 977, 983, 991, 997};

const ll MOD = 1000000007;
int n;

int main()
{
    cin >> n;
    int a = 0;
    ll res = 1;
    while(p[a] <= n)
    {
        int e = 1;
        int m = n / p[a];
        while(m)
        {
            e += m;
            m /= p[a];
        }
        res *= e;
        res %= MOD;
        a++;
    }
    cout << res << endl;

    return 0;
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    int needed[3] = {0,0,0}; //5,5,7
    for(int i=0;i<3;i++) {
        if(a[i]==5) {
            if(needed[0]==1 && needed[1]==1) {
                cout<<"NO";
                return 0;
            }
            if(needed[0]==0) needed[0]=1;
            else needed[1]=1;
                
                }
        else if(a[i]==7) {
            if(needed[2]==1) {
                cout<<"NO";
                return 0;
            }
            needed[2]=1;
        }
        
        
    }
    for(int i=0;i<3;i++) {
        if(needed[i]!=1) {
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	ll M; cin >> M;
	ll tot = 0, keta = 0;
	for (int i = 0; i < M; i++) {
		ll d, c; cin >> d >> c;
		tot += d * c;
		keta += c;
	}
	cout << (tot - 1) / 9 + keta - 1 << endl;
}


Measured memory_bytes: 3584
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// Nの入力
		int N = sc.nextInt();
		
		// viをPriorityQueueに格納
		PriorityQueue<Double> pq = new PriorityQueue<> ();
		for (int i = 0; i < N; i++) {
			pq.add(sc.nextDouble());
		}
		
		for (int i = 0; i < N-1; i++) {
			double x = pq.poll();
			double y = pq.poll();
			pq.add((x+y)/2);
		}
		
		System.out.println(pq.poll());
		
		sc.close();
	}
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
#define rep1(i,n) for (ll i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
ll mod = 1000000007;

int main(){
  ll n,m,x; cin >> n >> m >> x;
  vector<vector<ll>> v(n,vector<ll>(m+1));
  ll ans = 0;
  rep(i,n){
    rep(j,m+1){
      cin >> v[i][j];
      if(j==0) ans+= v[i][j];
    }
  }
  bool flgall = false;
  for(ll s=0; s<(1<<n); s++){
    ll cost = 0;
    vector<ll> u(m+1,0);
    u[0]=x;
    for(ll i=0; i<n; i++){
      if(s&(1<<i)){
        vector<ll> p = v[i];
        cost += p[0];
        for(ll j=1; j<=m; j++){
          u[j]+=p[j];
        }
      }
    }
    bool flg = true;
    for(auto e:u){
      if(e<x) flg = false;
    }
    if(flg){
      ans = min(ans, cost);
      flgall = true;
    }
  }
  if(flgall) cout << ans ;
  else cout << -1;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    sort(A.begin(), A.end());
    int answer;
    answer = A.at(N-1) - A.at(0); 
    cout << answer << endl;
}

Measured memory_bytes: 256
/*
    It is time for a counter-attack
*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
using namespace std;
typedef long long ll;
const ll N=1e5+10,M=10000,mod=1000000;
const ll OO=1e16;
#define SARAH ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define scan(A,n) for (int i=0;i<n;++i) cin>>A[i];
#define pb push_back
#define bg begin
#define des(A,n) sort(A,A+n);reverse(A,A+n)
#define en end
#define f first
#define s second
#define bs binary_search
#define fill2(A, x) for(int i=0;i<N;++i) for(int j=0;j<N;++j) A[i][j]=x;
#define set2(A, x) fill(A,A+N,x);
#define scan2(A, n, m) for(int i=0;i<n;++i) for(int j=0;j<m;++j) cin >> A[i][j];
#define set(A, x) memset(A, x, sizeof(A))
#define print(A, x) for (int i=0;i<x;++i) cout<<A[i]<< " ";
#define pii pair<int, int>
#define pll pair<ll, ll>
#define low lower_bound
#define high upper_bound
#define bits(x) __builtin_popcountll(x)
#define sz size
#define cl clear
#define all(A) A.bg(), A.en()
#define REPEAT main()
#define dig(n) log10(n)+1;
#define vi vector<int>
#define vl vector<ll>
ll n;
vector<int>v;
void factorize(){
    for(ll i=2;i<=sqrt(n);++i){
        int power=0;
        while(n%i==0){
            power++;
            n/=i;
        }
        if(power) v.pb(power);
    }
    if(n>1) v.pb(1);
}
int main(){
    ll ans=0;
    cin>>n;
    factorize();
    for(int i=0;i<v.sz();++i){
        int cur=v[i],nxt=1;
        while(cur>=nxt){
            cur-=nxt;
            nxt++;
            ans++;
        }
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 3644
N=int(input())
data = list(map(int, input().split()))
ans=1
minmin=data[0]
if N==1:
    ans=1
elif N>1:
    minmin=data[0]
    for i in range(1,N):

        if data[i]<=minmin:
            minmin=data[i]
            #if minmin<=data[i]:
            ans+=1
                #continue
        #if minmin<=data[i]:
            #ans+=1

print(ans)

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

template<class T>
ostream& operator<<(ostream& os,vector<T> const& v){for(auto itr=v.begin();itr!=v.end();++itr){if(itr!=v.begin())os<<' ';os<<*itr;}return os;}

signed main(){

  int N;
  cin>>N;
  vector<int> a(N);
  for(auto& ai:a)cin>>ai;
  
  auto p = a;
  auto n = a;

  if(prev_permutation(p.begin(),p.end()))cout<<p<<endl;
  cout<<a<<endl;
  if(next_permutation(n.begin(),n.end()))cout<<n<<endl;

}


Measured memory_bytes: 3168
#include<cstdio>
#include<cstring>
using namespace std;
int main(void)
{
	char migi[12]="yuiophjklnm";
	int len,i,j,cnt,flg,m;
	char buf[33];
	while(1)	{
		scanf("%s",buf);
		if(buf[0]=='#')	break;
		len=strlen(buf);
		m=0;
		for(j=0;j<11;j++)	{
			if(buf[0]==migi[j])	{
				m=1;
				break;
			}
		}
		cnt=0;
		for(i=1;i<len;i++)	{
			flg=0;
			for(j=0;j<11;j++)	{
				if(buf[i]==migi[j])	{
					flg=1;
					break;
				}
			}
			if(m!=flg)	{
				cnt++;
				m=flg;
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}


Measured memory_bytes: 968
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    X, Y = map(int, input().split())
    p = 10**9+7

    def combMod(n, r, p):
        numer = 1
        denom = 1
        for i in range(1, r+1):
            numer = numer * (n-r+i) % p
            denom = denom * i % p
        return numer * pow(denom, p-2, p) % p

    if (X+Y)%3==0 and Y<=X*2 and X<=Y*2:
        n = (X+Y)//3
        r = X-(X+Y)//3
        print(combMod(n, r, p))
    else:
        print('0')

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 3064