akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();


int main() {
    int n, k, x, y;
    vector<vector<ll>> arr;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        cin >> x >> y;
        arr.push_back({x, y});
    }
    sort(arr.begin(), arr.end());
    ll area = ll(INT_MAX) * ll(INT_MAX-2);
    // cout << area << endl;
    for(int i = 0; i < n; i++) {
        for(int j = i+k-1; j < n; j++) {
            if (j-i+1 < k) continue;
            vector<int> ys;
            for(int k2 = i; k2 <= j; k2++)
                ys.push_back(arr[k2][1]);
            sort(ys.begin(), ys.end());
            // cout << ys.size() << endl;
            // cout << arr[i][0] << "~" << arr[j][0] << endl;
            ll width = llabs(arr[j][0]-arr[i][0]);
            for(int yy = 0; yy <= ys.size()-k; yy++) {
                //cout << ys[yy] << "~y " << ys[yy+k-1] << endl;
                //cout << "area " << width*llabs(ys[yy+k-1]-ys[yy]) << endl;
                area = min(area, width*llabs(ys[yy+k-1]-ys[yy]));
            }
        }
    }
    cout << area << endl;
    return 0;
}




Measured memory_bytes: 256
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

x10,a = map(int,input().split())
xa = Base_10_to_n(x10, a)
print( len(xa) )

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int n = N;

		int count = 0;

		while(n > 0) {
			count = count + (n % 10);
			n = n / 10;
		}

		if(N % count == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 19796
#include<bits/stdc++.h>
using namespace std;
int dp[1405][1405];
int main(){
    int h, w; cin >> h >> w;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            bool c; cin >> c;
            dp[i][j] = !c;
        }
    }
    for (int i = 1; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            dp[i][j] = dp[i-1][j] * dp[i][j] + dp[i][j];
        }
    }
    
    stack<pair<int, int>> S;
    int ans = 0;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j <= w; j++)
        {  
            if (S.empty()){S.push(make_pair(dp[i][j], j));continue;}

            if (S.top().first < dp[i][j])
            {
                S.push(make_pair(dp[i][j], j));
            }else if(S.top().first > dp[i][j])
            {
                int target = j;
                while ((!S.empty()) && S.top().first >= dp[i][j])
                {
                    pair<int,int> num = S.top();S.pop();
                    ans = max(ans, (j-num.second) * num.first);
                    target = num.second;
                }
                S.push(make_pair(dp[i][j], target));
            }
        }
        
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 10768
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i=k;i<n;i++)
using namespace std;
int main(){
  int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  int ans;
  if(x<y){
    ans = min((x*a + y*b),(c*x*2+b*(y-x)));
    ans = min(ans,(c*y*2));
  }else{
    ans = min((x*a + y*b),(c*y*2+a*(x-y)));
    ans = min(ans,(c*x*2));
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
	while(1){
		int x, y;
		cin >> x >> y;
		if(x==0 && y==0) break;
		
		if(x>y){
			int tmp = x;
			x = y;
			y = tmp;
		}
		cout << x << " " << y <<endl;
	}
}


Measured memory_bytes: 3040
#include<bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{

#if !ONLINE_JUDGE

	freopen("in1.txt", "r", stdin);
	freopen("out1.txt", "w" , stdout);

#endif

	int n;
	cin >> n;
	string S;
	cin >> S;
	int x = 0;
	int maxi = 0;
	for (int i = 0; i < n; ++i)
	{
		if (S[i] == 'I')
		{
			x++;
		}
		else {
			x--;
		}
		maxi = max(maxi, x);
		/* code */
	}
	cout << maxi << endl;






	return 0;
}

Measured memory_bytes: 3580
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int prev = 0;
		long count = 0;
		for (int i = 1; i <= n; i++) {
		    int x = sc.nextInt();
		    count += Math.max(x - prev, 0);
		    prev = x;
		}
		System.out.println(count);
   }
}


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

using namespace std;

int main(){

int  x;
  cin>>x;
  int arr[x+1] = {};
  arr[0]=1;
  for(int i=0;i<=x;i++){
  	if(arr[i]==1){
      for(int j=100;j<=105;j++) if(i+j<=x)arr[i+j]=1;
    }
  }
  cout<<arr[x];
  return 0;
  
  
  
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    int N; cin >> N;
    vector<int> B(N+1);
    int INF = 10000000;
    B[0] = INF;
    B[N] = INF;
    for (int i = 1; i <= N-1; i++) {
        cin >> B[i];
    }

    Int ans = 0;
    for (int i = 0; i < N; i++) {
        ans += min(B[i], B[i+1]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 888
from math import *

def check(a,b,mid):
   # if mid>pi/2-ep:
    #    return 0
  #  aa=tanh(90-mid)*b
    if a*tan(mid)<=b:
        ans=a*a*b
        aa=a*tan(mid)*a*a
        ans-=(aa)/2.0
    else:
        
        ans=(a*b*b/tan(mid))/2.0
    return ans
        
a,b,x=map(int,input().split())

low=0
high=pi/2
ep=0.0000000001
while low<high and high-low>=ep:
    mid=(low+high)/2
   # print(mid)
    st=check(a,b,mid)
   # print(st)
    
    if st<x:
        high=mid
    else:
        low=mid
print(low/pi*180)
    

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

using namespace std;

const int MAX = 100005;

string s; int n = 0;

bool check(int k) {
	// k to n is fixed
	// 0 to n-k-1 fixed
	// unfixed: n-k to k-1
	for (int i=n-k; i<=k-1; i++) {
		if (s[i] != s[n-k]) { return false; }
	}
	return true;
}
int main() {
	// freopen("a.in", "r", stdin);
	cin >> s;
	n = s.length();
	int lo = 1;
	int hi = n;
	while (lo < hi) {
		int mid = (lo + hi + 1) / 2;
		if (check(mid)) { lo = mid; }
		else { hi = mid - 1; }
	}
	cout << lo << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;



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

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    ll A; double B; cin >> A >> B;
    ll C = B * 100 + 0.5;
    ll res = A * C;
    cout << res / 100 << endl;
}

Measured memory_bytes: 3704
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
    string s;
    int k;
    cin >> s >> k;
    int l=-1;
    for (auto &c:s) {
        int opp = ('z' - c + 1) % 26;
        if (opp <= k) {
            k -= opp;
            c = 'a';
        }
        l++;
    }
    s[l] = (s[l] - 'a' + k) % 26 + 'a';
    cout << s << '\n';
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define fast_io cin.tie(0);ios_base::sync_with_stdio(0);
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cout << endl; }
void show() { cout << endl; }
void pret() { cout << endl; exit(0);}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cout << " " << to_string(H); debug_out(T...);}
template <typename Head, typename... Tail> void show(Head H, Tail... T) {cout <<H<<" "; show(T...);}
template <typename Head, typename... Tail> void pret(Head H, Tail... T) {cout <<H<<" "; pret(T...);}
#define pr(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
typedef long long ll;
// #define int ll
typedef long double ld;
#define disp(x) cout<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(int)b;i++)
#define fo(i,a,b) for(int i=a;i<=(int)b;i++)
#define rf(i,a,b) for(int i=a;i>=(int)b;i--)
#define mp make_pair
#define pb emplace_back
#define F first
#define S second
#define endl '\n'
//cout.setf(ios::fixed);cout.precision(18)
const int MOD = 1e9+7;
const int maxn = 100000+10;

vector<pair<int, int> > v[maxn];
int ans[maxn], value;

void dfs(int id, int par, int exclude){
	int curr = 1;
	for(const auto &it:v[id]){
		if(it.first == par) continue;
		if(curr == exclude) curr++;
		ans[it.second] = curr++;
		value = max(value, curr - 1);
		dfs(it.first, id, curr - 1);
	}
}

int32_t main(){
	fast_io;
	int n;
	cin >> n;
	for (int i = 0; i < n - 1; ++i)
	{
		int x, y;
		cin >> x >> y;
		v[x].emplace_back(y, i);
		v[y].emplace_back(x, i);
	}
	dfs(1, -1, -1);
	show(value);
	for (int i = 0; i < n - 1; ++i)
	{
		show(ans[i]);
	}
	return 0;
}

Measured memory_bytes: 12548
#include <iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(true) {
        int h, w;
        cin>>h>>w;
        if(h==0 && w==0) break;
        for(int i=0; i<h; i++) {
            for(int j=0; j<w; j++) {
                if((i+j)&1) cout<<'.';
                else cout<<'#';
            }
            cout<<'\n';
        }
        cout<<'\n';
    }
    return 0;
}

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

string a;
int main()
{
    cin >> a;
    for (int i = 0; i < 19; i++) {
        if (i == 5 || i == 13) {
            cout << " ";
        } else {
            cout << a[i];
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
lis = list(map(int, input().split()))
mot = sum(lis)
liss = sorted(lis, reverse=True)

flag = True
for a in range(m):
    if liss[a] * 4 * m < mot:
        flag = False

if flag:
    print("Yes")
else:
    print("No")


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

const int mod = 1000000007;

int main() {
  int n, r;
  cin >> n >> r;
  if (n < 10) {
    cout << r + 100 * (10 - n) << endl;
  } else {
    cout << r << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        int N = Utils.ReadInts()[0];
        int[] S = Utils.ReadInts();

        bool result = Solve(N, S);

        Utils.ReturnYesOrNo(result);
    }

    private static bool Solve(int n, int[] vals)
    {
        Array.Sort(vals, IntDisComparetor.Instance);
        List<int> slimes = new List<int>();
        slimes.Add(vals[0]);
        vals[0] = int.MaxValue;
        int cnt = 0;
        for(int slimeNum = 1; slimeNum < vals.Length;)
        {
            cnt++;
            int index = 0;
            for(int i = 0; i < slimeNum; i++)
            {
                int item = slimes[i];
                bool exists = false;
                for(int x = index + 1; x < vals.Length; x++)
                {
                    if(vals[x] < item)
                    {
                        index = x;
                        slimes.Add(vals[index]);
                        vals[index] = int.MaxValue;
                        exists = true;
                        break;
                    }
                }
                if (!exists) return false;
                //index = Utils.FindFirstIndex(vals, p => p < item, index + 1);
                //if (index < 0) return false;

                //slimes.Add(vals[index]);
                //vals[index] = int.MaxValue;

            }
            slimes.Sort(IntDisComparetor.Instance);
            slimeNum = slimes.Count;
        }
        return (cnt == n);
    }
}

static class Utils
{
    public static int[] ReadInts()
    {
        return Console.ReadLine().Split().Select(int.Parse).ToArray();
    }

    public static int FindFirstIndex<T>(IList<T> source, Func<T, bool> func, int start)
    {
        for(int i = start; i < source.Count; i++)
        {
            if (func(source[i]))
            {
                return i;
            }
        }
        return -1;
    }

    public static void ReturnYesOrNo(bool result)
    {
        Console.WriteLine(result ? "Yes" : "No");
        Console.ReadLine();
    }
}

class IntDisComparetor : IComparer<int>
{
    public static IComparer<int> Instance { get; } = new IntDisComparetor();
    private IntDisComparetor()
    {

    }
    public int Compare(int x, int y)
    {
        return Comparer<int>.Default.Compare(y, x);
    }

}

Measured memory_bytes: 43172
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(){
        
    ios_base::sync_with_stdio(0);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int k,x;
    cin>>k>>x;
    for(int i=-(k-1);i<=(k-1);i++){
        cout<<x+i<<" ";
    }
    cout<<"\n";
    return 0;
}



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

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

  ll N; cin >> N;
  ll A; cin >> A;
  ll B; cin >> B;

  if ((B - A) % 2ll == 0) {
    cout << (B - A) / 2ll << '\n';
  } else {
    // ll ans1 = min(N - A - 1ll, B - 1ll);
    // ll ans2 = min(A + (B - A + 1ll) / 2ll, (N - B + 1ll) + (B - A + 1ll) / 2ll);
    ll ans = min(A + (B - A - 1ll) / 2ll, (N - B + 1ll) + (B - A - 1ll) / 2ll);
    cout << ans << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin 
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn atack(h : u64) -> u64 {
    if h == 1 {
        return 1;
    }else{
        return 2 * atack(h/2) + 1;
    }
}

fn main() {
    let h : u64 = read();
    let a : u64 = atack(h);

    println!("{}", a);

}


Measured memory_bytes: 4352
n,m=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
a=sorted(a)
diff=[]
bc=[]
for i in range(m):
    b,c=[int(x) for x in input().split()]
    bc.append((b,c))
bc=sorted(bc,key=lambda x : x[1],reverse=True)
# print(bc)
for b,c in bc:
    if len(diff)<=n:
        diff+=[c]*b
diff+=[0]*(n-len(diff))
# print(a)
# print(diff)
ans=[]
for i in range(n):
    ans.append(max(a[i],diff[i]))
print(sum(ans))

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

int main()
{
    string s;
    cin >> s;
    vector<int> a(26,0);
    string ans = "yes";
    for(int i=0;i<s.size();i++){
        if(a[s[i]-'a'] == 1){
            ans = "no";
            break;
        }
        a[s[i]-'a'] = 1;
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"

int main() {
	string st;
	while (getline(cin,st)) {
		string a, b; 
		a = st.substr(0, st.find(" "));
		b = st.substr(st.find(" ") + 1);
		int aa = stoi(a); int bb = stoi(b);

		cout <<to_string(aa+bb).size() << endl;
	}
	return 0;
}

Measured memory_bytes: 3244
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
struct node{
	double x,y;
}a,b;
node operator - (node a,node b)
{
	return (node){a.x-b.x,a.y-b.y};
}
double DJ(node a,node b)
{
	return a.x*b.x+a.y*b.y;
}
double CJ(node a,node b)
{
	return a.x*b.y-a.y*b.x;
}
double len(node a)
{
	return a.x*a.x+a.y*a.y;
}
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
signed main()
{
	a=(node){read(),read()};
	b=(node){read(),read()};
	int n=read();
	while(n--)
	{
		node c=(node){read(),read()};
		int x=CJ(b-a,c-a);
		if(x>0){puts("COUNTER_CLOCKWISE");continue;}
		if(x<0){puts("CLOCKWISE");continue;}
		int y=DJ(b-a,c-a);
		if(y<0){puts("ONLINE_BACK");continue;}
		double ma=max(len(c-a),len(c-b));
		if(ma>len(b-a)){puts("ONLINE_FRONT");continue;}
		if(ma<=len(b-a)){puts("ON_SEGMENT");continue;}
	}
	return 0;
}


Measured memory_bytes: 3104
#include <stdio.h>
#include <stdlib.h>
int main() {
  int *a,n,j,i,minj;
  int count=0,tmp=0;
  scanf("%d",&n);
  a=(int *)malloc(sizeof(int)*n);
  for(i=0;i<n;i++){
      scanf("%d",&a[i]);
  }
  for (i = 0; i < n-1; i++) {
    minj=i;
    for (j = i ; j <n ; j++) {
      if (a[minj]>a[j]) {
        minj=j;}}
        tmp=a[i];
        a[i]=a[minj];
        a[minj]=tmp;
        if (i!=minj) count++;
  }
    for(i=0;i<n;i++){
      if (i!=n-1) printf("%d ",a[i]);
      else printf("%d\n",a[i]);
    }
    printf("%d\n",count);
  return 0;
}



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

using namespace std;

int p[100010];

void init(int n)
{
    for(int i=0;i<n;i++)
    {
        p[i]=i;
    }
}

int fnd(int x)
{
    if(p[x]!=x)
    {
        p[x]=fnd(p[x]);
    }
    return p[x];
}

void unit(int a,int b)
{
    int fa=fnd(a),fb=fnd(b);

    if(fa!=fb)
    {
        p[fa]=fb;
    }
}

bool same(int a,int b)
{
    return fnd(a)==fnd(b);
}

int main()
{

    int n,m,q;

    cin>>n>>m;

    init(n);

    int a,b;
    for(int i=0;i<m;i++)
    {
        cin>>a>>b;
        unit(a,b);
    }

    cin>>q;

    for(int i=0;i<q;i++)
    {
        cin>>a>>b;

        if(same(a,b))
        {
            cout<<"yes"<<endl;
        }else
        {
            cout<<"no"<<endl;
        }
    }





    return 0;
}



Measured memory_bytes: 4104
using System;

public class p0554
{
	p0554(){
		string str;
		int tm;
		
		while((str=Console.ReadLine())!=null){
			tm = int.Parse(str);
			
			for(int i = 0; i < 3; ++i)
				tm += int.Parse(Console.ReadLine());
			
			Console.WriteLine("{0}\n{1}", tm/60, tm%60);
		}
	}
	
	public static int Main (string[] args)
	{
		new p0554 ();
		return 0;
	}
}

Measured memory_bytes: 5636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
const ll inf=1e18;

int main() {
  ll n,l;
  cin >> n >> l;
  vec a(n);
  for(ll i=0;i<n;i++) {
    cin >> a[i];
  }
  ll pos=-1;
  for(ll i=0;i<n-1;i++) {
    if(a[i]+a[i+1]>=l) {
      pos=i;
    }
  }
  if(pos==-1) {
    cout << "Impossible" << endl;
    return 0;
  }
  cout << "Possible" << endl;
  for(ll i=0;i<pos;i++) {
    cout << i+1 << endl;
  }
  for(ll j=n-2;j>pos;j--) {
    cout << j+1 << endl;
  }
  cout << pos+1 << endl;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define rep(i,a,b) for (int i=(a); i<(b); i++)
#define per(i,a,b) for (int i=(b-1); i>=(a); i--)
#define debug(x) cout << #x << " => " << x << endl
using namespace std;

#define fi first
#define se second
#define mp make_pair
typedef pair<int,int> pii;

#define pb push_back
typedef vector<int> vi;

typedef long long ll;
typedef long double ld;

///----------------------------------------------
bool hat[20];
int main() {

	///read
	int n,k; cin>>n>>k;
	rep(i,0,k) {
		int dig; scanf("%d",&dig);
		hat[dig]=true;
	}

	///prework
	rep(i,n,100000) {
		bool can=true;
		for (int tmp=i; tmp; tmp/=10) if (hat[tmp%10]) {
			can=false;
			break;
		}
		if (can) {
			cout << i;
			return 0;
		}
	}



}

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

typedef long long ll;

using namespace std;

const ll MOD = 1e9 + 7;
const ll INF = 1e12;

int main(){
  ll i,j,k,n,m;
  cin >> n;
  vector<pair<ll, ll> > v(n);
  for (i = 0; i < n; i++){
      cin >> v[i].second >> v[i].first;
  }
  sort(v.begin(), v.end());
  ll ret = 0;
  for (i = 0; i < n;i++){
      ret += v[i].second;
      if(ret>v[i].first){
          cout << "No" << endl;
          return 0;
      }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3328
n,m,q=map(int,input().split())
e=[list(map(int,input().split())) for i in range(q)]
a=[1]*n
now=0
while(True):
  tp=0
  for i in range(q):
    if(a[e[i][1]-1]-a[e[i][0]-1]==e[i][2]):
      tp+=e[i][3]
  if(tp>now):
    now=tp
    
  a[n-1]+=1
  for i in range(n-1):
    if(a[n-1-i]==m+1):
      a[n-2-i]+=1
  for i in range(n-1):
    if(a[i+1]==m+1):
      a[i+1]=a[i]
  if(a[0]==m+1):
    break

print(now)

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

int main(void){
    int a[100][100], b[100][100], n, m, l;
    long long  c[100][100];
    cin >> n >> m >> l;

    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }

    for(int i = 0; i < m; i++){
        for(int j = 0; j < l; j++){
            cin >> b[i][j];
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            for(int k = 0; k < m; k++){
                if(k == 0) c[i][j] = a[i][0] * b[0][j];
                else c[i][j] += a[i][k] * b[k][j];
            }
            cout << c[i][j];
            if(j != l-1) cout << ' ';
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3216
n = int(input())
s = input()

ans = s.count("R") * s.count("G") * s.count("B")
for i in range(n):
  for j in range(i+1,n):
    k = 2*j-i
    if k < n:
      if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
        ans -= 1
print(ans)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N; cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; ++i) { cin >> a[i]; --a[i]; }
    
    vector<int> ans(N);
    
    int id = N-1;
    while((int)a.size()>0){
        bool flg = true;
        for(int i=(int)a.size()-1; i>=0; --i){
            if(a[i] == i){
                ans[id--] = i+1;
                a.erase(a.begin()+i);
                flg = false;
                break;
            }
        }
        if(flg){
            cout << -1 << endl;
            return 0;
        }

    }

    for(auto ai:ans) cout << ai << endl;

}

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


int ary[100][100],ans[100][100];//[n][m]
bool isaru[100][100];
int tate[4]={0,1,0,-1};
int yoko[4]={1,0,-1,0};
int M,N,cnt;
void ser(int n,int m,int d){
	if(isaru[n][m]){
		cnt=max(cnt,d);
		if(ans[n][m]<d)ans[n][m]=d;
		isaru[n][m]=false;
		for(int i=0;i<4;i++){
			if(n+tate[i]>=0&&n+tate[i]<N&&m+yoko[i]>=0&&m+yoko[i]<M){
				ser(n+tate[i],m+yoko[i],d+1);
			}
		}
		isaru[n][m]=true;
	}
}

int main(){
	int cntm;
	while(1){
		cin>>M>>N;
		if(M==0&&N==0){
			break;
		}
		for(int i=0;i<N;i++){
			for(int j=0;j<M;j++){
				cin>>ary[i][j];
				isaru[i][j]=ary[i][j];
				ans[i][j]=0;
			}
		}
		cntm=0;
		for(int i=0;i<N;i++){
			for(int j=0;j<M;j++){
				cnt=0;
				ser(i,j,1);
				cntm=max(cntm,cnt);
			}
		}
		cout<<cntm<<endl;
	}
	return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#define N 100020
#define ll long long
using namespace std;
inline int read(){
  int x=0,f=1;char ch=getchar();
  while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
  while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
  return f?x:-x;
}
int to[N<<1], nxt[N<<1], val[N<<1], head[N], cnt;
void insert(int x, int y, int w) {
  to[++ cnt] = y; nxt[cnt] = head[x]; head[x] = cnt; val[cnt] = w;
  to[++ cnt] = x; nxt[cnt] = head[y]; head[y] = cnt; val[cnt] = - w;
}

int vis[N], col[N], failed;
int points, edges, a[3];

inline int mod3(int x) {
  return (x + 3) % 3;
}

int dfs(int x) {
  a[col[x]] ++;
  vis[x] = 1; points ++;
  for (int i = head[x]; i; i = nxt[i]) {
    edges += val[i] == 1;
  }
  for (int i = head[x]; i; i = nxt[i]) {
    if (!vis[to[i]]) {
      col[to[i]] = mod3(col[x] + val[i]);
      dfs(to[i]);
    } else if (col[to[i]] != mod3(col[x] + val[i])) {
      failed = true;
    }
  }
  return 0;
}

int main(int argc, char const *argv[]) {
  int n = read(), m = read();

  for (int i = 1; i <= m; ++ i) {
    int x = read(), y = read();
    insert(x, y, 1);
  }

  ll ans = 0;
  for (int i = 1; i <= n; ++ i) {
    if (vis[i]) {
      continue;
    }
    failed = false;
    edges = points = 0;
    memset(a, 0, sizeof a);
    dfs(i);
    if (failed) {
      ans += (ll) points * points;
    } else if (a[0] && a[1] && a[2]) {
      ans += (ll) a[0] * a[1] + (ll) a[1] * a[2] + (ll) a[2] * a[0];
    } else {
      ans += edges;
    }
  }

  printf("%lld\n", ans);

  return 0;
}

/*
我也不知道怎么做
*/

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll LCM(ll a,ll b){return (a*b)/GCD(a,b);}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int a;
	string s;
	cin >> a >> s;
	if (a >= 3200) cout << s << endl;
	else cout << "red" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,h,ar,area;
    scanf("%d %d %d",&a,&b,&h);
    if(h%2==0)
    {
        ar = (a+b)*h;
        area = ar / 2;

        printf("%d",area);
    }
    return 0;

}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CExceptionHandling solver = new CExceptionHandling();
        solver.solve(1, in, out);
        out.close();
    }

    static class CExceptionHandling {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = in.nextInt();

            int max = Integer.MIN_VALUE;
            int count = 0;
            for (int x : a) {
                if (x > max) {
                    max = x;
                    count = 1;
                } else if (x == max) {
                    count++;
                }
            }

            int second = Integer.MIN_VALUE;
            if (count > 1) {
                second = max;
            } else {
                for (int x : a) {
                    if (x == max)
                        continue;
                    second = Math.max(second, x);
                }
            }

            for (int x : a) {
                if (x != max)
                    out.println(max);
                else
                    out.println(second);
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 47468
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include <stdlib.h>
using namespace std;
int main()
{

int n,nn,counter=0; 
cin>>n; 
for (int i=0;i<n;i++)
{
      cin>>nn; 
      if (nn%2!=0 &&(i+1)%2!=0)
      {
      counter++;
      }
}
cout<<counter; 
	return 0;
}

Measured memory_bytes: 3468
X, N = [int(n) for n in input().split()]
p = [int(n) for n in input().split()]
p = set(p)

ans = 0
val = X
for i in range(1, 102):
    if i not in p and abs(X - i) < val:
        ans = i
        val = abs(X - i)
print(ans)




Measured memory_bytes: 9180
def insetionSort(A,n,g):
    global cnt
    for i in range(g,n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v
    return A

def shellSort(b,p):
    global cnt
    t = 1
    G = [1]
    while t*3+1 < p:
        t = t*3 +1
        G.append(t)
    G.reverse()
    m = len(G)
    for i in range(0,m):
        b = insetionSort(b,p,G[i])
    print(m)
    print(" ".join(map(str,G)))
    print(cnt)
    for t in b:
        print(t)

num = int(input())
lister = [int(input()) for s in range(num)]
cnt = 0
shellSort(lister,num)


Measured memory_bytes: 45520
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int n, x;
    cin >> n >> x;

    if (x == 1 || x == 2 * n - 1) {
        cout << "No" << endl;
        ret();
    }

    queue<int> q;
    for (int i = 1; i <= 2 * n - 1; i++) {
        if (i == x || i - 1 == x || i + 1 == x) {
            continue;
        }
        q.push(i);
    }

    deque<int> ans;
    ans.push_back(x - 1);
    ans.push_back(x);
    ans.push_back(x + 1);
    while (!q.empty()) {
        ans.push_front(q.front());
        q.pop();
        ans.push_back(q.front());
        q.pop();
    }

    cout << "Yes" << endl;
    while (!ans.empty()) {
        cout << ans.front() << endl;
        ans.pop_front();
    }


}


Measured memory_bytes: 4452
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int Q;

signed main(){
    cin >> Q;
    rep(i, Q){
        ll A, B;
        cin >> A >> B;
        if(A < B) swap(A, B);
        ll ans = B-1;
        ll ok = 0;
        ll ng = A;
        while(ng-ok > 1){
            ll m = (ok+ng) / 2;
            ll k = max(0LL, m-B-1)/2;
            if(m*(B+1)+(m-B-1)*k-k*k < A*B) ok = m;
            else ng = m;
        }
        ans += ok;
        cout << ans << endl;
    }
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {

	int n, t, ans = 0;
	cin >> n >> t;
	vector<pair<int, int>> ct(n);

	for (int i = 0; i < n; i++)cin >> ct[i].first >> ct[i].second;
	sort(ct.begin(), ct.end());
	for (int i = 0; i < n; i++) {
		if (ct[i].second <= t) {
			ans = ct[i].first;
			break;
		}
	}

	if (ans > 0)cout << ans << endl;
	else cout << "TLE" << endl;

	return 0;
}


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

#define FOR(i, l, r) for(size_t i = (l); i < (r); i = i + 1)
#define REP(i, n) FOR(i, 0, n)
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    REP(i, N) {
        cin >> S[i];
    }
  	

  	sort(S.begin(), S.end());
  	S.erase(unique(S.begin(), S.end()), S.end());

	cout << S.size() << endl;
  
  return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

int Euclidean_Algo(int x, int y) {
    int a = max(x, y) % min(x, y);
    int b = min(x, y);
    while (a != 0) {
        int temp = a;
        a = b % a;
        b = temp;
    }
    return b;
}

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b, c;
    cin >> a >> b >> c;
    
    if (c % Euclidean_Algo(a, b) == 0) cout << "YES" << endl; else cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
using namespace std;

#define max_n 100001
#define max_m 50
#define max_w 1000
#define max_h 1000
#define max_k 10000
#define max_l 10000
#define INF 9999999

typedef long long lint;

int main()
{
    int w,a,b;
    int ans;
    cin>>w>>a>>b;
    if(a==b){
        ans=0;
    }else if(a<b){
        if(a+w<=b){
            ans=b-a-w;
        }else{
            ans=0;
        }
    }else{
        if(b+w<=a){
            ans=a-b-w;
        }else {
            ans=0;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long 
#define mod 1000000007
using namespace std;

int n;
LL sol;
LL a[200006];
LL sum[2000006];

inline int qr()
{
	char a=0;int x=0,w=1;
	while(a<'0'||a>'9'){if(a=='-')w=-1;a=getchar();}
	while(a<='9'&&a>='0'){x=(x<<1)+(x<<3)+(a^48);a=getchar();}
	return x*w;
}

inline LL qrl()
{
	char a=0;LL x=0,w=1;
	while(a<'0'||a>'9'){if(a=='-')w=-1;a=getchar();}
	while(a<='9'&&a>='0'){x=(x<<1)+(x<<3)+(a^48);a=getchar();}
	return x*w;
}

inline LL mul(LL x,LL y)
{
	LL ans=0;
	while(y)
	{
		if(y&1)
			ans=(ans+x)%mod;
		y=y>>1;
		x=(x<<1)%mod;
	}
	return ans;
}

int main()
{
	n=qr();
	for(register int i=1;i<=n;i++)
	{
		a[i]=qr();
		sum[i]=sum[i-1]+a[i];
	}
	for(register int i=1;i<n;i++)
		sol=(sol+mul(a[i],sum[n]-sum[i]))%mod;
	printf("%lld\n",sol);
	return 0;
}

Measured memory_bytes: 6880
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<bitset>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)   
typedef long long ll;
const ll mod = 998244353;
const ll INF = 0x3f3f3f3f;
const ll maxn = 2e5 + 5;
const double pi = acos(-1.0);
const double eps=1e-9;
using namespace std;
ll qpow(ll a, ll b) { ll s = 1; while (b > 0) { if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1; }return s; }
list<char>li;
char s[maxn];
int main(){
	// in;
	// out;
	scanf("%s",s);
	for(int i=0;i<strlen(s);i++){
		li.push_back(s[i]);
	}
	int t;
	cin>>t;
	int ans=0;
	int flag=1;
	while(t--){
		int op;
		scanf("%d",&op);
		if(op==1){
			ans++;
			flag=-flag;
		}
		else if(op==2){
			int op1;
			scanf("%d",&op1);
			if(op1==1){
				getchar();
				char ss;
				scanf("%c",&ss);
				if(flag==1){
					li.push_front(ss);
				}
				else if(flag==-1){
					li.push_back(ss);
				}	
			}
			else if(op1==2){
				getchar();
				char ss;
				scanf("%c",&ss);
				if(flag==1){
					li.push_back(ss);
				}
				else if(flag==-1){
					li.push_front(ss);
				}
			}
		}
	}
	if(ans%2!=0) reverse(li.begin(),li.end());
	for(auto lis:li){
		cout<<lis;
	}
}

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

int a[30];
string s;
signed main(){
	cin>>s;
	rep(i,s.size()){
		a[s[i]-'a']++;
	}
	rep(i,26){
		if(a[i]%2){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}


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

const ll mod = 1e9 + 7;

template <class T> inline bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <class T> inline bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

ll n, k;
ll a[200009], f[200009];

bool isok(ll x) {
    ll sum = 0;
    rep(i, n) { sum += max(0ll, a[i] - x / f[i]); }
    return sum <= k;
}

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

    cin >> n >> k;
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> f[i];
    sort(a, a + n);
    sort(f, f + n, greater<ll>());

    ll l = -1, r = 1e18;
    while(r - l > 1) {
        ll mid = (l + r) / 2 + (l + r) % 2;
        if(isok(mid))
            r = mid;
        else
            l = mid;
    }
    cout << r << endl;
}

Measured memory_bytes: 3328
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pf push_front
#define pb push_back
using namespace std;
using ll = long long; using ld = long double;
using pii = pair<int,int>; using pil = pair<int,ll>;
using pli = pair<ll,int>; using pll = pair<ll,ll>;
const int MOD = 1000000007, MOD2 = 998244353;
const int INF = 0x3f3f3f3f, INF2 = 0x3f3f3f37;
const ll LINF = 0x3f3f3f3f3f3f3f3f, LINF2 = 0x3f3f3f3f3f3f3f3d;
const int N = 200005;

ll ans;
int n, m;
priority_queue<int> pq;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        pq.push(a);
    }
    while (m--) {
        int a = pq.top();
        pq.pop();
        pq.push(a >> 1);
    }
    while (n--) {
        ans += pq.top();
        pq.pop();
    }
    cout << ans << '\n';
}

Measured memory_bytes: 892
N,K=map(int,input().split())

ate=[0 for i in range(N+1)]
sushi=[]

for i in range(N):
    t,d = map(int,input().split())
    sushi.append([t,d])

sushi.sort(key=lambda x:x[1], reverse=True)

x=0
res=0

for s in sushi[:K]:
    if ate[s[0]]==0:
        x+=1
    ate[s[0]]+=1
    res+=s[1]

repl=K
delind=K-1

ans = res+x**2

while delind>=0 and repl<=N-1:
    f = False
    while delind>=0:
        t,d=sushi[delind]
        if ate[t]>1:
            ate[t]-=1
            res-=d
            delind-=1
            f=True
            break
        delind-=1

    while repl<=N-1:
        t,d=sushi[repl]
        if ate[t]==0:
            ate[t]+=1
            x+=1
            res+=d
            repl+=1
            f=f and True
            break
        repl+=1
    if f:
        ans=max(ans,res+x**2)

print(ans)


Measured memory_bytes: 68256
import sys
L,R = map(int,input().split())
mn = 10**10
cal = 0
for i in range(L,R+1):
    for j in range(i+1,R+1):
        
        cal = ((i%2019)*(j%2019))%2019
        if cal < mn:
            mn = cal
        if cal == 0:
            print(0)
            sys.exit()
print(mn)
        

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

s_list = [0 for _ in range(N)]
answer = S
stack = []
for i in range(N):
    if len(stack) == 0 and S[i] == ")":
        answer = "(" + answer
    elif len(stack) != 0 and S[i] == ")":
        stack.pop()
    else:
        stack.append(S[i])

print(answer + len(stack) * ")")


Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <sstream>
using namespace std;

typedef long long int64;
const int inf = (int)1e9;

int main()
{
	const int maxsize = 10002;
	
	while(true) {
		
		int n, r;
		vector<pair<int, int> > sheet[maxsize];
		
		scanf("%d%d", &n, &r);
		if(n == 0)
			break;
		
		for(int i = 0; i < n; ++i) {
			
			int x1, y1, x2, y2;
			scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
			
			x1 += 1, y1 += 1, x2 += 1, y2 += 1;
			
			sheet[x1].push_back(make_pair(y1, 1));
			sheet[x1].push_back(make_pair(y2, -1));
			sheet[x2].push_back(make_pair(y1, -1));
			sheet[x2].push_back(make_pair(y2, 1));
		}
		
		int size = 0, round = 0;
		
		int dp[2][maxsize] = {0};
		int *imos1, *imos2;
		imos1 = dp[0];
		imos2 = dp[1];
		
		for(int x = 1; x < maxsize; ++x) {
			
			fill(imos2, imos2 + maxsize, 0);
			
			for(int i = 0; i < sheet[x].size(); ++i) {
				int pos = sheet[x][i].first, val = sheet[x][i].second;
				imos2[pos] += val;
			}
			
			for(int y = 1; y < maxsize; ++y)
				imos2[y] = imos2[y - 1] + imos2[y];
			for(int y = 1; y < maxsize; ++y)
				imos2[y] = imos2[y] + imos1[y];
			
			for(int y = 1; y < maxsize; ++y) {
				int up = (imos1[y] == 0 && imos2[y] > 0) || (imos1[y] > 0 && imos2[y] == 0);
				int left = (imos2[y - 1] == 0 && imos2[y] > 0 || imos2[y - 1] > 0 && imos2[y] == 0);
				int exist = imos2[y] > 0;
				size += exist;
				round += up + left;
			}
			
			swap(imos1, imos2);
		}
		
		printf("%d\n", size);
		if(r == 2)
			printf("%d\n", round);
	}
	return 0;
}

/* ハラスメントに負けず */
/* 0完太陽にも負けず */
/* はやく人権を獲得したい */
/* nullmineralが書きましたが */
/* 責任はまったくとりません */

Measured memory_bytes: 2040
n = int(input())
a = list(map(int, input().split()))

alice = 0
bob = 0

for i in range(1,len(a)+1):
    if i % 2 != 0:
        alice += a.pop(a.index(max(a)))
    else:
        bob += a.pop(a.index(max(a)))

print(alice - bob)
        

Measured memory_bytes: 2940
import qualified Data.ByteString.Char8 as BS
import qualified Data.Maybe as MA

main = do
    [n, m] <- fmap (fst . MA.fromJust . BS.readInt) . BS.words <$> BS.getLine
    cs <- fmap (fmap (fst . MA.fromJust . BS.readInt)) . fmap BS.words . BS.lines <$> BS.getContents
    let candidates = case n of
                       1 -> fmap digit [0..9]
                       2 -> fmap digit [10..99]
                       3 -> fmap digit [100..999]
                       _ -> undefined

    case filter (check cs) candidates of
      [] ->
          putStrLn "-1"
      anss -> do
          let ans = minimum anss
          putStrLn $ foldl (++) "" (fmap show ans)

digit :: Int -> [Int]
digit x = nums
    where
        str = show x
        nums = fmap (\c -> read [c]) str

check :: [[Int]] -> [Int] -> Bool
check consts cand = and $ fmap (\[s, c] -> cand !! (s - 1) == c) consts


Measured memory_bytes: 892
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, K, R, S, P;
	string T;
	cin >> N >> K >> R >> S >> P >> T;

	Int ans = 0;
	for (Int i = 0; i < K; i++) {
		Int temp = i;
		Int te = -1;//前の手が何か　-1：なんでもいい　0：グー　1：チョキ 　2：パー
		while (temp<N) {
			if (-1==te) {
				if ('s' == T[temp]) {
					te = 0;
					ans += R;
					temp += K;
				}
				else if ('r' == T[temp]) {
					te = 2;
					ans += P;
					temp += K;
				}
				else {
					te = 1;
					ans += S;
					temp += K;
				}
			}
			else if (0==te) {
				if ('s'==T[temp]) {
					te = -1;
					temp += K;
				}
				else if ('r' == T[temp]) {
					te = 2;
					ans += P;
					temp += K;
				}
				else {
					te = 1;
					ans += S;
					temp += K;
				}
			}
			else if (1==te) {
				if ('s' == T[temp]) {
					te = 0;
					ans += R;
					temp += K;
				}
				else if ('r' == T[temp]) {
					te = 2;
					ans += P;
					temp += K;
				}
				else {
					te = -1;
					temp += K;
				}
			}
			else {//2==te
				if ('s' == T[temp]) {
					te = 0;
					ans += R;
					temp += K;
				}
				else if ('r' == T[temp]) {
					te = -1;
					temp += K;
				}
				else {
					te = 1;
					ans += S;
					temp += K;
				}
			}
		}
	}

	cout << ans << "\n";

}


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

int main() {
    int a,b;
    cin >> a >> b;
    if(a+b==3) cout << 3 << endl;
    else if (a+b==4) cout << 2 << endl;
    else cout << 1 << endl;
}

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

int n;
int a[100055];

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

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

	int res = 0;

	for (int i = 0; i < n; i++) res += a[a[i]] == i;

	cout << res / 2;

	return 0;
}

Measured memory_bytes: 640