akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		int k=sc.nextInt();
		System.out.println(""+Process(s,k));
	}

	private static long Process(String s, int k) {
		long r;
		// TODO 自動生成されたメソッド・スタブ
		//System.out.println("sの最後の文字は"+s.substring(s.length()-1, s.length()));
		int[] p=Structur(s);
		//System.out.println("PRINT");
		if(Simple(s)) {
			r=f(k*(long)s.length());
			return r;
		}else {
			if(s.substring(0, 1).equals(s.substring(s.length()-1, s.length()))) {
				//System.out.println("print");
				return s1(k,p);
			}else {
				return s2(k,p);
			}
		}
	}

	private static long s2(int k, int[] p) {
		// TODO 自動生成されたメソッド・スタブ
		long r;
		int[] q=new int[p.length];
		for(int i=0;i<p.length;i++) {
			q[i]=(int)f(p[i]);
		}

		//System.out.println("幹部は"+(sum(q))+"");
		r=k*(long)sum(q);
		return r;
	}

	private static long s1(int k, int[] p) {
		// TODO 自動生成されたメソッド・スタブ
		long r;
		//System.out.print("pの長さ"+p.length);
		int[] q=new int[p.length-1];
		q[p.length-2]=(int)f(p[0]+p[p.length-1]);
		//System.out.println("qのおしりは定義");
		for(int i=1;i<p.length-1;i++) {
			q[i-1]=(int)f(p[i]);
		}
		//System.out.println("幹部は"+(sum(q)*k)+"");
		//System.out.println((sum(q)*k)+"-"+f(p[0]+p[p.length-1])+"+"+f(p[0])+"+"+f(p[p.length-1]));
		r=(long)sum(q)*(long)k-(long)f(p[0]+p[p.length-1])+(long)f(p[0])+(long)f(p[p.length-1]);
		return r;
	}

	private static int sum(int[] q) {
		// TODO 自動生成されたメソッド・スタブ
		int r=0;
		for(int i=0;i<q.length;i++) {
			r=r+q[i];
		}
		return r;
	}

	private static long f(long l) {
		// TODO 自動生成されたメソッド・スタブ
		if(l%2==0) {
			return l/2;
		}else {
			return (l-1)/2;
		}
	}

	private static boolean Simple(String s) {
		// TODO 自動生成されたメソッド・スタブ
		if(g(s)==s.length()) {
			return true;
		}else return false;
	}

	private static int[] Structur(String s) {
		// TODO 自動生成されたメソッド・スタブ

		String str=s;
		int l=0;
		for(int i=0;str.length()!=0;i++) {
			str=str.substring(g(str));
			//System.out.println("str="+str);
			l=i;
		}
		int[] r=new int[l+1];
		//System.out.println("l="+l+", s="+s);
		String str2=s;
		for(int i=0;str2.length()!=0;i++) {
			//System.out.println("p["+i+"]="+g(str2));
			r[i]=g(str2);
			str2=str2.substring(r[i]);
		}
		//System.out.println("PriNT");
		return r;
	}

	private static int g(String s) {
		// TODO 自動生成されたメソッド・スタブ
		int r=0;
		String h=s.substring(0, 1);
		for(int i=0;i<s.length() && h.equals(s.substring(i, i+1)) ;i++) {
			//System.out.print("i="+i);
			r=i;
		}
		//System.out.println("g(s)="+(r+1));
		return r+1;
	}

}


Measured memory_bytes: 22228
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] f = new int[n][10];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 10; j++) {
				f[i][j] = sc.nextInt();
			}
		}
		int[][] p = new int[n][11];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 11; j++) {
				p[i][j] = sc.nextInt();
			}
		}
		sc.close();

		int ans = Integer.MIN_VALUE;
		for (int k = 1; k < 1024; k++) {
			String str = Integer.toBinaryString(k);
			StringBuilder sb = new StringBuilder(str);
			while (sb.length() < 10) {
				sb.insert(0, '0');
			}
			int sum = 0;
			for (int i = 0; i < n; i++) {
				int cnt = 0;
				for (int j = 0; j < 10; j++) {
					int flg = sb.charAt(j) - '0';
					if (flg == 1 && flg == f[i][j]) {
						cnt++;
					}
				}
				sum += p[i][cnt];
			}
			ans = Math.max(ans, sum);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 27204
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int h,w;
long long MOD = 1e9 + 7;
char grid[1003][1003];
int dp[1003][1003];

long long solve(int i, int j)
{
    if(i >= h || j >= w)
        return 0;
    if(grid[i][j] == '#')
        return 0;
    if(i == h - 1 && j == w - 1)
        return 1;
    if(dp[i][j] != -1)
        return dp[i][j];
    long long ans = 0;
    ans += solve(i + 1, j);
    ans %= MOD;
    ans += solve(i, j + 1);
    ans %= MOD;
    return dp[i][j] = (ans % MOD);
}
int main()
{
    IO;
    cin >> h >> w;
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
            cin >> grid[i][j];
    }
    memset(dp, -1, sizeof dp);
    cout << solve(0,0);
    return 0;
}


Measured memory_bytes: 5248
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

using PP = pair<ll, ll>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> P(A), Q(B), R(C);
    rep(i, 0, A) {
        cin >> P[i];
    }
    rep(i, 0, B) {
        cin >> Q[i];
    }
    rep(i, 0, C) {
        cin >> R[i];
    }
    priority_queue<PP> que;
    rep(i, 0, A) {
        que.push(PP(P[i], 0));
    }
    rep(i, 0, B) {
        que.push(PP(Q[i], 1));
    }
    rep(i, 0, C) {
        que.push(PP(R[i], 2));
    }
    ll ans = 0;
    ll sum = X + Y;
    while (sum > 0) {
        PP now = que.top();
        que.pop();
        if (now.second == 0 && X == 0) {
            continue;
        }
        if (now.second == 1 && Y == 0) {
            continue;
        }
        if (now.second == 0) {
            --X;
        }
        else if (now.second == 1) {
            --Y;
        }
        ans += now.first;
        --sum;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12908
/* https://codeforces.com/contest/1360/problem/H */
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;

#define f first
#define s second 
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define	lb lower_bound
#define	ub upper_bound
#define	sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert

const int MAX = INT_MAX;
const ll MOD = 1e9+7;

int main() {
	int S;
	cin>>S;
	vector<ll> dp(2001);
	dp[0] = 1;
	for (int i = 3;i <= S;++i) {
		for (int j = 3;j <= i;++j) {
			dp[i] = (dp[i] + dp[i-j]) % MOD;
		}
	}


	cout<<endl;
	cout<<dp[S]<<endl;
	return 0;
}


Measured memory_bytes: 3576
import math
N,T  = list(map(int,input().split()))
#d = int(T / N)
m = []

def ans():
    ans = 1
    for i in range(1,int(math.sqrt(T))):    
            if T % i ==0:
                m.append(i)
                m.append(T//i)
    for p in m:
        if p <= T // N:
            ans = max(ans,p)
    print (ans)
    
if T % N == 0:
    print (int(T / N))
else:
    ans()

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N;
  cin >> N;
  string S1, S2;
  cin >> S1 >> S2;
  ll ans = S1[0] == S2[0] ? 3 : 6;
  int before = S1[0] == S2[0] ? 0 : 1;
  int pos = S1[0] == S2[0] ? 1 : 2;
  while (pos < N)
  {
    if (before)
      ans *= S1[pos] == S2[pos] ? 1 : 3;
    else
      ans *= 2;
    ans %= MOD;
    before = S1[pos] == S2[pos] ? 0 : 1;
    pos += S1[pos] == S2[pos] ? 1 : 2;
  }
  cout << ans << endl;
  return 0;
}

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

int w,h;
int dp[1024][1024];
char ch[1024][1024];
const int mod=1e9+7;

int main(){
	cin>>h>>w;
	for(int i=1;i<=h;++i){
		for(int j=1;j<=w;++j){
			cin>>ch[i][j];
		}
	}
	if(ch[1][1]=='.') dp[1][1]=1;
	for(int i=1;i<=h;++i){
		for(int j=1;j<=w;++j){
			if(i==1&&j==1) continue;
			if(ch[i][j]=='.') dp[i][j]=dp[i-1][j]+dp[i][j-1],dp[i][j]%=mod;
		}
	}
	cout<<dp[h][w]<<"\n";
	return 0;
}

Measured memory_bytes: 5248
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(M)]

uf = UnionFind(N)
for i in range(M):
    uf.union(AB[i][0]-1,AB[i][1]-1)
ufr = uf.roots()
ans = 0
for i in ufr:
    ans = max(ans,uf.size(i))
print(ans)

Measured memory_bytes: 50068
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  if (S=="Sunny"){
    cout << "Cloudy" << endl;
  }else if (S=="Cloudy"){
    cout << "Rainy" << endl;
  }else{
    cout << "Sunny" << endl;
  }
}


Measured memory_bytes: 256
// In The Name Of Allah
// Mehrkish Makuei

#include <bits/stdc++.h>

#define pb push_back
#define debug1(x) cerr << #x << " : " << x << endl;
#define debug2(x, y ) cerr << #x << " : " << x << "  " << #y << " : " << y << endl;

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef vector <ll> vll;
typedef set <char> sch;
typedef set <ll> sll;

const ll MOD = 1e9 + 7;
const ll MAXN = 1e3 + 19;

ll n, x, y;

int main(){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	x = n * 800;
	y = ( n / 15 ) * 200;
	cout << x - y << endl;
	return 0;
}


Measured memory_bytes: 256
/* Author: $%U%$
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/
#include <bits/stdc++.h>
using namespace std;
#define fore(i, a, b) for (int i = a, to = b; i < to; i++)
#define foref(i, a, b) for (int i = b - 1, to = a; i >= to; i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define SZ(v) (int)v.size()
#define pb push_back
typedef long long Long;
typedef pair<int, int> Pair;
const int MX = 1e3;
const int INF = 1e9;
char A[MX + 2][MX + 2];
int D[MX + 2][MX + 2];
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1, -2, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2};
int dy[] = {1, -1, 0, 0, 1, -1, 1, -1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, 0, 1};
int n, m;
void bfs(int x, int y) {
  deque<Pair> Q;
  fore(i, 0, n) fore(j, 0, m) D[i][j] = INF;
  Q.pb({x, y});
  D[x][y] = 0;
  while (!Q.empty()) {
    Pair p = Q.front();
    Q.pop_front();
    int px = p.first, py = p.second;
    fore(i, 0, 4) {
      int xx = px + dx[i];
      int yy = py + dy[i];
      if (xx < 0 || yy < 0 || xx >= n || yy >= m) continue;
      if (A[xx][yy] == '#') continue;
      if (D[xx][yy] > D[px][py]) {
        D[xx][yy] = D[px][py];
        Q.push_front({xx, yy});
      }
    }
    fore(i, 4, 24) {
      int xx = px + dx[i];
      int yy = py + dy[i];
      if (xx < 0 || yy < 0 || xx >= n || yy >= m) continue;
      if (A[xx][yy] == '#') continue;
      if (D[xx][yy] > D[px][py] + 1) {
        D[xx][yy] = D[px][py] + 1;
        Q.push_back({xx, yy});
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n >> m;
  int sa, sb;
  cin >> sa >> sb;
  sa--;
  sb--;
  int ea, eb;
  cin >> ea >> eb;
  ea--;
  eb--;
  fore(i, 0, n) fore(j, 0, m) cin >> A[i][j];
  bfs(sa, sb);
  if (D[ea][eb] == INF) {
    cout << -1 << '\n';
  } else {
    cout << D[ea][eb] << '\n';
  }

  return 0;
}

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

int main()
{
 string s;
  cin>>s;
  int ans=0;
  for(int i=0;i<s.length();i++)
  {
    int c=0,j=i;
    while(s[j]=='A'||s[j]=='C'||s[j]=='G'||s[j]=='T')
      j++,c++;
      //cout<<c<<"\n";
    ans = max(ans,c);
  }
  cout<<ans<<"\n";
  
  return 0;
}

Measured memory_bytes: 256
import sys
L,R=map(int,input().split())
_min=2018
if L==0 or R-L>=2019:
  print(0) 
  sys.exit()
else:
  for l in range(L,R):
    for r in range(L+1,R+1):
      mm=(l*r)%2019
      if mm==0:
        print(0) 
        sys.exit()
      elif _min>mm:
        _min=mm
print(_min)    

Measured memory_bytes: 3064
input()

sticks = [int(x) for x in input().split(' ')]

cnt = 0
for i in range(len(sticks)):
    for j in range(i + 1, len(sticks)):
        for k in range(j + 1, len(sticks)):
            si = sticks[i]
            sj = sticks[j]
            sk = sticks[k]
            if si != sj and sj != sk and sk != si:
                if si + sj > sk and sj + sk > si and sk + si > sj:
                    cnt += 1

print(cnt)

Measured memory_bytes: 9196
x = input()
flag = True

for i in range(len(x),0,-1):
    if (i % 2 == 0):
        #print(i, x[0:int(i/2-1)], x[int(i/2 - 1):i-2])
        if (x[0:int(i/2-1)] == x[int(i/2 - 1):i-2] and flag):
            print(i-2)
            flag = False
        else:
            pass
    else:
        pass


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

int pol(int n){
    return n*(n+1)*(n+2)/6;
}

int main(){
    vector<int> any(1000001),odd(1000001);
    for(int i=1;i<=1000000;i++){
        any[i]=odd[i]=i;
    }
    for(int n=2;pol(n)<=1000000;n++){
        int p = pol(n);
        for(int i=0;i+p<=1000000;i++){
            any[p+i]=min(any[p+i],any[i]+1);
        }
    }
    for(int n=2;pol(n)<=1000000;n++){
        int p = pol(n);
        if(p%2==0) continue;
        for(int i=0;i+p<=1000000;i++){
            odd[p+i]=min(odd[p+i],odd[i]+1);
        }
    }
    int n;
    while(cin>>n,n){
        cout<<any[n]<<' '<<odd[n]<<endl;
    }

    return 0;
}

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

int main(int argc, char *argv[]){
  string s;
  cin >> s;
  for (int i = 1; i < s.length(); i++) {
    if(s[i] == s[i - 1])s.erase(i, 1), i--;
  }
  if(s.length()%2 == 0) std::cout << "o" << std::endl;
  else std::cout << s[0] << std::endl;
  return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
using ll = long long;

bool check_753(ll x) {
	string s;
	s = to_string(x);
	bool has7, has5, has3;
	has3 = has5 = has7 = false;	
	for (ll i=0; i<s.size(); ++i) {
		if (s[i] == '3') {
			has3 = true;
		} else if (s[i] == '5') {
			has5 = true;
		} else if (s[i] == '7') {
			has7 = true;
		} else {
			return false;
		}
	}
	return (has3 && has5 && has7);
}

int main () {
	ll N;
	cin >> N;
	// N以下の、各桁に3, 5, 7を少なくとも1つ含む数値を全て挙げる. 
	// 最小値は357
	if (N < 357) {
		cout << 0 << endl;
		return 0;
	}
	string s = to_string(N);
	// 桁数を調べる
	ll digits = s.size();
	// 同じ桁数の753数候補を作る
	vector<ll> candidates;
	ll i = 0;
	ll cand = 0;
	while (i <= N && cand/10 <= N) {
		cand = 0;
		// 3進法で値を区別して列挙する
		// 0 -> 3, 1 -> 5, 2 -> 7
		ll x = i+1;
		while (x > 0) {
			x = x - 1;
			cand *= 10;
			ll t = x%3;
			if (t == 0) {
				cand += 3;
			} else if (t == 1) {
				cand += 5;
			} else if (t == 2) {
				cand += 7;
			}
			x = (x - t) / 3;
		}
	//	cout << "i=" << i << " " << cand << endl;
		candidates.push_back(cand);
		++i;
	}
	ll sum = 0;
	for (ll i=0; i<candidates.size(); ++i) {
		if (candidates[i] <= N) {
			bool result = check_753(candidates[i]);
			if (result) {
				sum++;
			}
		}
	}
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 1400
from heapq import *
from collections import defaultdict

N,X,Y = map(int,input().split())
X -= 1
Y -= 1
cost_pri = defaultdict(list)
for i in range(N-1):
    cost_pri[i].append((i+1,1))
    cost_pri[i+1].append((i,1))
cost_pri[X].append((Y,1))
cost_pri[Y].append((X,1))
ans = [0]*(N-1)
for s in range(N):
    dist = [2**60]*N
    dist[s] = 0
    que = [(0,s)]
    heapify(que)
    while que:
        p = heappop(que)
        v = p[1]
        if dist[v] < p[0]:continue
        for e in cost_pri[v]:
            if dist[e[0]] > dist[v] + e[1]:
                dist[e[0]] = dist[v] + e[1]
                heappush(que,(dist[e[0]],e[0]))
    
    for a in dist[s+1:]:
        ans[a-1] += 1

for a in ans:
    print(a)

Measured memory_bytes: 59356
#include<map>
#include<iostream>
#include<queue>
#include<string>

using namespace std;

class sint{
	public:
	string st;int m;
	sint(){}
	sint(string a,int b){st=a;m=b;}
};

int musi(string str){
	queue<sint> state;
	map<string,int> mm;
	
	mm[str]=1;
	
	state.push(sint(str,0));
	
	while(1){
		
		if(state.empty()==1){
			break;
		}
		
		sint u;
		u=state.front();
		state.pop();
		
		
		
		//cout<<u.st<<" "<<u.m<<endl;
		
		int cont[3];
		cont[0]=cont[1]=cont[2]=0;
		for(int i=0;i<u.st.size();i++){
			if(u.st[i]=='r'){
				cont[0]++;
			}
			if(u.st[i]=='g'){
				cont[1]++;
			}
			if(u.st[i]=='b'){
				cont[2]++;
			}
		}
		int aaa=0;
		for(int i=0;i<3;i++){
			if(cont[i]==0){
				aaa++;
			}
		}
		if(aaa==2){
			return u.m;
		}
		
		for(int i=1;i<=u.st.size();i++){
			string nst=u.st;
			if(nst[i]!=nst[i-1]){
				if(nst[i]=='r'&&nst[i-1]=='g'){
					nst[i]=nst[i-1]='b';
				}
				if(nst[i]=='g'&&nst[i-1]=='b'){
					nst[i]=nst[i-1]='r';
				}
				if(nst[i]=='b'&&nst[i-1]=='r'){
					nst[i]=nst[i-1]='g';
				}
				if(nst[i-1]=='r'&&nst[i]=='g'){
					nst[i]=nst[i-1]='b';
				}
				if(nst[i-1]=='g'&&nst[i]=='b'){
					nst[i]=nst[i-1]='r';
				}
				if(nst[i-1]=='b'&&nst[i]=='r'){
					nst[i]=nst[i-1]='g';
				}
			}
			if(mm[nst]!=1){
				mm[nst]=1;
				state.push(sint(nst,u.m+1));
			}
			
		}
	}
	return -1;
}

int main(){
	
	while(1){
		string a;
		cin>>a;
		if(a=="0"){
			break;
		}
		int b=musi(a);
		if(b==-1){
			puts("NA");
		}else{
			printf("%d\n",b);
		}
	}
}

Measured memory_bytes: 1892
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
string s[2010];
int a[2010][2010],b[2010][2010];
int numa[2010*2010],numb[2010*2010];
int main()
{
	int i,j,k,n,m,x,y,h=0;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
	{
		cin>>s[i];
	}
	for(i=0;i<n;i++)
	{
		x=0;
		for(j=0;j<m;j++)
		{
			if(s[i][j]=='#')
			{
				if(x>0)
				{
					numa[h]=x;
					x=0;
					h++;
				}
			}
			else
			{
				a[i][j]=h;
				x++;
			}
		}
		if(x>0)
		{
			numa[h]=x;
			h++;
		}
	}
	h=0;
	for(i=0;i<m;i++)
	{
		x=0;
		for(j=0;j<n;j++)
		{
			if(s[j][i]=='#')
			{
				if(x>0)
				{
					numb[h]=x;
					x=0;
					h++;
				}
			}
			else
			{
				b[j][i]=h;
				x++;
			}
		}
		if(x>0)
		{
			numb[h]=x;
			h++;
		}
	}
	int ma=0;
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			ma=max(ma,numa[a[i][j]]+numb[b[i][j]]-1);
		}
	}
	printf("%d",ma);
	return 0;
}


Measured memory_bytes: 46976
#include<iostream>
#include<vector>
#include<string>

int main(){
    int n;
    std::cin >> n;
    std::vector<int> a2, a4, a;
    for(int i = 0; i < n; i++){
        int tmp;
        std::cin >> tmp;
        if(tmp % 4 == 0){
            a4.push_back(tmp);
        }else if(tmp % 2 == 0){
            a2.push_back(tmp);
        }else{
            a.push_back(tmp);
        }
    }

    // 例外処理
    if(a.empty()){
        std::cout << "Yes" << std::endl;
        return 0;
    }

    // aの要素の横には必ず4をいれ最終的に4の倍数で終われるかどうか
    if(a.size() - 1 < a4.size()){
        std::cout << "Yes" << std::endl;
    }else{
        // 最後4でなくてももう無ければOK
        if(a2.size() == 0 && a.size() - 1 == a4.size()){
            std::cout << "Yes" << std::endl;
        }else{
            std::cout << "No" << std::endl;
        }
    }
    return 0;
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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;
};

bool check(string s) {
  int n = s.size();
  bool ret = true;
  rep(i, 0, n / 2) {
    if (s[i] == s[n-1-i]) continue;
    ret = false;
  }

  return ret;
};

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

  string s;
  cin >> s;
  int n = s.size();

  string s1 = "", s2 = "";
  rep(i, 0, (n-1)/2) {
    s1 += s[i];
  }
  rep(i, (n+3)/2-1, n) {
    s2 += s[i];
  }

  bool a = check(s), b = check(s1), c = check(s2);

  if (a && b && c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
};


Measured memory_bytes: 256
N = int(input())
x = []
for i in range(N):
	x.append(list(input().split()))
	x[i][0] = float(x[i][0])
sum = 0
for i in range(N):
	if x[i][1] == 'JPY':
		sum += x[i][0]
	else:
		sum += x[i][0] * 380000.0
		
print(sum)
	

	

Measured memory_bytes: 3060
n = int(raw_input())
points = set([])
for _ in range(n):
	p = map(int, raw_input().split())
	points.add(tuple(p))
points = list(points)
def distance(p,q): return abs(p[0] - q[0]) + abs(p[1] - q[1])


def f(points):
	r = 0
	for u in [-1,1]:
		for v in [-1,1]:
			pps = [u*x + v*y for x,y in points]
			r = max(r, max(pps) - min(pps))
	return r
print f(points)

Measured memory_bytes: 125112
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

int lis(vector<int>& a) {
    int n = a.size();
    const int INF = 1e9;
    vector<int> dp(n + 1, INF);
    rep(i, n) *lower_bound(all(dp), a[i]) = a[i];
    return lower_bound(all(dp), INF) - dp.begin();
}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    cout << lis(a) << endl;
}

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

using namespace std;

const long long mod = 998244353;

signed main()
{
    long long n, m;
    cin >> n >> m;
    vector<long long > dp(n+1);
    vector<long long > prefix(n+1);
    prefix[0] = 0; prefix[1] = 1;
    dp[0] = 0; dp[1] = 1;

    vector<pair<long long, long long> > steps;
    for(int i = 0; i < m; i++)
    {
        long long l, m;
        cin >> l >> m;
        steps.push_back({l, m});
    }

    for(int i = 2; i <= n; i++)
    {
        dp[i] = 0;
        for(auto it: steps)
        {
            if((i - it.first) <= 0) continue;
            else if((i - it.second) > 0)
            {   
                int first = max(i-it.first, i-it.second-1);
                int second = min(i-it.first, i-it.second-1);
                dp[i] = (dp[i] + prefix[first] - prefix[second]) % mod;
                if(dp[i] < 0)
                {
                    dp[i] += mod;
                }
            }
            else if((i - it.first) > 0 && (i - it.second) <= 0)
            {
                dp[i] = (dp[i] + prefix[i - it.first]) % mod;
            }
        }
        prefix[i] = (prefix[i-1] + dp[i]) % mod;
        //cout << dp[i] << " " << prefix[i] << endl; 
    }

    cout << dp[n];
    return 0;
}

Measured memory_bytes: 6424
#include <stdio.h>
#define N_MAX 100

int main()
{
  int i, count = 0, n, tmp, flag = 1, a[N_MAX];

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }

  while(flag){
    flag = 0;
    for(i = n - 1; i > 0; i--){
      if(a[i] < a[i - 1]){
	tmp = a[i];
	a[i] = a[i - 1];
	a[i - 1] = tmp;
	flag = 1;
	count++;
      }
    }
  }

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

  return 0;
}



Measured memory_bytes: 2108
from collections import defaultdict, deque

n, q = map(int, input().split())

tree = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

count = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    count[p - 1] += x

ret = [0] * n
q = deque(maxlen = n)
q.append((0, 0))
while len(q) > 0:
    f, c = q.popleft()
    ret[c] = count[c] + ret[f]
    for n in tree[c]:
        if n != f:
            q.append((c, n))

print(*ret)


Measured memory_bytes: 65292
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int INF = 1000000007;

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

    int N, C;
    cin >> N >> C;
    int D[C][C];
    int color[N][N];
    for (int i=0; i<C; i++)
        for (int j=0; j<C; j++) cin >> D[i][j];
    for (int i=0; i<N; i++)
        for (int j=0; j<N; j++) cin >> color[i][j], --color[i][j];

    vector<vector<int> > cost(3, vector<int>(C, 0));
    for (int c=0; c<C; c++){
        for (int i=0; i<N; i++){
            for (int j=0; j<N; j++){
                int t = (i+j)%3;
                cost[t][c] += D[color[i][j]][c];
            }
        }
    }
        
    int ans = INF;
    int c[3];
    for (c[0] = 0; c[0]<C; ++c[0]){
        for (c[1] = 0; c[1]<C; ++c[1]){
            if (c[0] == c[1]) continue;
            for (c[2] = 0; c[2]<C; ++c[2]){
                if (c[0]==c[2] || c[1]==c[2]) continue;
                int tmp = 0;
                for (int i=0; i<3; i++) tmp += cost[i][c[i]];
                ans = min(ans, tmp);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1280
Num = list(map(int,input().split()))
A = Num[0]
B = Num[1]
C = Num[2]
K = Num[3]

if K <= A :
  print(K)
else:
  if K-A <= B:
    print(A)
  else:
    print(2*A+B-K)

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列 -92
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}



int main(){
    ll n,k;
    cin >> n >> k;
    ll x = n%k;
    cout << min(x,abs(k-x)) << endl;
}

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


int main() {
    int n, mi, ma;
    while(cin >> n >> mi >> ma, n) {
        vector<int> v(n);
        int gap=0, ans=0;
        for(int i=0; i<n; ++i) {
            cin >> v[i];
        }
        
        for(int i=mi-1; i<ma; ++i) {
            if(gap == v[i] - v[i+1]) {
                ans = max(ans, i+1);
            } else if(gap < v[i] - v[i+1]) {
                gap = v[i] - v[i+1];
                ans = i+1;
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3080
from collections import deque
import sys

n = int(input())

ab = []
for _ in range(n):
	ab.append(list(map(int,input().split())))

ab = sorted(ab, key=lambda x:x[1], reverse=True)

d = []
d = deque(d)
num = 0
while len(ab) > 0:
	d = deque([])
	d.append(ab.pop())
	while True:
		if len(ab) == 0:
			break
		if ab[-1][1] == d[0][1]:
			d.append(ab.pop())
		else:
			break
	for i in range(len(d)):
		a,b = d.pop()
		num += a
	if num > b:
		print('No')
		sys.exit()

print('Yes')


Measured memory_bytes: 55752
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M;
	while(cin>>N>>M) {
		vector<PII> AB(N);
		REP(i, N) cin>>AB[i].FI>>AB[i].SE;
		sort(ALL(AB));
		priority_queue<ll, vector<ll>, less<ll>> q;
		ll ans = 0;
		ll ABi = 0;
		REPR(i, M+1) {
			ll rest = M-i;
			while(ABi < N && AB[ABi].FI<=rest) {
				q.push(AB[ABi].SE);
				ABi++;
			}
//			DD(rest);
			ll v = 0LL;
			if(q.size()) {
				v = q.top();
				q.pop();
			}
//			DD(v);
			ans += v;
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 2936
//string _(){
//    set<pii> edges;
//    int n,m;
//    cin >> n >> m;
//    while(m--){
//        int u,v;
//        cin >> u >> v;
//        edges.insert(mp(u,v));
//        edges.insert(mp(v,u));
//    }
//    rep(x,2,n-1){
//        if(edges.count(mp(1,x)) && edges.count(mp(x,n)))
//            return "POSSIBLE";
//    }
//            return "IMPOSSIBLE";
//}
//
//
//
#include <set>
#include <iomanip>
#include <algorithm>
#include <cassert>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define mp make_pair
#define REP_INT(i,l,r) for(int i = l; i <= r; ++i)
#define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT)(__VA_ARGS__)
#define all(v) (v).begin(), (v).end()
#define T1 template<typename T> static
using namespace std;
typedef pair<int, int> pii;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
string _(){
    set<pii> edges;
    int n,m;
    cin >> n >> m;
    while(m--){
        int u,v;
        cin >> u >> v;
        edges.insert(mp(u,v));
        edges.insert(mp(v,u));
    }
    rep(x,2,n-1){
        if(edges.count(mp(1,x)) && edges.count(mp(x,n)))
            return "POSSIBLE";
    }
            return "IMPOSSIBLE";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        cout << _() << '\n';
}


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

int main(){
    constexpr unsigned long MOD = 1000000007;
    unsigned long N, M;
    cin >> N >> M;
    unsigned long p{1}, q{0}, i{0};
    for(unsigned long _ = 0, a; _ < M; ++_){
        cin >> a;
        while(++i != a)swap((q += p) %= MOD, p);
        swap(q = 0, p);
    }
    while(i++ != N)swap((q += p) %= MOD, p);
    cout << p << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

void scoring(int D, vector<int>& decline, vector<vector<int>>& satis);

int main(){
    int D;cin>>D;
    vector<int> decline(26);
    vector<vector<int>> satis(D, vector<int>(26));
    for(int i = 0;i < 26;i++){
        int c;cin>>c;
        decline[i] = c;
    }
    for(int d = 0;d < D;d++){
        for(int i  = 0;i < 26;i++){
            int s;cin>>s;
            satis[d][i] = s;
        }
    }
    scoring(D,decline,satis);
}

void scoring(int D, vector<int>& decline, vector<vector<int>>& satis){
    vector<int> schedule(D);
    for (int i = 0; i < D; i++){
        cin>>schedule[i];
        schedule[i]--;
    }
    vector<int> lastHeld(26, 0);
    ll sat = 0;
    for(int d = 1;d <= D;d++){
        int contest = schedule[d-1];
        lastHeld[contest] = d;
        for(int i = 0;i < 26;i++){
            if(i == contest){
                sat += satis[d-1][i];
            }
            sat -= decline[i] * (d-lastHeld[i]);
        }
        cout<<sat<<endl;
    }
}

Measured memory_bytes: 3676
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	vector<pair<int, int> > intervals(n);
	int x, l;
	for (int i = 0; i < n; ++i) {
		cin >> x >> l;
		intervals[i] = {x - l, x + l};
	}

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

	int removed = 0;
	int left = 0, right = 1;
	while (right < n) {
		if (intervals[right].first < intervals[left].second) {
			if (intervals[right].second < intervals[left].second) {
				left = right;
			}

			++removed;
		} else {
			left = right;
		}

		++right;
	}

	cout << n - removed << "\n";

	return 0;

}

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

using namespace std;
int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	vector<tuple<int, int>> a(n);
	for (int i = 0; i < n; i++) {
		int b;
		cin >> b;
		a[i] = make_tuple(b, i+1);
	}
	
	sort(a.begin(), a.end());
	
	for (int i = 0; i < n; i++) {
		cout << get<1>(a[i]) << ((i == n - 1) ? "\n" : " ");
	}
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int A=gi(),B=gi(),C=gi(),D=gi();
	ll N=gi()*4ll,ans=0;
	if(D<C*2&&D<B*4&&D<A*8){
		ll s=N/8;
		ans+=s*D,N-=8*s;
	}
	if(C<B*2&&C<A*4){
		ll s=N/4;
		ans+=s*C,N-=4*s;
	}
	if(B<A*2){
		ll s=N/2;
		ans+=s*B,N-=2*s;
	}
	printf("%lld\n",ans+N*A);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12); // debuged
    int T;
    T = 1;
    while (T--) solve();
}

// https://img.atcoder.jp/m-solutions2020/editorial.pdf
void solve() {
    int n, k;
    cin >> n >> k;
    vector<double> a(n);
    cin >> a;
    rep(i, n) a[i] = log(a[i]);
    // cerr << a << endl;
    
    // log関数はxが大きくなるほどyが近くなる
    // x最大付近のとき誤差が心配
    // cerr << fixed << setprecision(12) << log(1000000000) << " " << log(1000000000 - 1) << endl;
    // 小数点以下第9位で違う値
    
    double now = 0;
    rep(i, k) now += a[i];
    rep3(i, k, n) {
        if (now < now - a[i - k] + a[i]) {
            cout << "Yes" << endl;
        } else cout << "No" << endl;
    }
}



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

using namespace std;

struct edge {
  int to, cap, rev;
};

const int MAX_V = 101;

vector<vector<edge>> G(MAX_V);
vector<int> level(MAX_V), iter(MAX_V);

void add_edge(int from, int to, int cap) {
  G[from].push_back((edge){to, cap, (int)G[to].size()});
  G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
}

void bfs(int s) {
  fill(level.begin(), level.end(), -1);
  queue<int> que;
  level[s] = 0;
  que.push(s);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (size_t i = 0; i < G[v].size(); i++) {
      edge &e = G[v][i];
      if (e.cap > 0 && level[e.to] < 0) {
        level[e.to] = level[v] + 1;
        que.push(e.to);
      }
    }
  }
}

int dfs(int v, int t, int f) {
  if (v == t) return f;
  for (int &i = iter[v]; i < (int)G[v].size(); i++) {
    edge &e = G[v][i];
    if (e.cap > 0 && level[v] < level[e.to]) {
      int d = dfs(e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s, int t) {
  int flow = 0;
  for (;;) {
    bfs(s);
    if (level[t] < 0) return flow;
    fill(iter.begin(), iter.end(), 0);
    int f;
    while ((f = dfs(s, t, numeric_limits<int>::max())) > 0) {
      flow += f;
    }
  }
}

int main() {
  int V, E;
  cin >> V >> E;
  vector<int> c(E);
  for (int i = 0; i < E; ++i) {
    int from, to, cap;
    cin >> from >> to >> cap;
    add_edge(from, to, cap);
  }
  cout << max_flow(0, V - 1) << endl;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define ff first
#define ss second

int a[100000];
bool used[100000], vis[100000];
vector<int> edge[100000];
pii dfs(int x){
	vis[x] = 1;
	pii ret = {a[x], x};
	for(auto i: edge[x]){
		if(vis[i]) continue;
		ret = min(ret, dfs(i));
	}
	return ret;
}
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	int N, M; cin>>N>>M;
	for(int i=0; i<N; ++i) cin>>a[i];
	for(int i=0; i<M; ++i){
		int x,y; cin>>x>>y;
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	if(M==N-1) return !printf("0");
	long long ans = 0;
	for(int i=0; i<N; ++i){
		if(vis[i]) continue;
		pii t = dfs(i);
		ans += t.ff;
		used[t.ss] = 1;
	}
	vector<pii> vec;
	for(int i=0; i<N; ++i) if(!used[i]) vec.emplace_back(a[i], i);
	sort(vec.begin(), vec.end());
	if((int)vec.size() < N-M-2) cout<<"Impossible";
	else{
		for(int i=0; i<N-M-2; ++i) ans += vec[i].ff;
		cout<<ans;
	}
	return 0;
}

Measured memory_bytes: 7544
def g(a,b):
    while b:a,b=b,a%b
    return a

def f(a,m,b):
    x=a
    while x!=1:
        x=a*x%m
        b+=1
    return b        

while 1:
    x,m,y,my,z,mz = map(int, input().split())
    if x==0:break
    a,b,c=f(x,m,1),f(y,my,1),f(z,mz,1)
    d=a*b/g(a,b)
    print(int(c*d/g(c,d)))

Measured memory_bytes: 7660
n = int(input())
a = list(map(int,input().split()))
a.sort()
dp = [0 for i in range(a[-1])]
p = [0 for i in range(a[-1])]
for i in range(n):
    p[a[i]-1] += 1
ans = 1
for i in range(2,a[-1]+1):
    if dp[i-1] == 1:
        continue
    u = 0
    k = 1
    while i*k <= a[-1]:
        dp[i*k-1] = 1
        if p[i*k-1] != 0:
            u += p[i*k-1]
        k += 1
    if u == n:
        ans = -1
    elif u > 1:
        ans = min(ans,0)
if ans == 1:
    print('pairwise coprime')
elif ans == 0:
    print('setwise coprime')
elif a[0] == 1:
    print('setwise coprime')
else:
    print('not coprime')

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

int main(){
  int i;
  for(i=0;i<1000;i++){
    char c[20];
    scanf("%s", c);
    int j=0, cn[20]={};
    while(c[j]!='\0'){
      cn[j] = c[j] - 'A';
      j++;
    }
    int k;
    for(k=0;k<j-1;k++){
      if((cn[k]!=cn[k+1]) && (abs(cn[k]-cn[k+1])==3 || (cn[k]%3!=0&&cn[k+1]-cn[k]==-1) || (cn[k]%3!=2&&cn[k+1]-cn[k]==1)));
      else break;
    }
    if (k==j-1) printf("%s\n", c);
  }
  return 0;
}



Measured memory_bytes: 2068
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools

#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

a, b, c, d = map(int,input().split())
ans = 0
while True:
    if(c-b<=0):
        print("Yes")
        break
    elif(a-d<=0):
        print("No")
        break
    c= c-b
    a = a-d


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

int main() {
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;

    string tmp = "";
    rep(i, N) {
        tmp += S[i];
        tmp += T[i];
    }
    cout << tmp << endl;
}


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

#define clr(i, j)     memset(i, j, sizeof(i))
#define pb            push_back
#define mp            make_pair
typedef long long     ll;
bool kk=true;
//map<int,int>r;int arr[100000];
bool rr[3];
int main()

{
   /*
int n,m,k;   cin>>n>>m>>k;

for(int r=0;r<n;r++){

       cin>>a[r];

}
for(int r=0;r<n;r++){
for(int dd=0;dd<n;dd++){


       }

}*/
int n,m;
cin>>n>>m;
if(n==0){
        if(m==100){cout<<101;
}else{cout<<m;}return 0;}
else{
        int i=1;
    i*=(100);
    if(n==2){
        i*=100;
    }
if(m<=99){
    cout<<i*m;
}else{
cout<<101*i;}
}
}


Measured memory_bytes: 256