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

int main()
{
  string S;
  cin >> S;
  
  if(S == "Sunny")
  {
    cout << "Cloudy" << endl;
  }
  else if(S == "Cloudy")
  {
    cout << "Rainy" << endl;
  }
  else if(S == "Rainy")
  {
    cout << "Sunny" << endl;
  }
}

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

#ifdef _DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> ss(N);
    for (int i = 0; i < M; ++i) {
        int p; string s;
        cin >> p >> s;
        p--;
        ss[p].push_back(s == "AC");
    }
    int ac = 0, pen = 0;
    for (int i = 0; i < N; ++i) {
        int pen_i = -1;
        for (int j = 0; j < ss[i].size(); ++j) {
            if (ss[i][j]) {
                pen_i = j;
                break;
            }
        }
        if (pen_i >= 0) {
            ac++;
            pen += pen_i;
        }
    }
    cout << ac << " " << pen << endl;
}

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,x;
    cin >> a >> b >> x;
    if(a+b>=x && x>=a) cout << "YES" << "\n";
    else cout << "NO" << "\n";
    return 0;
}

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

int n, a[100005];
int main() {
	int i, t;
	cin >> n;
	for(i=1; i<=n; i++) scanf("%d", &t), a[t] = i;
	for(i=1; i<=n; i++) printf("%d ", a[i]);
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define int long long
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB(x) push_back(x)
#define MP make_pair
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define couty cout<<'Y'<<'e'<<'s'<<endl
#define coutn cout<<'N'<<'o'<<endl
#define coutY cout<<'Y'<<'E'<<'S'<<endl
#define coutN cout<<'N'<<'O'<<endl
//cout << std::fixed << std::setprecision(15);
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e9;
const long long MOD = 1e9+7;
signed main(){
    set<int> set;
    rep(i,3){
        int add; cin >> add;
        set.insert(add);
    }
    if(set.size()==2) couty;
    else coutn;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define F first
#define S second
#define int long long
#define lint long long
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;
using namespace __gnu_pbds;
template <typename T> 
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N=1e5+5, MOD=1e9+7;
const lint INF=1e18;
lint _add(lint x, lint y) {
    lint ret=x+y;
    while(ret<0LL) ret+=MOD;
    return ret;
}
lint _mult(lint x, lint y) {
    x%=MOD; y%=MOD;
    lint ret=x*y;
    ret%=MOD;
    while(ret<0LL) ret+=MOD;
    return ret;
}
inline int modpow(lint base, int exp, int modulo) {
  base %= modulo;  lint result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulo;
    base = (base * base) % modulo; exp >>= 1;
  }
  return result;
}
int n, k;
signed main()
{
    cin >> n >> k;
    int ans = n%k;
    if(ans > k/2)
    {
        ans = k - ans;
    }
    cout << ans;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define forn(i,a,b,c) for(int i=a;i<=b;i=i+c)
#define int long long
#define endl "\n"
#define mod 1000000007
#define double long double
#define pb push_back
#define mk make_pair
#define swap(x,y) (x^=y^=x^=y)
#define TT int ttt;cin>>ttt;while(ttt--)

using namespace std;

int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b); 
}
bool isPrime(int n){
    if(n < 2)
        return 0;
    if(n < 4)
        return 1;
    if(n % 2 == 0 or n % 3 == 0)
        return 0;
    for(int i = 5; i*i <= n; i += 6)
        if(n % i == 0 or n % (i+2) == 0)
            return 0;
    return 1;
}
int modexpo(int x,int p){
    int res = 1;
    x = x%mod;
    while(p){
        if(p%2)
            res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}

int max(int a,int b){
    if(a>b){
        return a;
    }
    return b;
}

double min(double a,double b){
    if(a<b){
        return a;
    }
    return b;
}

int32_t main(){
    IOS
    int n,m;
    cin>>n>>m;
    vector<int>g[n+1];
    int wt[n+1];
    for(int i=1;i<=n;i++){
        cin>>wt[i];
    }
    for(int i=1;i<=m;i++){
        int a,b;
        cin>>a>>b;
        g[a].pb(b);
        g[b].pb(a);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        int temp = wt[i];
        int flag=0;
        for(int j=0;j<g[i].size();j++){
            if(wt[g[i][j]]>=temp){
                flag=1;
            }
        }
        if(flag==0){
            ans++;
            //cout<<i<<" ";
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 10244
let () = Scanf.scanf "%d\n" @@ fun n ->
    let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
    let q = Scanf.scanf "%d\n" @@ fun n -> n in
    let bcs_ = Array.init q @@ fun _ -> Scanf.scanf "%d %d\n" @@ fun b c -> (b, c) in
    let sum = Array.fold_left (+) 0 as_ in
    let max_num = 100001 in
    let counts = Array.make (max_num + 1) 0 in
    ignore @@ Array.map (fun a -> Array.set counts a @@ (+) 1 @@ Array.get counts a) @@ as_;
    let calc_diff (b, c) =
        let count_b = Array.get counts b in
        ignore @@ Array.set counts b 0;
        ignore @@ Array.set counts c @@ (+) count_b @@ Array.get counts c;
        count_b * (c - b)
    in
    let accum values value = match values with
        [] -> [value]
        | values -> (value + List.hd values) :: values
    in
    let diffs = Array.map calc_diff @@ bcs_ in
    let accum_diffs = Array.of_list @@ List.rev @@ Array.fold_left accum [] diffs in
    ignore @@ Array.map (fun diff -> Printf.printf "%d\n" @@ (+) diff sum) @@ accum_diffs


Measured memory_bytes: 18112
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

bool cmp_pair_first(const pair<int, int> & f, const pair<int, int> & s)
{
    return (f.first == s.first) ? f.second < s.second : f.first < s.first;
}

int main()
{
    int N, Q;
    cin >> N >> Q;
    pair<int, int> b[N - 1];
    long long counter[N];

    for (int i = 0; i < N; i++) {
        counter[i] = 0;
    }

    for (int i = 0; i < N - 1; i++) {
        int _a, _b;
        cin >> _a >> _b;
        b[i] = make_pair(_a - 1, _b - 1);
    }

    for (int i = 0; i < Q; i++) {
        int p;
        long long x;
        cin >> p >> x;
        counter[p - 1] += x;
    }

    sort(b, b + N - 1, cmp_pair_first);
    for (int i = 0; i < N - 1; i++) {
        counter[b[i].second] += counter[b[i].first];
    }

    for (int i = 0; i < N; i++) {
        printf("%lld ", counter[i]);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  string s; cin >> s;
  int res = 0;
  for (int i = 0; i < 6; i++) res += s[i] == '1';
  cout << res << '\n';
}

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

int main(void){
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a+3);
	if(a[2] == a[0]+a[1]) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String S = scanner.next();
		String T = scanner.next();
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		String U = scanner.next();

		if (U.contentEquals(S)) {
			A -= 1;
		} else {
			B -= 1;
		}
		System.out.println(A + " " + B);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))


int main(void){
	string s;
	cin>>s;
	int count = 0;
	int ans = 0;
	rep(i,s.size()){
		if(s[i] == 'A' ||s[i] == 'T' ||s[i] == 'G' ||s[i] == 'C' ){
			count++;
		}else{
			chmax(ans,count);
			count = 0;
		}
	}
	chmax(ans,count);
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif
vector<P> items;
int N, K;

void Main() {
    cin >> N >> K;
    items.resize(N);
    rep(i, N) cin >> items[i].second >> items[i].first;
    sort(items.rbegin(), items.rend());
    ll ans = 0;
    set<ll> first;
    priority_queue<P, vector<P>, greater<>> second;
    rep(i, K) {
        P p = items[i];
        if (first.find(p.second) != first.end()) {
            second.push(p);
        } else {
            first.insert(p.second);
        }
        ans += p.first;
    }
    ll cnt = (ll) first.size();
    ans += cnt * cnt;
    ll ans2 = ans;
    ll res = 0;
    rep2(i, K, N) {
        P next = items[i];
        if (first.find(next.second) != first.end()) continue;
        if (!second.empty()) {
            first.insert(next.second);
            P pre = second.top();
            second.pop();
            ans2 -= pre.first;
            ans2 -= cnt * cnt;
            cnt++;
            ans2 += cnt * cnt;
            ans2 += next.first;
            res = max(res, ans2);
        }
    }
    cout << max(ans, res) << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 5752
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){
    // Your code here!
    cout<<fixed<<setprecision(10);
    int n;//データの個数
    cin>>n;
    while(n!=0)
    {
        int data[1000]={};
        double Ave={};//平均
        for(int i=0;i<n;i++)
        {
            cin>>data[i];
            Ave+=data[i];
        }//データセットに全てのデータを格納した
        Ave=Ave/n;
        double AVE={};
        for(int i=0;i<n;i++)
        {
            AVE+=(data[i]-Ave)*(data[i]-Ave);
        }
        AVE=AVE/n;
        cout<<sqrt(AVE)<<endl;
        cin>>n;
    }
    return 0;
}


Measured memory_bytes: 3252
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;
typedef vector<int> ivec;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


const int MOD=1000000007;
int INF=100100100100100;
int sa[100010];
signed main(){
  int n;cin>>n;
  int ans=0;
  rep(i,n){
    int a,b;cin>>a>>b;
    sa[i]=a+b;
    ans-=b;
  }
  sort(sa,sa+n,greater<int>());
  for(int i=0;i<n;i+=2){
    ans+=sa[i];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4380
#include <cstdio>
using namespace std;
#define INF (1<<29)
int N,M,R;
int d[201][201];
int r[9];
int A,B,C;
int res;
bool used [9];

void dfs(int c,int las,int dist) {
    if(c==R+1) {
        if(res>dist)res=dist; return;
    }
    for(int i=1;i<=R;i++)if(!used[i]) {
        used[i]=true;
        if(las==-1)dfs(c+1,i,0);
        else dfs(c+1,i,dist+d[r[las]][r[i]]);
        used[i]=false;
    }
}
int main () {
    scanf("%d%d%d",&N,&M,&R);
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            if(i!=j)d[i][j]=INF;
            
        }
    }
    for(int i=1;i<=R;i++)scanf("%d",&r[i]);
    
    for(int i=1;i<=M;i++)
    {
        scanf("%d%d%d",&A,&B,&C);
        if(d[A][B]>C)d[A][B]=d[B][A]=C;
    }
    for(int k=1;k<=N;k++){
        for(int i=1;i<=N;i++){
            for(int j=1;j<=N;j++){
                if(d[i][j]>d[i][k]+d[k][j]) d[i][j]=d[i][k]+d[k][j];
            }
        }
    }
    res=INF;
    dfs(1,-1,0);
    printf("%d\n",res);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <cmath>
#include <string>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    rep(i,abs(b-d)){
        if((d-b)>0)cout<<'U';
        else cout<<'D';
    }
    rep(i,abs(a-c)){
        if((c-a)>0)cout<<'R';
        else cout<<'L';
    }
    rep(i,abs(b-d)){
        if((d-b)>0)cout<<'D';
        else cout<<'U';
    }
    rep(i,abs(a-c)){
        if((c-a)>0)cout<<'L';
        else cout<<'R';
    }

    if((c-a)>0)cout<<'L';
    else cout<<'R';
    rep(i,abs(b-d)+1){
        if((d-b)>0)cout<<'U';
        else cout<<'D';
    }
    rep(i,abs(a-c)+1){
        if((c-a)>0)cout<<'R';
        else cout<<'L';
    }
    if((d-b)>0)cout<<'D';
    else cout<<'U';
    if((c-a)>0)cout<<'R';
    else cout<<'L';
    rep(i,abs(b-d)+1){
        if((d-b)>0)cout<<'D';
        else cout<<'U';
    }
    rep(i,abs(a-c)+1){
        if((c-a)>0)cout<<'L';
        else cout<<'R';
    }
    if((d-b)>0)cout<<'U';
    else cout<<'D';

    return 0;
}

Measured memory_bytes: 256
// AOJ 2867 Many Kinds of Apples
// 2018.3.29 bal4u

#include <stdio.h>

#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int c[1002];
int a[1002];

int main()
{
	int N, Q, i, t, x, d, ans;

	N = in();
	for (i = 1; i <= N; i++) c[i] = in();
	Q = in();
	ans = 0;
	while (Q--) {
		t = in(), x = in(), d = in();
		if (t == 1) {
			a[x] += d;
			if (a[x] > c[x]) { ans = x; break; }
		} else {
			a[x] -= d;
			if (a[x] < 0) { ans = x; break; }
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2104
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a,b;
int main()
{
	scanf("%d %d",&a,&b);
	if(a!=1&&b!=1)printf("1");
	if(a!=2&&b!=2)printf("2");
	if(a!=3&&b!=3)printf("3");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N, M;
  cin >> N >> M;
  N -= 1;
  M -= 1;
  cout << N * M << "\n";
}


Measured memory_bytes: 256
from sys import stdin, setrecursionlimit
from collections import deque


def main():
    input = stdin.buffer.readline
    n, q = map(int, input().split())
    g = [[] for _ in range(n)]
    for _ in range(n - 1):
        a, b = map(int, input().split())
        g[a - 1].append(b - 1)
        g[b - 1].append(a - 1)
    counts = [0] * n
    for _ in range(q):
        p, x = map(int, input().split())
        counts[p - 1] += x

    q = deque()
    q.append(0)
    seen = [False] * n
    seen[0] = True

    while q:
        v = q.popleft()

        for n_v in g[v]:
            if seen[n_v]:
                continue
            seen[n_v] = True
            counts[n_v] += counts[v]
            q.append(n_v)

    print(*counts)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 89876
package main

import (
	"fmt"
	"math"
)

func main() {
	// Code for C - Half and Half
	var A, B, C int
	var X, Y int
	fmt.Scanf("%d %d %d %d %d", &A, &B, &C, &X, &Y)

	var min = 1000000000
	for i := 0; i <= 100000; i++ {
		a := int(math.Max(0, float64(X-i)))
		b := int(math.Max(0, float64(Y-i)))
		cost := i*2*C + a*A + b*B
		if min > cost {
			min = cost
		}
	}

	fmt.Println(min)
}


Measured memory_bytes: 1840
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<utility>
#include <numeric>
#include<list>
using namespace std;
typedef long long ll;

void yes(){
cout<<"Yes"<<endl;
}
void no(){
cout<<"No"<<endl;
}
int main(){
ll n,t,a;
  cin>>n>>t>>a;
  ll h[n];
  for(ll i=0;i<n;i++){
  cin>>h[i];
  }
  ll ans=0;
  long double min=1000000000;
    for(ll i=0;i<n;i++){
  long double x=t-h[i]*0.006;

      long double div=a-x;
if(div<0)
  div=div*-1;
      if(div<min){
      min=div;
        ans=i+1;

      }
  }
  cout<<ans;
 return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int x,y;
    for(;;){
        scanf("%d %d\n",&x,&y);
        if(x==0 && y==0) break;
        else if(x <= y) printf("%d %d\n",x,y);
        else if(x > y) printf("%d %d\n",y,x);
    }
}


Measured memory_bytes: 2696
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
//if(strcmp(s[i],"AC")==0)
//if(s[l]=='#')
/*小文字判定
if((moji>= 'a') && (moji<='z')){
    printf("a\n");
    return 0;
  }
  */

int W_Length(char *str){
	int length = 0;
	while(*str++ != '\0')
		length++;
	return length;
}

void swap(long long int *a, long long int *b){
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
}
//swap(&a, &b)

double deg(double theta){//deg to theta
return theta*(2*3.14159265359)/360;
}

long long int cmp( const void *p, const void *q ) {
    return *(long long int*)p - *(long long int*)q;
}//ちいさい順
//qsort(a,n,sizeof(long long int),cmp);


int cmp_s(const void * left, const void * right)
{
	char *left_char = (char *)left;
  char *right_char = (char *)right;
  return strcmp(left_char, right_char);
}
//qsort(s,n,sizeof(s[0]),cmp_s);
//char s[n][11]

long long int GCD(long long int a, long long int b){
  long long int L=a,S=b;
  while(1){
    if(S>L){
      L=S+L;
      S=L-S;
      L=L-S;
    }
    if(L%S==0){
      return S;
    }
    L=L%S;
  }
  
}

long long int LCM(long long int a, long long int b){
  return a*b/(GCD(a,b));
}

int main (void)
{
	long long int p[5005],b,c,n,i,k,a[5005]={0},max,j=1,get[5005]={0},temp1,k_temp;
scanf("%lld %lld",&b, &c);

  printf("%lld",LCM(b,c));
return 0;
}


Measured memory_bytes: 1728
package main

import (
	"fmt"
)

type ll int64


func main() {

	var N int
	fmt.Scan(&N)

	a := make([]int, N+1)
	ans := 0
	ans_slice := make([]int,N+1)


	for i := 0 ; i < N ;i++ {
		//1 origin
		fmt.Scan(&a[i+1])
	}

	ans_flag := 0
	for i:= N; i > 0 ; i--  {//Nから1まで

		k:= i
		j := 1
		ans_flag = 0

		for k <= N  {
			ans_flag += ans_slice[k]
			j++
			k = i * j
		}


		if ans_flag % 2 != a[i] {

			ans++
			ans_slice[i] = 1

		}

	}

	fmt.Println(ans)
	for i:=1;i <=N ;i++  {
		if ans_slice[i] == 1 {
			fmt.Println(i)
			//fmt.Print(" ")
		}
	}
	//fmt.Println("")
}


Measured memory_bytes: 8320
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename Func>
ll findMin(ll L, ll R, Func f) { //[L, R)
    ll lo = L - 1, hi = R - 1;
    while (lo + 1 != hi) {
        ll mi = (lo + hi) / 2;
        if (f(mi) <= f(mi + 1)) hi = mi;
        else lo = mi;
    }
    return hi;
}
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



int N, M, S, G, U[201010], V[201010]; ll A[201010], B[201010];
vector<pair<int,int>> E[201010];
ll dst[201010]; int vis[201010];
ll line[201010];
//---------------------------------------------------------------------------------------------------
ll a, b;
ll f(ll x) {
    return x + (b + x + a - 1) / (x + a);
}
double fd(double x) {
    return x + 1.0 * b / (x + 1.0 * a);
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M >> S >> G;
    S--; G--;
    rep(i, 0, M) {
        cin >> U[i] >> V[i] >> A[i] >> B[i];
        U[i]--; V[i]--;

        E[U[i]].push_back({ V[i], i });
        E[V[i]].push_back({ U[i], i });
    }

    rep(i, 0, N) dst[i] = infl;

    min_priority_queue<pair<ll, int>> que;
    que.push({0, S});
    dst[S] = 0;
    while (!que.empty()) {
        auto q = que.top(); que.pop();

        ll d = q.first;
        int cu = q.second;

        if (vis[cu]) continue;
        vis[cu] = 1;

        if (cu == G) {
            printf("%lld\n", dst[cu]);
            return;
        }

        fore(p, E[cu]) {
            int to = p.first;
            a = A[p.second];
            b = B[p.second];

            ll t = findMin(d, infl, fd);

            ll nd = min(f(t), f(t + 1));

            if (nd < dst[to]) {
                dst[to] = nd;
                que.push({ nd, to });
            }
        }
    }

    printf("-1\n");
}



Measured memory_bytes: 26684
var lines = []; var X = []; var flag = false;
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var A = Number(lines[0].split("")[0])
    var B = Number(lines[0].split("")[1])
    var C = Number(lines[0].split("")[2])
    var D = Number(lines[0].split("")[3])

    var op = []; var ans = 0;

    // 0: + , 1: -
    for (var i = 0; i < 2; i++) {
        for (var j = 0; j < 2; j++) {
            for (var k = 0; k < 2; k++) {
                if (i === 0) { ans += A + B; op.push("+") }; if (i === 1) { ans += A - B; op.push("-") }
                if (j === 0) { ans += C; op.push("+") }; if (j === 1) { ans -= C; op.push("-") }
                if (k === 0) { ans += D; op.push("+") }; if (k === 1) { ans -= D; op.push("-") }

                if (ans === 7) {
                    console.log(A + op.shift() + B + op.shift() + C + op.shift() + D + "=7");
                    return (0)
                }
                var op = []
                var ans = 0;
            }
        }
    }
});

Measured memory_bytes: 21448
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

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

    int n;
    double p[3001];

    cin >> n;
    REP(i, n)
    cin >> p[i + 1];

    double dp[3001][3001];

    memset(dp, 0, sizeof(dp));

    dp[0][0] = 1;

    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            if (j > 0)
                dp[i][j] += (dp[i - 1][j - 1] * p[i]) + (dp[i - 1][j] * (1 - p[i]));
            else
                dp[i][j] += (dp[i - 1][j] * (1 - p[i]));
        }
    }

    double res = 0;

    for (int i = n / 2 + 1; i <= n; i++)
        res += dp[n][i];

    cout << setprecision(20) << res << endl;

    return 0;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    string s;
    cin >> s;
    cout << s.substr(0, 5) << " " << s.substr(6, 7) << " " << s.substr(14, 5) << endl;
}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long;
int main()
{
    int n,ans=0;
    cin>>n;
    vector<ll> l(n);
    rep(i,n) cin>>l[i];
    rep(i,n){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(l[i]==l[j]||l[j]==l[k]||l[k]==l[i]) continue;
                if(l[i]+l[j]>l[k]&&l[j]+l[k]>l[i]&&l[k]+l[i]>l[j]) ans++;
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int n; cin>>n;
    vector<int>a(n);
    for(auto&e:a)cin>>e;
    
    int odd_cnt=0,four_cnt=0;
    for(auto e:a){
        if(e%2==1)++odd_cnt;
        else if(e%4==0)++four_cnt;
    }
    
    if(odd_cnt==four_cnt+1&&n%2==1)cout<<"Yes"<<endl;
    else if(odd_cnt>four_cnt)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int n;
vector<string> s, ans;
map<string, int> cnt;

int main() {
    cin >> n;
    s.resize(n);
    int mx = 1;
    rep(i, n) {
        cin >> s[i];
        if (cnt.find(s[i]) == cnt.end()) {
            cnt[s[i]] = 1;
        } else {
            mx = max(mx, ++cnt[s[i]]);
        }
    }
    rep(i, n) {
        if (cnt[s[i]] == mx) {
            ans.push_back(s[i]);
            cnt[s[i]] = 0;
        }
    }
    sort(all(ans));
    for (auto &str : ans) {
        cout << str << endl;
    }
    return 0;
}

Measured memory_bytes: 28404
n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]
total = 0
for i in range(n + 2):
    total += abs(a[i] - a[i - 1])
for i in range(1,n+1):
    k = abs(a[i] - a[i-1]) + abs(a[i+1] - a[i])
    print(total - k + abs(a[i+1] - a[i-1]))


Measured memory_bytes: 14048
package main

import (
	"bufio"
	"fmt"
	"os"
)

func solve() {


	var N int
	Readf("%d", &N)

	var buf int;
	if (N % 2 ) == 1 {
		buf = (N+1) / 2;
	}else{
		buf = N / 2;
	}

	Writef("%f", float32(buf) / float32(N) )
}











//テンプレート
func main()  {

	//入力に必要
	defer io.Flush()
	solve()
}

var (
	io = bufio.NewReadWriter(
		bufio.NewReader(os.Stdin),
		bufio.NewWriter(os.Stdout),
	)
)

func Readf(format string, args ...interface{})  {
	fmt.Fscanf(io, format, args...)
}

func Writef(format string, args ...interface{})  {
	fmt.Fprintf(io, format, args...)
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
using ll = long long;

using namespace std;
int main(){
	int D, G;
	cin >> D >> G;
	vector<pair<int, int>>p(D);
	ll ans = pow(10,9), cnt,sum;
	rep(i, D) {
		cin >> p[i].first >> p[i].second;
	}

	for (int bit = 0; bit < (1 << D); bit++) {
		cnt = 0;
		sum = 0;
		rep(i, D) {
			if (bit & (1 << i)) {
				sum += (i + 1) * 100 * p[i].first + p[i].second;
				cnt += p[i].first;
			}
		}
		if (sum >= G) {
			ans = min(ans, cnt);
		}
		else {
			for (int i = D - 1; i >= 0; i--) {
				if (bit & (1 << i)) {
					continue;
				}
				else {
					for (int j = 0; j < p[i].first; j++) {
						if (sum >= G)break;
						sum += (i + 1) * 100;
						cnt++;
					}
				}
			}
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<queue>
#include<stack>
#include<string>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<cstdlib>
#include<typeinfo>
#include<sstream>
#include<list>
#include<set>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fori(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
int in()
{
	int x;cin>>x;
	return x;
}
int stringInt(string a)
{
	return atoi(a.c_str());
}
string intString(int a)
{
	stringstream ss;
	ss<<a;
	return ss.str();
}
vector<int> SieveOfEratosthenes(int x)
{
	vector<int> a;
	vector<int> b(x+1,0);
	for(int i=2;i<=x;i++)
	{
		if(b[i]==0)
		{
			a.push_back(i);
			for(int l=i;l<=x;l+=i)
			{
				b[l]=1;
			}
		}
	}
	return a;
}

struct Node
{
	int k;
	Node *p,*r,*l;
};
Node *root,*NIL;

void ins(int k)
{
	Node *y,*x,*z;
	z=(Node*)malloc(sizeof(Node));
	z->k=k;
	z->l=z->r=NIL;
	y=NIL;
	x=root;
	while(x!=NIL)
	{
		y=x;
		if(x->k > k)
		{
			x=x->l;
		}
		else
		{
			x=x->r;
		}
	}
	z->p=y;
	if(y==NIL)
	{
		root=z;
	}
	else if(z->k < y->k)
	{
		y->l=z;
	}
	else
	{
		y->r=z;
	}
	return ;
}
void ino(Node* root)
{
	if(root==NIL)return ;
	ino(root->l);
	cout<<" "<<root->k;
	ino(root->r);
	return ;
}
void pre(Node* root)
{
	if(root==NIL)return ;
	cout<<" "<<root->k;
	pre(root->l);
	pre(root->r);
	return ;
}
bool fin(Node* root,int x)
{
	if(root->k!=x)
	{
		if(root->k>x&&root->l==NIL)return false;
		if(root->k<x&&root->r==NIL)return false;
	}

	if(root->k==x)return true;

	else if(root->k > x)
	{
		return fin(root->l,x);
	}
	else return fin(root->r,x);
	return false;

}
int main()
{
	int n;
	root=NIL;
	cin>>n;
	rep(i,n)
	{
		string a;
		cin>>a;
		switch(a[0])
		{
		case'i':
			int x;
			cin>>x;
			ins(x);
			break;
		case'p':

			ino(root);
			cout<<endl;

			pre(root);
			cout<<endl;
			break;
		case'f':
			if(fin(root,in()))cout<<"yes"<<endl;
			else cout<<"no"<<endl;
			break;
		case'd':
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 19960
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const ll INF = (ll)(1e18);

int main(void){
  int a, b, q;
  cin >> a >> b >> q;
  vector<ll> s(a+2), t(b+2), x(q);
  s[0] = -INF; t[0] = -INF;
  REP(i, a) cin >> s[i+1];
  REP(i, b) cin >> t[i+1];
  s[a+1] = INF; t[b+1] = INF;
  REP(i, q) cin >> x[i];
  vector<ll> ans(q, INF);
  REP(i, q){
    auto is = lower_bound(ALL(s), x[i]);
    auto it = lower_bound(ALL(t), x[i]);
    ll ds[] = {*(is-1), *is};
    ll dt[] = {*(it-1), *it};
    REP(j, 2) REP(k, 2){
      ll st = labs(ds[j]-x[i])+labs(dt[k]-ds[j]);
      ll ts = labs(dt[k]-x[i])+labs(ds[j]-dt[k]);
      chmin(ans[i], min(st, ts));
    }
  }
  REP(i, q) cout << ans[i] << endl;
  return 0;
}

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

class stack {
public:
    int a[20000];
    int top = -1;
    
    void push(int v) {
        top++;
        a[top] = v;
        return;
    }
    
    int pop() {
        top--;
        return a[top+1];
    }
    
    bool empty() {
        if(top == -1) return true;
        return false;
    }
    
    int check() {
        return top;
    }
};

class point {
public:
    int p;
    int v;
};

int main() {
    
    stack s, ss;
    char c[20001];
    int cnt = 0, sum = 0;
    point list[20000];
    
    cin>>c;
    int j = 1;
    for(int i = 0; c[i] != 0; i++) {
        if(c[i] == '\\') {
            s.push(i);
        } else if(c[i] == '/') {
            if(s.empty()) continue;
            int pre = s.pop();
            int a = i - pre;
            sum += a;
            if(list[j-1].p > pre) {
                list[j-1].v += a;
                list[j-1].p = pre;
            } else {
                list[j].v = a;
                list[j].p = pre;
                j++;
            }
        }
    }
    

    
    int pre = 20001;
    for(int i = j-1; i > 0; i--) {
        if(pre < list[i].p) {
            int tmp = ss.pop();
            tmp += list[i].v;
            ss.push(tmp);
        } else {
            pre = list[i].p;
            ss.push(list[i].v);
        }
    }
    
    cout<<sum<<endl;
    cout<<ss.check()+1;
    while(!ss.empty()) {
        cout<<' '<<ss.pop();
    }
    cout<<endl;
    
    return 0;
}



Measured memory_bytes: 3160
#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 rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    LL N;cin >> N;   
    vector<LL> A(N);rep(i,N)cin >> A[i];
    LL Q;cin >> Q;
    vector<LL> B(Q);
    vector<LL> C(Q);
    rep(i,Q)cin >> B[i] >> C[i];
    map<LL,LL> m;
    rep(i,N)m[A[i]]++;
    LL ans = 0;
    for(auto t : m)ans += t.S*t.F;



    rep(i,Q){
        LL tmp = m[B[i]];
        ans -= tmp*B[i];
        ans += tmp*C[i];
        m[B[i]] = 0;
        m[C[i]] += tmp; 

        cout << ans << endl;
    }



}

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

int main() {
  string S;
  cin >> S;
  int count_1 = 0;
  //even = 0, odd = 1
  for (int i = 0; i < S.size(); i++) {
    if ((i%2==0) && (S.at(i) != '0')) {
      count_1++;
    }
    else if ((i%2==1) && (S.at(i) != '1')) {
      count_1++;
    }
  }
  
  int count_2 = 0;
  //even = 1, odd = 0
  for (int i = 0;i < S.size(); i++) {
    if ((i%2==0) && (S.at(i) != '1')) {
      count_2++;
    }
    else if ((i%2==1) && (S.at(i) != '0')) {
      count_2++;
    }
  }
  cout << min(count_1,count_2) << endl;
  
      
      
}

Measured memory_bytes: 512
#include <stdio.h>
int root(long long dtcdtc)
{
  int i = 1;
  while (dtcdtc / i != i)
  {
    //printf("i:%d",i);
    if (i > dtcdtc / 2)
      return (-1);
    i++;
  }
  if (dtcdtc % i != 0)
    return (-1);
  return (i);
}

int main()
{
  int n,d;
  scanf("%d%d",&n,&d);
  int i = 0;
  int j;
  int x[n][d];
  while (i < n)
  {
    j = 0;
    while (j < d)
    {
      scanf("%d",&x[i][j]);
      //printf("x[i][j]:%d\n",x[i][j]);
      j++;
    }
    i++;
  }
  long long dtcdtc = 0;
  i = 0;
  int k = 0;
  int cnt = 0;
  while (i < n)
  {
    j = i + 1;
    //printf("i:%d\n",i);
    while(j < n)
    {
      k = 0;
      dtcdtc = 0;
      //printf("j:%d\n",j);
      while (k < d)
      {
        //printf("dtcdtc:%d\n",dtcdtc);
        dtcdtc += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        //printf("%d",(x[i][k] - x[j][k]) * (x[i][k] - x[j][k]));
        //printf("x[i][k]:%d x[j][k]:%d dtcdtc:%d\n",x[i][k],x[j][k],dtcdtc);
        k++;
      }
      if (root(dtcdtc) > 0)
      {
        //printf("root:%d\n",root(dtcdtc));
        cnt++;
      }
      j++;
    }
    i++;
  }
  printf("%d",cnt);
  
}

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

using namespace std;

//#define FILE_IO

typedef long long LL;

const int mod = 1e9 + 7;
const int NMAX = 10005;

int N, K;
int fct[NMAX], ifct[NMAX], p2[NMAX];

int power(int x, int y)
{
    if(y <= 0)  return 1;
    int ans = power( (1LL * x * x) % mod, y >> 1 );
    if(y & 1) ans = (1LL * ans * x) % mod;
    return ans;
}

int pw2(int x) { if(x < 0) return 1; return p2[x]; }

int C(int N, int K)
{
    if(N < K)   return 0;
    int ans = (1LL * fct[N] * ifct[K]) % mod;
    ans = (1LL * ans * ifct[N - K]) % mod;
    return ans;
}

void pre(int N)
{
    fct[0] = 1;
    for(int i = 1; i <= N; i++) fct[i] = (1LL * fct[i - 1] * i) % mod;

    ifct[N] = power(fct[N], mod - 2);
    for(int i = N - 1; i >= 0; i--) ifct[i] = (1LL * ifct[i + 1] * (i + 1)) % mod;

    p2[0] = 1;
    for(int i = 1; i <= N; i++) p2[i] = (2LL * p2[i - 1]) % mod;
}

void calcMod(int N, int K)
{
    map<LL, int> mp;
    int cnt = 0;
    for(int msk = 0; msk < 1 << N; msk++)
    {
        vector<int> st, dr;
        for(int i = 0; i < N; i++)
            if( (msk >> i) & 1 )    dr.push_back(i);
            else    st.push_back(i);
        for(int i = N; i < N + K; i++)
            dr.push_back(i);

        for(int msk2 = 0; msk2 < 1 << (N + K); msk2++)
        {
            int b = __builtin_popcount(msk2);
            if(b != st.size())  continue;

            LL h = 0;
            vector<int> stt = st, drr = dr;
            for(int i = 0; i < N + K; i++)
                if( (msk2 >> i) & 1 )
                {
                    h = 1LL * h * (N + K) + stt.back(); stt.pop_back();
                }
                else
                {
                    h = 1LL * h * (N + K) + drr.back(); drr.pop_back();
                }
            if(!mp.count(h)) { cnt++; mp[h]; }
        }
    }
    printf("%d\n", cnt);
    cerr << cnt << '\n';
    exit(0);
}

int getNumberOfWays(int N, int M)
{
    if(N == 0)  return 1;
    M++;
    if(N == 1)  return M;
    int ans = (1LL * fct[M + 2 * N - 1] * ifct[M + N]) % mod;
    ans = (1LL * ans * M) % mod;
    ans = (1LL * ans * ifct[N]) % mod;
    return ans;
}

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    pre(10000);

    scanf("%d%d", &N, &K);
    if(N == K)
    {
        printf("%d\n", getNumberOfWays(N - 1, 0));
        return 0;
    }

    int ans = 0;
    for(int i = 0; i < K; i++)
    {
        int sol = getNumberOfWays(i, K - 1 - i);
        sol = (1LL * sol * C(N - 2 - i, K - 1 - i)) % mod;
        ans = (ans + sol) % mod;
    }
    ans = (1LL * ans * pw2(N - K - 1)) % mod;
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 384
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time

setrecursionlimit(10**6)
input=stdin.readline

V,E=map(int,input().split())
graph=[[0]*V for _ in range(V)]
for _ in range(E):
    u,v,d=map(int,input().split())
    u,v=u-1,v-1
    graph[u][v]=graph[v][u]=d
now=1
T_max=int(input().rstrip())
for _ in range(T_max):
    N_max=int(input().rstrip())
    for _ in range(N_max):
        new_id,dst=map(int,input().split())
    print(-1)

Measured memory_bytes: 4936
#include<iostream>
#include<algorithm>
using namespace std;
 
 
// 262144 = 2^18
int tree[262144];
 
 
int dfs(int a,int b,int k,int l,int r){
  if(r<=a || b<=l)return 0;
  if(a<=l && r<=b)return tree[k];
  int m=(l+r)/2;
  return dfs(a,b,k*2+1,l,m)+dfs(a,b,k*2+2,m,r);
}
 
int getSum(int a,int b){
  // 131072 = 2^17
  return dfs(a,b,0,0,131072);
}
 
void update(int i,int x){
  // 131072 = 2^17
  i+=(131072-1);
  tree[i]+=x;
  while(i){
    i=(i-1)/2;
    tree[i]+=x;
  }
}
 
int n,q;
int a,b,c;
int main(){
  cin>>n>>q;

  for(int i=0;i<q;i++){
    cin>>a>>b>>c;
    if(a==1){
      cout<<getSum(b,c+1)<<endl;
    }else{
      update(b,c);
    }
  }
  return 0;
}

Measured memory_bytes: 1960
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define i_inf int(1e9)
#define i_half_inf int(1e5)
#define ll_inf ll(1e9)*ll(1e9)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main() {
    int n, p[10];
    cin >> n;
    int maxp = 0;
    rep(i, n) {
        cin >> p[i];
        maxp = max(maxp, p[i]);
    }
    int ans = 0;
    bool devided = false;
    rep(i, n) {
        if (p[i] == maxp && !devided) {
            ans += (p[i] / 2);
            devided = true;
        } else ans += p[i];
    }
    cout << ans << endl;
    return 0;
}


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

struct iostream_init_struct
{ 
	iostream_init_struct()
	{
		std::cin.tie(0);
		std::cin.sync_with_stdio(false);
	}
} iostream_init;


int main()
{
	string s;
	cin >> s;
	s[5] = ' ';
	s[13] = ' ';
	cout << s;
	return 0;
}

Measured memory_bytes: 384
from math import gcd


#####segfunc#####
def segfunc(x, y):
    return gcd(x, y)
#################

#####ide_ele#####
ide_ele = 0
#################

class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(logN)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """

    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res


N = int(input())
A = list(map(int, input().split()))

seg = SegTree(A, segfunc, ide_ele)

mx = 1
for i in range(N):
    mx = max(mx, gcd(seg.query(0, i), seg.query(i + 1, N)))

print(mx)


Measured memory_bytes: 88284
#include <iostream>
using namespace std;
long long fact(int N);

int main(){
    int N;
    cin >> N;
    cout << fact(N) << endl;
    return 0;
}

long long fact(int N){
    return N <= 1 ? 1 : (N * fact(N - 1)) % 1000000007;
}


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

int main() {
  int n; cin >> n;
  map<string, int> mp;
    rep(i,n) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    mp[s]++;
  }
  ll ans = 0;
  for (auto& p : mp) {
    int s = p.second;
    ans += (ll)s*(s-1)/2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 11136
x=int(input())
y=format(x,"b").zfill(10)
ly=len(y)
ly=32-ly
pady="0"*ly
print(pady+y)
rev=2**32-1-x
z=format(rev,"b").zfill(10)
lz=len(z)
lz=32-lz
padz="0"*lz
print(padz+z)
left=x*2
if left>=2**32:
    left-=2**32
u=format(left,"b").zfill(10)
lu=len(u)
lu=32-lu
padu="0"*lu
print(padu+u)

right=x//2
v=format(right,"b").zfill(10)
lv=len(v)
lv=32-lv
padv="0"*lv
print(padv+v)



Measured memory_bytes: 5604
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std;
typedef long long ll;
int n,he;
ll a[1000009],b[1000009];
ll ans=0;
bool check(ll sum,ll k)
{
  he=1;
  for (int i=n;i>=1;i--)
  {
    if (a[he]*b[i]<=sum) {he++;continue;}
    if ((a[he]-sum/b[i])>k) return false;
    k-=a[he]-sum/b[i];
    he++;
  }
  return true;
}
int main()
{
  ll k;
  scanf("%d%lld",&n,&k);
  for (int i=1;i<=n;i++) scanf("%lld",&a[i]);
  for (int i=1;i<=n;i++) scanf("%lld",&b[i]);
  sort(a+1,a+1+n); sort(b+1,b+1+n);
  ll l=0,r=0;
  r=b[n]*a[n];ans=r;
  while (l<=r)
  {
      ll mid=(l+r)/(ll)2;
      if (check(mid,k)) ans=mid,r=mid-1;
      else l=mid+1;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 5888