akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
const ll MOD=1000000007LL;
int main(){
  ll n;
  cin>>n;
  vl a(n);
  rep(i,n)cin>>a[i];
  ll g=0;
  rep(i,n)g=__gcd(a[i],g);
  cout<<g<<endl;
}

Measured memory_bytes: 1024
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    static private Scanner scan = new Scanner(System.in);
    public static void main(String args[]) {
        int int1 = Integer.parseInt(scan.next());
        int int2 = Integer.parseInt(scan.next());

//        String str1 = scan.next();
//        int int3 = Integer.parseInt(scan.next());
//        String str1 = scan.next();

        int ans_int = 0;
        double ans_dob = 0;
        String ans = "";

        if(int1 >= 6){
            if(int1 <= 12){
                ans_int = int2/2;
            }else{
                ans_int = int2;
            }
            //        StringBuilder sb = new StringBuilder(str1);
        }else{
            ans_int = 0;
        }

//        sb.replace(0,4,"2018");
        PrintWriter out = new PrintWriter(System.out);
        out.println(ans_int);
        out.flush();
        scan.close();
    }
}


Measured memory_bytes: 21076
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main() {
  int n;
  while(cin >> n && n) {
    string s;
    cin >> s;
    while(n--) {
      string r="";
      for(int i=0; i<s.size()-1; i++) {
	if(s[i]!=s[i+1]) {
	  string t=s.substr(0,i+1);
	  s=s.substr(i+1);
	  stringstream ss;
	  ss << t.size();
	  string g;
	  ss >> g;
	  r+=g;
	  r+=t[0];
	  i=-1;
	}
      }
      if(s.size()) {
	stringstream ss;
	ss << s.size();
	string g;
	ss >> g;
	r+=g;
	r+=s[0];
      }
      s=r;
    }
    cout << s << endl;
  }
  return 0;
}


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

using namespace std;

#define INF 999999999

int main(){
	int n, p, now, m[50], k;
	while(1){
		cin >> n >> p;
		if(!n)break;
		for(k=0;k<n;k++){
			m[k] = 0;
		}
		k=0;
		now=p;
		while(1){
			if(now){
				m[k]++;
				now--;
			}
			else{
				now+=m[k];
				m[k]=0;
			}
			if(m[k]==p){
				cout << k << endl;
				break;
			}
			else{
				if(k!=n-1) k++;
				else k = 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1160
# coding: utf-8
# Here your code !
S = int(input())
N = list(map(int,input().split(" ")))


def seleSort(n,s):
    c =0
    for i in range(s):
        minj = i
        for j in range(i+1,s):
            if n[j]<n[minj]:
                minj = j
                
        n[i],n[minj]=n[minj],n[i]
        if i!= minj:
            c+=1
    print(" ".join(list(map(str,n))))
    print(c)
        
        
seleSort(N,S)

Measured memory_bytes: 7756
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;

auto mk_ret() {
    wchar[100][100] ret;
    foreach (i; 0..50) ret[i] = '#';
    foreach (i; 50..100) ret[i] = '.';
    return ret;
}
auto ret = mk_ret();

void main()
{
    auto ab = readln.split.to!(int[]);
    auto A = ab[0] - 1;
    auto B = ab[1] - 1;

    for (int i; A; i += 2) {
        for (int j; A && j < 100; j += 2) {
            --A;
            ret[i][j] = '.';
        }
    }
    for (int i = 51; B; i += 2) {
        for (int j; B && j < 100; j += 2) {
            --B;
            ret[i][j] = '#';
        }
    }
    
    writeln("100 100");
    foreach (line; ret) writeln(line);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int ans=1;
	char fer=s[0];
	for(int i=1;i<s.size();){
		if(s[i]==fer){
			i=i+2;
			fer=NULL;
		}
		else{
			fer=s[i];
			i++;
		}
		if(i>s.size())
			break;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

int Cmp(const void *a, const void *b){
  return *(int *)a - *(int *)b;
}

int Kushi(int N){
  int L[2*N];
  int i, S;
  for(i = 0;i < 2 * N;i++) scanf("%d", &L[i]);
  qsort(L, 2 * N, sizeof(int), Cmp);
  S = 0;
  for(i = 0;i < N;i++) S += L[2*i];
  return S;
}

int main(void){
  int N;
  scanf("%d", &N);
  printf("%d\n", Kushi(N));
  return 0;
}


Measured memory_bytes: 128
n= int(input())
jobs = []
for i in range(n):
    a,b = map(int,input().split())
    jobs.append([a,b])
jobs = sorted(jobs,key=lambda x:[x[1],x[0]])
time = 0
for t,e in jobs:
    time+=t
    if time>e:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 58560
def main():
    m = 100
    x = int(input())
    y = 0
    while True:
        m = m + int(m * 0.01)
        y += 1
        if x <= m:
            break
    print(y)


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


if __name__ == '__main__':
    main()


Measured memory_bytes: 63316
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main {
  int N, W;
  cin >> N >> W;
  vector<int> v(N), w(N);
  rep(i, N) cin >> v[i] >> w[i];
  int s = accumulate(all(v), 0LL);
  auto dp = vectors(N + 1, s + 1, INF);
  dp[0][0] = 0;
  loop(i, 1, N + 1) rep(j, s + 1) {
    dp[i][j] = dp[i - 1][j];
    if (j - v[i - 1] >= 0) cmin(dp[i][j], dp[i - 1][j - v[i - 1]] + w[i - 1]);
  }
  for (int j = s; j >= 0; j--) {
    if (dp[N][j] <= W) {
      cout << j << endl;
      break;
    }
  }
}



Measured memory_bytes: 10808
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int N, M;
struct edge{
  int to, cost;
  edge(int t, int c) {
    to = t, cost = c;
  }
};
int dist[100005];
vector<edge> G[100005];

void dfs(int v, int d) {
  if(dist[v] == 2e9) {
    dist[v] = d;
    for(auto to : G[v]) {
      dfs(to.to, d + to.cost);
    }
  } else {
    if(dist[v] != d) {
      cout << "No" << endl;
      exit(0);
    }
  }
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  FOR(i,0,M) {
    int l,r,d;
    cin >> l >> r >> d;
    G[l].push_back(edge(r, d));
    G[r].push_back(edge(l, -d));
  }
  FOR(i,0,N+1) dist[i] = 2e9;
  FOR(i,1,N+1) {
    if(dist[i] == 2e9) {
      dfs(i, 0);
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

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

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

    mf_graph<int> graph(N*M+2);
    int s = N * M;
    int t = N * M + 1;

    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            if(S[i][j]=='#') continue;
            int u = i * M + j;
            if((i+j)%2 == 0){
                graph.add_edge(s, u, 1);

                vector<int> vs;
                if(j > 0  ) vs.push_back(i * M + j-1);
                if(j < M-1) vs.push_back(i * M + j+1);
                if(i > 0  ) vs.push_back((i-1) * M + j);
                if(i < N-1) vs.push_back((i+1) * M + j);
                for(auto v : vs){
                    graph.add_edge(u, v, 1);
                }
            }else{
                graph.add_edge(u, t, 1);
            }
        }
    }

    cout << graph.flow(s, t) << endl;

    auto edges = graph.edges();
    for(auto e : edges){
        if(e.flow == 0) continue;
        if(e.from == s) continue;
        if(e.to   == t) continue;
        if(e.from % M == e.to % M){
            if(e.from / M < e.to   / M){
                S[e.from / M][e.from % M] = 'v';
                S[e.to   / M][e.to   % M] = '^';
            }else{
                S[e.from / M][e.from % M] = '^';
                S[e.to   / M][e.to   % M] = 'v';
            }
        }else{
            if(e.from % M < e.to % M){
                S[e.from / M][e.from % M] = '>';
                S[e.to   / M][e.to   % M] = '<';
            }else{
                S[e.from / M][e.from % M] = '<';
                S[e.to   / M][e.to   % M] = '>';
            }

        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            cout << S[i][j];
        }
        cout<<endl;
    }

    return 0;
}


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

int power(ll a, ll b=mod-2){
  ll res=1;
  while(b>0){
  if(b & 1) res=res*a%mod;
  a=a*a%mod;
  b>>=1;
  }
return res;
}

int main(){
  ll n,m,k;
  cin >> n >> m >> k;
  vector<ll>num(n);//i個の連続部分があるときの場合の数の配列
  num[0]=m;
  for(int i=1; i<n; i++){
    num[i]=(m-1)*num[i-1];
    num[i]%=mod;
  }
  reverse(num.begin(),num.end());//0個~に変換
  
  
  
  ll bunsi=1;
  for(ll i=1; i<=n-1; i++){
    bunsi*=i;
    bunsi%=mod;
  }//連続部分の配置の組み合わせn-1Ciの分子部分
  
  vector<ll>c(k+1);//n-1Ciの分母部分の配列
  c[0]=bunsi;
  for(int i=1; i<=k; i++){
   c[i]=c[i-1];
   c[i]*=i;
   c[i]%=mod;
   c[i]*=power(n-i,mod-2);
   c[i]%=mod;
  }
  
  ll ans=0;
  for(int i=0; i<=k; i++){
    ll x=bunsi;
    x*=power(c[i],mod-2);
    x%=mod;
    x*=num[i];
    x%=mod;
    ans+=x;
    ans%=mod;
  }
  
  cout << ans << endl;
  
  return 0;
}
  
  


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using pii = pair<int,int>;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    if(x == 5 || x == 7 || x == 3) cout << "YES" << '\n';
    else cout << "NO" << '\n';  
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <vector>

#define fix(n) cout<<fixed<<setprecision(n);
#define rep(i,n)   for (int i = 0; i < (n); ++i)
#define sort(a)    sort((a).begin(), (a).end());
#define uniq(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define reverse(a) reverse((a).begin(), (a).end());
#define out(d) cout << (d);
#define outl(d) std::cout<<(d)<<"\n";
#define Yes() printf("Yes\n");
#define No() printf("No\n");
#define YES() printf("YES\n");
#define NO() printf("NO\n");
#define ceil(x, y) ((x + y - 1) / (y))

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

const ll MOD = 1000000007; // 10^9 + 7

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12)

  ll n, p; cin >> n >> p;
  string s; cin >> s;

  if (10 % p == 0) {
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      if ((s[i] - '0') % p == 0) ans += i + 1;
    }
    outl(ans)
    return 0;
  }

  vector<int> d(n + 1);
  map<int, int> m;
  int ten = 1;
  for (int i = n-1; i >= 0; --i) {
    int a = (s[i]-'0') * ten % p;
    d[i] = (d[i+1]+a) % p;
    ten *= 10; ten %= p;

    if (m.find(d[i]) == m.end()) {
      m.insert(make_pair(d[i], 1));
    } else {
      m[d[i]]++;
    }
  }

  ll ans = 0;
  vector<int> cnt(p);
  for (int i = n; i >= 0; --i) {
    ans += cnt[d[i]];
    cnt[d[i]]++;
  }

  outl(ans)
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, ll> Pil;

ll K;

int main() {
    cin >> K;

    ll repsept[1000010];
    memset(repsept, 0, sizeof(repsept));
    repsept[1] = 7 % K;
    for (ll i = 2; i < 1000010; i++) {
        repsept[i] = ((10 * repsept[i-1] % K) + 7) % K;
    }

    int ans = -1;
    for (int i = 1; i < 1000010; i++) {
        if (repsept[i] == 0) {
            ans = i;
            break;
        }
    }

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

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

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

template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r) - sum(l-1);
  }
};

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  
  auto b=a;
  vsort(b);
  b.erase(unique(all(b)),b.end());
  // rep(i,b.size()) cout<<b[i]<<' ';
  // cout<<endl;
  BIT<ll> bit(b.size()+5);
  
  ll ans=0;
  rep(i,n){
    ll rank=lower_bound(all(b),a[i])-b.begin()+1;
    // cout<<rank<<endl;
    ans+=i-bit.sum(rank);
    bit.add(rank);
  }
  
  cout<<ans<<endl;
  
  
}


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

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

    int ans = 0;
    for(int i = 0; i < s.length(); i++) {
        ans += s[i] == '+' ? 1 : -1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
p=list(map(int,input().split()))
e=[0]*n
for i in range(n):
  e[i]=(1+p[i])/2

part=e[0:k]
kari=sum(part)
ans=kari
for i in range(n-k):
  kari+=e[i+k]
  kari-=e[i]
  if kari>ans:
    ans=kari
print(ans)

Measured memory_bytes: 73224
#include <stdio.h>

int main(void) {
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}



Measured memory_bytes: 2140
INPUT=input()

X=int(INPUT.split()[0])
Y=int(INPUT.split()[1])

count=0

if X==1:
    count +=300000
elif X==2:
    count +=200000
elif X==3:
    count +=100000

if Y==1:
    count +=300000
elif Y==2:
    count +=200000
elif Y==3:
    count +=100000

if X==1 and Y==1:
    count +=400000

print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cstring>
#include <string.h>
#include <sstream>
#include <map>
#include <iomanip>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <set>
#include <numeric>

using namespace std;
using ll = long long;

#define pb push_back
#define in insert
#define endl '\n'

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

    ll n, k;
    cin >> n >> k;
    vector<ll> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
    }
    ll sum = 0;
    sort(v.begin(), v.end());
    for(int i = 0; i < n - k; i++) {
        sum += v[i];
    }
    cout << sum;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int count = 0;
  for (int i = 0; i <= N; i += R){
    for (int j = 0; j <= N; j += G){
      if ((N - i - j) % B == 0 && N - i - j >= 0){
        count++;
      }
    }
  }
  cout << count;
}

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

using namespace std;

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

const int N = int(2e5) + 5;
const int inf = (int)1e9 + 7;

int n;
int p[N], ans;

int main(){
  scanf("%d", &n);
  for(int i = 1; i <= n; ++i){
    scanf("%d", p + i);
  }
  for(int i = n; i > 1; --i){
    if(p[i] == i){
      swap(p[i], p[i - 1]);
      ++ans;
    }
  }
  if(p[1] == 1){
    ++ans;
  }
  printf("%d\n", ans);
  return 0;
}


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

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

    ll val=0;
    for(int i=0;i<=n;i++){
        if(i%3==0 || i%5==0){
            continue;
        }else {
            val += i;
        }
    }
    cout << val;
    return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
int main () {
    string S ;
    cin >> S;
    if (S.at(2) == S.at(3) && S.at(4) == S.at(5)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<complex>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>

#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define rep(i,a) repi(i,0,a)
#define repd(i,a,b) for(int i = int(a); i >= int(b); i--)
#define repit(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())
#define pb push_back
#define mp make_pair
const double pi = acos(-1.0);

using namespace std;

typedef long long ll;

const int N = 6;

int n;
double room, a[6], sum[1 << N];

void input()
{
    cin >> room >> n;
    rep(i, n) cin >> a[i];

    sum[0] = 0.0;
    rep(i, n) sum[1 << i] = a[i];
    rep(i, 1 << n) if (__builtin_popcount(i) >= 2)
        sum[i] = sum[i & -i] + sum[i & i - 1];
}

typedef pair<double, double> P;

vector<set<P> > dp;

void solve()
{
    dp.assign(1 << n, set<P>());

    rep(i, n) dp[1 << i].insert(P(0.0, 0.0));
    rep(s, 1 << n) if (__builtin_popcount(s) >= 2) {
        for (int t = s; t = t - 1 & s; ) {
            double r = sum[t] / sum[s], l = 1.0 - r;
            repit(ii, dp[t]) repit(jj, dp[s ^ t]) {
                dp[s].insert(P(max(l + ii->first, jj->second - r),
                               max(r + jj->first, ii->second - l)));
                dp[s].insert(P(max(l + ii->first, jj->first - r),
                               max(r + jj->second, ii->second - l)));
                dp[s].insert(P(max(l + ii->second, jj->second - r),
                               max(r + jj->first, ii->first - l)));
                dp[s].insert(P(max(l + ii->second, jj->first - r),
                               max(r + jj->second, ii->first - l)));
            }
        }
    }

    double ans = -1.0;
    repit(it, dp[(1 << n) - 1])
        if (it->first + it->second <= room)
            ans = max(ans, it->first + it->second);

    if (ans >= 0.0)
        printf("%.16f\n", ans);
    else
        puts("-1");
}

signed main()
{
    int T; cin >> T;
    while (T--) {
        input();
        solve();
    }

    return 0;
}

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

using namespace std;
#define int long long
#define all(a) (a).begin(), (a).end()
#define ms(a,v) memset(a, v, sizeof(a))
#define sz(v) ((int)(v).size())
#define mp make_pair
#define pb push_back
#define prev biiiiirl_sai_de_casa_comi_pra_caralho
#define next trapezio_descendente
#define index eh_ele_que_nos_vai_buscar
#define left aqui_eh_37_anos_porra
#define R32 ({i32 x; scanf("%d", &x); x;})
#define RL ({long long x; scanf("%lld", &x); x;})
#define RC ({char x; scanf(" %c", &x); x;})
#define RI RL
#define ff first
#define ss second
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef long long ll;

int32_t main(){
  string s;
  cin >> s;
  int n = sz(s);

  string t;
  t.pb(s[0]);

  for(int i = 1; i < n; i++){
    if(s[i] == 'T' && !t.empty() && t.back() == 'S'){
      t.pop_back();
      continue;
    }

    t.pb(s[i]);
  }

  cout << sz(t) << endl;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    if(s[2]==s[3]){
        if(s[4]==s[5]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

using namespace std;

using ll = long long;

ll Count(int n) {
    ll sum = 0;
    while (n) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

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

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

    ll sum = 0;
    for (int i = 1; i <= n; ++i) {
        int m = Count(i);
        if (a <= m && m <= b) sum += i;
    }

    cout << sum << endl;

    return 0;
}


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


#include <bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define inf 10000000000000000
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;


int main(){


	int n;
	cin>>n;
	ll	 arr[3*n];

	ll csum=0;


	for(int i=0;i<3*n;i++){

		cin>>arr[i];
	}	
	ll l_sum[3*n+1],r_sum[3*n+1];

	priority_queue<int> pq;
	priority_queue<int ,vector<int>,greater<int> > min_pq;

	for(int i=0;i<3*n;i++){
		min_pq.push(arr[i]);
		csum+=arr[i];

		if(min_pq.size()>n){
			csum-=min_pq.top();min_pq.pop();

		}
		if(min_pq.size()==n) l_sum[i]=csum;
		else{
			l_sum[i]=-inf;
		}

	}
	csum=0;
	for(int i=3*n-1;i>=0;i--){
		pq.push(arr[i]);
		csum+=arr[i];

		if(pq.size()>n){
			csum-=pq.top();pq.pop();
		}
		if(pq.size()==n) r_sum[i]=csum; 
		else{
			r_sum[i]=inf;
		}
	}


	ll ans=-inf;

	for(int i=0;i<2*n+1;i++){
		// cout<<l_sum[i]<<"	"<<r_sum[i]<<endl;
		ans=max(ans,l_sum[i]-r_sum[i+1]);
	}
	cout<<ans<<endl;

	return 0;

}

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

int n,k;
vector<char> d(10);

bool check(string str){
	bool is = true;
	for(int i=0; i<str.size(); i++){
		for(int j=0; j<k; j++){
			if(str.at(i) == d.at(j)){
				is = false;
				break;
			}
		}
	}
	return is;
}

int main() {
	cin >> n >> k;
	for(int i=0; i<k; i++){
		cin >> d.at(i);
	}
	int ans = n;
	while(!check(to_string(ans))){
		ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

s = gets.chomp
puts (s[-1] == "s")? s + "es" : s+"s"


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

int main(){
  int N;
  cin >> N;
  
  vector<int> vec(N);
  for (int i = 0; i < N; i++){
    cin >> vec.at(i);
  }

  int cnt = 0;
  for (int i = 1; i < N - 1; i++){
    if ((vec.at(i - 1) < vec.at(i) && vec.at(i) < vec.at(i + 1)) || (vec.at(i - 1) > vec.at(i) && vec.at(i) > vec.at(i + 1))){
      cnt += 1;
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 3596
import java.util.*;
 
public class Main{
 
    void solve(){
        Scanner sc = new Scanner(System.in);
 
        while(true){
            int n = sc.nextInt();
            if(n==0) break;

            ArrayList<int[]> hr = new ArrayList<int[]>();

            for(int i=0; i<n; i++) 
                hr.add(new int[]{sc.nextInt(), sc.nextInt()});

            int m = sc.nextInt();
            for(int i=0; i<m; i++) 
                hr.add(new int[]{sc.nextInt(), sc.nextInt()});

            Collections.sort(hr, new Comparator<int[]>(){
                    public int compare(int[] a, int[] b){
                        if(a[0]<b[0]) return -1;
                        if(a[0]>b[0]) return 1;
                        if(a[1]<b[1]) return -1;
                        if(a[1]>b[1]) return 1;
                        return 0;
                    }
                });
 
            int[] dp = new int[n+m];
            Arrays.fill(dp,1);
            for(int i=0; i<n+m; i++){
                for(int j=0; j<i; j++){
                    if(hr.get(i)[0]==hr.get(j)[0]) break;
                    if(hr.get(i)[1]<=hr.get(j)[1]) continue;
                    dp[i] = Math.max(dp[i],dp[j]+1);
                }
            }
 
            int ans = 0;
            for(int i=0; i<n+m; i++) ans = Math.max(ans, dp[i]);
 
            System.out.println(ans);
        }
    }
 
    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 24880
#include <cstdio>
int main(){
	long long A,B,ans;
	scanf("%lld%lld",&A,&B);
	if (A==B) ans=1;
	else{
		int x=60;
		for (;((A>>x)&1)==((B>>x)&1);x--);
		long long C=(1ll<<x);
		A&=C-1;B&=C-1;
		for (;x>=0 && !((B>>x)&1);x--);
		B|=(1ll<<(x+1))-1;
		if (B+1>=A) ans=C*2-A;
			else ans=C*2+B-A*2+1;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
    long long A, B, C, K;
    cin >> A >> B >> C >> K;
    
    long long ans;
    
    if(K%2==0){
        ans=A-B;
    }
    else{
        ans=B-A;
    }
    
    if(ans>1000000000000000000){
        cout << "Unfair" << endl;
    }
    else{
        cout << ans << endl;
    }
}


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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, P; cin >> N >> P;
  ll even = 0;
  ll odd = 0;
  for (ll i = 0; i < N; i++) {
    ll a; cin >> a;
    if (a % 2 == 0) even++;
    else odd++;
  }
  if (odd == 0) {
    if (P == 0) {
      cout << (1LL << N) << endl;
    }else {
      cout << 0 << endl;
    }
  }else {
    cout << (1LL << (N-1)) << endl;
  }

  return 0;
}



Measured memory_bytes: 3696
import sys
sys.setrecursionlimit(10**9)
N = int(input())
a = [[] for _ in range(N)]
b = [[] for _ in range(N)]
for i in range(N-1):
    x, y, z = map(int, input().split())
    x, y, z = x-1, y-1, z % 2
    a[x].append([y, z])
    b[y].append([x, z])
dist = [0] * N
visited = [0] * N
print("")

def dfs(v, prev, dist, predist, visited):
    if visited[v]:
        return dist
    dist[v] = dist[prev] ^ predist
    visited[v] = 1
    for i in a[v]:
        dist = dfs(i[0], v, dist, i[1], visited)
    for i in b[v]:
        dist = dfs(i[0], v, dist, i[1], visited)
    return dist

dist = dfs(0, 0, dist, 0, visited)
for i in dist:
    print(i)

Measured memory_bytes: 94652
#include <bits/stdc++.h>
using namespace std;
/*******************??????********************/
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
	bool operator < (const P& a, const P& b) {
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}
double cross(const P& a, const P& b) {//??????
	return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {//??????
	return real(conj(a)*b);
}

struct L : public vector<P> {//??????
	L(const P &a, const P &b) {
		push_back(a); push_back(b);
	}
};

typedef vector<P> G;
struct C {//???
	P p; double r;
	C(const P &p, double r) : p(p), r(r) { }
};

int ccw(P a, P b, P c) {//??????????????????
	b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool intersectLL(const L& l,const L& m){
	//non-parallel || sameline
	return abs(cross(l[1]-l[0],m[1]-m[0])) > EPS || abs(cross(l[1]-l[0],m[0]-l[0])) < EPS;
}
bool intersectLS(const L& l,const L& s){
	// s[0] is left of l,s[1] is right of l
	return cross(l[1]-l[0],s[0]-l[0]) * cross(l[1]-l[0],s[1]-l[0]) < EPS;
}
bool intersectLP(const L& l,const P& p){
	return abs(cross(l[1]-p,l[0]-p)) < EPS;
}
bool intersectSP(const L& s,const P& p){
	return abs(s[0]-p)+abs(s[1]-p) - abs(s[1]-s[0]) < EPS;// triangle inequality
}
// ??´???????????????
bool orthogonalLL(const L &l1, const L &l2){
	return (dot(l1[0]-l1[1], l2[0]-l2[1]) <= EPS && dot(l1[0]-l1[1], l2[0]-l2[1]) >= -EPS);
}
// ??????????????????
bool parallelLL(const L &l1, const L &l2){
	return (cross(l1[0]-l1[1], l2[0]-l2[1]) <= EPS && cross(l1[0]-l1[1], l2[0]-l2[1]) >= -EPS);
}

P projection(const L& l,const P& p){
	double t = dot(p-l[0],l[0]-l[1]) / norm(l[0]-l[1]);
	return l[0] + t*(l[0]-l[1]);
}
P reflection(const L& l,const P& p){
	return p + 2. * (projection(l,p) - p);
}
double distanceLP(const L& l,const P& p){
	return abs(p - projection(l,p));
}
double distanceLL(const L& l,const L& m){
	return intersectLL(l,m) ? 0 : distanceLP(l,m[0]);
}
double distanceLS(const L& l,const L& s){
	if(intersectLS(l,s)) return 0;
	return min(distanceLP(l, s[0]),distanceLP(l, s[1]));
}

int main(void){
	int q;
	cin >> q;
	for(int i=0;i<q;i++){
		vector<P> p(4);
		int x,y;
		for(int j=0;j<4;j++){
			cin >> x >> y;
			p[j] = P(x,y);
		}
		L l0(p[0],p[1]),l1(p[2],p[3]);
		if(orthogonalLL(l0,l1))cout << 1 << endl;
		else if(parallelLL(l0,l1))cout << 2 << endl;
		else cout << 0 << endl;

	}

	return 0;
}

Measured memory_bytes: 3104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Dice {
	public String[] value;
	public Dice(String[] info, int size) {
		this.value = new String[size];
		for (int i = 0; i < size; i++) {
			this.value[i] = info[i];
		}
	}
}

public class Main {

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Dice dice = new Dice(br.readLine().split(" "), 6);
		String[] commands = br.readLine().split("");

		for (String command : commands) {
			String work = dice.value[0];
			if (command.equals("N")) {
				dice.value[0] = dice.value[1];
				dice.value[1] = dice.value[5];
				dice.value[5] = dice.value[4];
				dice.value[4] = work;
			} else if (command.equals("E")) {
				dice.value[0] = dice.value[3];
				dice.value[3] = dice.value[5];
				dice.value[5] = dice.value[2];
				dice.value[2] = work;
			} else if (command.equals("W")) {
				dice.value[0] = dice.value[2];
				dice.value[2] = dice.value[5];
				dice.value[5] = dice.value[3];
				dice.value[3] = work;
			} else {
				dice.value[0] = dice.value[4];
				dice.value[4] = dice.value[5];
				dice.value[5] = dice.value[1];
				dice.value[1] = work;
			}
		}
		System.out.println(dice.value[0]);
	}
}

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

int main()
{
    int a, b, c, x, y; std::cin >> a >> b >> c >> x >> y;
    int ans = 0;
    if(a+b > 2*c) {
        ans += std::min(x, y)*2*c;
        if(std::min(x, y) == x) {
            ans += (y-x)*b;
        } else {
            ans += (x-y)*a;
        }

        int ans1 = 0;
        ans1 += std::max(x, y)*c*2;

        ans = std::min(ans1, ans);
    } else {
        ans += a*x + b*y;
    }


    std::cout << ans << std::endl;
}

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

int main(){
  double R, answer;
  cin >> R;
  answer = 2 * R * 3.141;
  cout << answer << endl;
}


Measured memory_bytes: 3784
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N,Q; cin>>N>>Q;
    string t; cin>>t;
    //[l,r]
    //[l,r)の和
    vector<ll> X(N-1,0);
    rep(i,N-1){
        if(t[i]=='A' && t[i+1]=='C') X[i]++;
    }
    vector<ll> s(N,0);
    rep(i,N-1){
        s[i+1]=s[i]+X[i];
    }
    rep(i,Q){
        ll L,R; cin>>L>>R;
        cout<<s[R-1]-s[L-1]<<endl;
    }
}



Measured memory_bytes: 5108
#include<stdio.h>
int main()
{
    int A,B,T,S,M,R;
    scanf("%d %d",&A,&B);
    T=A+B;
    S=A-B;
    M=A*B;
    R=T;
    if(S>R)
        {R=S;}
    if(M>R)
        {R=M;}
    printf("%d\n",R);
    return 0;
    }


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

using namespace std;

const int N = 1e5 + 10;

int n, m;
vector<int> v[N];
int si[N];
queue<int> que;

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	
	memset(si, -1, sizeof si);
	
	cin >> n >> m;
	int a, b;
	while (m --)
	{
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}

	que.push(1);
	si[1] = 0;
	while (que.size())
	{
		int u = que.front();
		que.pop();
		for (auto& i : v[u])
		{
			if (si[i] == -1)
			{
				si[i] = u;
				que.push(i);
			}
		}
	}
	
	bool ok = true;
	for (int i = 1; i <= n; ++i)
	{
		if (si[i] == -1) 
		{
			ok = false;
			break;
		}
	}
	
	if (!ok) cout << "No\n";
	else
	{
		cout << "Yes\n";
		for (int i = 2; i <= n; ++i) cout << si[i] << '\n';
	}
	
	return 0;
}

Measured memory_bytes: 10576
import sys
from heapq import heappush, heappop
import numpy as np

def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())


def main():

    def dijkstra(xs, ss):
        def push(v, s, x):
            if s < 0: 
                return
            if dist[v, s] <= x:
                return
            dist[v, s] = x
            heappush(que, (x, v, s))
        
        inf = 10**18
        dist = np.full((n, MAX_S+1), inf, dtype=int)
        # time, remain, node
        que = []
        push(xs, ss, 0)
        while que:
            x, v, s = heappop(que)
            if dist[v, s] < x:
                continue
            ns = min(s+c[v], MAX_S)
            push(v, ns, x+d[v])
            for nv, a, b in adj[v]:
                push(nv, s-a, x+b)
        return np.min(dist, axis=1)

    n, m, s = mi()
    adj = [[] for i in range(n)]
    MAX_S = 0
    for i in range(m):
        u, v, a, b = mi()
        u -= 1
        v -= 1
        adj[u].append((v, a, b))
        adj[v].append((u, a, b))
        MAX_S = max(MAX_S, a)
    MAX_S *= n-1
    s = min(s, MAX_S)
    c, d = [0]*n, [0]*n
    for i in range(n):
        c[i], d[i] = mi()
    ans = dijkstra(0, s)
    print(*ans[1:], sep='\n')


if __name__ == '__main__':
    main()

Measured memory_bytes: 39028
//n,s,b
//b<=sqrt(n)
//b>sqrt(n),n=a0+a1*b,s=a0+a1 n-s=a1(b-1)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
long long n, s;
inline long long f(long long b, long long n)
{
    return n < b ? n : f(b, n / b) + (n % b);
}
int main()
{
    scanf("%lld%lld", &n, &s);
    if (n < s)
        return printf("-1"), 0;
    if (n == s)
        return printf("%lld", n + 1), 0;
    for (int i = 2; i <= sqrt(n)+1; ++i)
        if (f(i, n) == s)
            return printf("%lld", i), 0;
    long long temp = n - s, mini = 999999999999;
    for (int i = 1; i <= sqrt(temp); ++i)
        if (!(temp % i))
            if (f(temp / i + 1, n) == s)
                mini = min(mini, temp / i + 1);
    printf("%lld", mini == 999999999999 ? -1 : mini);
    return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


class BIT {
	std::vector<int> bit;
public:
	BIT(int size) :bit(size + 1, 0) {}
	void add(int i, int x) {//i番目にx加える
		i++;//BIT添え字は1～ｎだから
		while (i<(int)bit.size()) {
			bit[i] += x;
			i += i&-i;
		}
	}
	int sum(int a)const {//[0,a]の和
		a++;
		int res = 0;
		while (0<a) {
			res += bit[a];
			a -= a&-a;
		}
		return res;
	}
	int sum(int a, int b)const {//[a,b]の合計
		return sum(b) - sum(a - 1);
	}
};



int ans[100000];


vector<pair<int, int>> query[100000];
vector<int> child[100000];
BIT bit(100000);



int N;
int x[100000];
int L, Q;

void dfs(int u) {
	for (auto p : query[u]) {
		ans[p.second] = bit.sum(p.first - 1) + 1;
	}
	if (child[u].empty())return;
	bit.add(u, 1);
	for (int v : child[u]) {
		dfs(v);
	}
	bit.add(u, -1);
}


int main() {
	scanf("%d", &N);
	rep(i, N)scanf("%d", x + i);
	scanf("%d%d", &L, &Q);
	rep(i, Q) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--; b--;
		if (a > b)swap(a, b);
		query[a].emplace_back(b, i);
	}
	int nxt = 0;
	rep(i, N - 1) {
		if (query[i].empty() && child[i].empty())continue;
		while (nxt + 1 < N && x[nxt + 1] - x[i] <= L)nxt++;
		child[nxt].push_back(i);
	}
	dfs(N - 1);
	rep(i, Q)printf("%d\n", ans[i]);

	return 0;
}

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

int n;
struct node
{
	int num;
	int t;
} a[100005];

inline int cmp(node x,node y)
{
	if(x.t < y.t)return 0;
	else return 1;
}

int main()
{
	cin>>n;

	for(int i=1; i<=n; i++)
		a[i].num = i,cin>>a[i].t;

	sort(a+1,a+n+1,cmp);

	for(int i=n; i>=1; i--)
		cout<<a[i].num<<" ";

	return 0;
}

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

using namespace std;

const int N_MAX = 12;
const int Q_MAX = 52;

typedef long long ll;

int n, m, q;

int v[N_MAX];

int a[Q_MAX], b[Q_MAX], c[Q_MAX], d[Q_MAX];

ll ans;

void bk (int pos)
{
    if(pos == n + 1)
    {
        ll sum = 0;
        for(int i = 1; i <= q; i++)
            if(v[b[i]] - v[a[i]] == c[i])
                sum += d[i];
        ans = max(ans, sum);
        return;
    }
    for(v[pos] = v[pos - 1]; v[pos] <= m; v[pos]++)
        bk(pos + 1);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> q;
    for(int i = 1; i <= q; i++)
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    v[0] = 1;
    bk(1);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = b-1; i >= a; i--)
// #define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

////////////////////////////////////////////////////////

int main() {
    ll n; cin >> n;
    Vl l(n);
    rep(i, 0, n) cin >> l[i];

    ll ans = 0;

    rep(i, 0, n-2){
        rep(j, i+1, n-1){
            rep(k, j+1, n){
                Vl v;
                v.push_back(l[i]);
                v.push_back(l[j]);
                v.push_back(l[k]);
                sort(ALL(v));
                if(v[0]!=v[1] && v[1]!=v[2] && v[0]+v[1] > v[2]) ans++;
            }
        }
    }
    
    co(ans);

    return 0;
}




Measured memory_bytes: 3624
#include <stdio.h>
int main( void )
{
  int W, H, x, y, r;
  scanf("%d %d %d %d %d",&W, &H, &x, &y, &r);
  if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H){printf("Yes\n");}
  else{printf("No\n");}
  return 0;
}

Measured memory_bytes: 1012
#include <cmath>
#include <stdio.h>
using namespace std;

int mypow(int b, int n) {
    int r = 1;
    while(0 < n) {
        if(n%2 == 1) {
            r *= b;
            n--;
        }else{
            n /= 2;
            b *= b;
        }
    }
    return r;
}

int main() {
    int x;
    int max = 0;
    scanf("%d", &x);
    for(int i = 1;i < 1000;i++) {
        for(int j = 2;j < 10;j++) {
            int a = mypow(i, j);
            if(x < a)continue;
            max = max < a ? a : max;
        }
    }
    printf("%d\n", max);
    return 0;
}


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

using namespace std;

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

  vector<int> ans(N, 0);
  for (int i = 0; i < M; ++i) {
    int a, b; cin >> a >> b;
    a--, b--;
    ans[a]++, ans[b]++;
  }

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

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            new Main().solve(sc);
        }
    }

    void solve(Scanner sc) {
        int n = sc.nextInt();
        String s = sc.next();
        String t = sc.next();
        if (s.length() + t.length() <= n) {
            System.out.println(n);
        } else {
            for (int i = 0; i < s.length(); i++) {
                if (t.startsWith(s.substring(i))) {
                    System.out.println(s.length() + i);
                    return;
                }
            }
            System.out.println(s.length() + t.length());
        }
    }
}

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

int main()
{
	double x1,x2;
	double y1,y2;
	double distance;
	
	cin >> x1 >> y1 >> x2 >> y2;
	
	distance=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
	
	cout << fixed << setprecision(4) << distance << endl;
	
	return 0;
}

Measured memory_bytes: 1280
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int c[] = new int[n+1];
		for(int i=1;i<n;i++) c[i] = sc.nextInt();
		int dp[][][] = new int[2][2][n/2+1];
		
		for(int[][] a: dp) for(int[] b: a) fill(b, INF);
		dp[0][0][0] = 0;
		int x = 1;
		for(int i=1;i<=n;i++, x=1-x) for(int j=0;j<=n/2;j++) {
			dp[x][0][j] = min( dp[1-x][1][j], dp[1-x][0][j] );
			if(j>0)
			dp[x][1][j] = min( dp[1-x][0][j-1] + c[i-1] + c[i],
								 dp[1-x][1][j-1] - c[i-1] + c[i]);
//			debug(dp[i%2][0][j], dp[i%2][1][j]);
		}
		System.out.println( min(dp[1-x][0][n/2], dp[1-x][0][n/2] ) );
	}

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

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

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

namespace ABC132
{
    class A
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();

            foreach (var c in s)
            {
                int count = s.Where(x => x == c).Count();
                if ((count % 2) != 0 || (count / 2) == 2)
                {
                    Console.WriteLine("No");
                    return;
                }
            }
            Console.WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 13268