akhauriyash/Code-Regression huggingface dataset:
from heapq import heappush, heappop
import sys
INFTY=sys.maxsize

def readinput():
    n,x,y=list(map(int,input().split()))
    return n,x,y

def dijkstra(s,n,nList):
    '''優先度付きキューを使用したダイクストラ法

    パラメーター
    s: 始点
    n: 頂点の数
    nList: [ 
        [vertex1, cost1], [vertex2, cost2], ...
        [vertex1, cost1], [vertex2, cost2], ...
        ...
    ]

    返り値
    d: 始点sから各頂点vまでの最短経路上の辺の重みの総和d[v]のリスト
    '''

    WHITE=0
    GRAY=1
    BLACK=2
    color=[WHITE]*n
    d=[INFTY]*n

    HQ=[]

    d[s]=0
    heappush(HQ,(d[s],s))

    while(len(HQ)>0):
        #print(HQ)
        du,u=heappop(HQ)
        color[u]=BLACK

        if d[u]<du:
            continue

        for v in nList[u]:
            vw=1
            if color[v]!=BLACK:
                if d[u] + vw < d[v]:
                    d[v] = d[u] + vw
                    color[v]=GRAY
                    heappush(HQ, (d[v], v))
    return d

def main(n,x,y):
    nList=[]
    #nList.append([])
    nList.append([1])
    for i in range(1,n-1):
        nList.append([i-1,i+1])
    nList.append([n-2])
    nList[x-1].append(y-1)
    nList[y-1].append(x-1)
    #print(nList)

    dList=[]
    for i in range(n):
        dList.append(dijkstra(i,n,nList))
    #print(dList)
    
    hist=[0]*n
    for i in range(n-1):
        for j in range(i+1,n):
            hist[dList[i][j]]+=1
    
    for i in range(1,n):
        print(hist[i])

def main2(n,x,y):
    hist=[0]*n
    for i in range(1,n):
        for j in range(i+1,n+1):
            if i<=x:
                if j<=x:
                    d=j-i
                elif x<j and j<=y:
                    d=min(j-i,x-i+1+y-j)
                else:
                    d=x-i+1+j-y
            elif x<i and i<=y:
                if j<=y:
                    d=min(j-i,i-x+1+y-j)
                else:
                    d=min(j-i,i-x+1+j-y)
            else:
                d=j-i
            #print(i,j,d)
            hist[d]+=1
    for i in range(1,n):
        print(hist[i])

if __name__=='__main__':
    n,x,y=readinput()
    main2(n,x,y)


Measured memory_bytes: 9396
import sys
readline = sys.stdin.readline

def main():
    N, M, C = map(int, readline().rstrip().split())
    B = list(map(int, readline().rstrip().split()))
    ans = 0
    for _ in range(N):
        A = list(map(int, readline().rstrip().split()))
        if sum([a*b for a, b in zip(A, B)]) + C > 0:
            ans += 1
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
a=int(input())

a = a % 10

if a == 2 or a == 4 or a == 5 or a == 7 or a == 9:
    print("hon")
elif a == 0 or a == 1 or a == 6 or a == 8:
    print("pon")
else:
    print("bon")


Measured memory_bytes: 9168
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    S = list(ns())
    if S[0] == 'A' and 'C' in S[2:-1]:
        S.remove('A')
        S.remove('C')
        for s in S:
            if s.isupper():
                print('WA')
                return
        print('AC')
    else:
        print('WA')


if __name__ == '__main__':
    main()


Measured memory_bytes: 8900
#include "bits/stdc++.h"

typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;

signed main(){
    
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    int x1 = c + (b-d);
    int y1 = d + c-a;
    int x2 = x1 -y1 + d;
    int y2 = y1 +x1 - c;

    cout << x1 << " " << y1 << " " << x2 << " " << y2 ;

    return 0;
}
//g++ -std=c++14 code1.cpp


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

int main(void){
    double a, b, c, d, e, f, g, h, i;
    scanf("%lf %lf %lf", &a, &b, &c);
    scanf("%lf %lf %lf", &d, &e, &f);
    scanf("%lf %lf %lf", &g, &h, &i);

    if(atan2(d-a,g-a)==atan2(e-b,h-b)&&atan2(e-b,h-b)==atan2(f-c,i-c)){
        if(atan2(b-a,c-a)==atan2(e-d,f-d)&&atan2(e-d,f-d)==atan2(h-g,i-g)){
            printf("Yes");
        }
    } else{
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 256
#a,b=map(int,input().split())
n=int(input())
p=list(map(int,input().split()))
import copy
P=copy.deepcopy(p)
P.sort()
cnt=0
for i,j in zip(p,P):
        if i!=j:
                cnt+=1
if cnt<=2:
        print("YES")
else:
        print("NO")


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

int main() {
  std::array<uint64_t, 51> num;
  std::array<uint64_t, 51> p;
  num[0] = 1;
  p[0] = 1;
  for (int i = 0; i < 50; i++) {
    num[i + 1] = 2 * num[i] + 3;
    p[i + 1] = 2 * p[i] + 1;
  }

  uint64_t n, x;
  std::cin >> n >> x;
  uint64_t eat = 0;

  while (n != 0) {
    if (x == num[n]) {
      x -= num[n];
      eat += p[n];
    } else if (x == num[n] - 1) {
      x -= num[n] - 1;
      eat += p[n];
    } else if (2 + num[n - 1] < x && x < num[n] - 1) {
      x -= 2 + num[n - 1];
      eat += 1 + p[n - 1];
    } else if (x == 2 + num[n - 1]) {
      x -= 2 + num[n - 1];
      eat += 1 + p[n - 1];
    } else if (x == 1 + num[n - 1]) {
      x -= 1 + num[n - 1];
      eat += p[n - 1];
    } else if (1 < x && x <= num[n - 1]) {
      x -= 1;
    } else if (x == 1) {
      x -= 1;
    } else {
    }
    n--;
  }
  if (x == 1) {
    eat++;
  }

  std::cout << eat << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n&&n){
    int ansa=0,ansb=0;
    int a[n];
    int b[n];
    for(int i=0;i<n;i++){
      cin>>a[i]>>b[i];
      if(a[i]>b[i]) ansa+=(a[i]+b[i]);
      else if(b[i]>a[i]) ansb+=(a[i]+b[i]);
      else {
	ansa+=a[i];
	ansb+=b[i];
      }
    }
    cout<<ansa<<" "<<ansb<<endl;
  }
  return 0;
}

Measured memory_bytes: 3068
// 辺の重みが1だけだから、ダイクストラとか使わなくても普通のBFSで通るらしい
// 辺の重みが0と1なら、01BFS
// そうでないなら、ダイクストラを使うしかない
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> G(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    queue<int> que;
    vector<int> dist(n, -1);
    vector<int> pre(n, -1);
    dist[0] = 0;
    que.push(0);
    while (!que.empty()) {
        int v = que.front();
        que.pop();
        for (int u : G[v]) {
            if (dist[u] != -1) continue;
            dist[u] = dist[v] + 1;
            pre[u] = v;
            que.push(u);
        }
    }

    cout << "Yes" << endl;
    for (int i = 1; i < n; ++i) {
        cout << pre[i] + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 10580
function main(input) {
  const args = input.split("\n");
  const N = args[0];
  const V = args[1];
  const A = N.split('');
  const B = V.split('');
  
  var count = 0;
  for(var i = 0; i<3; i++) {
    if(A[i]===B[i]) {
      count++
    }
  }
  console.log(count);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 11468
S = input()
T = input()
lS = len(S)
lT = len(T)
C = []
for i in range(lS-lT+1):
    count = 0
    for j in range(lT):
        if S[i+j]!=T[j]:
            count += 1
    C.append(count)
print(min(C))

Measured memory_bytes: 67648
import sys
def input(): return sys.stdin.readline().rstrip()
def f(n,x):#レベルnのx番目
    if n==0:return 0 if x<=0 else 1
    if x<=1+A[n-1]:return f(n-1,x-1)
    return 1+P[n-1]+f(n-1,x-A[n-1]-2)
def main():
    n,x=map(int,input().split())
    global A,P
    A=[1, 5, 13, 29, 61, 125, 253, 509, 1021, 2045, 4093, 8189, 16381, 32765, 65533, 131069, 262141, 524285, 1048573, 2097149, 4194301, 8388605, 16777213, 33554429, 67108861, 134217725, 268435453, 536870909, 1073741821, 2147483645, 4294967293, 8589934589, 17179869181, 34359738365, 68719476733, 137438953469, 274877906941, 549755813885, 1099511627773, 2199023255549, 4398046511101, 8796093022205, 17592186044413, 35184372088829, 70368744177661, 140737488355325, 281474976710653, 562949953421309, 1125899906842621, 2251799813685245, 4503599627370493]
    P=[1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431, 67108863, 134217727, 268435455, 536870911, 1073741823, 2147483647, 4294967295, 8589934591, 17179869183, 34359738367, 68719476735, 137438953471, 274877906943, 549755813887, 1099511627775, 2199023255551, 4398046511103, 8796093022207, 17592186044415, 35184372088831, 70368744177663, 140737488355327, 281474976710655, 562949953421311, 1125899906842623, 2251799813685247]
    print(f(n,x))

if __name__=='__main__':
    main()

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

const int CASES = 4;

int gcd(int a, int b) { return a ? gcd(b%a, a) : b; }

void solve(){
    int N, K;
    cin >> N >> K;
    
    vector<int> A(N);
    for(int i = 0; i < N; ++i){
        cin >> A[i];
        if(A[i] == K){
            cout << "POSSIBLE\n";
            return;
        }
    }
    sort(A.begin(), A.end());

    if(A.back() < K){
        cout << "IMPOSSIBLE\n";
        return;
    }

    int g = A[0];
    for(int i = 1; i < N; ++i){
        g = gcd(g, A[i]);
    }

    if(K % g == 0){
        cout << "POSSIBLE\n";
        return;
    }

    cout << "IMPOSSIBLE\n";
    return;
}

int main() {
    #ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
    #else

    solve();

    #endif
    return 0;
}



Measured memory_bytes: 640
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <numeric>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define ALL(x)   (x).begin(),(x).end()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define mp       make_pair
#define eb       emplace_back
typedef pair<LL, double> P;
typedef pair<P, P> PP;

struct edge { int to; double cost; };

#define int LL

int x[1010], y[1010], r[1010];

double d[100100]; //距離
vector<edge> vec[100100];

void dijkstra() {
	for (int i = 0; i < 1100; i++)d[i] = DINF;
	priority_queue<P, std::vector<P>, std::greater<P>> pq;
	d[0] = 0;
	pq.push(make_pair(d[0], 0));//cost,to
	while (!pq.empty()) {
		P p = pq.top();
		pq.pop();
		int i = p.second;
		if (d[i] < p.first)continue;
		for (int k = 0; k < vec[i].size(); k++) {
			edge e = vec[i][k];
			if (d[e.to] <= d[i] + e.cost)continue;
			d[e.to] = d[i] + e.cost;
			pq.push(make_pair(d[e.to], e.to));
		}
	}
	
}

signed main() {
	int n;
	cin >> x[0] >> y[0] >> x[1000 + 1] >> y[1000 + 1];
	cin >> n;
	x[n + 1] = x[1001], y[n + 1] = y[1001];
	for (int i = 1; i <= n; i++) {
		cin >> x[i] >> y[i] >> r[i];
	}
	for (int i = 0; i <= n+1; i++) {
		for (int j = 0; j <= n + 1;j++) {
			if (i == j)continue;
			double num = sqrt(abs(x[i] - x[j])*abs(x[i] - x[j]) + abs(y[i] - y[j])*abs(y[i] - y[j]));
			vec[i].emplace_back(edge{ j,max(0.0,num - r[i] - r[j]) });
		}
	}
	dijkstra();
	cout <<fixed<<setprecision(20)<< d[n + 1] << endl;
	//cout << dijkstra() << endl;
	//system("pause");

}

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

double a, b;
int h, m;

int main(){
	cin >> a >> b >> h >> m;
	// 1 rotation minute=60 minute, 1 rotation hour=720 minute
	m+=h*60;
	double rm=(m%60)/60;
//	double am=acos(-1)*2*((double)(m%60)/(double)60), ah=acos(-1)*2*((double)m/(double)720);
	double am=(double)(m%60)/60, ah=(double)m/720;
//	cout << am << " " << ah << "\n";
//	double alpha=am-ah;
	double alpha=acos(-1)*2*(am-ah);
//	if (alpha<-acos(-1)) alpha+=acos(-1);
//	if (alpha>acos(-1)) alpha-=acos(-1);
//	cout << am-ah << " " << ah-am << "\n";
	cout << fixed << setprecision(18) << sqrt(a*a+b*b-2*a*b*cos(alpha)) << "\n";
}

Measured memory_bytes: 4212
import math
a, b, h, m = map(int, input().split())
m=m/60
bd=m*360
h=h+m
ad=h/12*360
d=abs(ad-bd)
ax=a*math.cos(math.radians(ad))
ay=a*math.sin(math.radians(ad))
ax = round(ax, 21)
ay = round(ay, 21)
bx=b*math.cos(math.radians(bd))
by=b*math.sin(math.radians(bd))
bx = round(bx, 21)
by = round(by, 21)
# print(math.cos(math.radians(60)))
# print(ax)
# print(ay)
# print(bx)
# print(by)
r=(bx-ax)**2+(by-ay)**2
r=math.sqrt(r)
print(r)

Measured memory_bytes: 9600
/*Made by Shivam Solanki*/
#include<bits/stdc++.h> 
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define ll long long int
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<pii> vp;
typedef vector<pll> vpll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef set<int> sii;
typedef set<ll> sll;
typedef priority_queue<int> pq;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
typedef queue<int> qii;
#define rep(i,k,n) for (int i = k; i < n; ++i) 
#define repr(i,k,n) for (int i = n; i>=k; --i)
#define repll(i,k,n) for (ll i = k; i < n; ++i) 
#define repllr(i,k,n) for (ll i = n; i >= k; --i) 
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int INF = 1e9+5;
const int MOD = 1e9+7;
 
void solve(){
    int n,k;
    cin>>n>>k;
    int ctr=0;
    while(n){
        n/=k;
        ctr++;
    }
    cout<<ctr;
} 
  
int main(){
    // #ifndef ONLINE_JUDGE  
        // freopen("input.txt", "r", stdin); 
        // freopen("output.txt", "w", stdout); 
    // #endif 
    // fastio;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
n = int(input())

def calc(n):
	counter = [[0 for _ in range(10)] for _ in range(10)]

	for i in range(1, n + 1):
		s = str(i)
		counter[int(s[0])][int(s[-1])] += 1

	cnt = 0
	for i in range(1, 10):
		for j in range(1, 10):
			if i == j:
				if counter[i][j] >= 1:
					cnt += counter[i][j] ** 2
			else:
				cnt += counter[i][j] * counter[j][i]
	return cnt

print(calc(n))


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

typedef long long ll;

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

    ll k;
    cin>>k;
    queue<ll> q;
    for(int i=1;i<10;i++)q.push(i);
    for(int i=0;i<k-1;i++){
    	ll x = q.front();
    	q.pop();
    	int j = x % 10;
    	if(j!=0)q.push(10 * x + j - 1);
    	q.push(10 * x + j);
    	if(j!=9)q.push(10 * x + j + 1);
    }
    cout << q.front() << '\n';
	return 0;
}

Measured memory_bytes: 1792
'use strict'
const Main = (arg) => {
  let input = arg.trim().split('\n');
  let AP = input[0].split(' ').map(Number)[0];
  let ap = input[0].split(' ').map(Number)[1];
  // console.log({ AP, ap });

  let Allap = 3 * AP + ap;
  let Answer = Math.floor(Allap / 2);
  console.log(Answer);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
s = list(input())
def solve(now, flg):
  for i in range(len(now)//2):
    if now[i] != now[(i+1)*(-1)]:
      flg += 1
      break
  return flg

flg = 0
now = s
flg = solve(now, flg)
now = s[:(s.__len__()-1)//2]
flg = solve(now, flg)
now = s[(s.__len__()+3)//2-1:]
flg = solve(now, flg)
print("Yes" if flg == 0 else "No")

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
class Program
{
    static int x;
    static List<int> s = new List<int>();
    static string result;
    static void Main()
    {
        string[] tmp = Console.ReadLine().Split(' ');
        s.Add(int.Parse(tmp[0]));
        s.Add(int.Parse(tmp[1]));
        if ((s[0] + s[1]) % 2 == 0) { result = ((s[0] + s[1]) / 2).ToString(); } else { result = "IMPOSSIBLE"; }

        Console.WriteLine(result);
            Console.Out.Flush();
        
    }

 


}

Measured memory_bytes: 13268
#include <stdio.h>

int main(void) {
	int i, j;
	int l[10];
	int v1, v2;
	int total;
	int x;
	double t;
	while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &l[0], &l[1], &l[2], &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v1, &v2) != EOF) {
		total = 0;
		for (i = 0; i < 10; i++)
			total += l[i];
		t = (double)total/(double)(v1+v2);
		x = t*v1;
		for (i = 0; i < 10; i++)
			if( (x -= (double)l[i]) <= 1.0)
				break;
		printf("%d\n", i + 1);
	}
	return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String n = String.valueOf(N);
		int num =Integer.valueOf(n.substring(0,1));
		
		if(num<Integer.valueOf(n.substring(1,2))){
			num++;
			System.out.println(""+num+num+num);
		}else if(num<Integer.valueOf(n.substring(2,3))){
			num++;
			System.out.println(""+num+num+num);
		}else {
			System.out.println(""+num+num+num);
		}
		
		sc.close();
	}
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int_fast64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
constexpr int MOD = 998244353;
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
inline int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
inline int lcm(int a,int b){ return a / gcd(a,b) * b;}
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }
 
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};

signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

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

    vector<bool> ng(n+1);
    vector<int> h(n+1);

    reps(i,n){
        cin >> h[i];
    }

    rep(i,m){
        int a, b;
        cin >> a >> b;
        if(h[a] < h[b]){
            ng[a] = true;
        }else if(h[a] > h[b]){
            ng[b] = true;
        }else{
            ng[a] = true;
            ng[b] = true;
        }
    }

    int res = 0;

    reps(i,n){
        if(!ng[i]){
            ++res;
        }
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 3992
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

{-
 - Next lexicographical permutation algorithm
 - by Project Nayuki, 2016. Public domain.
 - https://www.nayuki.io/page/next-lexicographical-permutation-algorithm
 -
 - Computes the next lexicographical permutation of the specified finite
 - list of numbers.
 - Returns Nothing if the argument is already the highest permutation.
 -}
nextPermutation :: Ord a => [a] -> Maybe [a]
nextPermutation xs =
  let
    len = length xs
    -- Reverse of longest non-increasing suffix
    revSuffix = findPrefix (reverse xs)
    suffixLen = length revSuffix
    prefixMinusPivot = take (len - suffixLen - 1) xs
    pivot = xs !! (len - suffixLen - 1)
    suffixHead = takeWhile (<= pivot) revSuffix
    newPivot : suffixTail = drop (length suffixHead) revSuffix
    newSuffix = suffixHead ++ (pivot : suffixTail)
  in
    if suffixLen == len
    then Nothing
    else Just (prefixMinusPivot ++ (newPivot : newSuffix))
  where
    findPrefix [] = []
    findPrefix (x:xs) =
      x : (if xs /= [] && x <= head xs then findPrefix xs else [])

main = do
  _ <- getInt
  [p', q'] <- replicateM 2 getIntList
  let (p, q) = if p' <= q' then (p', q') else (q', p')
  print $ solve p q 0
  where
    solve p q m | p == q = m
                | otherwise = let p' = (fromJust . nextPermutation) p
                              in solve p' q (m + 1)

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)

int main() {
	string s;
	cin >> s;
	int n = s.size() + 1;
	vector<ll> memo;
	memo.PB(0);
	int i = 0;
	int last = 0;
	while (1) {
		last = 0;
		while (s[i] == '<') {
			memo.PB(last+1);
			last++;
			i++;
			if (i == n - 1)goto end;
		}
		ll cnt = 0;
		while (s[i] == '>') {
			cnt++;
			i++;
			if (i == n - 1) {
				RFOR(j, cnt, 0) {
					if (j == cnt) {
						auto itr = memo.end();
						itr--;
						*itr = max(*itr, cnt);
						continue;
					}
					memo.PB(j);
				}
				goto end;
			}
		}
		RFOR(j, cnt, 0) {
			if (j == cnt) {
				auto itr = memo.end();
				itr--;
				*itr = max(*itr, cnt);
				continue;
			}
			memo.PB(j);
		}
	}

end:
	ll res = accumulate(ALL(memo), 0LL);
	pv(res)
	return 0;
}

Measured memory_bytes: 8304
function Main(input) {
  input = input.split("\n");
  tmp = input[0].split(" ");
  var answer = 0;
  var count = 0;
  var p = new Array();
  var number = new Array();
  for(var i=22;i<Number(tmp[1])+1;i++){
    if(i%10!=1){
      number[count] = String(i).split("");
      p[count] = number[count][0]*number[count][1];
    }
    count++;
    if(i%10==1){
      count--;
    }
  }
  for(var j=0;j<p.length;j++){
    if(p[j]<=tmp[0] && p[j]!=0){
      answer++;
    }
  }
  console.log(answer);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAX_NODE 101

int begin_times[MAX_NODE];
int end_times[MAX_NODE];
int c_time=0;
queue<int> g[MAX_NODE];

void dfs(int f){
  if(begin_times[f]>0)return;
  c_time++;
  begin_times[f]=c_time;
  while( !g[f].empty() ){
    int to = g[f].front();
    g[f].pop();
    if(end_times[to]>0)continue;
    dfs(to);
  }
  c_time++;
  end_times[f]=c_time;
}

int main(){
  int n;cin>>n;
  rep(i, n){
    int from;
    int count;
    cin>>from>>count;
    rep(j, count){
      int t;cin>>t;
      g[from].push(t);
    }
  }

  rep1(i, n)dfs(i);

  rep1(i, n){
    cout<<i<<' '<<begin_times[i]<<' '<<end_times[i]<<endl;
  }

  return 0;
}



Measured memory_bytes: 3164
import sys

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().strip().split()))

all_xor = 0
for a_i in A:
    all_xor ^= a_i

ans = []
for a_i in A:
    ans.append(all_xor ^ a_i)

print(*ans)

Measured memory_bytes: 31548
#include "bits/stdc++.h"

using namespace std;

#define rep(loop, N) for (int loop = 0; loop < N; loop++)

struct Node {
	Node* parent = NULL;
	vector<Node*> child;
	long long value = 0;
};
struct Edge {
	int parent = 0;
	int child = 0;
	bool operator <(const Edge& right) const { return parent < right.parent; }
};
struct Tree {
	vector<Node> node;
	Tree(int, vector<Edge>);
};
Tree::Tree(int nodeNum, vector<Edge> edge) {
	node.resize(nodeNum);
	for (Edge& it : edge) {
		node[it.child].parent = &node[it.parent];
		node[it.parent].child.push_back(&node[it.child]);
	}
}

map<long long, int> factorization(long long N) {
	map<long long, int> re;
	while (true) {
		if (N % 2 == 0) {
			N /= 2;
			re[2]++;
			if (N == 1) break;
		}
		else {
			break;
		}
	}
	for (int loop = 3; (long long)loop * (long long)loop <= N; loop += 2) {
		if (N % loop == 0) {
			N /= loop;
			re[loop]++;
			loop -= 2;
			if (N == 1) break;
		}
	}
	if (N > 1) re[N]++;
	return re;
}

struct Memo {
	long long fact = 0;
	long long fact_inv = 0;
	long long inv = 0;
};
class Combination1 {
private:
	long long m_module = 1000000007;
	vector<struct Memo> memo;
public:
	long long calculate(int, int);
	Combination1(int, long long);
};
long long Combination1::calculate(int n, int k) {
	return ((memo[n].fact * memo[k].fact_inv) % m_module * memo[n - k].fact_inv) % m_module;
}
Combination1::Combination1(int memo_max, long long module = 1000000007) {
	m_module = module;
	memo.push_back({ 1,1,0 });
	memo.push_back({ 1,1,1 });
	for (int loop = 2; loop <= memo_max; loop++) {
		struct Memo temp;
		temp.fact = (memo[loop - 1].fact * loop) % m_module;
		temp.inv = m_module - (memo[m_module % loop].inv * int(m_module / loop)) % m_module;
		temp.fact_inv = (memo[loop - 1].fact_inv * temp.inv) % m_module;
		memo.push_back(temp);
	}
}

class Combination2 {
private:
	int size = 0;
	bool add(int);
public:
	vector<int> sequence;
	bool next_combination(void);
	Combination2(int, int);
};
bool Combination2::add(int index) {
	if (index == (int)sequence.size() - 1 && sequence[index] == size - 1
		|| index < (int)sequence.size() - 1 && sequence[index] == sequence[index + 1] - 1) {
		if (index == 0) {
			return false;
		}
		else {
			bool re = add(index - 1);
			sequence[index] = sequence[index - 1] + 1;
			return re;
		}
	}
	else {
		sequence[index]++;
		return true;
	}
}
bool Combination2::next_combination(void) {
	return (sequence.size() == 0) ? false : add(sequence.size() - 1);
}
Combination2::Combination2(int n, int r) {
	size = n;
	for (int loop = 0; loop < r; loop++) sequence.push_back(loop);
	return;
}

void A_Lucky_7(void) {

	string N; cin >> N;

	rep(index, 3) {
		if (N[index] == '7') {
			cout << "Yes" << endl;
			return;
		}
	}
	cout << "No" << endl;
	return;
}

int main(void) {

	A_Lucky_7();
	return 0;
}


Measured memory_bytes: 3640
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	if a < b {
		fmt.Println(b + b - 1)
		return
	}
	if a > b {
		fmt.Println(a + a - 1)
		return
	}
	fmt.Println(a + a)
}

Measured memory_bytes: 512
<?php
    list($r, $c) = explode(" ", trim(fgets(STDIN)));
    $clumn_sum = array_fill(0, $c, 0);
    
    for($i = 0; $i < $r; $i++){
        $num = explode(" ", trim(fgets(STDIN)));
        echo implode(" ", $num)." ".array_sum($num)."\n";
        
        foreach($num as $key => $value){
            $clumn_sum[$key] += $value;
        }
    }
    
    echo implode(" ",$clumn_sum)." ".array_sum($clumn_sum)."\n";
    
    

Measured memory_bytes: 15396
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define ll long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define testcase ll T; cin >> T; for (ll tc = 1; tc <= T; tc++)
#define M 1000000007
#define MM 998244353
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
#define r2 1.41421356237
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

#define sizes 1000000
bool a[sizes+3]={};
vector<int>v[sizes];

int main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  //testcase {
  vector<int> prime;
    prime.pb(2);
    for(long long i=4;i<=sizes;i+=2) { a[i]=1; }
    for(long long i=3;i<=sizes;i+=2) {
      if(a[i]==0) {
        prime.pb(i);
        for(long long j=i*i;j<=sizes;j+=i) {
          a[j]=1;
        }
      }
    }
    int n,g=0;
    bool ok=1;
    cin>>n;
    for(int i=0;i<n;i++) {
    	int q;
    	cin>>q;
    	g=__gcd(g,q);
    	if(!a[q]) { v[q].pb(i); }
    	else {
    		int p=0;
    		while(p<prime.size()) {
    			if(q%prime[p]==0) { v[prime[p]].pb(i); while(q%prime[p]==0) { q/=prime[p]; } }
    			else if(q==1) { break; }
    			else if(!a[q]) { v[q].pb(i); break; }
    			else { p++; }
    		}
    	}
    }
    for(int i=2;i<sizes;i++) { if(v[i].size()>1) { ok=0; break; } }
    if(ok) { cout<<"pairwise coprime"; }
	else if(g==1) { cout<<"setwise coprime"; }
	else { cout<<"not coprime"; }
	//}  
  return 0;
}

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

using namespace std;

#define endl '\n'
#define Opy ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)

typedef long long ll;

int main()
{
    Opy;

/*-------------------------------------------------
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
-------------------------------------------------*/
    int t, cnt = 0;

    map< string, int> A;

    cin>> t;

    for(int i = 0; i< t; i++)
    {
        string tmp;

        cin>> tmp;

        A[tmp]++;

        cnt = max(cnt, A[tmp]);
    }

    auto it = A.begin();

    while( it != A.end())
    {
        if(cnt == it-> second)
        {
            cout << it->first<< endl;
        }

        it++;
    }

    return 0;
}


Measured memory_bytes: 19224
i = int(input())
taro = 0
hanako = 0

for k in range(0, i):
    a = input()
    a = a.split()
    [x, y] = a

    if x > y:
        taro = taro + 3
    elif y > x:
        hanako = hanako + 3
    elif x == y:
        taro = taro + 1
        hanako = hanako + 1

taro = str(taro)
hanako = str(hanako)
k = " "

ans = taro + k + hanako
print(ans)


Measured memory_bytes: 5600
/*
  #問題：
  


  #分析：
  #オブジェクト：
  
  #条件：
  

  #要求：
  

  #解法：
  
*/

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;


const unsigned int BIT_FLAG_0 = (1<<0);
const unsigned int BIT_FLAG_1 = (1<<1);
const unsigned int BIT_FLAG_2 = (1<<2);
const unsigned int BIT_FLAG_3 = (1<<3);
const unsigned int BIT_FLAG_4 = (1<<4);
const unsigned int BIT_FLAG_5 = (1<<5);
const unsigned int BIT_FLAG_6 = (1<<6);
const unsigned int BIT_FLAG_7 = (1<<7);


#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;

using Bint = mp::cpp_int;



int main(void){
  // int N; cin>>N;
  string S;
  cin>>S;
  int N=stoi(S);
  int ans=0;
  FOR(i,0,S.length() ){
    ans+=S[i]-48;
  }
  cerr<<ans<<endl;

  if(N%ans==0)  cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
}



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

namespace CSharpSample01
{
	class Program
	{

		static void Main(string[] args)
		{
			var N = int.Parse(Console.ReadLine());
			var inputList = new List<string>();

			for(int i = 0;i < N; i++)
			{
				inputList.Add(Console.ReadLine());
			}

			Console.WriteLine(inputList.Distinct().Count());
		}
	}
}

Measured memory_bytes: 48024
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define endl "\n"
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fb(i, a, b) for(ll i=a; i>=b; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector <int>
#define vl vector <long long>
#define pi pair <int, int>
#define sz(x) (int) x.size()
#define M 100005
#define mod 1000000007
using namespace std;

void solve()
{
	int k, a, b, ans= 0;
	cin>>k>>a>>b;
	f(i, a, b+1)
	{
		if(i%k == 0) ans++;
	}
	if(ans) cout<<"OK";
	else cout<<"NG";
}

int main()
{
    IOS
    int t = 1;
    //cin>>t;
    f(tno, 1, t+1)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};
const int mod = 1000000007;
#define Yes(ifeq) cout<<(( ifeq )? "Yes":"No")<<endl;

void Main(){
  int n,m;
  cin>>n>>m;
  vi a(n);
  cin>>a;
  int sum=0;
  sum = accumulate(rng(a),0);
  int cnt=0;
  
  rep(i,n){
    if(4*m*a[i] >= sum) cnt++;
  }
  Yes( cnt>=m );
  return;
  
} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N, K, C; cin >> N >> K >> C;
    bool bad[N]; F0R(i, N) {
        char c; cin >> c; bad[i] = c == 'x';
    }
    int bef[N+1], aft[N+1]; //max where last worker is at i-1, max where first worker is at i
    bef[0] = 0;
    FOR(i, 1, N+1) {
        bef[i] = bef[max(i-C-1, 0)] + 1;
        if (bad[i-1]) bef[i] = bef[i-1];
    }
    aft[N] = 0;
    F0Rd(i, N) {
        aft[i] = aft[min(N, i+C+1)]+1;
        if (bad[i]) aft[i] = aft[i+1];
    }

    vi begs, ends;
    FOR(i, 1, C+1) {
        if (aft[i] >= K) {
            begs.pb(0); ends.pb(i);
        }
        if (bef[N-i] >= K) {
            begs.pb(N-i);
            ends.pb(N);
        }
    }

    F0R(i, N-C) {
        if (bef[i] + aft[i+C] >= K) {
            begs.pb(i); ends.pb(i+C);
        }
    }

    if (C == 0) {
        if (bef[N] > K) return 0 ;
        F0R(i, N) {
            if (!bad[i]) cout << i+1 << endl;
        }
        return 0;
    }
    sort(all(begs)); sort(all(ends));
/*    F0R(i, N+1) {
       cout << bef[i] << " " << aft[i] << endl;
    }
    F0R(i, sz(begs)) {
        cout << begs[i] << " " << ends[i] << " test " << endl;
    }*/


    int cnt = 0;
    int p1 = 0, p2 = 0;
    vi ans;
    F0R(i, N) {
        while (p1 != sz(begs) && begs[p1] <= i) {
            cnt++; p1++;
        }
        while (p2 != sz(ends) && ends[p2] <= i) {
            cnt--; p2++;
        }
        if (cnt == 0) ans.pb(i+1);
    }
    F0R(i, sz(ans)) cout << ans[i] << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 5100
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <climits>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(0);
#define pb push_back
#define sz(s) (int)s.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#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 PI 3.14159265

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vi;
//const ll mod=(ll)1e9+7;
//const ll inf = (ll)1e16 + 7;
const int N=1e5+7;

int main(){
    fast;
    ll n,a,b,ans,x[N];
    cin>>n>>a>>b;
    forn(i,n) cin>>x[i];
    
    for1(i,n-1){
        if((x[i]-x[i-1])*a<b){
            ans+=(x[i]-x[i-1])*a;
        }else{
            ans+=b;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<cstdint>
#include<algorithm>
#include<numeric>
#include<string>

int64_t next_lunlun(int64_t k) {
  if(k < 12) return k+1;
  int64_t a = k+1;
  while(a%10 == 0) a/=10;
  if(a == 1) return k+1;
  a = k;
  int64_t d1 = a%10;
  for(int64_t d = 1;; ++d) {
    a /= 10;
    int64_t d2 = a%10;
    if(a == 0 ||(d1 < 9 && d2-1 <= d1+1 && d1+1 <= d2+1)) {
      // [a] d1+1 d1 d-1 ...
      ++d1;
      for(int64_t i = 0; i < d; ++i) {
        a = a*10+d1;
        d1 = std::max((int64_t)0, d1-1);
      }
      return a;
    }
    d1 = d2;
  }
  return 0;
}

int main() {
  int64_t K;
  std::cin >> K;
  int64_t ans = 0;
  for(int i = 0; i < K; ++i) ans = next_lunlun(ans);
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ios                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define fill(x, v) memset(x, v, sizeof(x))
const ll mod = 1000000007;
#define trace1(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z) cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
//--------dsu----------
vector<int> volume(1000000);
vector<int> parent(1000000);

void initialise_dsu()
{
    for (int i = 0; i < volume.size(); i++)
        volume[i] = 1;
    for (int i = 0; i < parent.size(); i++)
        parent[i] = i;
}

int find_par(int v)
{
    return (v == parent[v] ? v : parent[v] = find_par(parent[v]));
}

void union_sets(int a, int b)
{
    a = find_par(a);
    b = find_par(b);
    if (a != b)
    {
        if (volume[a] < volume[b])
            swap(a, b);
        parent[b] = a;
        volume[a] += volume[b];
    }
}

int power(int x, unsigned int y, int p)
{
    int res = 1;

    x = x % p;

    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;

        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
//-------------------------
string arr;
map<pair<char, char>, char> mpsym;

int main()
{
    ios;

    int r;
    long double pi = 6.28318530717958623200 / 2;
    cin >> r;
    cout << std::setprecision(50) << pi * 2 * r << '\n';
    return 0;
}

Measured memory_bytes: 10984
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <map>
#include <iomanip>
using namespace std;

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

    int len = S.length();

    if (S[len-1] == 's') {
        cout << S << "es" << endl;
    }else {
        cout << S << "s" << endl;
    }


    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=2e5;
const ll INF=1e18;
int N;
ll X,x[MAX_N];
ll psm[MAX_N+1];
int main(){
	cin>>N>>X;
	REP(i,N)cin>>x[i];
	psm[0]=0;
	REP(i,N){
		psm[i+1]=psm[i]+x[i];
	}
	ll ans=INF;
	FOR(k,1,N+1){
		ll tem=0;
		tem=(k+N)*X;
		int c=1;
		bool flg=true;
		for(int i=N-1;i>=0;i=max(i-k,-1)){
			ll v;
			if (c==1){
				v=5;
			}else{
				v=c*2+1;
			}
			if ((psm[i+1]-psm[max(0,i+1-k)])<(INF+v-1)/v){
				tem+=v*(psm[i+1]-psm[max(0,i+1-k)]);
				if (tem>=INF){
					flg=false;
					break;
				}
			}else{
				flg=false;
				break;
			}
			c++;
		}
		if (flg){
			ans=min(ans,tem);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3328
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
const ll MOD = 998244353;
signed main(){
  init_io();
  ll n,k;
  cin >> n >> k;
  vector<ll> l(k),r(k);
  vector<ll> dp(n+3,0);
  vector<ll> imo(n+3,0);
  for(int i=0;i<k;i++){
    cin >> l[i] >> r[i];
  }
  dp[1] = 1;
  for(int i=1;i<=n;i++){
    imo[i] = (imo[i]+imo[i-1]+MOD)%MOD;
    dp[i] = (dp[i]+imo[i]+MOD)%MOD;
    for(int j=0;j<k;j++){
      ll lm = min(n+1,i+l[j]);
      ll rm = min(n+1,i+r[j]+1);
      imo[lm] = (imo[lm]+dp[i]+MOD)%MOD;
      imo[rm] = (imo[rm]-dp[i]+MOD)%MOD;
    }
  }
  cout << dp[n]%MOD << endl;
}


Measured memory_bytes: 6364
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto S = readln.chomp;
    while (!S.empty) {
        if (S.length >= 5 && S[$-5..$] == "dream") {
            S = S[0..$-5];
        } else if (S.length >= 7 && S[$-7..$] == "dreamer") {
            S = S[0..$-7];
        } else if (S.length >= 5 && S[$-5..$] == "erase") {
            S = S[0..$-5];
        } else if (S.length >= 6 && S[$-6..$] == "eraser") {
            S = S[0..$-6];
        } else {
            writeln("NO");
            return;
        }
    }
    writeln("YES");
}

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;


int n; 

void dfs(string s, char mx) {
    if(s.size() == n){
        cout << s << endl;
        return;
    }
    for(char c = 'a'; c <= mx+1; c++){
        //c++ではcharは数字でもたれている
        string t = s;
        t += c;
        dfs(t, max(mx, c));
    }
}

int main(){
    cin >> n;
    dfs("", 'a'-1);
    return 0;
}

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

int main() {
  int a,b,c,n;
  cin>>a>>b>>c>>n;
  rep(i,n) {
    if(max(a,max(b,c))==a) a=a*2;
    else if(max(a,max(b,c))==b) b=b*2;
    else if(max(a,max(b,c))==c) c=c*2;
  }
  cout << a+b+c << endl;
}


Measured memory_bytes: 256
//Never stop trying
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp> 
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
//s.order_of_key(), *s.find_by_order()

using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
#define int ll
typedef double db;
typedef long double ld;

typedef pair<int,int> pi;
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;

#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

const int MOD = 1e9+7; //998244353
const ll INF = 1e18;
const int nx[4]={0,0,1,-1}, ny[4]={1,-1,0,0}; //right left down up

int32_t main(){
   boost;
	int a ; cin>>a;
	cout << a+a*a+a*a*a << endl;

   return 0;
}



Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll H, W;
  cin >> H >> W;
  vvc a(H, vc(W));
  rep(i, H){
    rep(j, W) cin >> a[i][j];
  }

  rep(i, W + 2) cout << '#';
  cout << endl;
  
  rep(i, H){
    cout << '#';
    rep(j, W) cout << a[i][j];
    cout << '#' << endl;
  }

  rep(i, W + 2) cout << '#';
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  if (a > b) {
    for (int i = 0; i < a; i++) {
      cout << b;
    }
  } else {
    for (int i = 0; i < b; i++) {
      cout << a;
    }
  }
  
  return 0;
}

Measured memory_bytes: 256