akhauriyash/Code-Regression huggingface dataset:
from collections import deque

n, m = map(int, input().split())
Edge = [list(map(int, input().split())) for i in range(m)]
adj = [[] for _ in range(n)]

for u, v in Edge:
    adj[u-1].append(v-1)

adj_bit = [0]*n
for i in range(n):
    for j in adj[i]:
        adj_bit[i] += 1 << j

for i in range(n):
    que = deque([(i, 0)])
    visited_a = [0] * n

    while que:
        v, visited = que.popleft()

        for dest in adj[v]:
            if visited_a[dest]:
                continue
            if dest == i:
                ans = [i+1]
                for j in range(1001):
                    if visited & 1:
                        ans.append(j+1)
                    visited >>= 1
                print(len(ans))
                print(*ans, sep='\n')
                exit()
            if visited & adj_bit[dest]:
                # print(i, v, dest, bin(visited), bin(adj_bit[dest]))
                continue
            visited_a[dest] = 1
            que.append((dest, visited + (1 << dest)))
else:
    print(-1)


Measured memory_bytes: 48192
import java.util.Scanner;

class Main {
	public static void main(String[] args){
    	Scanner cin = new Scanner(System.in);
		int a, b, c;
	    a = cin.nextInt();
    	b = cin.nextInt();
	    c = cin.nextInt();
    
	  	int res = serch_divisor_number(a, b, c);
	
    	System.out.println(res);
  	}
  	
  	private static int serch_divisor_number(int a, int b, int c) {
  		int ans = 0;
  		
  		for (int i = a; i <= b; i++) {
  			if (c % i == 0) ans++;
  		}
  		
  		return (ans);
  	}
}

Measured memory_bytes: 26312
#include<bits/stdc++.h>
using namespace std;
                       ///****   Hasebul Hassan Chowdhury ***////
#define ms(a,v)        memset(a,v,sizeof a)
#define lll            long long
#define FOR(i,a,b)     for(int i=a;i<=b;i++)
#define fast           ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Read           freopen("input.txt", "r", stdin)
#define Write          freopen("output.txt", "w", stdout)
#define INF            1e18


void solve()
{
   int n,d,cnt=0;
   cin>>n>>d;
   long double a,b;
   for(int i=1;i<=n;i++)
   {
       cin>>a>>b;
       long double num=(a*a)+(b*b);
       num=sqrt(num);
       if(num<=d) cnt++;
   }
   cout<<cnt<<endl;
}

int main()
{
    fast
    #ifndef ONLINE_JUDGE
    //Read;
    //Write;
    #endif
    //sieve();
    //int cnt=1;
    //int t; scanf("%d",&t); while(t--) solve();
    solve();
}


Measured memory_bytes: 3792
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 305
#define ll long long
#define mod 998244353
int n,m,b[N],ans=1;
bitset<N>a[N],t[N];
void insert(bitset<N> now)
{
	for(int i=m;i;i--)if(now[i])
		if(t[i][i])now^=t[i];
		else {t[i]=now;return ;}
	ans=ans<<1;ans%=mod;
}
int main()
{
	scanf("%d%d",&n,&m);int tt=1,pp=1;
	for(int i=1;i<m;i++)pp=(pp<<1)%mod;
	for(int i=1;i<=n;i++)
	{
		tt<<=1;tt%=mod;
		for(int j=1,x;j<=m;j++)
			scanf("%d",&x),a[i][j]=(x==1);
		insert(a[i]);
	}
	printf("%d\n",(ll)(tt-ans+mod)*pp%mod);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define M 1000000007
#define fors(i,n) for(int i=0;i<n;++i)
#define fore(i,a,b) for(int i=a;i<=b;++i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vv vector<int>
#define endl "\n"
#define test(i) cout<<i<<endl
#define itrt int t; cin>>t; fors(i,t)
#define itr1 int t; cin>>t;
#define ff first
#define ss second
#define pb push_back
#define vmp make_pair
#define ppb pop_back
#define sorta(a,n) sort(arr,arr+n)
#define sortv(x) sort(x.begin(),x.end())
void file(){
    #ifdef LOCAL
    freopen("demo.in","r",stdin);
    freopen("demo.out","w",stdout);
    #endif
}
int main(){
    fastio;
    file();
    int k,n;
    cin>>k>>n;
    vv v(n);
    fors(i,n){
        cin>>v[i];
    }
    int ans = v[n-1]-v[0];
	for(int i=2;i<n;++i){
	   // test(k-v[i]+v[i-1]);
	    ans = min(ans,k-v[i]+v[i-1]);
	}
	test(ans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
long long n,now,k,ans,cnt=0,tmp;
int main(){
  cin >> n >> now;
  long long a[n],b[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
    b[i]=abs(a[i]-now);
  }
  ans=b[0];
  for(int i=0;i<n;i++){
    ans=__gcd(b[i],ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
// #1140935 Solution for 0515: School Road by ryogo 
#include<iostream>
using namespace std;
int dp[20][20];
int main(){
	int a, b ,i, j, x, y;
	while(cin >> a >> b){
		if(a == 0 && b == 0) { break; }
		int n;
		cin>>n;
		for(i=0; i<=19; i++){for(j=0; j<=19; j++){dp[i][j] = 0;}}
		for(i=1; i<=n ; i++){
			cin >> x >> y; dp[y][x] = -1;
		}
		dp[1][1] = 1;
		for(i=1; i<=b; i++){
			for(j=1; j<=a; j++){
				if(i==1 && j==1){continue;}
				if(dp[i][j] != -1){
					dp[i][j] = dp[i][j-1] + dp[i-1][j];
				}
				else dp[i][j] = 0;
			}
		}
 
		cout << dp[b][a] << endl;
	}
}


Measured memory_bytes: 2996
#include <stdio.h>
#include <string.h>
int main(){
	char bolas1[10], bolas2[10], esc[10];
	int nb1, nb2;
//	int valor = strcmp(esc, bolas2);
	scanf("%s %s", bolas1, bolas2);
	scanf("%d %d", &nb1, &nb2);
	scanf("%s", esc);
	int valor = strcmp(esc, bolas1);
	if(valor==0){
		--nb1;
	} else {
		--nb2;
	}
	printf("%d %d \n", nb1, nb2);

	return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main () {

	while(true){
		int n;
		cin>>n;
		if(n==0)break;

		int max_p=0,max_d=0;
		for(int i=0;i<n;i++){
			int p,d1,d2;
			cin>>p>>d1>>d2;

			if(max_d<=d1+d2){
				max_d=d1+d2;
				max_p=p;
		}
	}
		cout<<max_p<<" "<<max_d<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include<algorithm>

using namespace std;

int N, M;
long long int MOD = 1000000007;

int main(void) {

	cin >> N >> M;

	long long int ans = 0;

	if (N == M) {
		ans = 1;
		for (int i = 1; i <= N; i++) {
			ans *= i; ans %= MOD;
		}
		ans *= ans;
		ans *= 2;
		ans %= MOD;
	}
	else if (abs(N - M) == 1) {
		ans = 1;
		for (int i = 1; i <= N; i++) {
			ans *= i; ans %= MOD;
		}
		for (int i = 1; i <= M; i++) {
			ans *= i; ans %= MOD;
		}
	}
	else {
		ans = 0;
	}

	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
program Sum_of_Large_Numbers;
const
  m: int64 = 1000000007;
  h: int64 = 500000004;
  s: int64 = 166666668;
var
  n, k: int64;
function f(i: int64): int64;
begin
  f := i*(((n+1)*(h*(i+1) mod m)-(s*((i+1)*(i*2+1) mod m) mod m)+1) mod m);
end;
begin
  read(n, k);
  writeln((m+(f(n+1)-f(k-1)) mod m) mod m);
end.

Measured memory_bytes: 1380
#include<iostream>
#include<cstdio>
#include<cstdlib>
#define re register
#define LL long long
#define N 2005
#define Maxn 4000000
using namespace std;
const int Mod=1e9+7;
int n,k;
LL f[N][N],fac[Maxn+5],inv_fac[Maxn+5];
inline LL C(int n,int m){ return (((fac[m]*inv_fac[n])%Mod)*inv_fac[m-n])%Mod; }
LL power(LL x,int P){
    LL ans=1,m=x;
    while(P){
        if(P&1) (ans*=m)%=Mod;
        P>>=1;(m*=m)%=Mod;
    }
    return ans;
}
int main(){
    cin>>n>>k; 
    if(k==1){ printf("%d\n",1);return 0;}
    //memset(f,0,sizeof(f)); 
    fac[0]=1; for(re int i=1;i<=Maxn;++i) fac[i]=(fac[i-1]*i)%Mod;
    inv_fac[Maxn]=power(fac[Maxn],Mod-2); for(re int i=Maxn-1;i>=0;--i) inv_fac[i]=(inv_fac[i+1]*(i+1))%Mod;
    f[0][0]=1;
    for(re int i=1;i<=n;++i){
        for(re int j=0;j<=i;++j){
            f[i][j]=f[i-1][j];
            if(!j) continue;
            (f[i][j]+=f[i][j-1]*(n-j+1)%Mod*C(k-2,n-i+(n-j+1)*(k-1)-1)%Mod)%=Mod;
        }
    }
    printf("%lld\n",f[n][n]);
    return 0;
}

Measured memory_bytes: 94080
/*▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ЗАПУСКАЕМ▒▀██████▄
░███▀▒▒▒▒▒ДЯДЮ▒▒▒▒▒▒▀█████
░▐██▒▒▒▒▒БОГДАНА▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄█████████████  █▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐*/
#include <iostream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <math.h>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <queue>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define DEBUG
#define fi first
#define se second
#define pqueue priority_queue
#define pb(x) push_back(x)
// #define endl '\n'
#define all(x) x.begin(), x.end()
#define int long long
#define mk(a, b) make_pair(a, b)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ull> vull;
typedef vector<ll> vll;
// typedef tuple<int, int, int> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector< vector<int> > vvi;
typedef vector<char> vc;

const ll INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1000000007;
// const ll MAXN = 3e5;
const ld eps = 1e-6;
const ld eps2 = 1e-9;
const ll MOD2 = 998244353;
const ll dosz = 5e5;
const ll SZ = (1<<18);
const ld PI = atan2l(0, -1);


void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
        // freopen("a.in", "r",stdin);
#else
       // freopen("input.txt", "r", stdin);
       // freopen("output.txt", "w", stdout);
#endif
}

void solve(){
    int n;
    cin >> n;
    vi kek(n+1);
    for(int i=0; i<n-1; i++){
        int beta;
        cin >> beta;
        kek[beta]++;
    }
    for(int i=1; i<=n; i++){
        cout << kek[i] << endl;
    }
}

signed main() {
    fast_io();
    int q = 1;
    // cout << fixed << setprecision(6);
    // cin >> q;
    while(q--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 4784
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define all(v) v.begin(),v.end()
using namespace std;

signed main(){
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    int q;
    cin>>q;
    rep(i,q){
        int k;
        cin>>k;
        cout<<binary_search(all(a),k)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3608
import java.util.*;

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

        long a = sc.nextInt();
        long b = sc.nextInt();
        long c = sc.nextInt();
        long d = c - a - b;
        boolean res = false;
        if(d <= 0) {
            res = false;
        } else {
            res = 4 * a * b < d * d;
        }

        System.out.println( res ? "Yes" : "No");
    }
}

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

int main() {
    int a, b, x;
    double angle_rad, angle_deg;
    double v;
    double pi = 2 * acos(0);

    scanf("%d %d %d", &a, &b, &x);

    v = a*a*b;

    if (v/2 == x) {
        angle_rad = atan2(b, a);
    }
    else {
        if (v/2 < x) {
            angle_rad = atan2(2*(a*a*b - x), a*a*a);
        }
        else {
            angle_rad = atan2(a*b*b, 2*x);
        }
    }

    angle_deg = angle_rad * (180 / pi);

    printf("%.10f\n", angle_deg);

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>
#include <stack>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 &y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 &y) {if (x < y) x = y;}


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 10;
    // const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 179;
    // const ld PI = 3.1415926535;
#endif

// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,sse3,sse4")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("avx2")
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, x;
    cin >> n >> m >> x;
    vector<pair<int, vector<int>>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first;
        a[i].second.resize(m);
        for (int j = 0; j < m; j++) {
            cin >> a[i].second[j];
        }
    }
    int ans = INF;
    for (int i = 0; i < (1 << n); i++) {
        vector<int> cnt(m, 0);
        int sum = 0;
        for (int j = 0; j < n; j++) {
            if ((i >> j) & 1) {
                sum += a[j].first;
                for (int w = 0; w < m; w++) {
                    cnt[w] += a[j].second[w];
                }
            }
        }
        bool ok = 1;
        for (int j = 0; j < m; j++) {
            ok &= (cnt[j] >= x);
        }
        if (ok) {
            chkmin(ans, sum);
        }
    }
    if (ans == INF) {
        cout << "-1\n";
        return 0;
    }
    cout << ans;
}
/*

*/  

Measured memory_bytes: 3632
#include <stdio.h>
int main(void)
{
  int a, b, c;
  int n1, n2, n3;
  scanf("%d %d %d",&a,&b,&c);
  if (a<=b && a<=c) { n1 =a;
  if (b<=c) {n2 = b; n3 = c;} else {n2 = c; n3 =b;}
   }
  if (b<=a && b<=c) { n1 =b;
  if (a<=c) {n2 = a; n3 = c;} else {n2 = c; n3 =a;}
   }
  if (c<=b && a>=c) { n1 =c;
  if (a<=b) {n2 = a; n3 = b;} else {n2 = b; n3 =a;}
   }
  printf("%d %d %d\n",n1, n2, n3);

  return 0;
}

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

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

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

ll sum(ll n) {
    return n*(n+1)/2;
}

int main(int argc, char const *argv[]) {
    ll n; std::cin >> n;
    if (n == 0) {
        std::cout << 0 << "\n";
        return 0;
    }
    std::cout << sum(n-1) << "\n";

    return 0;
}


Measured memory_bytes: 256
import math

x = int(input())

l = [1]

for i in range(x, 0, -1):
    if math.sqrt(i).is_integer():
        l.append(i)

    for j in range(2, 20):
        if pow(i, j) <= x:
            l.append(pow(i, j))

print(max(l))

Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"reflect"
	"strconv"
	"strings"
)

var in = newIo(bufio.NewScanner(os.Stdin))

func main() {
	in.setSplit(bufio.ScanLines)
	f := in.nextIntSlice(1, " ")
	n := f[0][0]
	t := f[0][1]
	ct := in.nextIntSlice(n, " ")
	print(format(solve(n, t, ct)))
}

func format(n int) string {
	if n == math.MaxInt32 {
		return "TLE"
	}
	return strconv.Itoa(n)
}

func solve(n int, t int, ct [][]int) int {
	result := math.MaxInt32
	for i := 0; i < len(ct); i++ {
		c1 := ct[i][0]
		t1 := ct[i][1]
		if t1 <= t && c1 < result {
			result = c1
		}
	}
	return result
}

func print(result ...interface{}) {
	for _, r := range result {
		kind := reflect.TypeOf(r).Kind()
		if kind == reflect.Array || kind == reflect.Slice {
			rv := reflect.ValueOf(r)
			cnv := make([]interface{}, rv.Len())
			for i := 0; i < rv.Len(); i++ {
				cnv[i] = rv.Index(i).Interface()
			}
			print(cnv...)
		} else {
			fmt.Println(r)
		}
	}
}

type io struct {
	sc *bufio.Scanner
}

func newIo(sc *bufio.Scanner) *io {
	i := new(io)
	i.sc = sc
	i.sc.Split(bufio.ScanWords)
	return i
}

func (i *io) setSplit(f bufio.SplitFunc) {
	i.sc.Split(f)
}

func (i *io) nextIntSlice(y int, delim string) [][]int {
	result := make([][]int, y)
	for j := 0; j < y; j++ {
		line := i.next()
		result[j] = perseIntSlice(strings.Split(line, delim))
	}
	return result
}

func (i *io) next() string {
	i.sc.Scan()
	return i.sc.Text()
}

func (i *io) nextInt() int {
	return perseInt(i.next())
}

func (i *io) nextLong() int64 {
	return perseLong(i.next())
}

func perseInt(s string) int {
	in, _ := strconv.Atoi(s)
	return in
}

func perseLong(s string) int64 {
	in, _ := strconv.ParseInt(s, 10, 64)
	return in
}

func perseIntSlice(s []string) []int {
	var r = make([]int, len(s))
	for i := 0; i < len(s); i++ {
		r[i] = perseInt(s[i])
	}
	return r
}


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

int main() {
  int A, B;
  cin >> A >> B;
  int N = 0;
  for(int i = A; i <= B; i++) {
    if(i / 10000 == i % 10 && (i / 1000) % 10 == (i / 10) % 10) {
      N++;
    }
  }
  cout << N << endl;
      
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#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
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

long long floor_sum(long long n, long long m, long long a, long long b) {
    long long ans = 0;
    if (a >= m) {
        ans += (n - 1) * n * (a / m) / 2;
        a %= m;
    }
    if (b >= m) {
        ans += n * (b / m);
        b %= m;
    }

    long long y_max = (a * n + b) / m, x_max = (y_max * m - b);
    if (y_max == 0) return ans;
    ans += (n - (x_max + a - 1) / a) * y_max;
    ans += floor_sum(y_max, a, m, (a - x_max % a) % a);
    return ans;
}

int main() {
  int T; cin >> T;
  for (int t = 0; t < T; ++t) {
    LL N, M, A, B; cin >> N >> M >> A >> B;
    cout << floor_sum(N, M, A, B) << endl;
  }
}


Measured memory_bytes: 3568
/*
        Author: Prokash
                CSE48, JU

*/

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

typedef long long ll;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int ara[2005];
int main()
{
    FAST;
    int n,k;
    cin>>n>>k;
    vector<int>v;
    while(n--)
    {
        int in;
        cin>>in;
        v.push_back(in);
    }
    sort(v.begin(),v.end());
    int ans=INT_MAX;
    for(int i=0;i+k<=v.size();i++)
    {
        ans=min(ans,(v[i+k-1]-v[i]));
    }
    cout<<ans<<endl;
    return 0;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;


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

    vector<ll>x(n+1);
    rep(i,n){
        cin>>x[i];
    }
    x[n]=X;

    sort(x.begin(),x.end());

    vector<ll>dis(n);
    rep(i,n){
        dis[i]=x[i+1]-x[i];
    }

    ll ans=dis[0];
    rep2(i,1,n){
        ans=__gcd(ans,dis[i]);
    }

    cout<<ans<<endl;

}



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

int main()
{
	int A[5], B[5], C, i, las, Ans, Q;
	for (i = 0; i < 5; i++)
		cin >> A[i];

	Ans = 0;

	for (i = 0; i < 5; i++) {
		if (A[i] < 10) {
			B[i] = A[i];
		}
		else if (A[i] < 100) {
			C = A[i] / 10;
			B[i] = A[i] - (C * 10);
		}
		else {
			C = (A[i] - 100) / 10;
			B[i] = A[i] - (C * 10) - 100;
		}
		if (B[i] != 0) {
			Q = 10 - B[i];
			A[i] = A[i] + Q;
		}
	}

	for (i = 0, las = 150; i < 5; i++) {
		if (las > B[i] && B[i] != 0)
			las = B[i];
		}
	if (las == 150)
		las = 0;
	for (i = 0; i < 5; i++)
		Ans += A[i];
	if (las != 0)
		Ans = Ans - (10 - las);
	cout << Ans;

	return 0;
}

Measured memory_bytes: 256
import math
import sys
n = int(input())
li = list(map(int, input().split()))
cnt=0
for i in range(n - 2):
    if (li[i+1] > li[i+2] and li[i+1] < li[i] or li[i+1] < li[i + 2] and li[i+1] > li[i]):
        cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
#include<vector>
#define SZ 262144
#define N_ 201000
using namespace std;
int IT[SZ + SZ];
int n, m, cnt;
struct Edge {
	int a, b, c;
	bool operator <(const Edge &p)const {
		return c < p.c;
	}
}E[SZ+SZ];
void Ins(int b, int e, int x) {
	b += SZ, e += SZ;
	while (b <= e) {
		IT[b] = min(IT[b], x);
		IT[e] = min(IT[e], x);
		b = (b + 1) >> 1, e = (e - 1) >> 1;
	}
}
void Put(int a, int b) {
	Ins(a, n - 1, b - a*2);
	Ins(0, a - 1, b - a*2 + n*2);
}
int UF[N_];
int Find(int a) {
	if (a == UF[a])return a;
	return UF[a] = Find(UF[a]);
}
int main() {
	int i, a, b, c;
	for (i = 1; i < SZ + SZ; i++)IT[i] = 2e9;
	scanf("%d%d", &n, &m);
	while (m--) {
		scanf("%d%d%d", &a, &b, &c);
		E[cnt++] = { a,b,c };
		Put(a, c+1);
		Put(b, c+2);
	}
	for (i = 0; i < n; i++) {
		int x = SZ + i, r = 2e9;
		while (x) {
			r = min(r, IT[x]);
			x >>= 1;
		}
		E[cnt++] = { i,(i + 1)%n,r + i*2 };
	}
	sort(E, E + cnt);
	for (i = 0; i < n; i++)UF[i] = i;
	long long res = 0;
	for (i = 0; i < cnt; i++) {
		int a = Find(E[i].a), b = Find(E[i].b);
		if (a != b) {
			res += E[i].c;
			UF[a] = b;
		}
	}
	printf("%lld\n", res);
}

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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    stack<char> st;

    int ans = 0;
    for(int i = 0;i < n;i++){
        if(st.size() == 0){
            st.push(s[i]);
        }else{
            if(st.top() == s[i]){
                st.push(s[i]);
            }else{
                st.pop();
                ans+=2;
            }
        }
    }

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



Measured memory_bytes: 512
n,k=gets.split.map(&:to_i)
if k==0
  puts n**2
  exit
end
c=0
(k+1).upto(n) do |i|
  c+=(n+1)/i*(i-k)+((n+1)%i>k ? (n+1)%i-k : 0)
end
puts c


Measured memory_bytes: 14328
while True:
    a = b = 0
    n = int(input())
    if n == 0:
            break
    for i in range(n):        
        c, d = map(int, input().split())
        if c > d:
            a+=c+d
        elif c < d:
            b+=c+d
        else:
            a+=c
            b+=d
    print(a, b)


Measured memory_bytes: 5608
x = int(input())
sq = []
for i in range(10**3):
    sq.append(i**5)
    sq.append(-i**5)
b = False
for i in range(len(sq)):
    for j in range(len(sq)-i):
        if sq[-i-1]-sq[j] == x:
            if i%2 == 0:
                m = -1
            else:
                m = 1
            if j%2 == 0:
                n = 1
            else:
                n = -1
            print(m*(1000-(i//2+1)), n*(j//2))
            b = True
            break
    if b:
        break



Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

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

    REP(i, n){
        if(s[i] != s[k - 1]) cout << '*';
        else cout << s[i];
    }
    cout << endl;
    return 0;
}

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

int main(void){
  int i=0;
  int a[100];
  char b[100];

  while(scanf("%s",b) != EOF){
    if(b[0] == '+'){
      a[i-2] = a[i-2] + a[i-1];
      i--;
    }

    else if(b[0] == '-'){
      a[i-2] = a[i-2] - a[i-1];
      i--;
    }

    else if(b[0] == '*'){
      a[i-2] = a[i-2] * a[i-1];
      i--;
    }

    else{
      a[i] = atoi(b);
      i++;
    }
  }
  printf("%d",a[0]);
  printf("\n");
  return 0;
}



Measured memory_bytes: 2140
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, const char * argv[]) {
    char a[10],b[10];
    scanf("%s %s",a,b);
    strcat(a,b);
    int c=atoi(a);
    for(int i=0;i<=10000;i++){
        if(c==i*i){
            printf("Yes");
            return 0;
        }
    }
    printf("No");
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
const int Maxn=100;
int a[Maxn+5];
int main(){
	int n;
	scanf("%d",&n);
	bool flag=1;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(!(a[i]&1)){
			if(a[i]%3!=0&&a[i]%5!=0){
				flag=0;
			}
		}
	}
	if(flag){
		puts("APPROVED");
	}
	else{
		puts("DENIED");
	}
	return 0;
}


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

int main() {
    long n, p;
    cin >> n >> p;

    if (n == 1) {
        cout << p << endl;
        return 0;
    }

    long ans = 1;

    long i = 1;
    while (1) {
        i++;

        long ss = 1;
        for (long j = 0; j < n; j++) {
            ss *= i;
            if (ss > p) {
                break;
            }
        }

        if (ss > p) {
            break;
        }

        if (p % ss == 0) {
            ans = i;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
using namespace std;
int a = 0, b = 0, c = 0, d = 0, e[1050] = {}, f[100010] , counto = 0, counto1 = 1145148;
double syo = 0, su = 0;
char mado[105][105];
string rik;
bool mazi[110], gi[110];
pair<int, int>n[110];
vector<int> r;
int main() 
{
	cin >> rik;
	if (rik[0] != 'A') {
		cout << "WA" << endl;
		return 0;
	}
	//cout << '1' << endl;
	for (int i = 2; i < rik.length()-1; i++) {
		if (rik[i] == 'C') {
			counto++;
		}
	}
	if (counto != 1) {
		cout << "WA" << endl;
		return 0;
	}
	//cout << '2' << endl;
	for (int i = 1; i < rik.length(); i++) {
		if (rik[i] <= 'Z'&&i == 1) {
			cout << "WA" << endl;
			return 0;
		}
		//cout << '1' << endl;
		if (rik[i] <= 'Z'&&i == rik.length() - 1) {
			cout << "WA" << endl;
			return 0;
		}
		//cout << '2' << endl;
		if (rik[i] <= 'Z'&&rik[i] != 'C'&&i >= 2 && i <= rik.length() - 2) {
			cout << "WA" << endl;
			return 0;
		}
	}
	cout << "AC" << endl;
	
	return 0;
}

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

using namespace std;

int main (int argc, char *argv[]) {
    string str, tmp;
    vector<string> v;
    getline(cin, str);
    for (int i = 0; i < str.length(); ++i) {
        if (str[i] == ' ' || str[i] == ',' || str[i] == '.') {
            v.push_back(tmp);
            tmp.clear();
            continue;
        }
        tmp.push_back(str[i]);
    }
    
    bool first = true;
    for (auto ss : v) {
        if (ss.length() > 2 && ss.length() < 7) {
            if (first) {
                cout<<ss; 
                first=false;
            }
            else cout <<" "<<ss;
        }
    }
    cout<<endl;
    return 0;
}


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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;


#define rep(i,n) for(ll i=0;i<n;i++)



int main() {

  cout<<fixed<<setprecision(10);

  string s; cin>>s;



  while( s != "-"){
    ll m; cin>>m;
    vint h(m); rep(i,m)cin>>h[i];
    ll n = s.size();

    rep(i,m){
      s = s.substr(h[i], n-h[i]) + s.substr(0, h[i]);
    }

    cout<<s<<endl;
    cin>>s;
  }




}




//






Measured memory_bytes: 3220
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n,a=0,b=0;
  string s;
  cin >> n >> s;
  for(int i=0;i<n;i++){
    if(s[i]=='('){
      a++;
    }else {
      if(a>0)a--;
      else b++;
    }
  }
  for(int i=0;i<b;i++)cout << '(';
  cout << s;
  for(int i=0;i<a;i++)cout << ')';
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        String S = scanner.next();

        int[] sArray = new int[S.length()];
        int[] zeroArray = new int[S.length()];
        int[] oneArray = new int[S.length()];

        for(int i=0; i<sArray.length; i++){
            if(S.charAt(i) == '0'){
                sArray[i] = 0;
            }else{
                sArray[i] = 1;
            }

            if(i % 2 == 0){
                zeroArray[i] = 0;
                oneArray[i] = 1;
            }else{
                zeroArray[i] = 1;
                oneArray[i] = 0;
            }
        }

        int oneDiff = 0;
        int zeroDIff = 0;

        for(int i=0; i<sArray.length; i++){
            if(sArray[i] != oneArray[i]){
                oneDiff++;
            }

            if(sArray[i] != zeroArray[i]){
                zeroDIff++;
            }
        }

        System.out.println(Math.min(oneDiff, zeroDIff));
    }
}


Measured memory_bytes: 26092
#include <bits/stdc++.h>
using namespace std;
template <class c> struct rge { c b, e; };
template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; }
template <class c> auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c> char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
template <class c> typename enable_if<sizeof dud<c>(0)!=1, debug&>::type operator<<(c i) {cerr << boolalpha << i; return * this; }
template <class c> typename enable_if<sizeof dud<c>(0)==1, debug&>::type operator<<(c i) {return * this << range(begin(i), end(i)); }
template <class c, class b> debug & operator <<(pair < b, c > d) {
  return * this << "(" << d.first << ", " << d.second << ")";
}
template <class c> debug & operator <<(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  return * this << "]";
}
#else
template <class c> debug & operator <<(const c&) { return * this; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


typedef long long ll;
typedef long double ld;

#define ar array

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound 

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

int main() {
    int n;
    cin >> n;
    switch(n%10) {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            cout << "hon" << endl; 
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            cout << "pon" << endl;
            break;
        case 3:
            cout << "bon\n";
    }
    return 0;    
}


Measured memory_bytes: 3664
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int solve(int n) {
  int ret = 1;
  for (int b = 1; b < n; ++b) {
    for (int p = 2; p < n; ++p) {
      int v = pow(b, p);
      // cout << v << endl;
      if (v > n) {
        break;
      }
      ret = max(ret, v);
    }
  }
  return ret;
}

int main() {
  int x;
  cin >> x;
  cout << solve(x) << endl;
}


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

vector<vector<int> > rot = {
	{0,1,2,3,4,5}, {0,2,4,1,3,5}, {0,4,3,2,1,5}, {0,3,1,4,2,5},
	{1,5,2,3,0,4}, {1,2,0,5,3,4}, {1,0,3,2,5,4}, {1,3,5,0,2,4},
	{2,5,4,1,0,3}, {2,4,0,5,1,3}, {2,0,1,4,5,3}, {2,1,5,0,4,3},
	{3,4,5,0,1,2}, {3,5,1,4,0,2}, {3,1,0,5,4,2}, {3,0,4,1,5,2},
	{4,0,2,3,5,1}, {4,2,5,0,3,1}, {4,5,3,2,0,1}, {4,3,0,5,2,1},
	{5,4,2,3,1,0}, {5,2,1,4,3,0}, {5,1,3,2,4,0}, {5,3,4,1,2,0}
};

vector<vector<vector<int> > > cond = {
	{},
	{{3,0,2}},
	{{1,1,4}},
	{{1,0,4},{2,2,3}},
	{{0,3,5}},
	{{0,2,5},{3,4,2}},
	{{0,1,5},{4,5,1}},
	{{0,0,5},{2,6,3},{4,4,1}}
};

struct State { int id, r; };
State pz[8];

string dice[8];
bool used[8];
bool adj[8][8];

char toggleCase(char c) {
	if (islower(c)) return toupper(c);
	return tolower(c);
}

string solve(int x) {
	if (x == 8) return "YES";
	for (int i=1; i<8; ++i) {
		if (used[i] || !adj[i][pz[x-1].id]) continue;
		for (int j=0; j<24; ++j) {
			pz[x].id = i;
			pz[x].r = j;
			bool ok = true;
			for (int k=0; k<(int)cond[x].size(); ++k) {
				int bloc1 = x;
				int face1 = rot[pz[bloc1].r][cond[x][k][0]];
				int bloc2 = cond[x][k][1];
				int face2 = rot[pz[bloc2].r][cond[x][k][2]];
				if (toggleCase(dice[pz[bloc1].id][face1]) != dice[pz[bloc2].id][face2]) {
					ok = false; break;
				}
			}
			if (ok) {
				used[i] = true;
				if (solve(x+1) == "YES") return "YES";
				used[i] = false;
			}
		}
	}
	return "NO";
}

int main() {
	while (cin >> dice[0], dice[0] != "0") {
		for (int i=1; i<8; ++i) {
			cin >> dice[i];
		}
		for (int i=0; i<8; ++i) {
			for (int j=i+1; j<8; ++j) {
				bool ok = false;
				for (int k=0; k<6 && !ok; ++k) {
					for (int l=0; l<6 && !ok; ++l) {
						if (toggleCase(dice[i][k]) == dice[j][l]) ok = true;
					}
				}
				adj[i][j] = adj[j][i] = ok;
			}
		}
		memset(used, false, sizeof used);
		used[0] = true;
		pz[0].id = 0;
		string res = "NO";
		for (int i=0; i<24; ++i) {
			pz[0].r = i;
			if (solve(1) == "YES") {
				res = "YES"; break;
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXLEN = 5;

char s[MAXLEN + 1]; int n;

bool solve() {
	REP(i, n - 1) if (s[i] == 'A'&&s[i + 1] == 'C') return true;
	return false;
}

void run() {
	scanf("%s", &s); n = strlen(s);
	printf("%s\n", solve() ? "Yes" : "No");
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 256
/**
 *   author: sahushivam
 *   created: 23 January 2019  09:22:56
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

#define REP(i, a, b) for(int i = a; i < b; i++)
#define RREP(i, a, b) for(int i = a-1; i >= b; i--)
#define PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff

void optimizeIO(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
}

int main(){
    optimizeIO();
    int n;
    cin>>n;
    int *h=new int[n];
    int *dp=new int[n];
    REP(i,0,n)cin>>h[i];
    dp[0]=0;
    dp[1]=abs(h[0]-h[1]);
    REP(i,2,n){
    	dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
    }
    cout<<dp[n-1];
return 0;
}

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

#define fto(i, x, y) for(auto i = (x); i <= (y); ++i)
#define fdto(i, x, y) for(auto i = (x); i >= (y); --i)
#define ftoa(i, x, y, a) for(auto i = (x); i <= (y); i += a)
#define ftoit(it, var) for (auto it = var.begin(); it != var.end(); ++it)

#define ii pair<int, int>
#define mp make_pair
#define ff first
#define ss second

#define vi vector<int>
#define vii vector<ii>
#define ll long long
#define vll vector<ll>

#define eb emplace_back
#define ef emplace_front
#define lb lower_bound
#define ub upper_bound

#define oo 1000000007
#define OO 1000000000000000007LL

using namespace std;

#define Pro "tmp"
#define maxN 1000007

int pSet[maxN];

int findSet(int i) {
    return pSet[i] == i ? i : pSet[i] = findSet(pSet[i]);
}

void unionSet(int x, int y) {
    pSet[findSet(x)] = findSet(y);
    return;
}

int main() {
    int n, m;
    scanf("%d%d", &n, &m);

    fto(i, 1, n) pSet[i] = i;
    fto(i, 1, m) {
        int x, y, z;
        scanf("%d%d%d", &x, &y, &z);
        unionSet(x, y);
    }

    set <int> st;
    fto(i, 1, n) st.insert(findSet(i));

    printf("%d\n", (int)st.size());
    return 0;
} 

Measured memory_bytes: 5376
import sys
import math
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
a,b,c=get_ints()
k=int(input())
flag=0
for i in range(k+1):
    if b>a and c>b:
        flag=1
        break
    else:
        if b<=a:
            b=b*2
        else:
            c=c*2
if flag==1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 61984
#pragma warning(disable:4996)
#include <stdio.h>

int main() {
	int n, k;
	char s[51];
	
	scanf("%d %d", &n, &k);
	scanf("%s", s);
	/*
	printf("%d %d", 'a', 'A');
	while (1);
	*/
	s[k-1] += 32;
	printf("%s", s);
}

Measured memory_bytes: 128
MOD = 10**9 + 7
import sys
from itertools import accumulate
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))

cs = accumulate(A)

ans = 0
for s,t in zip(cs, A[1:]):
    ans += s * t
    ans %= MOD

print(ans)





Measured memory_bytes: 92036
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 100005
#define rep(i,j,k) for(i=j;i<=k;++i)
int ans,odd,n,m,i,j,k;
int a[N],b[N],pos[3];
void read(int &p){
	p=0; char x=getchar();
	while(x<'0' || x>'9') x=getchar();
	while(x>='0'&&x<='9'){p=p*10+x-'0'; x=getchar();}
}
int main(){
//	freopen("in.txt","r",stdin);
	read(n); read(m);
	rep(i,1,m){
		read(a[i]);
		if(a[i]&1){
			odd++;
			if(odd>2) {puts("Impossible"); return 0;}
			pos[odd]=i;
		}
	}
	if(pos[1]) swap(a[1],a[pos[1]]);
	if(pos[2]) swap(a[m],a[pos[2]]);
	if(odd==0){
		b[ans=1]=1;
		rep(i,1,m) ans++,b[ans]=a[i];
		b[ans]--;
	}
	if(odd==1){
		rep(i,1,a[1]>>1) ans++,b[ans]=2;
		rep(i,2,m) ans++,b[ans]=a[i];
		ans++; b[ans]=1;
	}
	if(odd==2){
		rep(i,1,a[1]>>1) ans++,b[ans]=2;
		rep(i,2,m-1) ans++,b[ans]=a[i];
		ans++; b[ans]=2;
		rep(i,1,a[m]>>1) ans++,b[ans]=2;
	}
	rep(i,1,m) 
	if(i<m) printf("%d ",a[i]);
	else printf("%d\n",a[i]);
	printf("%d\n",ans);
	rep(i,1,ans)
	if(i<ans) printf("%d ",b[i]);
	else printf("%d\n",b[i]);
	return 0;
} 

Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
int main(){
  int h,w,i,j,k;
  scanf("%d%d",&h,&w);
  char s[h+1][w+1];
  int high[h+1][w+1],width[h+1][w+1];
  for(i=0;i<h;i++)
    scanf("%s",s[i]);
  for(i=0;i<h;i++)
    for(j=0;j<w;j++){
      high[i][j]=0;
      width[i][j]=0;
    }
  for(i=0;i<h;i++)
    for(j=0;j<w;j++){
      if(s[i][j]=='#')
        width[i][j]=0;
      else{
        int count=1;
        for(k=j+1;k<w;k++){
          if(s[i][k]!='#')
            count++;
          else
            break;
        }
        for(k=j;k<j+count;k++)
          width[i][k]=count;
        j+=count-1;
      }
    }
  for(j=0;j<w;j++)
    for(i=0;i<h;i++){
      if(s[i][j]=='#')
        high[i][j]=0;
      else{
        int count=1;
        for(k=i+1;k<h;k++){
          if(s[k][j]!='#')
            count++;
          else
            break;
        }
        for(k=i;k<i+count;k++)
          high[k][j]=count;
        i+=count-1;
      }
    }
  int max=0;
  for(i=0;i<h;i++)
    for(j=0;j<w;j++){
      if(high[i][j]==0 || width[i][j]==0){
        if(max<high[i][j]+width[i][j])
          max=high[i][j]+width[i][j];
      }
      else{
        if(max<high[i][j]+width[i][j]-1)
          max=high[i][j]+width[i][j]-1;
      }
    }
  printf("%d\n",max);
  return 0;
}


Measured memory_bytes: 35328
#include<bits/stdc++.h> 
using namespace std; 
#define int long long
const int mod = 1e9 + 7, maxn = 2e5 + 10;

int add(int a, int b){
	if(a + b >= mod){
		return a + b - mod;
	}
	return a + b;
}

int sub(int a, int b){
	if(a - b >= 0){
		return a - b;
	}
	return a - b + mod;
}

int mul(int a, int b){
	return (a * b) % mod;
}

int my_pow(int n, int k){
	if(k == 0) return 1;
	long long a = my_pow(n, k / 2);
	a = mul(a, a);
	if(k % 2) a = mul(a, n);
	return a;
}

int divide(int a, int b){
	return mul(a, my_pow(b, mod - 2));
}


int choose(int n, int k){
	int ret = 1;
	for(int i = 1; i <= k; i++){
		ret = mul(ret, divide(sub(add(n, 1), i), i));
	}
	return ret;
}
int fac[maxn];
int32_t main(){
	int n, a, b; cin>>n>>a>>b;
	int ans = sub(my_pow(2, n),  1);
	// the number of way to choose x flower out of n types of flowers(it must not be empty
	
	ans = sub(ans, choose(n, a));// minus the number of ways to choose a number of flowers
	ans = sub(ans, choose(n, b));
	cout<<ans<<endl;
}


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

using db = double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back

string trans(string s, int a, int b) {
	for(auto &c : s) if(isalpha(c)) {
		int t = c - 'a';
		t = (t * a + b) % 26;
		c = t + 'a';
	}
	return s;
}

int main() {
	ios :: sync_with_stdio(0);

	int n; cin >> n;
	string s; getline(cin, s);
	while(n --) {
		getline(cin, s);
		for(int a = 1; a < 26; a ++)
			for(int b = 0; b < 26; b ++) if(__gcd(a, 26) == 1) {
				string t = trans(s, a, b);
				bool f = 0;
				for(int i = 0; i < t.size(); i ++)
					if(t.substr(i, 4) == "this" || t.substr(i, 4) == "that")
						f = 1;
				if(f) {
					cout << t << '\n';
					goto done;
				}
			}
		done: ;
	}

	return 0;
}

Measured memory_bytes: 3132
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	n := getInt()
	m := [26]int{}
	for j := 0; j < 26; j++ {
		m[j] = 100
	}
	for i := 0; i < n; i++ {
		s := getString()
		x := [26]int{}
		for _, v := range s {
			x[int(v-'a')]++
		}
		for j := 0; j < 26; j++ {
			m[j] = min(m[j], x[j])
		}
	}

	for i := 0; i < 26; i++ {
		for j := 0; j < m[i]; j++ {
			fmt.Print(string(i + 'a'))
		}
	}
	out()
}


Measured memory_bytes: 640
N = int(input())
S = input()

east = [0]*N
west = [0]*N
for i in range(N):
    if S[i] == 'E':
        east[i] = 1
    else:
        west[i] = 1

sum_east = [0]*(N+1)
sum_west = [0]*(N+1)
for i in range(N):
    sum_west[i+1] = sum_west[i] + west[i]
    sum_east[N-i-1] = sum_east[N-i] + east[N-i-1]
#print(sum_west, sum_east)

ans = 10**6
for i in range(N):
    ans = min(ans, sum_west[i] + sum_east[i+1])
    #print(ans)

print(ans)


Measured memory_bytes: 31820
using System;

class _0135 {
    static readonly double hr = 360.0 / 12.0 / 60.0;
    static readonly double mr = 360.0 / 60.0;
    public static void Main() {
        string[] strs;
        double time, snr, lnr, ang;
        int n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++) {
            strs = Console.ReadLine().Split(':');
            time = double.Parse(strs[0]) * 60 + double.Parse(strs[1]);
            snr = time * hr;
            while (snr > 360) snr -= 360;
            lnr = time * mr;
            while (lnr > 360) lnr -= 360;
            ang = (Math.Abs(lnr - snr) > 180) ? 360 - Math.Abs(lnr - snr) : Math.Abs(lnr - snr);
            if (ang < 30)
                Console.WriteLine("alert");
            else if (90 <= ang && ang <= 180)
                Console.WriteLine("safe");
            else
                Console.WriteLine("warning");
        }
    }
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, d;
  cin >> n >> d;
  
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    if (x * x + y * y <= d * d) ans++;
  }
  
  cout << ans << '\n';
}

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

typedef long long ll;


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

int main() {
	ll a, b; cin >> a >> b;
	ll maxNum = gcd(a, b);

	ll ans = 1;
	for (ll i = 2; i*i <= maxNum; i++) {
		if (maxNum % i == 0) {
			ans++;
			while (maxNum % i == 0) {
				maxNum /= i;
			}
		}
	}
	if (maxNum != 1)ans++;
	cout << ans<< endl;
	
	return 0;
}

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

int main(){
    int n = 0, m = 0;

    std::cin >> n >> m;

    if(n==m){
     std::cout <<"Yes"<< std::endl;   
    }
    else{
        std::cout <<"No"<<std::endl;
    }
    return 0;
}


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

int main(){
  int x,y;
  char s[100];
  int stack[100];
  int n=0;

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      x = stack[--n];
      y = stack[--n];
      stack[n++] = x+y;
    } else if ( s[0] == '-' ){
      x = stack[--n];
      y = stack[--n];
      stack[n++] = y - x;
    } else if ( s[0] == '*' ){
      x = stack[--n];
      y = stack[--n];
      stack[n++]=x*y;
    } else {
      x = atoi(s);
      stack[n] = x;
      n++;

    }
  }
  printf("%d\n",stack[--n]);

  return 0;
}

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

typedef struct {
  double x,y;
} P;

void print(P p) {
  printf("%f %f\n", p.x, p.y);
}

double deg = M_PI / 3;

void kock(int n, P p1, P p2) {
  if(!n) return;
  P s = {(2 * p1.x + 1 * p2.x) / 3,
	 (2 * p1.y + 1 * p2.y) / 3};
  P t = {(1 * p1.x + 2 * p2.x) / 3,
	 (1 * p1.y + 2 * p2.y) / 3};
  P u = {(t.x - s.x) * cos(deg) - (t.y - s.y) * sin(deg) + s.x,
	 (t.x - s.x) * sin(deg) - (t.y - s.y) * cos(deg) + t.y};
  kock(n - 1, p1, s);
  print(s);
  kock(n - 1, s, u);
  print(u);
  kock(n - 1, u, t);
  print(t);
  kock(n - 1, t, p2);
}

int main() {
  int n;
  P p1 = {0, 0}, p2 = {100, 0};
  scanf("%d", &n);
  print(p1);
  kock(n, p1, p2);
  print(p2);
  return 0;
}



Measured memory_bytes: 1996