akhauriyash/Code-Regression huggingface dataset:
n = int(input())

first = []
second = []

for i in range(n):
    x,y = map(int,input().split())
    first.append(x)
    second.append(y)
count = 0
flag = 1
for i in range(n):
    if first[i] == second[i]:
        count += 1
        if count == 3:
            flag = 0
            print("Yes")
            break
    else:
        count = 0

if flag:
    print("No")

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

using namespace std;

int N;

int visit(int cnt, int idx, vector<int> &a, vector<bool> &v){
//  cout << idx;
  if(cnt > N) return -1;
  else if(v[idx]) return -1;
//  else if(a[idx] == 1) return cnt+1;
  else{
    if(idx == 1) return cnt;
    v[idx] = true;
    return visit(cnt + 1, a[idx], a, v);
  }
}

int main(void) {
  cin >> N;
  
  vector<int> a(N);
  vector<bool> v(N, false);
  for(int i = 0; i < N; i++){
    cin >> a[i];
    a[i]--;
  }
  cout << visit(1, a[0], a, v);
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
using namespace std;
const int MAX = 1e5 + 10;
const ll MOD = 1e9 + 7;
int N, M, K, Q;

int f(int x, int y) {
	if (x <= y) return abs(y - x);
	else return INF;
}

int main()
{
	int i, j, k;
	int x, y;
	scanf("%d%d", &x, &y);
	int mini = INF;
	mini = min(mini, f(x, y));
	mini = min(mini, f(-x, y) + 1);
	mini = min(mini, f(x, -y) + 1);
	mini = min(mini, f(-x, -y)+ 2);
	printf("%d", mini);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = 998244353;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

const Int N = 300;
Int mem[N+1][N*N+1];
Int n;

vector<Int> A;

Int dfs(Int i, Int a, Int bc){
  
  if(i == n) return a >= bc;
  if(mem[i][a] != -1) return mem[i][a];
  
  Int resA = dfs(i+1, a + A[i], bc);
  Int resB = dfs(i+1, a, bc + A[i]) * 2;
  Int res = (resA + resB)%mod;
  mem[i][a] = res;
  return res;
}


Int dfs2(Int i, Int a, Int bc){
  if(i == n) return a == bc;
  if(mem[i][a] != -1) return mem[i][a];
  Int resA = dfs2(i+1, a + A[i], bc);
  Int resB = dfs2(i+1, a, bc + A[i]);
  Int res = (resA + resB)%mod;
  mem[i][a] = res;
  return res;
}



signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  
  
  cin>>n;
  A.resize(n);
  cin>>A;
  
  Int all = 1;
  for(Int i=0;i<n;i++) all = all * 3 % mod;
  
  memset(mem, -1,sizeof(mem));
  Int a = dfs(0, 0, 0);
  
  memset(mem, -1,sizeof(mem));
  Int b = dfs2(0, 0, 0);
  //pr(a, b);
  Int ans = ((a - b+mod)%mod) * 3 % mod;
  ans = (all-ans+mod)%mod;
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 211968
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>



using namespace std;

string s;
int n;
int cnt=0;
char flag;



int main(){
    cin >> n;
    cin >> s;
    for(int i=0;i<n;i++){
        if(s[i] == 'A' ){
            flag = s[i];
        }
        else if(s[i] == 'B' && flag == 'A'){
            flag = 'B';
        }
        else if(s[i] == 'C' && flag == 'B'){
            cnt++;
            flag = 0;
        }
        else flag = 0;
    }

    cout << cnt << endl;


return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    vector<ll> h(N);
    ll ans = 0;
    rep(i, N)
    {
        int h;
        cin >> h;
        if (h >= K) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
fn get_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().to_string()
}

fn reads<T>() -> Vec<T>
    where
        T: std::str::FromStr,
        <T as std::str::FromStr>::Err: std::fmt::Debug {
    get_line().split(' ').map(|x| x.parse().unwrap()).collect()
}

use std::cmp;

fn main() {
    let nm: Vec<usize> = reads();

    let n = cmp::min(nm[0], nm[1]);
    let m = cmp::max(nm[0], nm[1]);

    let modv = 1000000007;

    let prdf = |s, t| {
        let mut res = 1;

        for i in s..(t + 1) {
            res *= i;
            res %= modv;
        }

        res
    };

    let res = if m - n > 1 {
        0
    }
    else if m - n > 0 {
        prdf(1, n) * prdf(1, m) % modv
    }
    else {
        let np = prdf(1, n);

        (2 * np % modv) * np % modv
    };

    println!("{}", res);
}


Measured memory_bytes: 4352
#include<cstdio>
#include<functional>
#include<algorithm>
#define MM 20000000000000000
int dp[101][101][301];
using namespace std;
int main(void)
{
	int i,j,k,n,w1[100],v[100],w0,w2[100],mx;
	long long w;
	scanf("%d %lld",&n,&w);
	for(i=0;i<n;i++)	scanf("%d %d",&w1[i],&v[i]);
	w0=w1[0];
	for(i=0;i<n;i++)	w2[i]=w1[i]-w0;
	for(i=0;i<=n;i++)	{
		for(j=0;j<=n;j++)	{
			for(k=0;k<=3*n;k++)	dp[i][j][k]=-1;
		}
	}
	
//	for(i=0;i<n;i++)	printf("w1=%d\n",w1[i]);
	
	dp[0][0][0]=0;
	for(i=0;i<n;i++)	{
		for(j=0;j<=n;j++)	{
			for(k=0;k<=3*n;k++)	{
				if(dp[i][j][k]!=-1)	{
					dp[i+1][j][k]=max(dp[i+1][j][k],dp[i][j][k]);
					if(j<n)	{
						dp[i+1][j+1][k+w2[i]]=max(dp[i+1][j+1][k+w2[i]],dp[i][j][k]+v[i]);
//						printf("dp=%d %d %d %d %d\n",dp[i+1][j+1][k+w2[i]],i+1,j+1,k+w2[i],w2[i]);
						
					}
				}
			}
		}
	}
	mx=-1;
	for(j=0;j<=n;j++)	{
		for(k=0;k<=3*n;k++)	{
			if(w>=(long long)w0*j+k)	{
				mx=max(mx,dp[n][j][k]);
			}
		}
	}
	printf("%d\n",mx);

	return 0;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long int n;
    long int ans1 = pow(10,12);
    cin >> n;
    for(long int i=1;i<sqrt(n)+1;i++){
        if (n%i==0){
            long int ans = ((i-1)+(n/i-1));
            ans1 = min(ans,ans1);
        }
    }
    cout << ans1 << endl;
} 


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

int main(){
    int x,y,q,r;
    while(cin >> x >> y){
        while(1){
            q = x/y;
            r = x - q*y;
            if(r == 0) break;
            x = y;
            y = r;
        }
        cout << y << endl;
    }
}

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

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int[] V = new int[N];
        int[] C = new int[N];
        string[] input = Console.ReadLine().Split(' ');
        
        for(int i = 0; i < N; i++)
        {
            V[i] = int.Parse(input[i]);
        }
        input = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++)
        {
            C[i] = int.Parse(input[i]);
        }
        int ans = 0;
        for (int i = 0; i < N; i++)
        {
            if (V[i] > C[i]) { ans += V[i] - C[i]; }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    ll N;cin >> N;
    cout << N*(N-1)/2 << endl;
}

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

int main() {
  string s;
  cin >> s;
  reverse(s.begin(),s.end());
  vector<string>t={ "dream", "dreamer","erase", "eraser"};
  for(int i=0; i<4; i++){
    reverse(t[i].begin(),t[i].end());
  }
  
  bool can=true;
  for(int i=0; i<s.size();){
    bool can2=false;
    for(int j=0; j<4; j++){
      string A=t[j];
      if(s.substr(i,A.size())==A){
        i+=A.size();
        can2=true;
      }
    }
    if(can2==false){
      can=false;
      break;
    }
  }
  if(can){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
      
  
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, P> T;

const ll mod = 1000000007;
const ll INF = 1000000100;

ll N;
ll a[100010];
vector<ll> vec;

ll ans;

ll pow_mod(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2 == 1)
	{
		return x * pow_mod(x, y - 1) % mod;
	}
	else
	{
		ll half = pow_mod(x, y / 2);
		return half * half % mod;
	}
}

ll div_mod(ll x)
{
	return pow_mod(x, mod - 2);
}

void init()
{
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
		vec.push_back(a[i]);
	}
}

void output()
{
	cout << ans << endl;
}

bool kiwosorasetai()
{
	ll sum[100010];
	for (int i = 0; i <= N; i++)
	{
		sum[i] = 0;
	}
	for (int i = 0; i < N; i++)
	{
		if (i)
		{
			sum[i + 1] = sum[i] - 1;
		}
		else
		{
			sum[i + 1] = sum[i] + 1;
		}
	}
	for (int i = 1; i < N; i++)
	{
		
	}
	return true;
}

void solve()
{
	sort(vec.begin(), vec.end());
	
	ll lb = -1, ub = vec.size();
	while (lb + 1 < ub)
	{
		ll mid = (lb + ub) / 2;
		
	}
}

int main()
{
	//init();

	//solve();

	string s;
	cin >> s;
	for (int i = 0; i < s.length() / 2; i++)
	{
		if (s[i] != s[s.length() - i - 1])
		{
			ans++;
		}
	}

	cout << ans << endl;

	//output();

	cin >> N;
}

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

using namespace std;

long long MAX=1<<18;
long long tab[1<<19];
long long dane[200005];

void up(long long v, long long x)
{

    v+=MAX;
    tab[v]=x;
    v/=2;

    while(v>1)
    {
        tab[v]=max(tab[v*2], tab[v*2+1]);
        v/=2;
    }

    return;
}

long long m(long long b)
{
    long long w=0;
    long long a=MAX;
    b+=MAX-1;

    w=max(tab[a], tab[b]);

    while(a/2!=b/2)
    {

        if(a%2==0)
        {
            w=max(w, tab[a+1]);
        }

        if(b%2==1)
        {
            w=max(w, tab[b-1]);
        }

        a/=2;
        b/=2;

    }

    return w;
}


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

    int n;
    long long a, MX;
    cin>>n;

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

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

        MX=m(dane[i]);

        up(dane[i], MX+a);
    }

    cout<<max(m(n), tab[MAX+n]);

    return 0;
}


Measured memory_bytes: 5376
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int i = 1;
		while(i <= n){
			int x = i;
			if(x % 3 == 0){
				System.out.printf(" %d", i);
			} else{
				while(x > 0){
					if(x % 10 == 3){
						System.out.printf(" %d", i);
						break;
					}
					x/= 10;
				}
			}
		i++;
		}
		System.out.printf("\n");
	}
}

Measured memory_bytes: 39444
#include <bits/stdc++.h>
/*cout<<setprecision(5)<<ret<<endl;で、数字部分を計5桁表示かつゼロ埋め無*/
/*cout<<fixed<<setprecision(5)<<ret<<endlで、小数部のみ5桁表示かつゼロ埋め有*/
using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
/* [Shift+Command+b]（コンパイル）ー＞[Ctrl+Shift+`]（ターミナル起動）ー＞[./a.out] */

//////////////////
//  A
int main(void){
    int a;cin>>a;
    cout<<3*a*a<<endl;
    return 0;
}
//////////////////
//  B
/*int main(void){

    return 0;
}*/
//////////////////
//  C 
/*int main(void){

    return 0;
}*/
//////////////////
//  D
/*int main(void){

    return 0;
}*/


Measured memory_bytes: 3640
while True:
  H, W = map(int, input().split())
  if W == 0 and H == 0:
    break
  #最上段
  for i in range(W):
    print("#", end="")
  print() 
  #真ん中
  for j in range(H - 2):
    for i in range(W):
      if i == 0 or i == W -1:
        print("#", end="")
      else:
        print(".", end="")
    print()
  #最下段
  for i in range(W):
    print("#", end="")
  print() 
  #改行
  print()
  


Measured memory_bytes: 7008
al = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
N = int(input())
M = N
v = 1
while True:
    if(M<=26**v):
        break
    M -= 26**v
    v += 1
for i in range(v):
    N -= 26**i  
ans = []
for i in range(v):
    ans.append("a")
for i in range(v):
    ans[-i-1]=al[N%26]
    N = N//26
ans.reverse()
anss = ""
for i in range(len(ans)):
    anss += ans[-i-1]
print(anss)
    


  

Measured memory_bytes: 9224
n = int(input())
l = [1]*100010
l[0] = 0
l[1] = 0
for i in range(2,10**5+10):
  if l[i]:
    for j in range(2*i,10**5+10,i):
      l[j] = 0
while not l[n]:
  n += 1
print(n)


Measured memory_bytes: 3828
#include <iostream>
#include <stack>

void get_input(int* arr) {
    for (int i = 0; i < 10; i++) {
        std::cin >> arr[i];
    }
}

char* solve(int* balls) {
    std::stack<int> a, b;
    a.push(0); b.push(0);

    for (int i = 0; i < 10; i++) {
        if (balls[i] > a.top() && balls[i] > b.top()) {
            if (a.top() > b.top()) {
                a.push(balls[i]);
            } else {
                b.push(balls[i]);
            }
        } else if (balls[i] > a.top() && balls[i] < b.top()) {
            a.push(balls[i]);
        } else if (balls[i] < a.top() && balls[i] > b.top()) {
            b.push(balls[i]);
        } else {
            return "NO";
        }
    }
    return "YES";
}

int main(void) {
    int balls[10];
    int n;
    std::cin >> n;

    for (int i = 0; i < n; i++) {
        get_input(balls);
        std::cout << solve(balls) << std::endl;
    }

    return 0;
}

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> I(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i]--;
    I[A[i]] = i;
  }

  int now = -1, cnt = 0;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int j = I[i];
    if (now < j) cnt++; else {
      ans = max(ans, cnt);
      cnt = 1;
    }
    now = j;
  }
  ans = max(ans, cnt);
  cout << N - ans << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
  return 0;
}

Measured memory_bytes: 1792
#input
S = str(input())

#output
if S == "SUN":
    print(7)
elif S == "MON":
    print(6)
elif S == "TUE":
    print(5)
elif S == "WED":
    print(4)
elif S == "THU":
    print(3)
elif S == "FRI":
    print(2)
else:
    print(1)

Measured memory_bytes: 2940
//probrem_c.go

package main

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

const (
	constMod = int(1e9) + 7
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

// -----------------------------------------

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

func getIntSlice(n int) []int {
	ns := []int{}
	for i := 0; i < n; i++ {
		ns = append(ns, getInt())
	}
	return ns
}

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

func getStringSlice(n int) []string {
	ss := []string{}
	for i := 0; i < n; i++ {
		ss = append(ss, getString())
	}
	return ss
}

// -----------------------------------------

// Sort Fanction

func sortIntSlice(ns []int) []int {
	sort.Sort(sort.IntSlice(ns))
	return ns
}

func rsortIntSlice(ns []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(ns)))
	return ns
}

// -----------------------------------------

// Num Fanction

//numModPow(a, n, m) = a^n % m
func numModPow(a int, n int, m int) int {
	result := 1

	for n > 0 {
		if n%2 == 1 {
			result = (result * a) % m
		}

		a = (a * a) % m
		n >>= 1
	}

	return result
}

// numGcd(a, b) = gcd(a, b)
func numGcd(a int, b int) int {
	if b == 0 {
		return a
	}

	return numGcd(b, a%b)
}

// numLcm(a, b) = lcm(a, b)
func numLcm(a int, b int) int {
	return a * b / numGcd(a, b)
}

// numModInv(a, p) = a^(-1) % p
func numModInv(a int, p int) int {
	if a == 1 {
		return 1
	}

	return p - numModInv(p%a, p)*(p/a)%p
}

// numModFrac(n) = n! % constMod
func numModFrac(n int) []int {
	frac := []int{1}

	for i := 1; i <= n; i++ {
		frac = append(frac, i*frac[i-1]%constMod)
	}

	return frac
}

// numModConb(n, r) = nCr % constMod
func numModConb(n int, r int) int {
	frac := numModFrac(n)

	return (frac[n] / ((frac[n-r] * frac[r]) % constMod)) % constMod
}

// -----------------------------------------

func solve() {

	k, n := getInt(), getInt()
	a := getIntSlice(n)

	var ltable []int

	for i := 0; i < n-1; i++ {
		ltable = append(ltable, a[i+1]-a[i])
	}

	ltable = append(ltable, a[0]-a[len(a)-1]+k)

	rsortIntSlice(ltable)

	fmt.Fprintln(wr, k-ltable[0])

}

// -----------------------------------------

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}


Measured memory_bytes: 11392
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

template<typename T>
void cout_mat(vector<vector<T>  > &mat){
    for(int i=0; i<mat.size(); i++){
        vector<T> vec = mat[i];
        cout_vec(mat[i]);
    }
}

ll calc(vector<int> vec, vector<vector<int>> &F, vector<vector<ll>> &P){
    int cnt=0;
    ll ans=0;
    for(int i=0; i<(int)F.size(); i++){
        int tmp=0;
        for(int j=0; j<10; j++){
            cnt+=vec[j];
            tmp+=vec[j]&F[i][j];
        }
        ans+=P[i][tmp];
    }
    if(cnt==0){
        return -MOD*MOD;
    }else{
        return ans;
    }
}

ll full_search(vector<int> &vec,vector<vector<int>> &F, vector<vector<ll>> &P){
    if((int)vec.size()==10){
        return calc(vec, F, P);
    }

    ll ret=-MOD*MOD;

    vec.push_back(1);
    ret=max(ret,full_search(vec, F, P));
    vec.pop_back();
    
    vec.push_back(0);
    ret=max(ret,full_search(vec, F, P));
    vec.pop_back();

    return ret;
}

int main(){
    int N;
    cin >> N;
    vector<vector<int>> F(N,vector<int>(10,0));
    for(int i=0; i<N; i++){
        for(int j=0; j<5; j++){
            for(int k=0; k<2; k++){
                cin >> F[i][j*2+k];
            }
        }
    }

    vector<vector<ll>> P(N,vector<ll>(11,0));
    for(int i=0; i<N; i++){
        for(int j=0; j<11; j++){
            cin >> P[i][j];
        }
    }

    //cout_mat(P);
    //cout_mat(F);

    vector<int> vec(0);
    cout << full_search(vec, F, P) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdint.h>
#include <algorithm>
#include <string>

using namespace std;

static string str;
static string str1 = "dream";
static string str2 = "dreamer";
static string str3 = "erase";
static string str4 = "eraser";

int32_t main()
{
  cin >> str;

  reverse(str.begin(), str.end());

  reverse(str1.begin(), str1.end());
  reverse(str2.begin(), str2.end());
  reverse(str3.begin(), str3.end());
  reverse(str4.begin(), str4.end());

  uint32_t index = 0;
  while(index < str.size()){

    if(str2.compare(str.substr(index, str2.size())) == 0){
      index += str2.size();
    } else if(str4.compare(str.substr(index, str4.size())) == 0){
      index += str4.size();
    } else if(str1.compare(str.substr(index, str1.size())) == 0){
      index += str1.size();
    } else if(str3.compare(str.substr(index, str3.size())) == 0){
      index += str3.size();
    } else{
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;

  return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int e=0;
	for(int i=0;a*i<=d;i++){
		for(int j=0;b*j<=d;j++){
			if((d-i*a-j*b)%c==0&&d-i*a-j*b>=0)
				e++;
		}
	}
	cout<<e<<endl;
	return 0;
}

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

int main() {
  int A1, A2, A3; cin >> A1 >> A2 >> A3;
  A1 + A2 + A3 >= 22 ? cout << "bust" << endl : cout << "win" << endl;
}

Measured memory_bytes: 3600
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int f[10005];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int sum = 0;
	vector<int> ans;
	for(int i = 1; sum < n; ++i){
		sum += i;
		ans.push_back(i);
	}
	rep(i,ans.size()){
		if(ans[i] == sum - n) continue;
		cout << ans[i] << endl;
	}
	return 0;
}

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

#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
int powmod(int a,int l, int md){a%=md; int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
int invmod(int a, int md){return powmod(a,md-2,md);}
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
typedef vector<int> vi; typedef pair<int, int> ii; typedef vector< ii > vii;
#define pb push_back
int __set(int b, int i) {return b|(1LL<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1LL<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return (((a%md)*(b%md))%md+md)%md;}
int addmod(int a, int b, int md) {return ((a%md+b%md)%md+md)%md;}
int submod(int a, int b, int md) {return (((a%md-b%md)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int MOD=1e9+7;
int dp[200010][2];
int seen[200010][2];
signed main(void)
{
	IOS;
	int n,k; cin>>n>>k;
	vi cnt(k+1);
	cnt[k]=1;
	for(int i = k-1; i>=1; i--) {
		int tp=k/i;
		cnt[i]=powmod(tp,n,MOD);
		for(int j = 2; j*i<=k; j++) {
			cnt[i]-=cnt[j*i];
			cnt[i]%=MOD;
			cnt[i]+=MOD;
			cnt[i]%=MOD;
		}
	}
	int ans=0;
	for(int i = 1; i <= k; i++) {
		ans += i*cnt[i];
		ans%=MOD;
	}
	cout<<ans<<endl;
	return 0;
}

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

#define N 4
#define X 0
#define Y 1
#define Z 2
#define W 3

int main()
{
	while (true)
	{
		int n;
		cin >> n;
		if (!n)
		{
			break;
		}

		for (int i=0; i<n; i++)
		{
			int val1[N], val2[N];
			for (int j=0; j<N; j++)
			{
				cin >> val1[j];
			}
			for (int j=0; j<N; j++)
			{
				cin >> val2[j];
			}

			int ans[N];

			ans[X] = val1[X]*val2[X]
					 -val1[Y]*val2[Y]
					 -val1[Z]*val2[Z]
					 -val1[W]*val2[W];

			ans[Y] = val1[X]*val2[Y]
					 +val1[Y]*val2[X]
					 +val1[Z]*val2[W]
					 -val1[W]*val2[Z];

			ans[Z] = val1[X]*val2[Z]
					 -val1[Y]*val2[W]
					 +val1[Z]*val2[X]
					 +val1[W]*val2[Y];

			ans[W] = val1[X]*val2[W]
					 +val1[Y]*val2[Z]
					 -val1[Z]*val2[Y]
					 +val1[W]*val2[X];

			cout << ans[X] << ' '
				 << ans[Y] << ' '
				 << ans[Z] << ' '
				 << ans[W] << '\n';
		}
	}

		return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define M 1000000007
#define INF ((1LL<<62LL) - 1)

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

    int n; cin >> n;
    int ans = 0;

    for(int i=1;i<=n;i++){
        int r = n%i;
        int q = n/i;

        if(r!=0){
            ans+=q;
        } else{
            if(q>=1) ans+=(q-1);
        }
    }
    cout << ans << "\n";


}


Measured memory_bytes: 3648
r, c = map(int, input().split())
sheet = [[0 for x in range(c+1)] for y in range(r+1)]
for j in range(r):
    for i,x in enumerate(list(map(int, input().split()))):
        sheet[j][i] = x
        sheet[-1][i] += x
    sheet[j][-1] = sum(sheet[j][:-1])

sheet[-1][-1] = sum(sheet[-1][:-1])
print('\n'.join([' '.join(map(str,x)) for x in sheet]))


Measured memory_bytes: 5748
import sys
#import time
#import copy
#from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import itertools
#input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def ri():
    return list(map(int, input().split()))
def rs():
    return list(input().strip())

n = str(input())

lst = n[-1]
if lst == "0" or lst =="1" or lst =="6" or lst =="8":
    print("pon")
elif lst=="3":
    print("bon")
else:
    print("hon")

Measured memory_bytes: 61872
def main():
    A = int(input().strip())
    B = int(input().strip())
    C = int(input().strip())
    X = int(input().strip())
    
    count = 0
    for ai in [x*500 for x in range(A+1)]:
        Xa = X - ai
        if Xa < 0: break
        for bi in [x*100 for x in range(B+1)]:
            Xb = Xa - bi
            if Xb < 0: break
            for ci in [x*50 for x in range(C+1)]:
                Xc = Xb - ci
                if Xc < 0: break

                if Xc == 0:
                    count += 1
    return count
if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3064
use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();

    let x: u64 = s.trim().parse().unwrap();

    println!("{}",
        if x < 1200 {
            "ABC"
        }
        else {
            "ARC"
        }
    );
}


Measured memory_bytes: 380
def check(n):
    if set(list(map(int, str(n)))) & D:
        return 1
    else:
        return 0


N, K = map(int, input().split())
D = set(list(map(int, input().split())))

surplus = 0
while check(N + surplus):
    surplus += 1
print(N + surplus)


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

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

int arr[200005], out[200005];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, ree = 0; cin >> n;

    for(int i = 1; i <= n; ++i)
        cin >> arr[i];

    for(int i = n; i; --i){
        int tot = 0;
        for(int j = i; j <= n; j += i)
            tot += out[j] % 2;
        if(tot % 2 != arr[i])
            out[i] = ++ree ? 1 : 0;
    }

    cout << ree << "\n";

    for(int i = 1; i <= n; ++i)
        if(out[i])
            cout << i << " ";

    return 0;
}


Measured memory_bytes: 2432
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;

typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

int main(void){
    int s, w;
    cin >> s >> w;
    if(s <= w) cout << "unsafe" << endl;
    else cout << "safe" << endl;
    return 0;
}

Measured memory_bytes: 3636
my ($n,$m)=split / /,<STDIN>;
my %c1=();
my %c2=();
for(my $i=0;$i<$m;$i++){
    my ($a,$b)=split / /,<STDIN>;
    $c1{$b-0}=1 if $a==1;
    $c2{$a-0}=1 if $b==$n;
}
my $p=0;
foreach my $t(keys(%c1)){
    if($c2{$t}){
        $p=1;
        last;
    }
}
print $p ? "POSSIBLE" : "IMPOSSIBLE";

Measured memory_bytes: 28928
N, M, X = map(int, input().split())
books = [list(map(int, input().split())) for _ in range(N)]

ans = -1

for bits in range(1 << N):
    cost = 0
    a = [0] * M
    for i in range(N):
        if (bits >> i) & 1 == 1:
            cost += books[i][0]
            for j in range(M):
                a[j] += books[i][j + 1]

    if min(a) >= X:
        ans = min(cost, ans) if ans >= 0 else cost

print(ans)


Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
#define mem(ar,value) memset(ar,value,sizeof(ar))
#define all(x) x.begin(),x.end()
#define len(s) (int)s.size()
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define maxall(v) *max_element(all(v))
#define minall(v) *min_element(all(v))
#define mod 1e9+7
#define limit 200005
#define READ freopen("input.txt","r",stdin)
#define WRITE freopen("output.txt","w",stdout)
#define d1(x) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<endl;
#define d2(x,y) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<" | "#y" = "<<y<<endl;
#define d3(x,y,z) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<" | "#y" = "<<y<<" | "#z" = "<<z;
#define GG {printf("-1"); return 0;}
#define inf 1e9*2
#define y1 asdas
#define ll long long
#define writesize(a) printf("%d\n",len(a));
#define writeall(a) for(int i=0;i<len(a);i++) printf("%d ",a[i]);
int n,ans,mx;
int main()
{
	mx=-1;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int tut=i,t2=0;
		while(tut%2==0)
		{
			t2++;
			tut/=2;
		}
		if(t2>=mx)
		{
			mx=t2;
			ans=i;
		}
	}
	printf("%d\n",ans);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
	string S[3];
	cin >> S[0] >> S[1] >> S[2];
	int pointer[3]={};
	int player = 0;
	while(true){
		if(pointer[player]==S[player].size()){
			break;
		}
		pointer[player]+=1;
		player = S[player][pointer[player]-1]-'a';
	}
	cout << (char)(player +'A');
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

inline void print_vector(vector<int> &A){
    for (auto&& x : A){
        cout << x << " ";
    }
    cout << endl;
}

inline void solve() {
    int S, W;
    cin >> S >> W;

    if (W >= S) {
        cout << "unsafe" << endl;
        return;
    } else {
        cout << "safe" << endl;
    }
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    int t = 1;
    // cin >> t;

    for (int _ = 0; _ < t; _++) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3652
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,K; cin >> N >> K;
    vector<int> h(N);
    rep(i,N) cin >> h[i];

    int ans = 0;
    rep(i,N) if (h[i] >= K) ans++;

    cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e9) + 1;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
#define scn(n) scanf("%d", &n)
#define scns(s) scanf("%s", &s)
#define pri(n) printf("%d", n)
#define priln(n) printf("%d\n", n)
#define pris(s) printf("%s", s)
#define prisln(s) printf("%s\n", s)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
  int n;
  scn(n);

  if (n % 2 == 0) {
    pri(n / 2);
  } else {
    pri(n / 2 + 1);
  }

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/abc106/editorial.pdf
　　　https://atcoder.jp/contests/abc106/submissions/3024983
　　　https://imoz.jp/algorithms/imos_method.html
・二次元累積和
・最後にどこを足し引きするかは上記参考の二次元いもすと同じ話だと思う。
"""

N, M, Q = map(int, input().split())
LR = [[0] * (N+1) for i in range(N+1)]
for i in range(M):
    l, r = map(int, input().split())
    LR[l][r] += 1

# 縦横両方について累積和を出す
# 先頭1行1列は0のままにしておく
for i in range(1, N+1):
    for j in range(2, N+1):
        LR[i][j] += LR[i][j-1]
for i in range(1, N+1):
    for j in range(2, N+1):
        LR[j][i] += LR[j-1][i]

for i in range(Q):
    p, q = map(int, input().split())
    # +左上 -右上 -左下 +右下
    ans = LR[p-1][p-1] - LR[p-1][q] - LR[q][p-1] + LR[q][q]
    print(ans)


Measured memory_bytes: 13300
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  char c; cin >>c;
  string res = "A";
  if ('a' <= c && c <= 'z') res = "a";
  cout <<res <<endl;
}

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

const int N = 1e5 + 5;

int n, l;
int mx, idx;
int len[N];

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

	cin >> n >> l;

	for(int i = 1; i <= n; i++) {
		cin >> len[i];
	}

	for(int i = 1; i < n; i++) {
		if(len[i] + len[i + 1] > mx) {
			mx = len[i] + len[i + 1];
			idx = i;
		}
	}

	if(mx < l) {
		cout << "Impossible\n";
		return 0;
	}

	cout << "Possible\n";
	for(int i = 1; i < idx; i++) {
		cout << i << '\n';
	}
	for(int i = n - 1; i > idx; i--) {
		cout << i << '\n';
	}
	cout << idx << '\n';

	return 0;
}

Measured memory_bytes: 1280
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc134/tasks/abc134_c

n = int(input())
a = [int(input()) for _ in range(n)]

max_a = 0
sec_max_a = 0
for i in range(n):
    if max_a <= a[i]:
        sec_max_a = max_a
        max_a = a[i]
    elif sec_max_a < a[i]:
        sec_max_a = a[i]

for i in range(n):
    if a[i] == max_a:
        print(sec_max_a)
    else:
        print(max_a)


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


int main()
{
	int N, M;
	cin >> N >> M;

	set<int> from1, toN;
	for (int i = 1; i <= M; i++) {
		int a, b;
		cin >> a >> b;
		if (a == 1) from1.insert(b);
		if (b == 1) from1.insert(a);
		if (a == N) toN.insert(b);
		if (b == N) toN.insert(a);
	}

	bool possible = false;
	for (int i = 2; i < N; i++) {
		if ((from1.find(i) != from1.end()) && (toN.find(i) != toN.end()))
		{
			possible = true;
			break;
		}
	}
	if (possible) cout << "POSSIBLE" << endl;
	else  cout << "IMPOSSIBLE" << endl;

	return 0;
}


Measured memory_bytes: 9600
X = input()
N = len(X)

sum_s = 0
ans = 0
for i in range(N):
    if X[i] == 'S':
        sum_s += 1
    elif X[i] == 'T':
        if sum_s > 0:
            sum_s -= 1
        else:
            ans += 1

print(ans+sum_s)


Measured memory_bytes: 3500
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second

int main(){
    int N;
    cin >> N;
    vector<int> H(N);
    for(int i = 0; i < N; i++) cin >> H[i];
    int sum = 1;
    for(int now = 1; now < N; now++){
        bool can = true;
        for(int i = 0; i < now; i++){
            if(H[now] < H[i]) can = false;
        }
        if(can) sum++;
    }
    cout << sum << endl;

}


Measured memory_bytes: 3576
//for ( auto &i: a ){
//		cin >> i;
//}
#include <bits/stdc++.h>
# define ll      long long 
# define in      freopen("input.txt", "r", stdin);
# define out     freopen("output.txt", "w", stdout);
# define all(vc) vc.begin(),vc.end()
# define fi      first
# define se      second
# define str     string 
# define pb      push_back
# define speed   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
# define time    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
using namespace std;
ll a,b,c,d,e,f,mn=1e9,mx,cnt,bnt,sum,seven,four; str jul,s,cal,kcal;bool ok=false;
set <int> st; map <char, int> mp; vector <ll> vc1;
void botsolve(){
	vector <int> arr(a);
	for (int i = 0; i < a; ++i){
		cin>>arr[i];
	}
	sort(all(arr));
	for (int i = 1; i < a; ++i){
		if(((arr[i]-arr[i-1])*b)<=c) cnt+=((arr[i]-arr[i-1])*b);
		else cnt+=c;
	}
	cout<<cnt;
}
int main(){
	speed;
	//in out
    cin>>a>>b>>c;
    botsolve();

	time;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll m=1000000007,d[222][222],n;
int main() {
  cin>>n;
  d[0][0]=1;
  for(ll i=0;i<n;i++){
    char c;cin>>c;
    for(ll j=0;j<=n;j++){
      d[i][j]%=m;
      if(c=='D'){
        d[i+1][j]+=d[i][j]*j%m;
        if(j)d[i+1][j-1]+=d[i][j]*j*j%m;
      }else if(c=='U'){
        d[i+1][j]+=d[i][j]*j%m;
        if(j<n)d[i+1][j+1]+=d[i][j];
      }else d[i+1][j]+=d[i][j];
    }
  }
  cout<<d[n][0]%m<<endl;
  return 0;
}


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

using namespace std;

int main() {
    // insert code here...＃
    string numbers;
    int a=0;
    while (true) {
        a=0;
        cin>>numbers;
        if(numbers=="0")break;
        for (int i=0; i<numbers.length(); i++) {
            a+=int(numbers[i])-48;
        }
        cout<<a<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3228
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdio.h>
using namespace std;
typedef long long ll;
ll a[1000000];
int main()
{
	int n,k;
	int i;
	cin>>n>>k;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	ll ans=999999999;
	for(i=1;i+k-1<=n;i++)
	{
		ll tem=a[i+k-1]-a[i];
		if((a[i]<0)&&(a[i+k-1]<0)) 
		{
			tem+=abs(a[i+k-1]);
			//cout<<"temp="<<tem<<"abs(a[i+k-1])="<<abs(a[i+k-1])<<endl;
		}
		if((a[i]<0)&&(a[i+k-1]>0)) tem+=min(-a[i],a[i+k-1]);
		if((a[i]>0)&&(a[i+k-1]>0)) tem+=a[i];
		ans=min(ans,tem);
		
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int nextperm(int A[], int N, int M){
  int memo = 0 ;
  for(int i=N;i>0;i--){
    if(A[i] < M){
      memo = i ;
      break ;
    } 
}
  if(memo == 0) return 0 ;
  A[memo]++ ;
  for(int i=memo+1;i<N;i++){
    A[i] = A[memo] ;
  }
  return 1 ;
}

int main(){
  int N, M, Q, ans = 0, score = 0 ;
  cin >> N >> M >> Q ;
  int A[Q], B[Q], C[Q], D[Q], num[N+1] ;
  for(int i=0;i<Q;i++){
    cin >> A[i] >> B[i] >> C[i] >> D[i] ;
  }
  for(int i=0;i<(N+1);i++){
    num[i] = 1 ;
  }  
  num[N] = 0 ;
  while(nextperm(num, N, M)){
    score = 0 ;
    for(int i=0;i<Q;i++){
      if(num[B[i]]-num[A[i]] == C[i]){
        score += D[i] ;
      }
      ans = max(ans, score) ;
    }
  }
  cout << ans << endl ;
  return 0 ;
}  

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(int, h, w);
  vector<vector<string>> vv(h, vector<string>(w));
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j) cin >> vv.at(i).at(j);

  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j) {
      if (vv.at(i).at(j) == "snuke") {
        char col = 'A' + j;
        cout << col << (i + 1) << endl;
      }
    }

  return 0;
}

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

int main()
{
  int n;
  cin >> n;
  if(n % 3 == 0)
  {
    cout << (n / 3) * (n / 3) * (n / 3) << endl;
  }
  else
  {
    int ans = n * n * n;
    double ans1 = ans * 1.0 / 27.0;
    printf("%.7f\n",ans1);
  }
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int n,m;
    cin >> n >> m;
    vector<int> num(n,1);
    vector<bool> f(n);
    f[0]=true;
    rep(i,0,m){
        int x,y;
        cin >> x >> y;
        --x;
        --y;
        if(f[x]){
            f[y]=true;
            if(num[x]==1) f[x]=false;
        }
        --num[x];
        ++num[y];
    }
    int ans=0;
    rep(i,0,n) if(f[i]) ++ans;
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using Pa = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int N = S.size();
    for(int i=0;i<N;i++) cout << 'x';
    cout << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define erep(i, a, b) for (int i = a; i <= (int)(b); i++)
#define per(i, a, b) for (int i = (b)-1; i > (a); i--)
#define eper(i, a, b) for (int i = ((int)(a)); i >= b; i--)
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
const int INF = (1 << 30) - 1;
const int MOD = 1000000007;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int ans = 0;
  char c[3];
  rep(i, 0, 3) {
    cin >> c[i];
    if (c[i]-'0' == 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256