akhauriyash/Code-Regression huggingface dataset:
n, x = map(int, input().split())
an = list(map(int, input().split()))
c = 0
for i in sorted(an):
    if x >= i:
        x -= i
        c += 1
    else:
        print(c)
        exit()
if x > 0:
    print(c - 1)
else:
    print(c)


Measured memory_bytes: 2940
/*=============================================================================================================================/*
                                               Bismillahir Rahmanir Rahim

      _     ____  ___  ____   _   _  _         ___  ____   _         _     __  __
     / \   / ___||_ _|| __ ) | | | || |       |_ _|/ ___| | |       / \   |  \/  |
    / _ \  \___ \ | | |  _ \ | | | || |        | | \___ \ | |      / _ \  | |\/| |
   / ___ \  ___) || | | |_) || |_| || |___     | |  ___) || |___  / ___ \ | |  | |
  /_/   \_\|____/|___||____/  \___/ |_____|   |___||____/ |_____|/_/   \_\|_|  |_|

   _   __           __  __  __
  |_) (_  _  o__   /   (_  |_
  |_)o__)(_  || |  \__ __) |__

    ___                    _   _      _                _ _               __   ___                 _         _        _
   / __|_ _ ___ ___ _ _   | | | |_ _ (_)_ _____ _ _ __(_) |_ _  _   ___ / _| | _ ) __ _ _ _  __ _| |__ _ __| |___ __| |_
  | (_ | '_/ -_) -_) ' \  | |_| | ' \| \ V / -_) '_(_-< |  _| || | / _ \  _| | _ \/ _` | ' \/ _` | / _` / _` / -_|_-< ' \
   \___|_| \___\___|_||_|  \___/|_||_|_|\_/\___|_| /__/_|\__|\_, | \___/_|   |___/\__,_|_||_\__, |_\__,_\__,_\___/__/_||_|
                                                            |__/                           |___/


   FB: https://facebook.com/SIAsibul
   Gmail: asibulislam8@gmail.com

/*=============================================================================================================================*/

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vii;
typedef vector<pil> vil;
typedef vector<pli> vli;
typedef vector<pll> vll;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,n) for(ll i=0;i<(n);i++)
#define f1(i,n) for(ll i=1;i<=(n);i++)
#define f2(i,a,n) for(ll i=(a);i<=(n);i++)
#define fr(i,n,a) for(ll i=(n);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))
#define nl "\n"


const int INF = 1e9 + 5;
const int MXN = 2e5 + 5;
const int MOD = 1e9 + 7;


int main(){
    int a, b, c, k; cin >> a >> b >> c >> k;
    int cnt = 0;
    while(a >= b && cnt < k){
        b *= 2;
        cnt++;
    }

    while(b >= c && cnt < k){
        c *= 2;
        cnt++;
    }

    if(a < b && b < c) cout << "Yes\n";
    else cout << "No\n";
    return 0;
 }


Measured memory_bytes: 3600
cards = [list(input()+p) for p in ['A','B','C']]
player = 0
while True:
    if len(cards[player]) == 1:
        print(cards[player][0])
        break 
    else:
        tmp = cards[player].pop(0)
        if tmp == 'a':
            player = 0
        elif tmp == 'b':
            player = 1
        else:
            player = 2

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

using namespace std;

const int ms = 57;
char arr[ms][ms];
int x[] = {1, -1, 0, 0};
int y[] = {0, 0, 1, -1};
pair<int, int> parent[ms][ms];
bool used[ms][ms];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);


    int n, m;
    cin >> n >> m;

    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
            cin >> arr[i][j];

    deque<pair<int, int> > bfs;
    bfs.push_back(make_pair(1, 1));
    used[1][1] = 1;

    while(!bfs.empty())
    {
        pair<int, int> t = bfs.front();
        bfs.pop_front();

        for(int i = 0; i < 4; ++i)
        {
            int xx = t.first + x[i], yy = t.second + y[i];

            if(xx >= 1 && xx <= n && yy >= 1 && yy <= m && !used[xx][yy] && arr[xx][yy] == '.')
            {
                //cout << xx << ' ' << yy << "  and it`s parent  " << t.first << ' ' << t.second <<  '\n';
                used[xx][yy] = 1;
                bfs.push_back(make_pair(xx, yy));
                parent[xx][yy] = t;
            }
        }
    }


    if(parent[n][m] == make_pair(0, 0))
        cout << -1 << '\n';
    else
    {
        int xx = n, yy = m;

        while(xx != 1 || yy != 1)
        {
            arr[xx][yy] = '*';

            pair<int, int> next = parent[xx][yy];

            xx = next.first, yy = next.second;
        }

        arr[1][1] = '*';

        int answer = 0;

        for(int i = 1; i <= n; ++i)
        {
            for(int j = 1; j <= m; ++j)
            {
                if(arr[i][j] == '.')
                    ++answer;
            }
        }

        cout << answer << '\n';
    }

















    /*vector<vector<int> > arr(3, vector<int>(3));

    for(int i = 0; i < 3; ++i)
        for(int j = 0; j < 3; ++j)
            cin >> arr[i][j];

    int f_sum = arr[0][0] + arr[0][1] + arr[0][2], s_sum = arr[1][0] + arr[1][1] + arr[1][2], t_sum = arr[2][0] + arr[2][1] + arr[2][2];

    for(int i = 0; i <= f_sum / 3; ++i)
    {
        int a1 = i, bsum = f_sum - 3 * i;

        if((s_sum - bsum) % 3 == 0 && (t_sum - bsum) % 3 == 0)
            return cout << "Yes\n", 0;
    }


    cout << "No\n";*/

}


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

using namespace std;

int main()
{
  int n;
  scanf("%d", &n);
  int temp = n, sum = 0;
  for(; temp > 0; temp /= 10) sum += (temp % 10);
  if(n % sum == 0) printf("Yes\n");
  else printf("No\n");
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

unsigned short scan_sentence(unsigned char * str, unsigned short length_max);
void count_alphabet(unsigned char * str, unsigned short * num_check, unsigned short length);

int main(){
	unsigned short usW_D_length;        	/* 文字列長格納の変数 */
	unsigned char ubW_D_str[1200];      	/* 文字列格納の配列 */
	unsigned short usW_D_num_check[26]; 	/* アルファベットの数を記録する配列 */
	unsigned short usW_C_i;             	/* ループ変数 */
	
	/* 文字列配列の初期化 */
	for(usW_C_i = 0;usW_C_i < 1200;usW_C_i++){
		ubW_D_str[usW_C_i] = 0;
	}
	/* アルファベットの数を記録する配列の初期化 */
	for(usW_C_i = 0;usW_C_i < 26;usW_C_i++){
		usW_D_num_check[usW_C_i] = 0;
	}
	
	/* 文字列入力 */
	usW_D_length = scan_sentence(ubW_D_str, 1200);
	
	/* アルファベットの数をカウント */
	count_alphabet(ubW_D_str, usW_D_num_check, usW_D_length);
	
	/* カウントした結果を出力 */
	for(usW_C_i = 0;usW_C_i < 26;usW_C_i++){
		/* a : (aの個数) の形式で出力 */
		printf("%c : %d\n", (usW_C_i + 97), *(usW_D_num_check + usW_C_i));
	}
	
	return 0;
}

/* 関数名：文字列入力 */
/* 概要：文字列を入力する。その長さを返す */
/* 引数：文字列を格納する配列の先頭アドレス、その配列の大きさ */
/* 戻り値：入力された文字列の長さ */
unsigned short scan_sentence(unsigned char * str, unsigned short length_max)
{
	unsigned short usW_C_count_text = 0;	/* 文字列長カウンタ */
	unsigned short usW_C_i;             	/* ループ変数 */

	/* 文字列の入力 */
	for(usW_C_i = 0;usW_C_i < length_max;usW_C_i++){
		scanf("%c", str + usW_C_i);
		/* 入力終了の処理 */
		if(*(str + usW_C_i) == EOF){
			break;
		}
		/* 文字数をカウント */
		usW_C_count_text++;
	}

	/* 文字列長を返す */
	return usW_C_count_text;
}

/* 関数名：アルファベットカウント */
/* 概要：渡された文字列に各アルファベットが何文字含まれるか調べる */
/* 引数：文字列が格納された配列の先頭アドレス、アルファベットの数を記録する配列の先頭アドレス、文字列の長さ */
/* 戻り値：なし */
void count_alphabet(unsigned char * str, unsigned short * num_check, unsigned short length)
{
	unsigned short usW_C_i;
	unsigned char ubW_D_alphabet;
	for(usW_C_i = 0;usW_C_i < length;usW_C_i++){
		if(((65 <= *(str + usW_C_i)) && (*(str + usW_C_i) <= 90)) || ((97 <= *(str + usW_C_i)) && (*(str + usW_C_i) <= 122))){
			ubW_D_alphabet = *(str + usW_C_i) & 0x1F;
			*(num_check + (ubW_D_alphabet - 1)) += 1;
		}
	}
}




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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

// #define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);i++)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
// #define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl

int main(){
	int N;cin>>N;
	vi A(N),B(N),C(N-1);
	rp(i,N){cin>>A[i];--A[i];}
	rp(i,N)cin>>B[i];
	rp(i,N-1)cin>>C[i];

	int pre = A[0];
	int ans = B[pre];
	up(i,1,N,1){
		int now = A[i];
		ans += B[now];
		if(now==pre+1){
			ans+=C[pre];
		}
		pre = now;
	}

	ote(ans);
}


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

int main(){
	string b;
	cin>>b;
	if(b=="A")cout<<"T"<<endl;
	if(b=="T")cout<<"A"<<endl;
	if(b=="C")cout<<"G"<<endl;
	if(b=="G")cout<<"C"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL read()
{
    char c=getchar();LL f=1,sum=0;
    while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0' && c<='9'){sum=sum*10+c-'0';c=getchar();}
    return sum*f;
}
LL n,L,L0;
struct node{
	LL v;
	double t;
}q[500005],p;
int head,tail;
int main()
{
	n=read();L0=L=read();
	double T=0.0;
	for(int i=1;i<=n;i++)
	{
		p.t=read();p.v=read();
		while(p.v>L)
		{
			if(L+q[head].v<p.v)
			{
				L+=q[head].v;
				T-=q[head].v*q[head].t;
				head++;
			}
			else
			{
				LL x=p.v-L;
                T-=x*q[head].t;
                L+=x;
                q[head].v-=x;
			}
		}
		L-=p.v;T+=p.v*p.t;
		q[++tail]=p;
		while(head<tail && q[tail].t<=q[tail-1].t)
		{
			q[tail-1].t=(q[tail-1].t*q[tail-1].v+q[tail].t*q[tail].v)/(double)(q[tail].v+q[tail-1].v);
			q[tail-1].v+=q[tail].v;
			tail--;
		}
		printf("%.7lf\n",T/(double)(L0-L));
	}
	return 0;
}


Measured memory_bytes: 16896
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
//ll INF = 1LL<<40;
int INF = 1LL<<15;
int xv[4] = {-1, 1, 0, 0};
int yv[4] = {0, 0, -1, 1};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int A, B, C;
    cin >> A >> B >> C;
    int ans = C-(A-B);
    if(ans < 0){
        cout << 0 << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    int sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;

    string ans = "";
    int diffx, diffy;
    // 1st one way
    diffx = abs(sx - gx);
    for (int i = 0; i < diffx; i++)
    {
        ans += 'R';
    }
    diffy = abs(sy - gy);
    for (int i = 0; i < diffy; i++)
    {
        ans += 'U';
    }
    // 1st return
    for (int i = 0; i < diffx; i++)
    {
        ans += 'L';
    }
    for (int i = 0; i < diffy; i++)
    {
        ans += 'D';
    }
    // 2nd one way
    ans += 'D';
    for (int i = 0; i < diffx + 1; i++)
    {
        ans += 'R';
    }
    for (int i = 0; i < diffy + 1; i++)
    {
        ans += 'U';
    }
    ans += 'L';
    // 2nd return
    ans += 'U';
    for (int i = 0; i < diffx + 1; i++)
    {
        ans += 'L';
    }
    for (int i = 0; i < diffy + 1; i++)
    {
        ans += 'D';
    }
    ans += 'R';
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Map.Entry;

 class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
    public static void main(String[] args) {
    	
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int[] u = new int[N];
        int[] v = new int[N];
        int[] w = new int[N];
        long[] weight = new long[N];
		ArrayList<HashMap<Integer, Integer>> adj = new ArrayList<HashMap<Integer, Integer>>();
		for(int i = 0; i < N; i++) { adj.add(new HashMap<Integer, Integer>()); }
		for(int i=0;i<N-1;i++) {
            u[i] = sc.nextInt()-1;        	
            v[i] = sc.nextInt()-1;        	
            w[i] = sc.nextInt()%2;
            adj.get(u[i]).put(v[i],w[i]);
            adj.get(v[i]).put(u[i],w[i]);
        }
        
		LinkedList<Integer> queue = new LinkedList<Integer>();
		queue.add(0);
		queue.add(-1);
		queue.add(0);
		int[] answers = new int[N];
		while(!queue.isEmpty()) {
			int node = queue.poll();
			int parent = queue.poll();
			int value = queue.poll();
		
			answers[node] = value;
			for(Entry<Integer, Integer> entry : adj.get(node).entrySet()) {
				int next_node = entry.getKey();
				int next_w = entry.getValue();
				
				if(next_node == parent) { continue; }
				queue.add(next_node); queue.add(node); queue.add((value+next_w)%2);
			}
		}
		
		for(int i=0;i<N;i++) {
	        System.out.println(answers[i]);			
		}
    }
}

Measured memory_bytes: 115944
h, w = map(int, input().split())
S = []
S.append(['.'] * (w + 2))
for i in range(h):
    S.append(list('.' + input() + '.'))
S.append(['.'] * (w + 2))

ans = 'Yes'
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if S[i][j] == '#':
            if S[i - 1][j] == '.' and S[i + 1][j] == '.' and S[i][j - 1] == '.' and S[i][j + 1] == '.':
                ans = 'No'
                break
                
print(ans)

Measured memory_bytes: 3064
x1, y1, x2, y2 = gets.chomp.split(" ").map(&:to_i)

x3 = x2 - (y2 - y1)
y3 = y2 + (x2 - x1)
x4 = x3 - (y3 - y2)
y4 = y3 + (x3 - x2)

puts "#{x3} #{y3} #{x4} #{y4}"

Measured memory_bytes: 1788
#include <iostream>

using namespace std;

int main(){
  int N;
  cin >> N;
  int A[2][N];
  int i,j;
  for(i = 0;i < 2;i++){
    for(j = 0;j< N;j++){
      cin >> A[i][j];
    }
  }
  int count = 0;
  int max = 0;

  count = A[0][0];
  for(i = 0;i < N;i++){
    count += A[1][i];
  }
  max = count;

  for(i = 0;i < N-1;i++){
    count -= A[1][i];
    count += A[0][i+1];
    if(max < count) max = count;
  }

  cout << max << endl;


}


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

#define endl '\n'
#define int ll
using namespace std;
typedef long long ll;

const int N = 110, V = 100005;
const ll INF = (1ll<<60);

ll w, n;
ll weight[N], val[N];
ll dp[N][V];

void init();
void process();

int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    init();
    process();
    cout.flush();
    return 0;
}

void init()
{
    cin >> n >> w;
    for(int i = 1; i <= n; i++) cin >> weight[i] >> val[i];
    for(int i = 0; i <= 100000; i++) dp[0][i] = INF;
    for(int i = 0; i <= n; i++) dp[i][0] = 0;
}

void process()
{
    ll ans = 0;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= 100000; j++)
        {
            dp[i][j] = dp[i-1][j];
            if(j >= val[i]) 
            {
                dp[i][j] = min(dp[i][j], dp[i-1][j-val[i]]+weight[i]);
                if(dp[i][j] <= w) ans = max(ans, j);
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 80128
from itertools import product
N = int(input())

An = []
Xn, Yn = [], []

for i in range(N):
    An.append(int(input()))
    Xn.append([])
    Yn.append([])
    for j in range(An[i]):
        x, y = map(int, input().split())
        Xn[i].append(x)
        Yn[i].append(y)

ans = 0
for prod in product("01", repeat=N):
    # bits : i 番目の bit が 1 なら i は正直者として, 仮定する
    bits = list(map(int, prod))
    flag = True

    # bits のリストで矛盾が無いかを調べる
    for i in range(N):
        # i が不親切と仮定するなら,調べる必要はない
        if bits[i] != 1:
            continue

        # B[i] == 1, つまり i が正直者である場合, A_i 個の証言を調べる
        for j in range(An[i]):
            # 「i の証言 : y_ij = 1 のとき x_ij == 1 (正直者である)」に矛盾がある場合
            if Yn[i][j] == 1 and bits[Xn[i][j]-1] == 0:
                flag = False

            # 「i の証言 : y_ij = 0 のとき x_ij == 0 (不親切である)」に矛盾がある場合
            elif Yn[i][j] == 0 and bits[Xn[i][j]-1] == 1:
                flag = False

    # flag が True => bits のリストで矛盾がない
    if flag:
        ans = max(ans, bits.count(1))

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
using pis = pair<int, string>;
#define all(x) (x).begin(), (x).end()
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  //cout << fixed << setprecision(15)

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

  int ans = 0;

  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      if (l[i] == l[j]) continue;
      for (int k = j+1; k < n; k++) {
        if ((l[i] == l[k]) || (l[j] == l[k])) continue;
        if ((l[i] + l[j] > l[k]) && (l[j] + l[k] > l[i]) && (l[k] + l[i] > l[j])) ans++;
      } 
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3656
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define M 998244353
#define all(x) x.begin(),x.end()
using namespace std;
struct custom_hash
{
	static uint64_t splitmix64(uint64_t x)
	{
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}
};
#define safe_map unordered_map<ll, ll, custom_hash>

inline int mex(unordered_set<int> st)
{
	int m = 0;
	while (st.find(m) != st.end())
	{
		m += 1;
	}
	return m;
}
inline int calculateGrundy(int n)
{
	if (n == 1)
		return 0;
	unordered_set<int> mexi;
	for (int i = 1; i <= sqrt(n); i += 1)
	{
		if (n % i == 0)
		{
			if (n / i != n)
				mexi.insert(calculateGrundy(n / i));
			mexi.insert(calculateGrundy(i));
		}
	}
	return mex(mexi);
}
inline ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
ll power(ll x, ll y)
{
	ll res = 1;

	x = x % N;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % N;
		y = y >> 1;
		x = (x * x) % N;
	}
	return res;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll s, w;
	cin >> s >> w;
	if (w >= s)
	{
		cout << "unsafe";
	}
	else
		cout << "safe";
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <climits>

int solve(std::vector<int>& a)
{
    int num = 0;
    for(int i = 0; i < a.size(); i++)
    {
        if(a[i]==num+1)
        {
            num++;
        }
    }

    return a.size() - num;
}

int main()
{
    int N; std::cin >> N;
    std::vector<int> a(N, 0);
    bool cond = false;
    for(int i = 0; i < N; i++)
    {
        std::cin >> a[i];
        if(a[i]==1) cond = true;
    }
    int ans = -1;
    if (cond)
        ans = solve(a);
    std::cout << ans << std::endl;
    return 0;
}

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

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	ll ans = 0;
	for (int b = m + 1; b <= n; b++) {
		int temp = (n + 1) / b;
		ans = ans + 1LL * temp * (b - m);
		if ((n + 1) % b <= m) continue;
		else ans = ans + 1LL * ((n+1) % b - m);
	}
	if (m == 0) ans = 1LL * n * n;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))

ball_list = [0]*N

for i in range(N,0,-1):
  num_list = list(range(i,N+1,i))#-1で使う
  if num_list == []:
    ball_list[i-1] = a[i-1]
  else:
    sum_ = 0
    for j in num_list:
      sum_+=ball_list[j-1]
    if sum_%2 == a[i-1]:
      ball_list[i-1] = 0
    elif (sum_+1)%2 == a[i-1]:
      ball_list[i-1] = 1
    else:
      ball_list[i-1] = -1
if -1 not in ball_list:
  ball_sum = sum(ball_list)
  if ball_sum == 0:
    print(0)
  else:
    print(ball_sum)
    ans = [str(i+1) for i, x in enumerate(ball_list) if x == 1]
    print(' '.join(ans))
else:
  print('-1')

Measured memory_bytes: 24628
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
#define PII pair<int, int>
#define debug std::cout << "---debug---" << std::endl;
using namespace std;
const int maxn = 1e5 + 7;
const int mod = 1e9 + 7;

ll a, b, c, k;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    //freopen("E:\\myprogram\\data.in", "r", stdin);
    //freopen("E:\\myprogram\\data.out", "w", stdout);
    cin >> a >> b >> c >> k;
    ll ans = 0;
    ans += min(a, k); k -= min(a, k);
    k -= min(b, k);
    ans -= min(c, k);
    cout << ans << endl;
    return 0;
}

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

int main(){
    int N,M;
    cin>>N>>M;
    
    vector<pair<int,int>> ans;
    
    int left=1,right=N;
    while(left<right){
        int sh=N%2==0&&right-left<=N/2;
        ans.push_back(make_pair(left+sh,right));
        ++left;
        --right;
    }
    
    for(int i=0;i<M;++i){
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}


Measured memory_bytes: 4212
N=int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))
a = 1
if T[0]>A[0] or A[-1]>T[-1] or T[-1]!=A[0]:
    a*=0
for i in range(1,N-1):
    if T[i-1]!=T[i]:
        if T[i]>A[i]:
            a*=0
            break
        else:
            a*=1
            
    elif A[i]!=A[i+1]:
        if T[i]<A[i]:
            a*=0
            break
        else:
            a*=1
    else:        
        a=(a*min(T[i],A[i]))%(10**9+7)
print(a)

Measured memory_bytes: 18756
from itertools import permutations
from math import factorial
n = int(input())
patern = factorial(n)
town = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for rute in permutations(range(n)):
    road = 0
    for i in range(n-1):
        x,y = town[rute[i]]
        nx,ny = town[rute[i+1]]
        road += ((x-nx)**2 + (y-ny)**2)**(1/2)
    ans += road
print(ans/patern)

Measured memory_bytes: 3188
#include <iostream>
#define mod 1000000007

using namespace std;

int main()
{
    int h, w, k, dp[110][10]={0};
    cin>>h>>w>>k;
    dp[0][1]=1;
    for (int i=1; i<=h; i++)
    {
        for (int j=0; j<(1<<(w-1)); j++)
        {
            bool ok=true, upd[10]={0};
            for (int l=1; l<w-1; l++) if (j&(1<<(l-1)) && j&(1<<l)) ok=false;
            if (ok)
            {
                for (int l=1; l<w; l++)
                {
                    if (j&(1<<(l-1)))
                    {
                        dp[i][l]=(dp[i][l]+dp[i-1][l+1])%mod;
                        dp[i][l+1]=(dp[i][l+1]+dp[i-1][l])%mod;
                        upd[l]=1; upd[l+1]=1;
                    }
                }
                for (int l=1; l<=w; l++)
                {
                    if (!upd[l]) dp[i][l]=(dp[i][l]+dp[i-1][l])%mod;
                }
            }
        }
    }
    cout<<dp[h][k]<<endl;
    return 0;
}


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

int main(void)
{
	int num, pair= 0;
	int relation[100000] = {};

	cin>>num;
	for(int i= 0; i<num; i++)
		cin>>relation[i];

	for(int i= 0; i<num; i++)
		if(i==relation[relation[i]-1]-1)
			pair++;

	pair/= 2;
	cout<<pair<<endl;

	return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n, m, x;cin >> n >> m >> x;
    int a = 0;
    int b = 0;
    inc(i, 0, m){
        int aa;cin >> aa;
        if(aa < x) a++;
        if(aa > x) b++;
    }
    cout << min(a, b) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int mod=1000000007;
const int maxn=200005;
struct node{
  int x,v;
  void read(){
    scanf("%d%d",&x,&v);
  }
  bool operator <(const node &B)const{
    return x<B.x;
  }
}P[maxn];
int typ[maxn];
int seq[maxn];
bool cmp(const int &a,const int &b){
  return P[a].v<P[b].v;
}
int n;
int Min[maxn],Max[maxn];
int c[maxn];
void add(int x,int w){
  for(;x<maxn;x+=x&(-x))c[x]=(c[x]+w)%mod;
}
int sum(int x){
  if(x<0)return 0;
  int ans=1;
  for(;x;x-=x&(-x))ans=(ans+c[x])%mod;
  return ans;
}
vector<int> L[maxn];
int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;++i)P[i].read();
  sort(P+1,P+n+1);
  for(int i=1;i<=n;++i)seq[i]=i;
  sort(seq+1,seq+n+1,cmp);
  for(int i=1;i<=n;++i)P[seq[i]].v=i;
  Min[n]=P[n].v;Max[1]=P[1].v;
  for(int i=n-1;i>=1;--i){
    Min[i]=min(Min[i+1],P[i].v);
  }
  for(int i=2;i<=n;++i){
    Max[i]=max(Max[i-1],P[i].v);
  }
  for(int i=1;i<=n;++i){
    L[Max[i]].push_back(Min[i]);
  }
  for(int i=1;i<=n;++i){
    for(vector<int>::iterator pt=L[i].begin();pt!=L[i].end();++pt){
      int l=*pt;
      add(i,(sum(i)-sum(l-2)+mod)%mod);
    }
  }
  printf("%d\n",(sum(n)-sum(n-1)+mod)%mod);
  return 0;
}


Measured memory_bytes: 16256
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<10)
#define LLINF (1<<30)
#define MOD 1000000007
# define rep(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;

int main() {
    int h, w;
    char grid[100][100];
    vector<int>dh, dw;
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        bool yoko = true;
        for (int j = 0; j < w; j++) {
            cin >> grid[i][j];
            if (grid[i][j] == '#')yoko = false;
        }
        if (yoko == false) dh.pb(i);
    }
    for (int i = 0; i < w; i++) {
        bool tate = true;
        for (int j = 0; j < h; j++) {
            if (grid[j][i] == '#')tate = false;
        }
        if (tate == false) dw.pb(i);
    }
    for (int i = 0; i < dh.size(); i++) {
        for (int j = 0; j < dw.size(); j++) {
            cout << grid[dh[i]][dw[j]];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
bool fl;
int main () {
    cin >> n;
    for (int i = 0; i < n; i++) {
	char ch;
	cin >> ch;
	if (ch == 'Y')
	    fl = 1;
    }
    if (fl)
	cout << "Four" << endl;
    else
	cout << "Three" << endl;
}


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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> p(n, 0);
    rep(i, k){
        int d;
        cin >> d;
        rep(j, d){
            int a;
            cin >> a;
            p[a-1]+=d;
        }
    }
    int ans = 0;
    rep(i, n){
        if(p[i]==0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#define Max 2000
 
int n,A[Max];


int solve(int x,int y){
  if(A[x]==y)return 1;
  if(x==n)return 0;
  else{
    if (solve(x+1,y) || solve(x+1,y-A[x]))
      return 1;
  }
  return 0;
}




int main(){

int q,i,M[200];
   
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
   
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&M[i]);
  }
   
  for(i=0;i<q;i++){
    if(solve(0,M[i])==1)
      printf("yes\n");
    else printf("no\n");
  }
  return 0;
}
 

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define pic pair<ll,char>
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii > 
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll arr[50][50];
ll temp[50][50];
signed main()
{
    fast;
    ll n,k;
    cin>>n>>k;
    ll i,j;
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            cin>>arr[i][j],temp[i][j] = arr[i][j];
        k--;
    while(k)
    {
        if(k&1)
        {
            ll p[50][50]={{0}};
            for(i=0;i<n;i++)
                for(j=0;j<n;j++)
                    for(ll x=0;x<n;x++)
                        p[i][j] = (p[i][j]+temp[i][x]*arr[x][j])%mod;
            for(i=0;i<n;i++)
                for(j=0;j<n;j++)
                    arr[i][j] = p[i][j];
        }
        k= k/2;
                    ll p[50][50]={{0}};
            for(i=0;i<n;i++)
                for(j=0;j<n;j++)
                    for(ll x=0;x<n;x++)
                        p[i][j] = (p[i][j]+temp[i][x]*temp[x][j])%mod;
            for(i=0;i<n;i++)
                for(j=0;j<n;j++)
                    temp[i][j] = p[i][j];
    }
    ll ans = 0;
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            ans = (ans+arr[i][j])%mod;
    cout<<ans;
}

Measured memory_bytes: 384
import Control.Monad
import Control.Monad.ST
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Array
import Data.Array.ST

main = do
    [n,w]<-map read.words<$>getLine::IO [Int]
    wvs<-replicateM n $ unfoldr (B.readInt.B.dropWhile(<'!'))<$>B.getLine::IO[[Int]]
    print $ f n w wvs

f n w wvs = runST $ do
    dp <- newArray ((0,0),(n,w)) 0 :: ST s (STUArray s (Int,Int) Int)
    forM_ [(i,wi,vi,j)|(i,[wi,vi])<-zip [1..] wvs,j<-[0..w]] $ proc dp
    readArray dp (n,w)

proc dp (i,wi,vi,j) = writeArray dp (i,j) =<<
    if j< wi then readArray dp (i-1,j)
             else max.(+vi) <$> readArray dp (i-1,j-wi) <*> readArray dp (i-1,j)

Measured memory_bytes: 79868
#include<bits/stdc++.h>
using namespace std;
int main(){
 int A, B , C ,D;
 cin >> A >> B >> C >> D;
 int a_die ;
 if(C % B ==0) {
   a_die = C /B;
 }
 else{
   a_die = (C/B)+1;
 }
 int t_die ;
 if(A % D ==0) {
   t_die = A/D;
 }
 else {
   t_die = (A/D)+1;
 }
 if(t_die >=a_die)cout << "Yes" << endl;
 else cout << "No" << endl;
}

Measured memory_bytes: 3632
import java.security.KeyStore.TrustedCertificateEntry
import java.util
import java.util.{ArrayList, Collections, Comparator, List => JList}
import scala.math._

import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.{Failure, Success, Try}

object Main{
  val LINE_SEPARATOR = "\n"
  def main(args: Array[String]): Unit = {
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString(LINE_SEPARATOR);
      println(solve(input).trim());
    }
  }

  def init (nRows: Int, nCols: Int, default: Int) = Array.tabulate(nRows,nCols)( (x,y) =>  default)

  def sortIgnoreCase1(list: JList[String]): JList[String] = {
    val r = new ArrayList[String](list)
    Collections.sort(r, new Comparator[String] {
      override def compare(o1: String, o2: String): Int = o1.compareToIgnoreCase(o2)
    })
    r
  }

  def solve(input: String): String = {
    val s = input
    val list = for (i <- 0 to s.length; j <- 0 to s.length) yield s.drop(i).dropRight(j)
    list.map(l => if (l.matches("""(A|C|G|T)*""")) l.length else 0).max.toString
  }

  def gcd(m: Long, n: Long): Long = n match {
    case 0 => m
    case _ => gcd(n, m % n)
  }
  def lcm(a: Long, b: Long): Long = a * b / gcd(a, b)

  val tests=List(
    """ATCODER""".stripMargin -> """3
                                   |""".stripMargin,
    """HATAGAYA""".stripMargin -> """5
                                    |
                                                   |
                              |""".stripMargin,
    """SHINJUKU""".stripMargin -> "0"
  )

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}

Measured memory_bytes: 27296
n,k=map(int,input().split())
x=list(map(int,input().split()))
a=[]
for i in range(n-k+1):
    a1=abs(x[i])+abs(x[i+k-1]-x[i])
    a2=abs(x[i+k-1])+abs(x[i+k-1]-x[i])
    a.append(min(a1,a2))
print(min(a))


Measured memory_bytes: 62576
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    A = list(map(int, readline().split()))

    ans = 0

    for i in range(N):
        for j in range(i + 1, N):
            score = abs(A[i] - A[j])
            ans = max(ans, score)

    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    ll a,b;
    cin >> a>>b;
    cout << a/b << " " << a%b << " " <<setprecision(13)<<std::fixed<< (double)a/b << endl;
    return 0;
}


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

int main() {
    ll N; cin>>N;
    for (ll i = floor(sqrt(N)); i > 0; i--){
        if(N%i==0){
            cout<<(i-1)+(N/i-1)<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int n;
    cin >> n;
    double a, sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a;
        sum += 1 / a;
    }
    cout << setprecision(20) << 1 / sum << endl;
    return 0;
}

Measured memory_bytes: 3792
use std::io::{stdin, BufRead, BufReader};

fn main() {
    let input = BufReader::new(stdin());
    for line in input.lines() {
        let mut values: Vec<u32> = line.unwrap()
            .split_whitespace()
            .filter_map(|x| x.parse::<u32>().ok())
            .collect();
        if values.len() == 1 {
            continue;
        }
        values.sort();
        let values: Vec<u32> = values.into_iter().map(|x| x.pow(2)).collect();
        if values[2] == (values[0] + values[1]) {
            println!("YES");
        } else {
            println!("NO");
        }

    }
}



Measured memory_bytes: 5024
macro_rules! scan_sub {
    ( $itr:ident, $t:ty ) => {
        let mut buf = String::new();
        let $itr = {
            while buf.trim().len() == 0 {
                buf = String::new();
                std::io::stdin().read_line(&mut buf).unwrap();
            }
            buf.split_whitespace().map(|n| n.parse::<$t>().unwrap())
        };
    };
}

macro_rules! scan {
    ( $x:ident; Vec<$t:ty> ) => {
        scan_sub!(itr, $t);
        let $x = itr.collect::<Vec<_>>();
    };
    ( $( $x:ident ),*; $t:ty ) => {
        scan_sub!(itr, $t);
        let mut itr = itr;
        $(
            let $x = itr.next().unwrap();
        )*
    };
}

fn to_26(n: usize) -> String {
    let mut l = 0;
    let mut d = 1;
    let mut m = 0;
    while m < n {
        l += 1;
        d *= 26;
        m += d;
    }

    let mut k = n - (m - d) - 1;
    let mut res = vec![];
    for _ in 0..l {
        let c = k % 26;
        res.push(('a' as u8 + c as u8) as char);
        k /= 26;
    }

    res.reverse();
    res.into_iter().collect::<String>()
}

fn main() {
    scan!(n; usize);

    println!("{}", to_26(n));
}


Measured memory_bytes: 2092
#include <iostream>
#include <map>
#include <vector>

typedef long long ll;

int N;
ll A[200005], mark[200005];
std::map<ll, std::vector<int> > occ;

int main() {
  std::cin >> N;
  ll mA = 0;
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i];
    mA = std::max(mA, A[i]);
    mark[i] = 1;
    occ[A[i]].push_back(i);
  }

  int ans = N;
  for (int i = 0; i < N; ++i) {
    if (mark[i] == 0)  continue;
    if (occ[A[i]].size() > 1) {
      mark[i] = 0;
      ans--;
    }
    for (ll x = A[i]; x <= mA; x += A[i]) {
      if (occ.find(x) == occ.end()) continue;
      for (int j : occ[x]) {
        if (i == j) continue;
        if (mark[j])  ans--;
        mark[j] = 0;
      }
    }
  }

  std::cout << ans << "\n";



  return 0;
}


Measured memory_bytes: 28520
#include <iostream>

using namespace std;

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

   if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
   {
       cout << "Bad" << endl;
   }
   else
   {
       cout << "Good" << endl;
   }

   return 0;
}

Measured memory_bytes: 256
sx, sy, tx, ty = gets.split(' ').map(&:to_i)
ans = []

dx = tx - sx
dy = ty - sy
# path1
# [rrr,uuuuuuuu]
ans << 'R'*dx << 'U'*dy
ans << 'L'*dx << 'D'*dy

# path2
ans << 'D' << 'R'*(dx+1) << 'U'*(dy+1) << 'L'
ans << 'U' << 'L'*(dx+1) << 'D'*(dy+1) << 'R'

puts ans.join


Measured memory_bytes: 14256
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,P;
    cin >> N >> P;
    ll A[55];
    rep(i,0,N) cin >> A[i];
    ll oo = 0, ee = 0;
    rep(i,0,N){
        if(A[i] % 2 == 1){
            oo++;
        }else{
            ee++;
        }
    }
    if(oo == 0){
        if(P == 1){
            print(0);
        }else{
            ll ans = pow(2,ee);
            print(ans);
        }
        return 0;
    }
    ll ans = pow(2, ee) * pow(2, oo) / 2;
    print(ans);

    

}

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

const int mod = 1000000007;
const int inv = 500000004;

int a[3010];
long long dp[2][3010][3010];

int main(){
	int n, q; scanf("%d%d", &n, &q);
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	int now = 0, pre = 1;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			dp[now][i][j] = a[i] > a[j];
		}
	}
	long long pw = 1;
	while (q--){
		pw = pw * 2 % mod;
		swap(now, pre);
		int x, y; scanf("%d%d", &x, &y);
		x--, y--;
		if (x > y) swap(x, y);
		dp[now][x][y] = (dp[pre][y][x] * inv + dp[pre][x][y] * inv) % mod;
		dp[now][y][x] = (dp[pre][x][y] * inv + dp[pre][y][x] * inv) % mod;
		for (int i = 0; i < n; i++){
			if (i == x || i == y) continue;
			dp[now][i][x] = (dp[pre][i][x] * inv + dp[pre][i][y] * inv) % mod;
			dp[now][x][i] = (dp[pre][x][i] * inv + dp[pre][y][i] * inv) % mod;
			dp[now][i][y] = (dp[pre][i][y] * inv + dp[pre][i][x] * inv) % mod;
			dp[now][y][i] = (dp[pre][y][i] * inv + dp[pre][x][i] * inv) % mod;
		}
		swap(now, pre);
		for (int i = 0; i < n; i++){
			dp[now][i][x] = dp[pre][i][x];
			dp[now][x][i] = dp[pre][x][i];
			dp[now][i][y] = dp[pre][i][y];
			dp[now][y][i] = dp[pre][y][i];
		}
	}
	long long ans = 0;
	for (int i = 0; i < n; i++){
		for (int j = i + 1; j < n; j++){
			ans = (ans + dp[now][i][j]) % mod;
		}
	}
	printf("%d\n", ans * pw % mod);
	return 0;
}


Measured memory_bytes: 141696
import math
MAX = 7400000
prime = [1]*MAX
prime[0] = prime[1] = 0
res = []
sq = int(math.sqrt(MAX))
for i in xrange(2, sq+1):
    q = len(res)
    if prime[i]:
        res.append(i)
        for j in xrange(i*i, MAX, i):
            prime[j] = 0
    prime[i] = q
for i in xrange(sq+1, MAX):
    q = len(res)
    if prime[i]:
        res.append(i)
    prime[i] = q

def solve(m, n):
    # [m,m*m)
    sat = [0]*(m*m)
    for i in xrange(m, m*m):
        if not sat[i]:
            if n == 0:
                return i
            n -= 1
            for j in xrange(i, m*m, i):
                sat[j] = 1
    # [m*m,\inf)
    idx = prime[m*m]
    return res[idx+n]
while 1:
    m, n = map(int, raw_input().split())
    if m==0:
        break
    print solve(m, n)

Measured memory_bytes: 257864
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

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



int main(){fastio
    ll x;cin>>x;
    ll ans=2*(x/11);
    if(x%11>=7)ans+=2;
    else if(x%11>=1)ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

class Comb {
 public:
  Comb(int n) {
    fact[0] = fact[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < n; i++){
        fact[i] = fact[i-1] * i % kMod;
        inv[i] = kMod - inv[kMod%i] * (kMod / i) % kMod;
        finv[i] = finv[i-1] * inv[i] % kMod;
    }
  }

  LL nCr(int n, int r) const {
    LL numerator = fact[n];
    LL denominator = finv[r] * finv[n-r] % kMod;
    return (numerator * denominator) % kMod;
  }

 private :
  static constexpr int kMax = 1e5;
  LL fact[kMax];
  LL inv[kMax];
  LL finv[kMax];
};

int main() {
  int N, K; std::cin >> N >> K;
  std::vector<LL> A(N);
  for (int i = 0; i < N; ++i) std::cin >> A[i];
  std::sort(A.begin(), A.end());

  Comb c(N);

  LL sum_max = 0, sum_min = 0;
  for (int i = 0; i <= N-K; ++i) {
    LL pattern = c.nCr(N-i-1, K-1) % kMod;
    sum_min += (A[i] * pattern)%kMod;
  }
  for (int i = N-1; i >= K-1; --i) {
    LL pattern = c.nCr(i, K-1) % kMod;
    sum_max += (A[i] * pattern)%kMod;
  }

  std::cout << (sum_max + kMod - sum_min) % kMod << std::endl;
}


Measured memory_bytes: 3328
#include <stdio.h>

int main() {
int i,a,b,x;
char op;
for (  i == 0 ; 1  ;  i++){
scanf("%d %c %d",&a,&op,&b);
if(op=='+') x=(a+b);
else if(op=='/') {x=a/b;}
else if(op=='*') {x=a*b;}
else if(op=='-') {x=a-b;}
else if(op=='?') {break;}
printf("%d\n",x);
}
return 0;
}

Measured memory_bytes: 600
#ifdef __GNUC__
#pragma GCC target("avx2")
#pragma GCC optimize ("O25")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#define iss std::cin
#endif
#include "bits/stdc++.h"
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#define rep(i, times) for(ll i = 0; i < (times); ++i)
#define p(x) (cout << x << "\n")
using ll = long long; using ld = long double; using namespace std;

#ifndef __GNUC__
string text =
R"X(
776013196293085 2.60
)X";
stringstream iss{text};
#endif 

void procedures( ) {
	boost::multiprecision::cpp_dec_float_100 A;
	boost::multiprecision::cpp_dec_float_100 B;
	iss >> A >> B;
	p(ll(A * B));
};
int main( ) {
	cin.tie(0);	ios::sync_with_stdio(0);
	procedures( );
}


Measured memory_bytes: 3740
import sys
s = input()

day_list=["SUN", "SAT", "FRI", "THU", "WED", "TUE", "MON", ]

if s == "SUN":
    print(7)
    sys.exit()
for i in range(len(day_list)):
    if s == day_list[i]:
        print(i)




Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            sS = Console.ReadLine().Trim().Split(' ');
            int iK = int.Parse(sS[0]);
            sS = Console.ReadLine().Trim().Split(' ');
            List<int> lstInp = new List<int>();
            for (int i = 0; i < sS.Length; i++) { lstInp.Add(int.Parse(sS[i])); }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = 0;
            for (int i = 0; i < lstInp.Count; i++)
            {
                List<int> lstBuf = new List<int>();
                lstBuf.Add(lstInp[i]);
                lstBuf.Add(iK - lstInp[i]);
                iOut += lstBuf.Min() * 2;
            }

            // 出力
            Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


Measured memory_bytes: 13396
#include <iostream>
using namespace std;
int main(void){
  int n,m;
  cin>>n>>m;
  int x[n];
  for(int i=0;i<n;i++){
      cin>>x[i];
  }
  for(int i=1;i<=m;i++){
      for(int j=0;j<n-1;j++){
          if(x[j]%i>x[j+1]%i){
              int a=x[j];
              x[j]=x[j+1];
              x[j+1]=a;
          }
      }
  }
  for(int i=0;i<n;i++){
      cout<<x[i]<<endl;
  }
    
}

Measured memory_bytes: 3096