akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

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

  private void run() {
    while(sc.hasNext()) {
      int n = sc.nextInt();
      int m = sc.nextInt();

      if(n == 0 && m == 0) break;

      int[][] costs = new int[m][m];
      int[][] times = new int[m][m];

      for(int i = 0; i < m; i++) {
        for(int j = 0; j < m; j++) {
          costs[i][j] = INFINITY;
          times[i][j] = INFINITY;
        }
      }

      for(int i = 0; i < n; i++) {
        int a = sc.nextInt() - 1;
        int b = sc.nextInt() - 1;
        int cost = sc.nextInt();
        int time = sc.nextInt();

        costs[a][b] = cost;
        costs[b][a] = cost;
        times[a][b] = time;
        times[b][a] = time;
      }

      for(int i = 0; i < m; i++) {
        for(int j = 0; j < m; j++) {
          if(i == j) continue;
          for(int k = 0; k < m; k++) {
            if(i == k || j == k) continue;

            costs[j][k] = Math.min(costs[j][k], costs[j][i] + costs[i][k]);
            times[j][k] = Math.min(times[j][k], times[j][i] + times[i][k]);
          }
        }
      }

      int k = sc.nextInt();

      for(int i = 0; i < k; i++) {
        int p = sc.nextInt() - 1;
        int q = sc.nextInt() - 1;
        int r = sc.nextInt();

        switch(r) {
        case 0:
          System.out.println(costs[p][q]); break;
        case 1:
          System.out.println(times[p][q]); break;
        }
      }
    }
  }

  private Scanner sc = new Scanner(System.in);
  private static final int INFINITY = 100000000;
}

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

int PrimeNumber();
int main(){
  
  int i, j, n, m[10000], count=0;
  
  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d", &m[i]);
  }
  
  for(j=0; j<n; j++){
    if(PrimeNumber(m[j])==1)
      count++;
  }
  
  printf("%d\n", count);
  return 0;
}

int PrimeNumber(x){
  int i;
  if(x==2)
    return 1;
  else if(x<2||x%2==0)
    return 0;
  i=3;
  while(i<= sqrt(x)){
    if(x%i==0)
      return 0;
    i=i+2;
  }
  return 1;
} 

Measured memory_bytes: 632
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double INF=1e+10;
const long double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		// if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
int main(){
	int a;scanf("%d",&a);
	while(a--){
		int t;scanf("%d",&t);
		if(t%2==0&&t%3&&t%5){
			printf("DENIED\n");return 0;
		}
	}
	printf("APPROVED\n");
}

Measured memory_bytes: 128
n = gets.to_i
z = Array.new(n)
w = Array.new(n)

n.times do |i|
  x, y = gets.split.map(&:to_i)
  z[i] = x + y
  w[i] = x - y
end

puts [z.max - z.min, w.max - w.min].max


Measured memory_bytes: 17508
M = int(input())

def tanri(a,y,nenri,tax):
    w = 0
    for i in range(y):
        w += int(a * nenri)
        a -= tax
    return a+w
def fukuri(a, y, nenri, tax):
    for i in range(y):
        a += int(a * nenri) - tax 
    return a

for i in range(M):
    A = int(input())
    Y = int(input())
    N = int(input())
    max_ = 0
    for i in range(N):
        t, nenri, tax = list(map(float,input().split()))
        max_ = max(max_, tanri(A,Y,nenri,tax) if t == 0 else fukuri(A,Y,nenri,tax))

    print(int(max_))

Measured memory_bytes: 6744
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;


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

    vector<ll> ans;
    if (K % 2 == 0) {
        ans.push_back(K / 2);
        for (ll i = 0; i < N - 1; i++) {
            ans.push_back(K);
        }
    } else {
        for (ll i = 0; i < N; i++) {
            ans.push_back((K + 1) / 2);
        }

        for (ll i = 0; i < N / 2; i++) {
            if (ans.back() == 1) {
                ans.erase(ans.end() - 1);
            } else {
                ans.back()--;
                while (ans.size() != N) {
                    ans.push_back(K);
                }
            }
        }
    }

    for (ll i = 0; i < ans.size(); i++) {
        cout << ans[i] << " \n"[i == ans.size() - 1];
    }
}

Measured memory_bytes: 6384
def main():
    def change(x,y):

        if x % 2 == 1:
            x -= 1
        y += x//2
        x = x // 2
        return x, y


    A, B, K = map(int,input().split())

    cnt = 0
    while True:
        A, B = change(A,B)
        cnt += 1
        if cnt == K:
            break
        B, A = change(B,A)
        cnt += 1
        if cnt == K:
            break
    print(A,B)


    return


main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first

#ifdef DEBUG
#define DBG(...) {string dst__=#__VA_ARGS__;dreplace(dst__);stringstream dss__; dss__<<dst__; debug(dss__,__VA_ARGS__);}
#else
#define DBG(...)
#endif
void debug(stringstream& ds){cerr<<endl;return;}
template<typename F, typename... R>void debug(stringstream& ds,const F& f, const R&... r){string n; ds>>n; cerr<< n <<'='<<f<<' '; debug(ds,r...);}
void dreplace(string &s){int l=s.length(),n=0;for(int i=0; i<l; ++i){if(s[i]=='(')++n;if(s[i]==')')--n;if(s[i]==','&&!n)s[i]=' ';}}

typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
typedef pair<int,int>PI; typedef vector<int> VI;
template<typename T> using V = vector<T>;
constexpr LL LINF=334ll<<53; constexpr int INF=15<<26; constexpr LL MOD=1E9+7;

struct Edge{
    int from,to;
    Edge(int from,int to)
        : from(from),to(to) {};
};
typedef vector<vector<Edge>> Graph;

int defineDepth(Graph &T, vector<int> &p, vector<int> &dep,vector<vector<int>> &dtov,int root){
    fill(p.begin(),p.end(),-1);
    int ret =0;
    queue<int> Q;
    Q.push(root);
    p[root]=root;
    dtov[0].push_back(root);
    while(!Q.empty()){
        int nex=Q.front();
        Q.pop();
        for(auto &x: T[nex]){
            if(p[x.to]==-1){
                p[x.to]=x.from;
                Q.push(x.to);
                dep[x.to]=dep[x.from]+1;
                ret=max(ret,dep[x.to]);
                dtov[dep[x.to]].push_back(x.to);
            }
        }
    }
    return ret;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    Graph t(n);
    vector<int> dep(n),par(n),dp(n);
    vector<vector<int>> dtov(n);
    for(int i=1; i<n; ++i){
        int tmp;
        cin >> tmp; --tmp;
        t[tmp].push_back(Edge(tmp,i));
        t[i].push_back(Edge(i,tmp));
    }
    int deepest=defineDepth(t,par,dep,dtov,0);
    for(int i=deepest; i>=0; --i){
        for(int x : dtov[i]){
            VI tmp;
            for(auto &e : t[x]){
                if(e.to==par[x])continue;
                tmp.push_back(dp[e.to]);
            }
            sort(tmp.begin(),tmp.end(),greater<int>());
            for(int j=0; j<tmp.size(); ++j){
                dp[x]=max(dp[x],tmp[j]+j+1);
            }
        }
    }
    cout << dp[0] <<endl;


    return 0;
}



Measured memory_bytes: 12416
#include <iostream> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
#define int long long
#define mod 1000000007
#define rep(i,n)  for(int i=0; i<n; i++)
#define all(v)  v.begin(),v.end()
using namespace std;

int jousu(int, int);
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int kurai(int x00, int y00) {
	int z00 = (x00%jousu(10,y00)) / jousu(10, y00-1);
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}


signed main() {
	int a,n, k, q;
	cin >> n >> k >> q;
	vector<int>vec(n,0);
	for (int i = 0; i < q; i++) {
		cin >> a;
		vec[a-1]++;
	}
	for (int i = 0; i < n; i++) {
		if (vec[i] > q-k)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}


Measured memory_bytes: 1408
// inputに入力データ全体が入る
function Main(input) {
    input = input.split(' ');
    //文字列から10進数に変換するときはparseIntを使います
    var a = parseInt(input[0], 10);
    var b = parseInt(input[1], 10);
    
    var a_real = 1;
    var b_real = 1;
    var a_count = 1
    var b_count = 1
    var ans = 0;
    while ( true ) {
        while ( true ) {
            a_count++;
            a_real += a_count;
            if (a_real > a) {
                break;
            }
        }
        b_count = a_count + 1;
        b_real = a_real + b_count;
        if ( (a_real - a) == (b_real - b)) {
            break;
        }
    }
    ans = a_real - a;
    console.log(ans);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 11468
import java.io.*;
import java.util.*;
import java.util.stream.Collector;
import java.util.stream.Collectors;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int Q = sc.nextInt();

        final Solver solver = new Solver();
        solver.solve(S, Q, sc);
    }
}

class Solver {
    public void solve(String S, int Q, Scanner sc) {
        final List<Character> str = new LinkedList<>();
        for (char ch : S.toCharArray()) {
            str.add(ch);
        }

        boolean rev = false;
        for (int i = 0; i < Q; i++) {
            int t = sc.nextInt();

            switch (t) {
                case 1:
                    rev = !rev;
                    break;
                case 2:
                    int f = sc.nextInt();

                    boolean addFirst = (f == 1) ? !rev : rev;

                    char c = sc.next().charAt(0);
                    str.add(addFirst ? 0 : str.size(), c);
                    break;
            }
        }

        if (rev) {
            Collections.reverse(str);
        }
        System.out.println(str.stream().map(String::valueOf).collect(Collectors.joining()));
    }
}




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

int main() {
int N;
cin>>N;
long double sum=0.0;
for(auto i=0; i<N; ++i)
{
long double p;
string k;
cin>>p>>k;
if(k[0]=='B')
{
p=p*380000.0;
}

sum +=p;
}
cout <<sum<<endl;
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n + 1);
    rep(i, n) cin >> a[i + 1];
    vector<int> H(n + 1);
    for (int i = n; i >= 1; i--)
    {
        int sum = 0;
        int j = i;
        while (j <= n)
        {
            sum += H[j];
            j += i;
        }
        if (sum % 2 == a[i])
            H[i] = 0;
        else
            H[i] = 1;
    }

    //指定の形に変換
    vector<int> ans;
    for (int i = 1; i <= n; i++)
    {
        if (H[i] == 1)
            ans.push_back(i);
    }
    cout << ans.size() << endl;
    rep(i, ans.size()) cout << ans[i] << " ";
    cout << endl;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define vv(T) std::vector<std::vector<T>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

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

	vector<ll> A(n);
	for (int i = 0; i < n; ++i)
	{
		ll a;
		cin >> a;

		if (a == 0LL)
		{
			cout << 0 << endl;
			return 0;
		}
		A[i] = a;
	}

	ll ans = A[0];
	ll mx = 1'000'000'000'000'000'000;
	for (int i = 1; i < n; ++i)
	{
		if (ans * A[i] > mx || ans > mx/A[i])
		{
			ans = -1;
			break ;
		}
		ans *= A[i];
	}
	cout << ans << endl;
}



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

//UnionFind


struct UnionFind{
    vector<int> par;
    vector<int> rank;
    vector<int> size;

    //こいつがいわゆるコンストラクタ
    //初期化している
    UnionFind(int N) : par(N),rank(N),size(N){
        for(int i=0;i<N;i++){
            par[i]=i;
            size[i]=1;
            rank[i]=0;
        }
    }

    int find(int x){
        if(x == par[x]) return x;
        return par[x] = find(par[x]);
    }


    void unite(int x, int y){
        int rx,ry;
        rx = find(x);
        ry = find(y);
        if(rx == ry){
            return;
        }
        else{
            if(rank[rx]<rank[ry]){
                par[rx]=ry;
                size[ry]+=size[rx];
            }
            else{
                par[ry]=rx;
                size[rx]+=size[ry];
                if(rank[rx]==rank[ry]){
                    rank[rx]++;
                }
            }
        }
    }


    bool same(int x,int y){
        return find(x) == find(y);
    }
};

int main(){
    int N,M;
    cin>>N>>M;
    UnionFind tree(N);
    // vector<int> a(M);
    // vector<int> b(M);
    for(int i=0;i<M;i++){
        int x,y;
        cin>>x>>y;
        tree.unite(x-1,y-1);
        // cin>>a.at(i)>>b.at(i);
    }

    // for(int i=0;i<M;i++){
    //     tree.unite(a.at(i)-1,b.at(i)-1);
    // }
    
    vector<int> ans(N);
    for(int i=0;i<N;i++){
        ans.at(i)=tree.size.at(i);
    }
    sort(ans.begin(),ans.end());
    reverse(ans.begin(),ans.end());
    cout<<ans.at(0)<<endl;
}

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

int main(void){
    double w,h,x,y;
    int d = 0;
    cin >> w >> h >> x >> y;
    if(w == x+x && h == y+y) d = 1;
    cout << w/2*h << ' ' << d << endl;
}


Measured memory_bytes: 256
a,b,c,d = map(int, input().split())
if a > c:
  if a > d:
    print('0')
    exit()
  elif b < d:
    print(str(b-a))
    exit()
  else:
    print(str(d-a))
    exit()
else:
  if c > b:
    print('0')
    exit()
  elif d < b:
    print(str(d-c))
    exit()
  else:
    print(str(b-c))
    exit()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,c,d;
  string s;
  cin >> n >> a >> b >> c >> d >> s;
  bool cana=true,canb=true,can2=false;
  for(int i=a-1;i<c-2;i++){
    if(s[i]=='#'&&s[i+1]=='#'){
      cana=false;
    }
  }
  for(int i=b-1;i<d-2;i++){
    if(s[i]=='#'&&s[i+1]=='#'){
      canb=false;
    }
  }
  if(c>d){
    for(int i=b-1;i<=d-1;i++){
      if(s[i-1]=='.'&&s[i]=='.'&&s[i+1]=='.'){
        can2=true;
      }
    }
  }
  else{
    can2=true;
  }
  if(cana&&canb&&can2){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

int main(){
    string s;
    cin >> s;
    int count =0;
    for(int i=0;i<4;i++){
        if(s[i]=='+')   count++;
        else    count--;  
    }
    cout << count << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] a = new long[N];

		double invsum = 0;
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextLong();
			invsum += 1.0 / (double) a[i];
		}
		System.out.println(1.0 / invsum);

	}

}


Measured memory_bytes: 22996
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()


template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }




void solve(void)
{
  int A,B,C;
  cin>>A>>B>>C;
  if((A-C)*(B-C) < 0)
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);

std::cout << std::fixed;
std::cout << std::setprecision(9);
solve();

return 0;
}


Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll n,ans=0,m,l;
  cin >> n;
  ll vals[10][10]={};
  for(int i=1;i<=n;i++){
    l = i%10;
    string t = to_string(i);
    m = t[0]-'0';
    vals[m][l]++;
  }
  for(int i=0;i<=9;i++){
    for(int j=0;j<=9;j++){
      ans += vals[i][j]*vals[j][i];
    }
  }
  cout << ans <<endl;
}


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

#define FO(i,a,b) for (int i = (a); i < (b); i++)
#define sz(v) int(v.size())

using namespace std;

int n, k;
int o[500005], a[500005];

int rt[1000005], rtt[1000005], T;
bool rpv[500005];

bool qs(int l, int r) {
    l = max(l,0);
    r = min(r,n);
    for (l += n, r += n; l < r; l /= 2, r /= 2) {
        if (l&1) if (rtt[l++] == T) return true;
        if (r&1) if (rtt[--r] == T) return true;
    }
    return false;
}

void up(int i) {
    for (i += n; i; i /= 2) rtt[i] = T;
}

void go(int i, int j) {
    if (i == j) return;
    else {
        int pv = i + rand() % (j-i);
        T++; up(a[pv]);
        for (int t = pv-1; t >= i; t--) {
            rpv[t] = qs(a[t]-k+1, a[t]+k);
            if (rpv[t]) up(a[t]);
        }
        T++; up(a[pv]);
        for (int t = pv+1; t < j; t++) {
            rpv[t] = qs(a[t]-k+1, a[t]+k);
            if (rpv[t]) up(a[t]);
        }

        vector<int> l, r;
        FO(t,i,pv) {
            if (rpv[t] || a[t] < a[pv]) l.push_back(a[t]);
            else r.push_back(a[t]);
        }
        FO(t,pv+1,j) {
            if (rpv[t] || a[t] > a[pv]) r.push_back(a[t]);
            else l.push_back(a[t]);
        }
        int apv = a[pv];
        int t = i;
        for (int x : l) a[t++] = x;
        int md = t;
        a[t++] = apv;
        for (int x : r) a[t++] = x;
        assert(t == j);
        go(i,md);
        go(md+1,j);
    }
}

int main() {
    scanf("%d %d", &n, &k);
    FO(i,0,n) {
        scanf("%d", o+i); o[i]--;
        a[o[i]] = i;
    }
    go(0,n);
    FO(i,0,n) o[a[i]] = i+1;
    FO(i,0,n) printf("%d\n", o[i]);
}

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

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

    double odd, ans;
    odd = ceil(N / 2);
    ans = odd / N;

    printf("%.6f", ans);
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if (a*b%2 == 0) {
    cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }
}


Measured memory_bytes: 256
import sys
from io import StringIO
import unittest
import itertools

# タグ、順列、組み合わせ

# abcd・・a=<b=<=<d・・という塊は、広義単調増加等と言うらしい。
#     参考：単調増加等の説明：https://mathtrain.jp/tantyou
# そして、この組み合わせを網羅するには、重複組合せを使える。
#     参考：重複組合せ：https://mathtrain.jp/tyohukuc
# 最大の組み合わせ数は20C10になる、と思ったが、違う。20C10が正しいらしい。
# 実装方法はこんな感じ。
#     https://qiita.com/junkls/items/10384950963056cc8e08
# 問題文の意味が分かりずらい・・15分かかった。
# 例)
# ---入力例---
#   3 4 3
#   1 3 3 100
#   1 2 2 10
#   2 3 2 10

#   1 3 3 100の場合・・
#   「3番目の数字 - 1番目の数字 = 3になる場合100点加算。」という意味。

# ---出力---
#   110
#   ->A[1, 3, 4]の時・・
#     「1 3 3 100」->A[3](つまり4) - A[1](つまり1) = 3 だから100点加算。
#     「1 2 2  10」->A[2](つまり3) - A[1](つまり1) = 2 だから 10点加算。
#     「2 3 2  10」->A[3](つまり4) - A[2](つまり3) = 1(=2じゃない) だから 加算なし。

def resolve():
    n, m, q = map(int, input().split())

    num_list = [list(map(int, input().split())) for i in range(q)]

    targets = list(itertools.combinations_with_replacement(range(1, m+1), n))

    point = 0
    for target in targets:
        work_point = 0
        for num in num_list:
            # 条件を満たすならポイント加算。
            # ※targetsは0始まりの配列、num_listは1始まるの値が格納されているので、targetの添え字を指定するとき-1している。
            if target[num[1]-1] - target[num[0]-1] == num[2]:
                work_point += num[3]

        # 最適解を格納
        point = max(point, work_point)

    print(point)




class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3 4 3
1 3 3 100
1 2 2 10
2 3 2 10"""
        output = """110"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328"""
        output = """357500"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """10 10 1
1 10 9 1"""
        output = """1"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

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

int main(){
	int m;
	cin >> m;
	cout << 48 - m << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define EPS 1e-14

#define all(v) v.begin(),v.end()
#define INF 1<<30
#define mp make_pair
#define pb push_back

#define fi first
#define se second

#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

typedef long long ll;

//STONEBANK: BLAST FROM THE DAST

int main(){
	int N;
	int bt=0,bx=0,by=0;

	cin >> N;
	rep(i,N){
		int t,x,y;
		cin >> t >> x >> y;
		t = t - bt;
		x = x - bx;
		y = y - by;

		int d = abs(x) + abs(y);
		if(d > t || t%2 != d%2){
			cout << "No" << endl;
			return 0;
		}


		bt = t;
		bx = x;
		by = y;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,a,b;
int ans[500005];

int main(void){
	scanf("%d%d%d",&n,&a,&b);
	int cur=n;
	int pos=0;
	int mxa=0;
	for(int i=0;i<b;i++){
		int us=min(a,cur-(b-i-1));
		if(us<=0){
			printf("-1\n");
			return 0;
		}
		if(i==0 && us!=a){
			printf("-1\n");
			return 0;
		}
		for(int j=0;j<us;j++){
			ans[pos++]=cur-us+j+1;
		}
		cur-=us;
		if(cur<=-1){
			printf("-1\n");
			return 0;
		}
	}
	if(pos<n){
		printf("-1\n");
		return 0;
	}
	for(int i=0;i<n;i++){
		printf("%d%c",ans[i],i+1==n?'\n':' ');
	}
	return 0;
}


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

int f(ll a, ll b){
    return max(to_string(a).size(),to_string(b).size());
}

int main(){
	ll n;cin>>n;
    int ans=10;
    for(ll i=1; i*i<=n; i++){
        if(n%i==0) ans=min(ans,f(i,n/i));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
Ss = input()

BASE = 10**9 + 7
MOD = 2**61 - 1

def genRollingHash_AllRight(Ss, lenInit, BASE, MOD):
    As = [ord(S) for S in Ss]
    hashS = 0
    for A in As[:lenInit]:
        hashS = (hashS*BASE + A) % MOD
    yield hashS

    powB_L = pow(BASE, lenInit, MOD)
    for Aadd, Asub in zip(As[lenInit:], As[:len(As)-lenInit]):
        hashS = (hashS*BASE + Aadd - Asub*powB_L) % MOD
        yield hashS

def isOK(k):
    hashSs = list(genRollingHash_AllRight(Ss, k, BASE, MOD))
    setHashS = set()
    for i in range(k, N-k+1):
        setHashS.add(hashSs[i-k])
        if hashSs[i] in setHashS:
            return True
    return False

ng, ok = N//2 + 1, 0
while abs(ok-ng) > 1:
    mid = (ng+ok) // 2
    if isOK(mid):
        ok = mid
    else:
        ng = mid

print(ok)


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

int main(void){
  
  std::string s;
  std::cin >> s;

  if(s == "Sunny") std::cout << "Cloudy" << std::endl;
  if(s == "Cloudy") std::cout << "Rainy" << std::endl;
  if(s == "Rainy") std::cout << "Sunny" << std::endl;
  
  
  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
hs = gets.split.map(&:to_i)
ans = 0
t_ans = 0
cur = nil
(0..n-1).each do |i|
  h = hs[i]
  if cur && h <= cur
    t_ans += 1
  else
    t_ans = 0
  end
  ans = [ans, t_ans].max
  cur = h
end
puts ans

Measured memory_bytes: 11140
#include<bits/stdc++.h>
#define range(a,l,r) (l<=a && a<=r)
using namespace std;
typedef long long ll;

ll n;
pair<ll,ll> c[100100];
int use[100100];
const ll inf = 1e15;
const long double sq2 = sqrt(2);
const long double PI = acos(-1);
const long double EPS = 1e-8;

int main(){
  scanf("%lld",&n);
  ll maxy = -inf, miny = inf;
  pair<ll,ll> left(inf,inf);

  for(int i=0;i<n;i++){
    scanf("%lld%lld",&c[i].first,&c[i].second);
    complex<long double> p(c[i].first,c[i].second);
    p *= complex<long double>(cos(PI/4),sin(PI/4));
    c[i].first = (ll)(p.real() * sq2 + (p.real()>0?+EPS:-EPS));
    c[i].second = (ll)(p.imag() * sq2) + (p.imag()>0?+EPS:-EPS);
    //cerr << c[i].first << " " << c[i].second << endl;
    maxy = max(maxy, c[i].second);
    miny = min(miny, c[i].second);
    left = min(left, c[i]);
  }
  //cerr << left.first << " " << left.second << endl;
  //cerr << miny << " " << maxy << endl;
  
  ll l=-1,r=1e10;
  while(r-l>1){
    //cerr << l << " " << r << endl;
    ll mid = (l+r)/2;
    //cerr << mid << endl;

    bool ok = false;
    if(maxy <= left.second + mid){
      //cerr << mid << endl;
      memset(use,0,sizeof(use));
      for(int i=0;i<n;i++){
	if( range(c[i].first, left.first, left.first+mid)
	    && range(c[i].second, maxy-mid, maxy) )use[i] = 1;
      }
      //for(int i=0;i<n;i++)cerr << use[i] << " "; cerr << endl;

      ll rl = inf, rr = -inf, rd = inf, ru = -inf;
      for(int i=0;i<n;i++){
	if(!use[i]){
	  rl = min(rl, c[i].first); rr = max(rr, c[i].first);
	  rd = min(rd, c[i].second); ru = max(ru, c[i].second);
	}
      }
      if(rr-rl<=mid && ru-rd<=mid)ok = true;
    }

    if(miny >= left.second - mid){
      //cerr << mid << endl;
      memset(use,0,sizeof(use));
      for(int i=0;i<n;i++){
	if( range(c[i].first, left.first, left.first+mid)
	    && range(c[i].second, miny, miny+mid) )use[i] = 1;
      }
      //for(int i=0;i<n;i++)cerr << use[i] << " "; cerr << endl;

      ll rl = inf, rr = -inf, rd = inf, ru = -inf;
      for(int i=0;i<n;i++){
	if(!use[i]){
	  rl = min(rl, c[i].first); rr = max(rr, c[i].first);
	  rd = min(rd, c[i].second); ru = max(ru, c[i].second);
	}
      }
      if(rr-rl<=mid && ru-rd<=mid)ok = true;
    }

    if(ok)r = mid;
    else l = mid;
  }

  cout << r << endl;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
using namespace std;
using namespace __gnu_pbds;
auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int k;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>k;
    for(int i=1;i<=k;i++)
        cout<<"ACL";
    return 0;
}


Measured memory_bytes: 3596
from collections import defaultdict
n,m=map(int,input().split())
l=[int(i) for i in input().split()]
d=defaultdict(int)
sm=0 
d[0]=1 
ans=0 
for i in l: 
    sm+=i 
    sm%=m 
    ans+=d[sm]
    d[sm]+=1 
print(ans)

Measured memory_bytes: 14508
X, N = map(int, input().split())
if N: p = list(map(int, input().split()))
else: print(X); exit()
length = 10**4+2
ans = -1
for i in range(-1,103):
  if length > abs(X - i) and i not in p:
    length = abs(X - i)
    ans = i
print(ans)

Measured memory_bytes: 61704
from sys import stdin
s = stdin.readline()[:-1]

length = len(s)

dp = [[0 for i in range(13)]for j in range(100100)]

s = list(reversed(s))

dp[0][0]=1
ten = 1
mod = 1000000007


for i in range(length):
	if s[i] == '?':
		for num in range(10):
			d = num*ten
			for j in range(13):
				k = (j+d)%13
				dp[i+1][k] += dp[i][j]
				dp[i+1][k] %= mod
	else:
		num = int(s[i])
		d = num*ten
		for j in range(13):
			k = (j+d)%13
			dp[i+1][k] += dp[i][j]
			dp[i+1][k] %= mod
	ten *= 10
	ten %= 13

print(int(dp[length][5]%mod))

Measured memory_bytes: 100308
#include<stdio.h>
int main()
{
    int n,t,k=0,temp;
    scanf("%d %d",&n,&t);
    int ac[n],at[n],az[n],min=1001;
    for(int i=0; i<n; i++)
    {
        scanf("%d %d",&ac[i],&at[i]);
    }
    for(int j=0; j<n; j++)
    {
        if(at[j]> t)
        {
            ac[j]=1002;

        }
        if(ac[j]<min)
        {
            min=ac[j];
        }

    }


    if(min!=1001)
    {
    printf("%d",min);
    }
    else
    {
        printf("TLE");
    }
    return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }


    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        string S = cin.next();
        int ans = 0;
        for (int i = 0; i < S.Length; i++)
        {
            ans += S[i] - '0';
        }

        for (int i = 0; i < S.Length; i++)
        {
            int tmp = 0;
            if (S[i] == '0') continue;
            for (int j = 0; j < i; j++)
            {
                tmp += (int)(S[j] - '0');
            }
            tmp += (S[i] - '0') - 1;
            for (int j = i + 1; j < S.Length; j++)
            {
                tmp += 9;
            }
            ans = Math.Max(ans, tmp);
        }
        Console.WriteLine(ans);
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 11092
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// #include<deque>
// #include<multiset>
// #include<bitset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

const int N = 1e5;
vector<int> g[N];
int used[N];
int used2[N];
int n, m;
int visi = 0;
void dfs(int i) {
  if(used[i]) {
    return;
  }
  used[i] = 1;
  visi++;
  for(int j : g[i]) {
    dfs(j);
  }
}

int topo[N];
int id = 0;
void dfs2(int i) {
  if(used2[i]) {
    return;
  }
  used2[i] = 1;
  for(int j : g[i]) {
    dfs2(j);
  }
  topo[i] = id++;
}

int used3[N];
int par[N];
void dfs3(int i, int p = -1) {
  if(used3[i]) {
    return;
  }
  used3[i] = 1;
  par[i] = p + 1;
  sort(begin(g[i]), end(g[i]), [](int a, int b) {
        return topo[a] > topo[b];
      });
  for(int j : g[i]) {
    dfs3(j, i);
  }
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> m;
  for(int i = 0; i < n + m - 1; i++) {
    int a, b; cin >> a >> b;
    a--; b--;
    g[a].emplace_back(b);
  }
  for(int i = 0; i < n; i++) {
    dfs(i);
    if(visi == n) {
      dfs2(i);
      dfs3(i);
      break;
    }
  }
  for(int i = 0; i < n; i++) cout << par[i] << "\n";
  return 0;
}


Measured memory_bytes: 14464
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint K; cin >> K;
    const lint N = 50;
    lint q = K / N, r = K % N;
    cout << N << "\n";
    vec<lint> res(N, q);
    range(i, 0, N - 3) res.at(i) += (N - 1) - r;
    range(i, N - 3, N - 1) res.at(i) += (r / 3) * N + (N - 1) - (r - r / 3);
    res.at(N - 1) += ((r / 3) + r % 3) * N + (N - 1) - (r - r / 3 - r % 3);
    range(i, 0, N) cout << res.at(i) << " ";
    cout << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <math.h>
#include <algorithm>

const int coin[6] = { 500,100,50,10,5,1 };

using namespace std;

int main(){
	
	int answer[5] = { 0 };

	int in = 0, change = 0, n = 0;



	for (int j = 0; j < 5; j++) {
		n = 0;
		cin >> in;
		if (in == 0) break;
		change = 1000 - in;
		for (int i = 0; i < 6; i++) {
			while (change >= coin[i]) {
				change -= coin[i];
				n++;
			}
		}
		answer[j] = n;
	}


	for (int j = 0; j < 5; j++) {
		if (answer[j] == 0) break;
		cout << answer[j] << endl;
	}

	return 0;
}


Measured memory_bytes: 3080
#include <stdio.h>

int
main(int argc, char *argv[])
{
  char s[101]; long long k;
  scanf("%s", s);
  scanf("%lld", &k);


  int i = 0;
  while(s[i] == '1'){
    i++;
  }

  if((long long)i >= k) printf("1\n");
  else printf("%c\n", s[i]);

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define endl '\n'
#define main() int main()
#define ff1(i,n) for(int i=1;i<=n;++i)
#define ff0(i,n) for(int i=0;i<n;++i)
#define pi acos(-1.0)
#define ms(a, x) memset(a, x, sizeof(a))
#define lowbit(x) ((x)&(-(x)))
#define pb push_back
#define binarycount __builtin_popcount(x)
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define fir first
#define sec second
#define debug(x) cout<<x<<'\n'
#define sa(a) scanf("%d", &a)
#define sab(a, b) scanf("%d%d", &a, &b)
#define pa(a) printf("%d",a)
#define pab(a,b) printf("%d%d",a,b)
#define pii pair<string,int>
using namespace std;
#define maxn 3005
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
const double eps = 1e-8;
ll gcd(ll a, ll b) {return b==0?a:gcd(b, a%b);}
ll lcm(ll a, ll b) {return a/gcd(a, b)*b;}
int max(int x,int y){if(x>y) return x;return y;}
ll powmod(ll a,ll b){
    ull ans = 1, pow = a%mod;
    while(b) { if(b&1) ans = (ans*pow)%mod; pow = (pow*pow)%mod; b >>= 1; }
    return ans%mod;
}

int n;
double a[maxn];
double dp[maxn][maxn];
main()
{
	IO;
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	dp[1][1]=a[1];
	dp[1][0]=1-a[1];
	for(int i=2;i<=n;i++)
	{
		for(int j=0;j<=i;j++)
		{
			dp[i][j]=dp[i-1][j-1]*a[i]+dp[i-1][j]*(1-a[i]);
		}
	}
	int k=n/2+1;
		double ans=0;
	for(int j=k;j<=n;j++)
	{
		//cout<<dp[n][j]<<endl;
		ans+=dp[n][j];
	}
	printf("%.11lf\n",ans);
}


Measured memory_bytes: 68992
/*
±¾±¦±¦µÄ³ÌÐò±ðÏë¿´£¡£¡

name: [ÏÄ±¦±¦]
run time:[] ms
compilation time: [] s
output memory: [] MiB
where: []
state: []
*/
#include<bits/stdc++.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, m;
	
	cin>>n>>m;
	
	cout<<n*(n-1)/2+m*(m-1)/2<<endl;
	
	return 0; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read(){
    int x=0,c=getchar(),f=0;
    for(;c>'9'||c<'0';f=c=='-',c=getchar());
    for(;c>='0'&&c<='9';c=getchar())
    x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
const int maxn = 1e2 + 10;

int main() {
    int n = read() , m = read();
    cout << n + m / 2 << endl;
    return 0;
}


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

int main(){
  int a;
  cin >> a;
  vector<int> p(a);
  for(int i=0;i<a;i++){
    cin >> p.at(i);
  }
  vector<int> q(a);
  q = p;
  sort(q.begin(),q.end());

// 昇順との違いが2つ以下ならで比べれば良いのでは　☓>と<の数を調べる
  int r=0,l=0;
  for(int i=0;i<a;i++){
    if(p.at(i) == q.at(i)) r += 1;

  }
  if(a - r<=2) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			long k = in.nextLong();
			int n = 50;
			long l = k / n;
			int m = (int)(k % n);

			long[] a = new long[n];
			for (int i = 0; i < n; i++) {
				a[i] = i;
			}
			for (int i = 1; i <= m; i++) {
				a[n-i]++;
			}

			for (int i = 0; i < n; i++) {
				a[i] += l;
			}

			out.println(n);
			for (int i = 0; i < n; i++) {
				if (i == 0) {
					out.print(a[i]);
				} else {
					out.print(" "+a[i]);
				}
			}
			out.print("\n");
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 21460
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        String ans = "";
        if (y % 2 == 0 && 2 * x <= y && 4 * x >= y) {
            ans = "Yes";
        } else {
            ans = "No";
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35816
#include <stdio.h>
int main () {
  int flag = 1, n, a[100], num = 0, i, j, tmp;

  scanf("%d", &n);
  for(i = 0 ; i < n ; i++) {
    scanf("%d", &a[i]);
  }

  while(flag) {
    flag = 0;
    for(j = n-1 ; j > 0 ; j--) {
      if(a[j] < a[j-1]) {
	tmp = a[j];
	a[j] = a[j-1];
	a[j-1] = tmp;
	num++;
	flag = 1;
      }
    }
  }
  for(i = 0 ; i < n ; i++) {
    printf("%d", a[i]);
    if(i != n - 1) printf(" ");
  }
  printf("\n");
  printf("%d\n", num);

  return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  // 入力
  ll D; cin >> D;
  ll N = 26;
  vector<ll> c(N); rep(i,N) cin >> c[i];

  vector<vector<ll> > s(D , vector<ll>(N));
  rep(i,D) rep(j,N) cin >> s[i][j];

  vector<ll> t(D); rep(i,D) {cin >> t[i]; t[i]--;};

  // score計算
  ll score = 0;
  vector<set<ll> > set(N);
  rep(i,N) set[i].insert(0);

  rep(i,D){
    score += s[i][t[i]];
    set[t[i]].insert(i + 1);

    rep(j,N){
      score -= (i - (*rbegin(set[j])) + 1) * c[j];
    }
    cout << score << endl;
  }

}


Measured memory_bytes: 3744