akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for (int (i)=0; (i) < (n); (i)++)

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

    for (int i = 0; i <= N; ++i) {

        for (int j = 0; j <= N; ++j) {

            ll x = i;
            ll y = j;
            ll z = N - x - y;
            if (z < 0) break;
            if (x * 10000 + y * 5000 + z * 1000 == Y) {
                cout << x << " " << y << " " << z << endl;
                exit(0);
            }

        }
    }

    cout << "-1 -1 -1" << endl;

}


Measured memory_bytes: 3604
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#define enld '\n'
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,K;
  cin >> N >> K;
  int ans = inf;
  for(int i=0; i<=N; i++){
    int now = 1;
    for(int j=0; j<i; j++){
      now *= 2;
    }
    for(int j=i; j<N; j++){
      now += K;
    }
    chmin(ans,now);
  }
  cout << ans << "\n";
  return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        //入力
        long n = int.Parse(Console.ReadLine());
        long[] d = Console.ReadLine().Split().Select(long.Parse).ToArray();

        Array.Sort(d);
        long ans = d[d.Length/2] - d[d.Length/2-1];

        //出力
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 21472
def main():
  n = int(input())
  wlist = list(map(int, input().split()))
  min_diff = float('inf')
  for i in range(1, n):
    s1 = sum(wlist[:i])
    s2 = sum(wlist[i:])
    diff = abs(s1-s2)
    if min_diff > diff:
      min_diff = diff
  print(min_diff)
main()

Measured memory_bytes: 9160
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(n)-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define mod 1000000007
#define INF 1000000000000000000
/****************************/
vi g[100010];
bool used[100010];
int dp[100010];
vi topo;
void tp(int x)
{
	used[x]=true;
	rep(i,SZ(g[x]))
	{
		if(!used[g[x][i]]) 
		{
			tp(g[x][i]);
		}
	}
	topo.push_back(x);
}
int n,m;
int main()
{
	cin>>n>>m;
	rep(i,m)
	{
		int a,b;
		cin>>a>>b;
		g[a].pb(b);
	}
	memset(used,false,sizeof(used));
	rep3(i,1,n+1)
	{
		if(!used[i])
		{
			tp(i);
		}
	}
	zero(dp);
	reverse(topo.begin(),topo.end());
	rep(i,SZ(topo))
	{
		int x=topo[i];
		rep(j,SZ(g[x]))
		{
			dp[g[x][j]]=max(dp[g[x][j]],dp[x]+1);
		}
	}
	int ans=0;
	rep3(i,1,n+1)
	{
		ans=max(ans,dp[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8056
list=input().split(" ")
N=int(list[0])
K=int(list[1])
move_list=input().split(" ")
for i in range(N):
    move_list[i]=int(move_list[i])
move_list.insert(0,0)
list_count=[0 for i in range(N+1)]
find_loop=[]

now=1
count=0
flag=0
while(count<K):
    if list_count[now]==1:
        find_loop.append(now)
    elif list_count[now]==2:
        flag=1 #ループ省略する場合フラッグを立てる
        break
    list_count[now]+=1
    now=move_list[now]
    count+=1

if flag==0:
    now=1
    for i in range(K):
        now=move_list[now]
    print(now)
    
else:
    tmp=(K-count)%len(find_loop)
    print(find_loop[tmp])

Measured memory_bytes: 25968
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
void main()
{
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long[] L = new long[](cast(size_t)(N));
    foreach (i; 0 .. cast(size_t)(N))
    {
        L[i] = input.front.to!long;
        input.popFront;
    }

    solve(N, L);
}

void solve(long N, long[] L)
{
    long ans;
    foreach (i; 0 .. N)
        foreach (j; i + 1 .. N)
            foreach (k; j + 1 .. N)
            {
                auto v = [L[i], L[j], L[k]];
                v.sort();
                if (v[2] < v[0] + v[1] && v[0] != v[1] && v[1] != v[2] && v[0] != v[2])
                    ans++;
            }
    writeln(ans);
}


Measured memory_bytes: 4612
n = int(input())
h_list = list(map(int, input().split()))

count = 0
max_count = 0
pre_height = -1

for height in h_list:
    if (pre_height < height):
        if (max_count < count):
            max_count = count
        count = 0
        pre_height = height
        
        continue
    
    count += 1
    pre_height = height

if (max_count < count):
    max_count = count

print(max_count)

Measured memory_bytes: 14224
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

    int D, alp = 26;
    cin >> D;
    vector<int> c(alp);
    vector<vector<int>> s(D, vector<int>(alp));
    for (int i = 0; i < alp; i++) {
        cin >> c[i];
    }
    for (int i = 0; i < D; i++) {
        for (int j = 0; j < alp; j++) {
            cin >> s[i][j];
        }
    }

    int ans = 0;
    vector<int> last(alp, 0);
    for (int i = 0; i < D; i++) {
        int lastchoise = 0;
        int lastans = ans;

        for (int j = 0; j < alp; j++) {
            int sat = lastans;

            sat += s[i][j];
            for (int k = 0; k < alp; k++) {
                if (k != j) {
                    sat -= c[k] * (i + 1 - last[k]);
                }
            }

            if (ans < sat) {
                ans = sat;
                lastchoise = j;
            }
        }

        last[lastchoise] = i + 1;

        cout << lastchoise + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    // input
    ll N;
    cin >> N;
    vector<ll> A(N + 1);
    for (int i = 1; i <= N; ++i) {
        cin >> A[i];
    }
    // output
    vector<ll> B(N + 1);
    ll M = 0;
    for (int i = N; i > 0; --i) {
        int tmp = 0;
        for (int j = i; j <= N; j += i) {
            tmp += B[j];
        }
        if (tmp % 2 != A[i]) {
            M++;
            B[i]++;
        }
    }
    cout << M << endl;
    for (int i = 1; i <= N; ++i) {
        if (B[i] == 1) {
            cout << i << ' ';
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3968
#include <stdio.h>
#include <string.h>

int main(void) {
	int table[30];
	int in, i;

	memset(table, 0, sizeof(table));
	for(i = 0; i < 28; i++) {
		scanf("%d", &in);
		table[in - 1] = 1;
	}

	for(i = 0; i < 30; i++) {
		if(!table[i])
			printf("%d\n", i + 1);
	}

	return 0;
}

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

int num(char c){
    if(c == 'A'){
        return 10;
    }
    if(c == 'B'){
        return 11;
    }
    if(c == 'C'){
        return 12;
    }
    if(c == 'D'){
        return 13;
    }
    if(c == 'E'){
        return 14;
    }
    if(c == 'F'){
        return 15;
    }
    return 0;
}

int main (){
    char x,y;
    cin >> x >> y;
    if(num(x)> num(y)){
        cout << '>';
    }else if(num(x) < num(y)){
        cout << '<';
    }else{
        cout << '=';
    }
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;
public class Main{

	static int INF = 2 << 27;
	static int m;
	static int n;
	static int k;
	static int d;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			Data[] data = new Data[n];
			for(int i = 0; i < n; i++) {
				data[i] = new Data(sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt());
			}
			for(int i = 0; i < n; i++) {
				for(int j = i + 1; j < n; j++) {
					boolean check = check(data,i,j);
					if(check) data[j].up |= (1 << i);
				}
			}
			boolean[] dp = new boolean[1 << n];
			dp[0] = true;
			for(int i = 0; i < dp.length; i++) {
				if(!dp[i]) continue;
				ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();
				for(int j = 0; j < 5; j++) {
					list.add(new ArrayList<Integer>());
				}
				for(int j = 0; j < n; j++) {
					if((i & (1 << j)) != 0 || (i & data[j].up) != data[j].up) continue;
					list.get(data[j].c).add(j);
				}
				for(int j = 1; j < 5; j++) {
					ArrayList<Integer> lX = list.get(j);
					for(int k = 0; k < lX.size()-1; k++) {
						for(int l = k + 1; l < lX.size(); l++) {
							int next = i | (1 << lX.get(k) | (1 << lX.get(l)));
							dp[next] = true;
						}
					}
				}
			}
			int max = 0;
			for(int i = 0; i < dp.length; i++) {
				if(dp[i]) max = Math.max(max, Integer.bitCount(i));
			}
			System.out.println(max);
			
		}
	}
	static boolean check(Data[] data, int a, int b) {
		int dis = (int)(Math.pow(data[a].x - data[b].x, 2) + Math.pow(data[a].y - data[b].y, 2));
		return dis < Math.pow(data[a].r + data[b].r,2);
	}
	static class Data {
		int up = 0;
		int x;
		int y;
		int r;
		int c;
		Data(int a, int b, int c, int d) {
			this.x = a;
			this.y = b;
			this.r = c;
			this.c = d;
		}
	}
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, k, a, b, cnt = 0, ans;
  cin >> n >> k;

  vector<pair<int, int>> p(n);

  rep(i, n) cin >> p[i].first >> p[i].second;
  sort(p.begin(), p.end());

  for (auto pp : p) {
    if (k - pp.second > 0)
      k -= pp.second;
    else {
      cout << pp.first << endl;
      return 0;
    }
  }

  return 0;
}


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

int main() {
	int l = 0 , v1, v2;
	char a;
	vector<int> L, V1, V2;
	vector<vector<int>> LL;
	while (cin >> l >> a) {
		L.push_back(l);
		for (int i = 1; i < 10; i++) {
			cin >> l >> a;
			L.push_back(l);
		}
		cin >> v1 >> a >> v2;
		LL.push_back(L); V1.push_back(v1); V2.push_back(v2);
		L.clear();
	}
	for (int i = 0; i < LL.size(); i++) {
			double t = 0, wa = 0,li;
			for (int k = 0; k < 10; k++)wa += LL[i][k];
			t = wa / (V1[i] + V2[i]);li = t*V1[i];
			for (int k = 0; k < 10; k++) {
				li -= LL[i][k]; 
				if (li <= 0) {
					cout << k + 1 << endl; break;
				}
		}
	}
	return 0;
}

Measured memory_bytes: 3148
#include<stdio.h>
#include<vector>
using namespace std;
int c[300];
vector<int> list[3];
int main(){
	int a,b,cc,n;
	while(1){
	scanf("%d %d %d %d",&a,&b,&cc,&n);
	if(a==0)return 0;
	list[0].clear();
	list[1].clear();
	list[2].clear();	
	int m=a+b+cc;
	int i;
	for(i=0;i<m;i++)c[i]=-1;
	for(i=0;i<n;i++){
		int x,y,z,r;
		scanf("%d %d %d %d",&x,&y,&z,&r);
		x--;y--;z--;
		if(r==0){
			list[0].push_back(x);
			list[1].push_back(y);
			list[2].push_back(z);
		}
		else{
			c[x]=1;
			c[y]=1;
			c[z]=1;
		}
	}
	for(i=0;i<list[0].size();i++){
		int x=list[0][i];
		int y=list[1][i];
		int z=list[2][i];
		if(c[x]==1&&c[y]==1)c[z]=0;
		if(c[y]==1&&c[z]==1)c[x]=0;
		if(c[z]==1&&c[x]==1)c[y]=0;
	}
	for(i=0;i<m;i++){
		if(c[i]==-1)printf("2\n");
		else printf("%d\n",c[i]);
	}
	}
}

Measured memory_bytes: 1080
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int N, M;
vector<vector<int>> link;
int INF = INT32_MAX;
vector<int> bfs(int s_pos)
{
  vector<int> cost(N, INF);
  cost[s_pos] = 0;
  queue<int> pos_queue;
  pos_queue.push(s_pos);

  while (pos_queue.size())
  {
    int pos = pos_queue.front();
    pos_queue.pop();
    rep(i, link[pos].size())
    {
      int ni = link[pos][i];
      if (cost[ni] == INF)
      {
        cost[ni] = pos;
        pos_queue.push(ni);
      }
    }
  }
  return cost;
}

int main()
{
  cin >> N >> M;
  link.resize(N);
  rep(i, M)
  {
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    link[A].push_back(B);
    link[B].push_back(A);
  }

  vector<int> cost = bfs(0);
  rep(i, N)
  {
    if (cost[i] == INF)
    {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  rep(i, N - 1)
  {
    cout << cost[i + 1] + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 10176
#include <iostream>
#include <map>
using namespace std;
int main()
{
  int N;
  cin >> N;
  long A[N];
  for (int i = 0; i < N; i++)
    cin >> A[i];
  long S[N + 1];
  S[0] = 0;
  for (int i = 0; i < N; i++)
    S[i + 1] = S[i] + A[i];
  map<long, long> mp;
  for (int i = 0; i <= N; i++)
  {
    if (mp.find(S[i]) == mp.end())
      mp[S[i]] = 1;
    else
      mp[S[i]] = mp[S[i]] + 1;
  }
  long ans = 0;
  for (auto m : mp)
    ans += m.second * (m.second - 1) / 2;
  cout << ans << endl;
  return 0;
}

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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#endif

using namespace std;

#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) ((a).begin(),(a).end())
#define rall(a) ((a).rbegin(),(a).rend()) //sortで大きい順
#define UNIQUE(v) (v.erase(unique(all(v)),v.end()))
#define SUM(a) (accumulate(all(a),0))
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

int main(){
  int n,m; cin >> n >> m;
  vvi cost(n, vi(n,1<<29) ),isedge(n,vi(n));

  rep(i,m){
    int a,b,c; cin >> a >> b >> c; a--; b--;
    cost[a][b] = cost[b][a] = c;
    isedge[a][b] = isedge[b][a] = true;
  }

  int ans = 0;
  rep(k,n) rep(i,n) rep(j,n)
    if(cost[i][j] > cost[i][k] + cost[k][j]){
      cost[i][j] = cost[i][k] + cost[k][j];
      if(isedge[i][j] == true){
	isedge[i][j] = isedge[j][i] = false;
	ans++;
      }
    }

  cout << ans << endl;
}

Measured memory_bytes: 384
from bisect import bisect_left,bisect
n,l,t = (int(i) for i in input().split())
x,y,c = [[int(i) for i in input().split()]],[0],0
ans = [(x[0][0]-t)%l if x[0][1]-1 else (x[0][0]+t)%l]
ans2 = ans[0]
for _ in range(n-1):
	a,b = (int(i) for i in input().split())
	x.append([a,b])
	if b!=x[0][1]: c+=1
	y.append(c)
	if b-1: ans.append((a-t)%l)
	else: ans.append((a+t)%l)
ans.sort()
if x[0][1]-1: ans3 = bisect_left(ans,ans2)
else: ans3 = bisect(ans,ans2)-1
num = int(t/(l/2))
if x[0][1]-1:
	p = (-(t-num*(l/2))*2+x[0][0])%l
	d = (y[-1]*num+y[-1]-y[bisect_left(x,[p,0])-1])%n
else:
	p = ((t-num*(l/2))*2+x[0][0])
	d = (y[-1]*num+y[bisect_left(x,[p,3])-1])%n
if x[0][1]-1: d = -d
for i in range(n): print(ans[(ans3-d+i)%n])

Measured memory_bytes: 23976
// compressed relationship code
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstring>
#include <cassert>
#include <unordered_set>
using namespace std;
#define rep(i,a,n) for (int i=a;i<(n);i++)
#define per(i,a,n) for (int i=(n)-1;i>=(a);i--)
typedef long long ll;

ll hashPoint(ll y, ll x) {
    return (y << 32) + x;
}

int main() {
    ios_base::sync_with_stdio(false);
    ll h, w, n;
    cin >> h >> w >> n;
    unordered_set<ll> b, check;
    rep(i, 0, n) {
        ll y, x;
        cin >> y >> x;
        rep(yy, y - 2, y + 1) rep(xx, x - 2, x + 1) {
            check.insert(hashPoint(yy, xx));
        }
        b.insert(hashPoint(y, x));
    }
    vector<ll> res(10, 0);
    
    for (auto pt : check) {
        ll y = pt >> 32;
        ll x = pt & ((1ll << 32) - 1ll);
        
        if (x <= 0 || y <= 0 || x + 2 > w || y + 2 > h) continue;
        //cout << y << " " << x << endl;
        int cnt = 0;
        rep(yy, y, y + 3) rep(xx, x, x + 3) {
            if (b.count(hashPoint(yy, xx))) cnt++;
        }
        res[cnt]++;
    }
    res[0] = (w - 2) * (h - 2);
    rep(i, 1, 10) res[0] -= res[i];
    rep(i, 0, 10) cout << res[i] << endl;
    return 0;
}


Measured memory_bytes: 40720
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main(void){
int n;cin >> n;
int h[1000000];for(int i = 1; i <= n; i++) cin >> h[i];

int dp[1000000];

dp[1] = 0;
for(int i = 2; i <= n; i++){
        if(i - 2) {dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]) );}
        else {dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);}
        }
cout << dp[n] << "\n";
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
#define ll long long
using namespace std;
 
int main(){
	
	ll x;cin>>x;
	for(ll i=0;i<=150;i++){
		for(ll j=-i;j<=i;j++){
			if(i*i*i*i*i-j*j*j*j*j==x){cout<<i<<" "<<j<<'\n';return 0;}
		}
	}
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
using namespace std;
#define M_PI 3.141592
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()

struct point
{
	bool b[4];
};



int main()
{
	point a[5][5];
	for (int i = 0; i < 5; i++)
	{
		for (int l = 0; l < 5; l++)
		{
			for (int k = 0; k < 4; k++)
			{
				a[i][l].b[k] = false;
			}
		}
	}

	for (int i = 0; i < 5; i++)
	{
		string str;
		cin >> str;
		for (int l = 0; l < 4; l++)
		{
			a[i][l].b[1] = a[i][l + 1].b[3] = str[l] - '0';
		}

		if (i != 5 - 1)
		{
			cin >> str;
			for (int l = 0; l < 5; l++)
			{
				a[i][l].b[2] = a[i + 1][l].b[0] = str[l] - '0';
			}
		}
	}
	int x, y, v;
	x = y = 0;
	v = 1;
	while (1)
	{
		int d[4] = { -1 + 4,0 + 4,+1 + 4,+2 + 4 };
		int dx[4] = { 0,1,0,-1 };
		int dy[4] = { -1,0,1,0 };
		char dc[5] = "URDL";
		for (int i = 0; i < 4; i++)
		{
			int di = (v + d[i]) % 4;
			if (a[y][x].b[di])
			{
				x += dx[di];
				y += dy[di];
				v = di;
				cout << dc[di];
				break;
			}
		}
		if (x == y&&x == 0)
		{
			cout << endl;
			return 0;
		}
	}



}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

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

  while(1){
    ll R,C,Q;
    cin>>R>>C>>Q;
    if(R==0&&C==0&&Q==0){
      break;
    }

    vector<ll> A(Q),B(Q),Ca(Q);
    rep(i,Q){
      cin>>A[i]>>B[i]>>Ca[i];
    }

    vector<bool> usedR(R,false),usedC(C,false);
    ll cntr=0,cntc=0;
    ll cnt=0;
    for(ll i=Q-1;i>=0;i--){
      ll a,b,c;
      a=A[i]; b=B[i]; c=Ca[i];

      if(a==0){
        if(c==0){
          if(usedR[b])continue;
          usedR[b]=true;
          cntr++;
        }else{
          if(usedR[b])continue;
          usedR[b]=true;
          cnt+=(C-cntc);
          cntr++;
        }
      }else{
        if(c==0){
          if(usedC[b])continue;
          usedC[b]=true;
          cntc++;
        }else{
          if(usedC[b])continue;
          usedC[b]=true;
          cnt+=(R-cntr);
          cntc++;
        }
      }

    }
    cout<<cnt<<endl;
  }

  return 0;
}



Measured memory_bytes: 4208
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int a,b,k; cin >> a >> b >> k;
    rep(i,k){
        if(i%2){
            if(b%2){
                --b;
            }
            a += b/2;
            b/=2;
        } else {
            if(a%2){
                --a;
            }
            
            b += a/2;
            a/=2;
        }
    }
    cout << a << " " << b << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	
	unsigned long long  n,sum=0;
	cin>>n;
	for(long long  i =1;i<=n;i++)
	{
		if(i%3!=0&&i%5!=0)
		sum+=i;
		
		
		
	}
	cout<<sum;
	
}

Measured memory_bytes: 3580
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

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

    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n){
        cin >> d[i]; 
    }

    sort(d.begin(),d.end());
    int cnt=0;
    rep(i,n-1){
        if(d[i]==d[i+1]){
            cnt+=1;
        }
    }

    cout << n-cnt;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<string> vecstr;
typedef vector<char> vecchar;
typedef vector<bool> vecbool;
typedef vector<vector<bool>> vec2bool;
typedef vector<vector<int>> vec2int;
typedef vector<vector<double>> vec2d;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
////////////////////////////////////////////////
int main() {
  init();
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  string s2;
  vector<bool> tate;
  REP(i, n) {
    if (i < n - 1 && s[i] == s[i + 1]) {
      s2.push_back(s[i]);
      tate.push_back(false);
      i++;
    } else {
      s2.push_back(s[i]);
      tate.push_back(true);
    }
  }
  // cout << s << endl;
  // cout << s2 << endl;
  // for (auto e : tate) {
  //   cout << e;
  // }
  // cout << endl;
  int m = tate.size();
  vecll dp(m, 0);
  if (tate[0]) {
    dp[0] = 3;
  } else {
    dp[0] = 6;
  }
  for (int i = 1; i < m; i++) {
    if (tate[i - 1]) {
      dp[i] = (dp[i - 1] * 2) % MOD;
    } else {
      if (tate[i]) {
        dp[i] = dp[i - 1];
      } else {
        dp[i] = (dp[i - 1] * 3) % MOD;
      }
    }
  }
  // REP(i, m) { cout << dp[i] << endl; }
  cout << dp[m - 1] << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

void syuturyoku( int A[], int N )
{
   int i;
   for ( i = 0; i < N; i++ ) {
      if ( i > 0 ) {
         printf(" ");
      }
      printf("%d", A[i]);
   }
   printf("\n");
}

void insertionSort( int A[], int N )
{
   int i, j, v;
   for ( i = 1; i < N; i++ ) {
      v = A[ i ];
      j = i - 1;
      while ( j >= 0 && A[ j ] > v ) {
         A[ j + 1 ] = A[ j ];
         j--;
      }
      A[ j + 1 ] = v;
      syuturyoku( A, N );
   }
}

int main()
{
   int N, i, j;
   int A[100];

   scanf("%d", &N);
   for ( i = 0; i < N; i++ ) {
      scanf("%d", &A[i]);
   }
   syuturyoku( A, N );
   insertionSort( A, N );

   return 0;
}

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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int,int> p;

int dy[4]={-1,1,0,0};
int dx[4]={0,0,1,-1};

string X;
int main(){
    ios::sync_with_stdio(false);
    cin >> X;
    
    int s_num = 0;
    int st_num = 0;
    REP(i,X.size()) {
        if (X[i]=='S') {
            s_num++;
        }
        else {
            if (s_num) {
                st_num++;
                s_num--;
            }
        }
    }
    
    cout << X.size() - 2 * st_num << endl;
    
    return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



int main(){
        int n,a,b,c,d;
        string s;
        cin>>n>>a>>b>>c>>d>>s;
        s=s.substr(a-1,max(c,d)-a+1);
        b=b-a+1;
        c=c-a+1;
        d=d-a+1;
        a=1;
        if(s.find("##")<s.size()-1||s[c-1]=='#'||s[d-1]=='#'){
            cout<<"No"<<endl;
        }
        else if(c<d){
            cout<<"Yes"<<endl;
        }
        else if(d<c&&s.rfind("...")>=b-2&&s.find("...")<d-1){
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
}

Measured memory_bytes: 772
n = input()
op_cnt = len(n) - 1
for i in range(2 ** op_cnt):
  op = ['-'] * op_cnt#['-', '-', '-']
  for j in range(op_cnt):
    if ((i >> j) & 1):
      op[-1-j] = '+'
  formula = ''
  for p_n, p_o in zip(n, op + ['']):#(1,+),(2,+),(3,+),(4,'')
    formula += (p_n + p_o)
  if eval(formula) == 7:#'1+2+3+4'
    print(formula + '=7')
    break

Measured memory_bytes: 9128
n = int(input())
a = list(map(int,input().split()))
B = []
A = [0]+a+[0]
for i in range(1,len(A)):
    B.append(abs(A[i-1]-A[i]))
sum = sum(B)
for i in range(n):
    tmp = abs(A[i+2]-A[i])-abs(A[i+1]-A[i])-abs(A[i+2]-A[i+1])
    print(sum+tmp)

Measured memory_bytes: 14048
h1,h2=map(int,input().split())
k1,k2=map(int,input().split())
a,b,c,d=map(int,input().split())
e,f,g,h=h1*a,h2*b,k1*a,k2*b
o,n,m,v=h1//10*c,h2//20*d,k1//10*c,k2//20*d
z,y=o+n+e+f,m+v+g+h
if z>y:
    print("hiroshi")
elif z<y:
    print("kenjiro")
else:
    print("even")


Measured memory_bytes: 5600
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#include<list>
#include<limits>
#include<bitset>
#include<ctype.h>
#include<set>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007LL;
const ll INF=1000000000;
const int MAX=100001;
const double EPS=1e-10;
int main(){
    int a,b;
    cin>>a>>b;
    int ans=0;
    for(int i=a;i<=b;i++){
        string s=to_string(i);
        string t=s;
        reverse(s.begin(),s.end());
        if(s==t){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

                           


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static AtCoder.Io;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var a = BigInteger.Parse(ReadString());
            var b = BigInteger.Parse(ReadString());
            var s = a > b ? "GREATER" : a < b ? "LESS" : "EQUAL";
            Console.WriteLine($"{s}");
        }
    }

    public static class Io
    {
        public static string ReadString() => Console.ReadLine();
        public static string[] ReadStringArray() => ReadString().Split(' ');
        public static int ReadInt() => int.Parse(ReadString());
        public static long ReadLong() => long.Parse(ReadString());
        public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
        public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray();
        public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse);
        public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse);
    }
}


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

using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
struct edge{int nxt,to;}e[MAXN*8-10000];//一定要开8倍空间 
struct data{int x,y,id;}dat[MAXN];
int n,d,a,b,x,y,head[MAXN],vis[MAXN],cnt[MAXN],tot=0;
ll res=0;

void add_edge(int from,int to)
{
	e[++tot].nxt=head[from];e[tot].to=to;head[from]=tot;
	e[++tot].nxt=head[to];e[tot].to=from;head[to]=tot;
}

bool operator < (data a,data b)
{
	if(a.x!=b.x) return a.x<b.x;
	return a.y<b.y;
}

void solve(int k)
{
	sort(dat+1,dat+n+1);
	int cur,lst,l,r;
	for(cur=lst=l=r=1;cur<=n;cur++)
	{
		while((dat[l].x<dat[cur].x+d||dat[l].x==dat[cur].x+d&&dat[l].y<dat[cur].y-k)&&l<=n) l++;
		while((dat[r].x<dat[cur].x+d||dat[r].x==dat[cur].x+d&&dat[r].y<=dat[cur].y+k)&&r<=n) r++;
		if(l>n) break;
		cnt[dat[cur].id]+=r-l;lst=max(lst,l);
		if(lst>=r) continue;
		
		add_edge(dat[cur].id,dat[lst].id);
		for(;lst<r-1;lst++) add_edge(dat[lst].id,dat[lst+1].id);
	}
}

void dfs(int x)
{
	vis[x]=true;res+=cnt[x];
	for(int i=head[x];i;i=e[i].nxt)
		if(!vis[e[i].to]) dfs(e[i].to);
}

int main()
{
	scanf("%d%d%d",&n,&a,&b);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&x,&y),dat[i]={x+y,x-y,i};
	
	d=max(abs(dat[a].x-dat[b].x),abs(dat[a].y-dat[b].y));
	solve(d);
	for(int i=1;i<=n;i++) swap(dat[i].x,dat[i].y);
	solve(d-1);
	
	dfs(a);printf("%lld",res);
	return 0;
}

Measured memory_bytes: 10112
#define __LOCAL_DEBUG__
#include<bits/stdc++.h>
using namespace std;
#ifdef __LOCAL_DEBUG__
#else
#endif
#define REP(i, n) for (int i = (0); i < (n); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define EACH(x, arr) for (auto& x : arr) 
#define ITR(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define CLR(x, v) memset(x, v, sizeof (x))
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int) x.size()
template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
using ll = signed long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAXN = 700;

int n;
void MAIN() {
    string s;
    cin >> n >> s;
    VI cnt(26);
    EACH(c, s) cnt[c - 'a']++;
    ll res = 1;
    REP(i, 26) res = res * (cnt[i] + 1), res %= MOD;
    res += MOD - 1;
    res %= MOD;
    cout << res << endl;
} 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int TC = 1;
    // cin >> TC;
    REP(tc, TC) {
    // while (cin >> n, n) {
        // cout << "Case " << tc + 1 << ": ";
        MAIN();
    }
    return 0;
}


Measured memory_bytes: 512
import scala.io.StdIn.readLine
import scala.annotation.tailrec

object Main{
  def main(args: Array[String]): Unit ={
    val n : Int = readLine().toInt
    val A : Array[Int] = readLine().split(' ').map(_.toInt)
    println(new Solve(n, A).YesWeCan())
  }
}

class Solve(val n : Int, val A : Array[Int]){
  @tailrec
  private def gcd(a : Int, b : Int): Int = if(b == 0) a else gcd(b, a % b)
  val Front : Array[Int] = new Array[Int](n)
  val Back : Array[Int] = new Array[Int](n)
  def prevS(): Unit ={
    Front(0) = 0; Back(n-1) = 0;
    for(i <- 1 until n) Front(i) = gcd(Front(i-1), A(i-1))
    for(i <- n - 2 to 0 by -1) Back(i) = gcd(A(i+1), Back(i+1))
  }
  def YesWeCan(): Int = {
    prevS()
    solve()
  }
  @tailrec
  private def solve(idx : Int = 0, res : Int = -1) : Int = {
    if(idx == n) res
    else{
      val USA : Int = gcd(Front(idx), Back(idx))
      solve(idx + 1, if(USA > res) USA else res)
    }
  }
}

Measured memory_bytes: 46584
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


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

	string s;
	cin >> s;

	if (s[0] == s[1] || s[1] == s[2] || s[0] == s[2])
	{
		cout << "No";
	}
	else
	{
		cout << "Yes";
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF 100000000
#define MAX 100001
//#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define pb push_back
#define mp make_pair
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d)<<endl;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(a)-1;i>=(b);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()
#define IN(n, a, b) ((a)<=(n)&&(n)<(b))

void show(int a, int b, int c){
    cout << a << " " << b << " " << c << endl;
}
signed main(){ INIT;
    VAR(int, n, Y);
    Y /= 1000;

    REP(x, Y/10+1) REP(y, Y/5+1){
        int z1 = n - x - y, z2 = Y - 10 * x - 5 * y;
        if(z1 >= 0 && z1 == z2 && x + y + z1 == n){
            show(x, y, z1);
            RET;
        }
    }
    OUTL("-1 -1 -1");
RET;}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int n,t,x,i,a,ans=0,sum;
	scanf("%d %d",&n,&t);
	for(i=0;i<n;i++){
    	scanf("%d ",&a);
        if(a<=t) x=a;
        else{            
            sum=a-ans;
            if(sum>=t) x=x+t;
            else x=x+sum;
            ans=a;
        }
    }
    x=x+t;
    printf("%d\n",x);    
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#define M 1000000007L
long n,m;
long f(long x) {
  return x-1?x*f(x-1)%M:1;
}
main() {
  std::cin>>n>>m;
  std::cout<<f(n)*f(m)*((abs(n-m)<2)+(n==m))%M;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <vector>

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

    std::vector<int> num_children(s.length(), 0);

    for (int direction = 0; direction < 2; direction++) {
        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s[i] == 'R') {
                count++;
            } else {
                num_children[i - 1] += (count + 1) / 2;
                num_children[i] += count / 2;
                count = 0;
            }
        }

        std::reverse(num_children.begin(), num_children.end());
        std::reverse(s.begin(), s.end());

        for (int i = 0; i < s.length(); i++) {
            s[i] = s[i] == 'R' ? 'L' : 'R';
        }
    }

    for (auto n : num_children) {
        std::cout << n << " ";
    }
    putchar('\n');
}


Measured memory_bytes: 1024
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
N,K=map(int,input().split())

A=list(map(int,input().split()))
mod=10**9+7
Am=[-i for i in A if i<0]
Ap=[i for i in A if i>=0]

Am.sort()
Ap.sort()
Am=deque(Am)
Ap=deque(Ap)



if N==K:
    c=1
    for a in A:
        c*=a
        c%=mod

elif len(Ap)==0 and K%2:
    c=1
    while K :
        c*=Am.popleft()

        K-=1

        c%=mod
    c=-c
    c%=mod
    #print("unko")

else:
    #print(unko)
    c=1
    h=0
    a="unko"
    b="unko"
    while K and (Am or Ap) :
        if Am and Ap:
            if Am[-1]>Ap[-1]:

                a=Am.pop()
                c*=a
                h+=1
            else:

                b=Ap.pop()
                c*=b

        elif Am:
            a=Am.pop()
            c*=a
            h+=1
        elif Ap:
            b=Ap.pop()
            c*=b
        K-=1
        c%=mod

    if h%2:
        if Am and Ap and a!="unko" and b!="unko":
            if Am[-1]*a>Ap[-1]*b:
                a=Am.pop()
                c*=a
                c*=pow(b,mod-2,mod)
            else:
                b=Ap.pop()
                c*=b
                c*=pow(a,mod-2,mod)
        elif Am and b!="unko":
            a=Am.pop()
            c*=a
            c*=pow(b,mod-2,mod)
        else:
            b=Ap.pop()
            c*=b
            c*=pow(a,mod-2,mod)


print(c%mod)


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

int M, N;
string S, T;
int dp[2002][2002];

int rec(int a, int b)
{
  if(~dp[a][b]) return(dp[a][b]);
  int ret = 0;
  if(S[a] == 'O' && S[a + 1] == 'I') ret = max(ret, rec(a + 2, b) + 2);
  if(T[b] == 'O' && T[b + 1] == 'I') ret = max(ret, rec(a, b + 2) + 2);
  if(S[a] == 'O' && T[b    ] == 'I') ret = max(ret, rec(a + 1, b + 1) + 2);
  if(T[b] == 'O' && S[a    ] == 'I') ret = max(ret, rec(a + 1, b + 1) + 2);
  return(dp[a][b] = ret);
}


int main()
{
  memset(dp, -1, sizeof(dp));

  cin >> M >> N;
  cin >> S;
  cin >> T;

  int ret = 0;

  S += "~~"; T += "~~";

  for(int i = 0; i <= M; i++) {
    for(int j = 0; j <= N; j++) {
      if(S[i] == 'I') ret = max(ret, rec(i + 1, j) + 1);
      if(T[j] == 'I') ret = max(ret, rec(i, j + 1) + 1);
    }
  }

  cout << ret << endl;
}

Measured memory_bytes: 17008
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

void b_shift_only(void) {
	int n;
	int* a;
	cin >> n;
	a = (int*)calloc(n, sizeof(int));
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int cnt = 0;
	bool det_odd = false;
	while (true) {
		for (int i = 0; i < n; i++) {
			if ((a[i] & 0x1) == 0x1) {
				det_odd = true;
			}
			else {
				a[i] = a[i] >> 1;
			}
			if (det_odd)break;
		}
		if (det_odd)break;
		cnt++;
	}
	cout << cnt << endl;
}

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

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














int L, R, d;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> L >> R >> d;
	int ans = 0;
	rep(x, L, R + 1) if (x % d == 0) ans++;
	cout << ans << endl;
}







Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>

typedef long long ll;
typedef unsigned short int unsi;
typedef unsigned int uni;
typedef unsigned long int unli;

using namespace std;

int main(){
	string S;
	cin >> S;
	
	int l = S.length();
	int Count = 0;
	
	if (l % 2 == 0) {
		for (int i = 0; i < l / 2; i++) {
			if (S[i] != S[l - 1 - i]) {
				Count++;
			}
		}
	} else {
		for (int i = 0; i < (l - 1) / 2; i++) {
			if (S[i] != S[l - 1 - i]) {
				Count++;
			}
		}
	}

	cout << Count << endl;
}

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

using namespace std;

int main(){

   while(1){
      int n;
      cin>> n;
      if(!n) break;
      string s[n];
      for(int i=0; i<n; i++) cin>> s[i];

      for(int i=1; i<n; i++){
         for(int j=0; j<s[i].size(); j++){
            if(s[i][j]!='.'){
               s[i][j-1]='+';
               break;
            }else{
               s[i][j]=' ';
            }
         }
      }
      for(int i=0; i<n; i++){
         for(int j=0; j<s[i].size(); j++){
            if(s[i][j]=='+'){
               for(int k=i-1; k>=0; k--){
                  if(s[k][j]==' ') s[k][j]='|';
                  else break;
               }
            }
         }
      }

      for(int i=0; i<n; i++){
         cout<< s[i]<< endl;
      }
   }
   return 0;
}

Measured memory_bytes: 3740
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.rank = [0] * (n + 1)
        self.size = [1] * (n + 1)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.find(self.par[x])

    def sizeCheck(self, x):
        x = self.find(x)
        return self.size[x]

    def sameCheck(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

n, m = map(int, input().split())
bridge = []
for i in range(m):
  bridge.append(list(map(int, input().split())))
ans = [0] * m
ans[m - 1] = int(n * (n - 1) / 2)

uf = UnionFind(n)
index = m - 1
while index > 0:
  li = bridge[index]
  if uf.sameCheck(li[0], li[1]):
    ans[index - 1] = ans[index]
    index -= 1
  else:
    s0 = uf.sizeCheck(li[0])
    s1 = uf.sizeCheck(li[1])
    uf.union(li[0], li[1])
    ans[index - 1] = ans[index] - s0 * s1
    index -= 1
print(*ans, sep = "\n")

Measured memory_bytes: 36528
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<cstring>
#include<string>
using namespace std;
int main(){
	long long a,b;
    scanf("%lld %lld",&a,&b);
    if(a>0)puts("Positive");
    	else if(b>=0)puts("Zero");
    		else if((a&1)^(b&1))puts("Positive");
    			else puts("Negative");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
int main(){
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    for(ll i=k;i<=n+1;i++){
        ll l=i*(i-1)/2;
        ll r=(n+n-i+1)*i/2;
        ans=(ans+r-l+1)%mod;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3656
# AOJ ITP2_3_C: Count
# Python3 2018.6.24 bal4u

n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
	b, e, k = map(int, input().split())
	s = a[b:e]
	print(s.count(k))


Measured memory_bytes: 5636
//しゃくとり法（尺取り法）

#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int N, M, K;
  cin >> N >> M >> K;
  vector <int> A(N);
  vector <int> B(M);
  rep(i,N) cin >> A[i];
  rep(i,M) cin >> B[i];

  ll t = 0;
  //Bを全部読む時間 この下のwhile内でK以下にする
  rep(i,M) t += B[i];

  int j = M;
  int ans = 0;
  //iはAを読む冊数
  rep(i,N + 1){
    while (j > 0 && t > K){
      j--;
      t -= B[j];  //0-indexedでj番目の本を読むのを諦める
    }
    if (t > K) break;  //j == 0のときのため
    ans = max(ans, i + j);
    if (i == N) break;
    t += A[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4848