akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<iomanip>
#define pi 3.14159265358979323846
using namespace std;

int main()
{
	int a[7] ={},up=1,S=2,E=3,W=4,N=5,down=6,i,t1,t2;
	string s;
	for(i=1;i<7;i++){
		cin>>a[i];
	}
	cin.ignore();
	getline(cin,s);
	for(i=0;i<s.size();i++){
		if(s[i] == 'S'){
			t1=S;t2=N;
			S=up;N=down;
			up=t2;down=t1;
		}
		if(s[i] == 'N'){
			t1=S;t2=N;
			N=up;S=down;
			up=t1;down=t2;
		}
		if(s[i] == 'E'){
			t1=E;t2=W;
			E=up;W=down;
			up=t2;down=t1;
		}
		if(s[i] == 'W'){
			t1=E;t2=W;
			W=up;E=down;
			up=t1;down=t2;
		}
	}
	cout<<a[up]<<endl;
}



Measured memory_bytes: 3228
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long K = sc.nextLong();
		int[] A = new int[N];
		int[][] B = new int[N][2];
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextInt();
			B[i] = new int[] { A[i], i };
		}

		Arrays.sort(B, new Comparator<int[]>() {
			@Override
			public int compare(int[] o1, int[] o2) {
				if (o1[0] != o2[0])
					return Integer.compare(o1[0], o2[0]);
				else
					return Integer.compare(o1[1], o2[1]);
			}
		});

		long[][] sum = new long[N][60];
		int[][] dst = new int[N][60];
		for (int i = 0; i < sum.length; ++i)
			for (int j = 0; j < sum[i].length; ++j)
				sum[i][j] = -1;
		for (int i = 0; i < N; ++i) {
			int j = i;
			while (j + 1 < N && B[j][0] == B[j + 1][0]) {
				dst[B[j][1]][0] = (B[j + 1][1] + 1) % N;
				sum[B[j][1]][0] = B[j + 1][1] - B[j][1] + 1;
				++j;
			}
			sum[B[j][1]][0] = N + B[i][1] - B[j][1] + 1;
			dst[B[j][1]][0] = (B[i][1] + 1) % N;
			i = j;
		}
		for (int i = 0; i + 1 < sum[0].length; ++i) {
			for (int j = 0; j < N; ++j) {
				sum[j][i + 1] = Math.min(sum[j][i] + sum[dst[j][i]][i], Long.MAX_VALUE / 3);
				dst[j][i + 1] = dst[dst[j][i]][i];
			}
		}

		long res = K * N;
		int pos = 0;
		while (res > 0) {
			int p = 59;
			while (p >= 0 && sum[pos][p] > res) {
				--p;
			}
			if (p == -1)
				break;
			res -= sum[pos][p];
			pos = dst[pos][p];
		}

		ArrayDeque<Integer> dq = new ArrayDeque<>();
		while (res > 0) {
			if (res >= sum[pos][0]) {
				res -= sum[pos][0];
				pos += sum[pos][0];
			} else {
				dq.addLast(A[pos]);
				++pos;
				--res;
			}
			pos %= N;
		}
		PrintWriter pw = new PrintWriter(System.out);
		while (!dq.isEmpty()) {
			pw.print(dq.pollFirst() + (dq.isEmpty() ? "\n" : " "));
		}
		pw.close();
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> T(N);
  for(int i = 0; i < N; ++i){
    cin >> T[i];
  }
  vector<int> R;
  for(int i = 1; i < N; ++i){
    R.push_back(T[i]-T[i-1]-1);
  }
  sort(R.rbegin(), R.rend());
  int ans = T[N-1] + 1 - T[0];
  for(int i = 0; i < K-1; ++i) ans -= R[i];
  cout << ans << endl;
}



Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;

int main() {
  int n, m, r;
  cin >> n >> m >> r;
  vector<int> p(r);
  for (int i = 0; i < r; ++i) {
    cin >> p[i];
    --p[i];
  }
  vector<vector<int>> g(n, vector<int>(n, INF));
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    g[a][b] = c;
    g[b][a] = c;
  }
  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
  sort(p.begin(), p.end());
  int ans = INF;
  do {
    int dist = 0;
    for (int i = 0; i < r - 1; ++i) {
      dist += g[p[i]][p[i + 1]];
    }
    ans = min(ans, dist);
  } while (next_permutation(p.begin(), p.end()));
  cout << ans << endl;
}


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

#define int long long
#define ll long long
#define f1(i,a,b) for(i=a;i<b;i++)
#define f2(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;

int n,w;
int value[101],weight[101];

int dd[101][100001];
int dp(int ind, int val)
{
	if(val==0)
		return 0;
	if(ind==n)
		return 1e15L;
	if(val<0)
		return 1e15L;
	if(dd[ind][val]!=1e16L)
		return dd[ind][val];
	int best=min(dp(ind+1,val),weight[ind]+dp(ind+1,val-value[ind]));
	dd[ind][val]=best;
	return best;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/in.txt","r",stdin);
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/out.txt","w",stdout);
    // #endif

    cin>>n>>w;
    int i;
    f1(i,0,n)
    cin>>weight[i]>>value[i];
    int ans=0;
    f1(i,0,101)
    {
    	for(int j=0;j<100001;j++)
    		dd[i][j]=1e16L;
    }
    f1(i,0,100000+1)
    {
    	int minw=dp(0,i);
    	if(minw<=w)
    		ans=i;
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 79232
#include <iostream>
#include <string>

using namespace std;

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

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

  int ans = 0; 
  while(true) {
    ans++;
    int tmp = ans * k - ans + 1;
    if(tmp >=n) {
      break;
    } else {
      continue;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>

int main()
{
    std::cout << std::setprecision(10);
    int N, M;
    std::cin >> N >> M;

    std::vector<std::vector<int>> edge(N);
    for (int i=0; i<M; ++i) {
        int s, t;
        std::cin >> s >> t;
        edge[s-1].push_back(t-1);
    }

    double opt = N+M;
    for (int i=0; i<N-1; ++i) { // 削除する部屋でループ
        std::vector<double> v(N);
        v[N-1] = 0.0;
        for (int j=N-2; j>=0; --j) { // DP計算
            double sum = 0.0;
            double maxv = 0.0;
            for (int t : edge[j]) { // 部屋内通路ループ
                sum += v[t];
                maxv = std::max(maxv, v[t]);
            }
            int nLink = edge[j].size();
            if (nLink > 1 && i == j) {
                sum -= maxv;
                nLink -= 1;
            }
            v[j] = (sum + nLink) / nLink;
        }
        opt = std::min(opt, v[0]);
    }

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

Measured memory_bytes: 1408
#include <bits/stdc++.h> 
#include <bits/types/stack_t.h>
using namespace std; 
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI1 3.14159265358979311599796346854418516159057617187500

typedef long long int ll;  

int main() 
{ 
    FIO
    ll t;
    //cin >> t;
    t=1;
    while(t--)
    {
        int n,m;
        cin >> n >> m;

        bool vis[n+1];
        int h[n];

        for(int i=0;i<n;i++)
        {
            cin >> h[i];
            vis[i+1] = 1;
        }
        
        while(m--)
        {
            int a,b;
            cin >> a >> b;

            if(h[a-1]<=h[b-1])
                vis[a] = 0;
            
            if(h[b-1]<=h[a-1])
                vis[b] = 0;
        }

        int ans = 0;
        for(int i=1;i<=n;i++)
        {
            if(vis[i])
                ans++;
        }
        cout << ans << endl;
    }
    return 0; 
} 


Measured memory_bytes: 4144
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll pow(ll x,ll y){
  if(y==0) return 1;
  ll res=pow(x,y/2);
  res*=res;
  res%=mod;
  if(y%2==1) res*=x;
  return res%mod;
}
ll ans[100005]={0};
int main(){
  char a,b,c;
  cin>>a>>b>>c;
  if(a=='7'||b=='7'||c=='7') cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 3600
#include<iostream>
#include<list>
#include<vector>
#include<string>
#include<cmath>

using namespace std;
int main(){
  	string s;
    cin >> s;
	int digit = s.size();
    if (digit == 1){
      cout << s << endl;
      return 0;
    }
  
  	int max = pow(2, digit-1);
    long allSum = 0;
    bool plusFlag[digit-1];
    for(int i = 0; i < max; i++){
      // cout << i << endl;
      for(int tmp = 0; tmp < digit; tmp++){
        plusFlag[tmp] = false;
      }
      long iSum = 0;
      int q = i;
      int r = 0;
      int cntDigit = 0;
      while(q > 0){
        r = q % 2;
        q = q / 2;
        if (r == 1){
          plusFlag[cntDigit] = true;
        }
        cntDigit++;
      }
      string sNum = s.substr(0, 1);
      for(int tmp = 0; tmp < digit; tmp++){
        if(!plusFlag[tmp]){
          sNum += s.substr(tmp+1, 1);
        }
      	else{
          // cout << sNum << endl;
          iSum += stol(sNum);
          sNum = s.substr(tmp+1, 1);
        }
      }

      iSum += stol(sNum);
      // cout << sNum << endl;
      // cout << "===============" << endl;
      allSum += iSum;
    }
    
    cout << allSum << endl;
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, l;
    cin >> n >> l;

    int min = 1e9;
    int eat;
    int sum = 0;
    for (int i = 0; i < n; ++i){
        int score = l + i;
        if(abs(score) < min){
            min = abs(score);
            eat = score;
        }
        sum += score;
    }
    cout << sum - eat << endl;
}

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

using namespace std;

int main()
{
  long long n, a, b;
  cin >> n >> a >> b;
  long long buff = n % (a + b);
  long long div = n / (a + b);

  if (buff > a)
  {
    cout << div * a + a;
  }
  else
  {
    cout << div * a + buff;
  }

  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun floorSum(n: Long, m: Long, a: Long, b: Long): Long {
    var ans = 0L
    var a1 = a
    var b1 = b
    if (a1 >= m) {
        ans += (n - 1) * n * (a1 / m) / 2
        a1 %= m
    }
    if (b1 >= m) {
        ans += n * (b1 / m)
        b1 %= m
    }
    val yMax = (a1 * n + b1) / m
    val xMax = (yMax * m - b1)
    if (yMax == 0L) return ans
    ans += (n - (xMax + a1 - 1) / a1) * yMax
    ans += floorSum(yMax, a1, m, (a1 - xMax % a1) % a1)
    return ans
}

fun PrintWriter.solve(sc: FastScanner) {
    val t = sc.nextInt()
    for (i in 0 until t) {
        val n = sc.nextLong()
        val m = sc.nextLong()
        val a = sc.nextLong()
        val b = sc.nextLong()
        println(floorSum(n, m, a, b))
    }
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 53896
let n, ans = read_int (), ref 0
let ss, a_s = Array.(make n 0, init n @@ fun _ -> Scanf.scanf " %d" (+) 0)
let _ = Array.(sort (-) a_s; ss.(0) <- a_s.(0); iteri (fun i a -> if i > 0 then ss.(i) <- ss.(i - 1) + a) a_s;
  iteri (fun i a -> if i = n - 1 || a_s.(i + 1) <= 2 * ss.(i) then incr ans else ans := 0) a_s); Printf.printf "%d\n" !ans

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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int in() {int x; cin>>x; return x;}
string stin() {string s; cin>>s; return s;}
/***** MAIN *****/
signed main() {
  int n = in();
  int m = in();
  if(n <= m) {
    cout << "unsafe";
  } else {
    cout << "safe";
  }
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 3632
#include <stdio.h>
int main(void){
  int a;
  scanf("%d",&a);
  if(a==0){
    printf("0");
  }
  else{
  switch(a%3){
    case 0:
      printf("%d",3);
      break;
    case 1:
      printf("%d",1);
      break;
    case 2:
      printf("%d",2);
      break;
    default:
      break;
  }
 }  
 return 0; 
}

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

int memo[2001][2001];
string ds[2001];

int main() {
	// your code goes here
	int h,w;
	cin>>h>>w;
	for(int y=0;y<h;y++){
		cin>>ds[y];
		int c=0;
		for(int x=0;x<w;x++){
			char c1=ds[y][x];
			c=c1=='#'?0:c+1;
			memo[y][x]=c;
		}
		c=0;
		for(int x=w-1;x>=0;x--){
			c=memo[y][x]==0?0:max(c,memo[y][x]);
			memo[y][x]=c;
		}
	}
	int ans=0;
	for(int x=0;x<w;x++){
		int c=0;
		int ts2[2001];
		for(int y=0;y<h;y++){
			char c1=ds[y][x];
			c=c1=='#'?0:c+1;
			ts2[y]=c;
		}
		c=0;
		for(int y=h-1;y>=0;y--){
			c=ts2[y]==0?0:max(c,ts2[y]);
			if(ans<c+memo[y][x])ans=c+memo[y][x];
		}
	}
	cout<<ans-1<<"\n";
	return 0;
}

Measured memory_bytes: 19968
import java.lang.Math

fun main(args: Array<String>) {
    val (H, W, N) = readInputLine().split(" ").map { it.toInt() }
    val (sy, sx) = readInputLine().split(" ").map { it.toInt() }
    val S = readInputLine().reversed().toCharArray()
    val T = readInputLine().reversed().toCharArray()

    // 左右レンジチェック
    var low = 1
    var high = W
    for (i in 0 until N) {
        when (T[i]) {
            'L' -> high = Math.min(W, high + 1)
            'R' -> low = Math.max(1, low - 1)
        }
        when (S[i]) {
            'L' -> low++
            'R' -> high--
        }
        if (low > high) {
            println("NO")
            return
        }
    }

    if (sx < low || high < sx) {
        println("NO")
        return
    }

    // 上下レンジチェック
    low = 1
    high = H
    for (i in 0 until N) {
        when (T[i]) {
            'U' -> high = Math.min(H, high + 1)
            'D' -> low = Math.max(1, low - 1)
        }
        when (S[i]) {
            'U' -> low++
            'D' -> high--
        }
        if (low > high) {
            println("NO")
            return
        }
    }

    if (sy < low || high < sy) {
        println("NO")
        return
    }

    println("YES")
}

fun readInputLine(): String {
    return readLine()!!
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - 高橋くんのバグ探し
            var line = Console.ReadLine();
            string s = "";

            foreach(var c in line)
            {
                switch (c)
                {
                    case '1':
                        s += '9';
                        break;
                    case '9':
                        s += '1';
                        break;
                    default:
                        s += c;
                        break;
                }
            }

            Console.WriteLine(s);
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
#include <map>
using namespace std;

const double PI=acos(-1);

int main(){
    long n, k;
    cin >> n >> k;
    vector<long> ll, lr;
    bool z = false;
    for(long i = 0; i < n; i++){
        long a;
        cin >> a;
        if(z) lr.push_back(a);
        else ll.push_back(a);
        if(a == 1){
            lr.push_back(a);
            ll.push_back(a);
            z = true;
        }
    }
    if(n == k) cout << "1" << endl;
    else cout << ceil((n-1)/(double)(k-1)) << endl;
    return 0;
}

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

int main(){
    int N,K; cin >> N >> K;
    bool used[15]={};
    for(int i=0;i<K;i++){
        int d; cin >> d;
        used[d]=true;
    }
    for(int i=0;i<=100000;i++){
        if(i<N) continue;
        string s=to_string(i);
        bool check=true;
        for(int j=0;j<s.size();j++){
            if(used[s[j]-'0']){
                check=false;
                break;
            }
        }
        if(check){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(final String[] args){
        final Scanner sc = new Scanner(System.in);
        
        final String input = sc.next();

        for (int i = 0; i < input.length(); i++) {
            System.out.print("x");
        }
        System.out.println();
        sc.close();
    }
}

Measured memory_bytes: 21844
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <list>
#include <numeric>
using namespace std;

long long combi(long long n, long long k) {
  if (n == k || k == 0)
    return 1;
  else {
    return combi(n - 1, k - 1) + combi(n - 1, k);
  }
}

long long gcd(int a, int b){
  if (a%b == 0){
    return(b);
  }
  else{
    return(gcd(b, a%b));
  }
}

int main(){
  long long N;
  cin >> N;

  if(N%1000 == 0){
    cout << "0" << endl; 
  }
  else{
  cout << 1000-(N%1000) << endl;
  }
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ll n;
	cin>>n;
	ll ar[n+1];
	ar[0]=2,ar[1]=1;
	for(int i=2;i<=n;++i){
		ar[i]=ar[i-1]+ar[i-2];
	}
	cout<<ar[n];
	return 0;
}


Measured memory_bytes: 3600
#include <iostream>

using namespace std;

static constexpr auto Limit = 2000000;

int main()
{
    bool marked[Limit] = { true, true };
    bool is_prime[Limit] = {};

    for( int i=0; i<Limit; ++i ) {
        if ( marked[i] || is_prime[i] )
            continue;
        
        is_prime[i] = true;
        
        for( int j=i; j<Limit; j+=i ) {
            marked[j] = true;
        }
    }

    int n;
    while( cin >> n ) {
        if ( n == 0 )
            break;

        int gap = 0;
        if ( !is_prime[n] ) {
            while( !is_prime[--n] );

            ++gap;
            while( !is_prime[++n] )
                ++gap;
        }
        cout << gap << endl;
    }
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{

	int N;
	cin >> N;
	fyg(N+1,1) {
		if (N%y==0) {
			if (y<10&&N/y<10) {
				ce("Yes")
					return 0;
			}
		}
	}
	ce("No")
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << (b-a==c-b?"YES":"NO");    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}


int main(){

    int n;
    cin >> n;
    vector<pair<int, int>> r(n), b(n);
    REP(i,n){
        scanf("%d %d", &r[i].second, &r[i].first);
    }

    REP(i,n){
        scanf("%d %d", &b[i].first, &b[i].second);
    }

    sort(r.begin(), r.end(),greater<pair<int,int>>());
    sort(b.begin(), b.end());
    int result = 0;
    REP(i,n){
        REP(j,r.size()){
            if(b[i].first>r[j].second&&b[i].second>r[j].first){
                result++;

                remove(r, j);
                break;
            }
        }
    }
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
x1,y1,x2,y2 = list(map(int,input().split()))
x_margin = x2-x1
y_margin = y2-y1

x3 = x2-y_margin
y3 = y2 + x_margin

x4 = x3 - x_margin
y4 = y3 - y_margin

print(x3 , end=" ")
print(y3 , end=" ")
print(x4 , end=" ")
print(y4 , end=" ")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int left = a + b;
  int right = c + d;
  if (left > right) {
    cout << "Left";
  } else if (left < right) {
    cout << "Right"; 
  } else {
    cout << "Balanced";
  }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
 int u=1e5+5;
int main(){
	int n;
	cin>>n;
	long double a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	if(n>2){
		
	long double dp[n+1][n+1];
	memset(dp,0,sizeof dp);
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
	dp[i][0]=dp[i-1][0]*(1-a[i-1]);
	for(int i=1;i<=n;i++)
	dp[0][i]=dp[0][i-1]*(a[i-1]);
	dp[0][0]=0;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n-i;j++){
		dp[i][j]=dp[i][j-1]*(a[i+j-1])+dp[i-1][j]*(1-a[i+j-1]);
	}
	double d=0;
	for(int i=n;i>=(n+1)/2;i--)
	d+=dp[n-i][i];
	
	
	cout<<fixed<<setprecision(9)<<d;
}
	else
	{
		long double d=1;
		for(int i=0;i<n;i++)
		d*=a[i];
		cout<<fixed<<setprecision(9)<<d;
	}
}

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

const int mod = 1e9 + 7;

long long bp(long long a, int n) {
	if(n == 0) return 1;
	if(n & 1) return a * bp(a % mod, n - 1) % mod;
	return bp(a * a % mod, n / 2) % mod;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int x[n], y[n], id[n];
	for(int i = 0; i < n; i++) {
		cin >> x[i]  >> y[i];
		id[i] = i;
	}
	sort(id, id + n, [&](int i, int j) {
		if(x[i] + y[i] == x[j] + y[j]) return x[i] < x[j];
		return x[i] + y[i] < x[j] + y[j];
	});
	int ans1 =  abs(x[id[n - 1]] - x[id[0]]) + abs(y[id[n - 1]] - y[id[0]]);
	sort(id, id + n, [&](int i, int j) {
		if(x[i] - y[i] == x[j] - y[j]) return x[i] < x[j];
		return x[i] - y[i] < x[j] - y[j];
	});
	int ans2 =  abs(x[id[n - 1]] - x[id[0]]) + abs(y[id[n - 1]] - y[id[0]]);
	cout << max(ans1, ans2) << endl;
	return 0;
}


Measured memory_bytes: 5956
#include <bits/stdc++.h> 
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<char> vc;
typedef map<long long,long long> mpi;
#define vbi vector<bool> 
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define alr(x) x.rbegin(),x.rend()
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define endl '\n'
#define cnl cout<<endl;
#define frr(i,b) for(ll i=0; i<b;i++)
#define fb(i,b) for(ll i=b-1; i>=0; i--)
#define pi  3.141592653589793238
#define ms(x,v) memset(x,v,sizeof(x))
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define deb(x) cout<<#x<<" = "<<x<<"\n";
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
const int N = 2e5 + 5;
ll i,j,k;
void solve(){
   ll n; cin>>n;
   vl v(n);
   for(i=0;i<n;i++){
    cin>>v[i];
   }
   ll x=1;
   ll ans=0;
   for(i=0;i<n;i++){
     if(v[i]>x or v[i]<x) ans++;
     else if(v[i]==x){
      x++;
     }
   }
   if(ans==n){
    cout<<-1<<endl;
    return ;
   }
   cout<<ans<<endl;





 return ; 
 
}
signed main(){
   
 //CASET
         solve();
  

 
    return 0;
}



Measured memory_bytes: 1792
N,K = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
ans = 100000000000
for i in range(N-K+1):
  le = l[i]
  ri = l[i+K-1]
  ans = min(ans,abs(le)+abs(ri-le),abs(ri)+abs(ri-le))
print(ans)


Measured memory_bytes: 14252
function main(input) {
  var list = input[1].split(" ").map(v=>v-0);
  var ans = 1000;
  list.forEach(v=>{
    var cnt = 0;
    while(v%2==0){
      v/=2;
      cnt++;
    }
    ans = Math.min(ans,cnt);
  });
  console.log(ans);
    
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <string> vs;
#define mod 1000000007

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    vii a;
    ll in=0;
    while(in<s.size())
    {
        ll low=in;
        while(low<s.size() && s[low]==s[in])
        {
            low++;
        }
        ll o;
        if(s[in]=='L')
            o=0;
        else
            o=1;
        a.pb(mp(o,low-in));
        in=low;
    }
    ll num=0;
    vii b;
    for(ll i=1;i<(ll)a.size()-1 && num<k;i+=2)
    {
        a[i].F=a[i-1].F;
        num++;
    }
    if(num<k)
    {
        if(s.back()!=s[0])
        {
            a.back().F=a[0].F;
        }
    }
    ll ans=0;
    in=0;
    while(in<a.size())
    {
        ll low=in;
        ll k=0;
        while(low<a.size() && a[low].F==a[in].F)
        {
            k+=a[low].S;
            low++;
        }
        ans+=k-1;
        in=low;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2500
//                                      KiSmAt
#include "bits/stdc++.h"
using namespace std;
 
using ll = long long;
 
const ll inf = 1e18;
const int N = 2 * 1e5 + 10;

ll res;
double a[N], dp[N];

void solve(){
    ll n;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    dp[0] = 1;
    for(int i = 1; i <= n; ++i){
        for(int j = i; j >= 0; --j){
            dp[j] = (dp[j - 1] * a[i] + dp[j] * (1 - a[i])); 
        }
    }
    double ans = 0;
    ll req = (n + 1) / 2;
    for(int i = req; i <= n; ++i){
        ans += dp[i];
    }
    cout << fixed << setprecision(9) << ans;
}
 
int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
// nEro

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int DP1[200005], DP2[200005];

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

  int now = 1, Index = 0;
  while (Index < N){
    if (S[Index] == 'x'){
      Index++; continue;
    }else{
      DP1[Index] = now; now++;
      Index += C + 1;
    }
  }

  if (now < K){
    return 0;
  }

  now = K; Index = N - 1;
  while (Index >= 0){
    if (S[Index] == 'x'){
      Index--; continue;
    }else{
      DP2[Index] = now; now--;
      Index -= C + 1;
    }
  }
  
  if (now > 0){
    return 0;
  }

  for (int i = 0; i < N; i++){
    if (DP1[i] == DP2[i] && DP1[i] != 0){
      cout << i + 1 << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 3332
while True:
    f, m, r = [int(n) for n in input().split()]
    if f == m == r == -1:
        break
    if (f==-1 or m==-1) or (f+m < 30):
        ans = 'F'
    elif 30 <= f+m < 50:
        ans = 'D'
        if 50 <= r:
            ans = 'C'
    elif 50 <= f+m < 65:
        ans = 'C'
    elif 65 <= f+m < 80:
        ans = 'B'
    else:
        ans = 'A'
    print(ans)


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

int solve(long long gcd) {
    int ans = 1; // 1
    long long x = 2;
    while (x * x <= gcd) {
        if (gcd % x == 0) {
            ans += 1;
            while (gcd % x == 0) {
                gcd /= x;
            }
        }
        x++;
    }
    
    if (gcd >= x) {
        ans++;
    }
    return ans;
}

int main()
{
    long long A, B;
    cin >> A >> B;
    
    long long gcd;
    
    while (true) {
        if (A < B) {
            long long C = A;
            A = B;
            B = C;
        }
        
        if (A % B == 0) {
            gcd = B;
            break;
        } else {
            A = A % B;
        }
    }
    
    cout << solve(gcd) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, c;
	int x = 0, i;
	scanf("%d %d %d", &a, &b, &c);
	for(i = a; i <= b; i++)
	{
		if(c%i == 0)
		{
			x++;
		}
	}
	printf("%d\n", x);
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <bits/stdc++.h>
 
using namespace std;
 
#define MOD 1000000007
 
inline int add(int a, int b)
{ return (a + b) % MOD; }
 
inline int sub(int a, int b)
{ return (a - b + MOD) % MOD; }
 
inline int mul(int a, int b)
{ return 1LL * a * b % MOD; }
 
// ????´?
struct warp
{
    int x1, y1, x2, y2;
 
    bool operator<(const warp &w) const
    {
        if (x1 != w.x1)
            return x1 < w.x1;
        return y1 < w.y1;
    }
};
 
// return d = gcd(a, b) = ax + by
int extgcd(int a, int b, int &x, int &y)
{
    int g = a;
    x = 1;
    y = 0;
    if (b != 0)
        g = extgcd(b, a % b, y, x), y -= a / b * x;
    return g;
}
 
// ?±?a?????????
int inv(int a)
{
    int x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x % MOD) % MOD;
}
 
int fact[200010];   // ??¶???n!
void init_factorial()
{
    fact[0] = 1;
    for (int i = 0; i < 200000; ++i)
        fact[i + 1] = mul(fact[i], i + 1);
}
 
// ????????°??????n????????????????????????k??????
inline int nck(int n, int k)
{ return mul(mul(fact[n], inv(fact[n - k])), inv(fact[k])); }
 
 
int N, M, K, dp[100010];
// dp[i] := ??°?¬¬i???????´???\??£??¶???????????°
vector<warp> warps;
 
inline int calc(int x1, int y1, int x2, int y2) // ???????´??¨???????s??°t???????????°
{
    if (x2 < x1 or y2 < y1)
        return 0;
    return nck(x2 - x1 + y2 - y1, x2 - x1);
}
 
int solve()
{
    memset(dp, 0, sizeof(dp));
    sort(begin(warps), end(warps));
    warps.push_back((warp) {N, M, N + 1, M + 1});
    for (int i = 0; i <= K; ++i)
    {
        dp[i] = nck(warps[i].x1 + warps[i].y1, warps[i].y1);
        for (int j = 0; j < i; ++j)
        {
            dp[i] = add(dp[i], mul(dp[j], sub(calc(warps[j].x2, warps[j].y2, warps[i].x1, warps[i].y1),    // j???????????°i?????????????´???????
                                              calc(warps[j].x1, warps[j].y1, warps[i].x1, warps[i].y1)))); // j???????????°i?????????
        }
    }
    return dp[K];
}
 
bool input()
{
    warps.clear();
    scanf("%d%d%d", &N, &M, &K);
    --N;
    --M;
    int a, b, c, d;
    for (int i = 0; i < K; ++i)
    {
        scanf("%d%d%d%d", &a, &b, &c, &d);
        warps.push_back((warp) {a - 1, b - 1, c - 1, d - 1});
    }
    return N + 1 or M + 1 or K;
}
 
int main()
{
    init_factorial();
    while (input())
        cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 4440
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int n;cin >> n;
	string a,b;cin >> a >> b;
	
	int ans = a.size() + b.size();
	
	int ma = 0;
	REP(i,a.size())
	{
		bool flag = true;
		for(int j = 0;i+j < a.size()&&j<b.size();j++)
		{
			if(a[i+j] != b[j])flag = false;
		}
		if(flag)
		{
			ma = max(ma,(int)(a.size()-i));
		}
	}
	
	cout << ans - ma << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <math.h>

using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
static const ll maxLL = (ll)1 << 62;

int main() {
	ll N, M; cin >> N >> M;
	cout << (1900 * M + (N - M) * 100)*pow(2, M) << endl;;

	return 0;
}

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

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }

int main(){
  double n;
  cin >> n;
  cout << (int(n+1)/2)/n << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

struct FordFulkerson {
	using Flow = int;
	int n;
	vector<vector<Flow>> g;
	vector<bool> used;
	FordFulkerson(int n) :n(n), g(n, vector<Flow>(n)), used(n) {};
	void addArcCap(int from, int to, Flow cap) {
		g[from][to] += cap;
	}
	void addEdgeCap(int from, int to, Flow cap) {
		g[from][to] += cap;
		g[to][from] += cap;
	}
	Flow maximumFlow(int s, int t) {
		Flow total = 0;
		while (true) {
			fill(used.begin(), used.end(), false);
			Flow f = augment(s, t, INF);
			if (f == 0)return total;
			total += f;
		}
	}
	Flow augment(int v, int t, Flow f) {
		if (v == t)return f;
		used[v] = true;
		for (int to = 0; to < n; to++) {
			if (!used[to] && g[v][to] > 0) {
				Flow d = augment(to, t, min(f, g[v][to]));
				if (d > 0) {
					g[v][to] -= d;
					g[to][v] += d;
					return d;
				}
			}
		}
		return 0;
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int V, E; cin >> V >> E;
	FordFulkerson ff(V);
	rep(i, 0, E) {
		int u, v, c; cin >> u >> v >> c;
		ff.addArcCap(u, v, c);
	}
	cout << ff.maximumFlow(0, V - 1) << endl;
	return 0;
}

Measured memory_bytes: 3232
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long LL;

int main () {
        LL n;
        cin >> n;
        if (n <= 6) {
                cout << 1 << endl;
        } else if (n <= 11) {
                cout << 2 << endl;
        } else {
                LL ans1 = (n - 6) / 11;
                ans1 = ans1 * 2 + 1;
                LL ans2 = (n - 6) % 11;
                if (ans2 != 0) {
                        if (ans2 <= 5)  ans1++;
                        else    ans1 += 2;
                }
                cout << ans1 << endl;
        }
        return 0;
}


Measured memory_bytes: 256
const N=parse(Int,readline())
const P=map(x->parse(Int,x),split(readline()))
const A=zeros(Int,N)
const B=zeros(Int,N)
const Ta=zeros(Int,17,N)
function init()
	B[1]=1
	for i=1:N
		A[P[i]]=i
		if i>1
			B[i]=B[i>>1]+1
		end
		Ta[1,i]=P[i]
	end
	for k=2:17
		L=1<<(k-2)
		for i=1:N-L+1
			Ta[k,i]=Ta[k-1,i]
			if i+L+L<=N+1&&Ta[k,i]<Ta[k-1,i+L]
				Ta[k,i]=Ta[k-1,i+L]
			end
		end
	end
end
function query(L,R)
	if L>=R
		return 0
	end
	b=B[R-L]
	X=max(Ta[b,L],Ta[b,R-(1<<(b-1))])
	X
end
init()
function main()
	ans=0
	for i=N-1:-1:1
		id=A[i]
		L1L=0
		L1R=id
		if query(1,id)<i
			L1R=0
		end
		while L1R-L1L>1
			L1M=div(L1R+L1L,2)
			if query(L1M,id)>i
				L1L=L1M
			else
				L1R=L1M
			end
		end
		L1=id-L1L
		L2L=0
		L2R=L1L
		while L2R-L2L>1
			L2M=div(L2R+L2L,2)
			if query(L2M,L1L)>i
				L2L=L2M
			else
				L2R=L2M
			end
		end
		L2=L1L-L2L
		R1L=id+1
		R1R=N+1
		if query(id,N+1)==i
			R1L=N+1
		end
		while R1R-R1L>1
			R1M=div(R1R+R1L,2)
			if query(id,R1M)>i
				R1R=R1M
			else
				R1L=R1M
			end
		end
		R1=R1L-id
		R2L=R1R
		R2R=N+1
		if query(R1R,N+1)<i
			R2L=N+1
		end
		while R2R-R2L>1
			R2M=div(R2R+R2L,2)
			if query(R1R,R2M)>i
				R2R=R2M
			else
				R2L=R2M
			end
		end
		R2=R2L-R1L
		ans+=i*(L1*R2+R1*L2)
	end
	println(ans)
end
main()


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

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

a_min = min(a)
a_max = max(a)
a_min_index = 0
a_max_index = 0

for i,x in enumerate(a):
    if x == a_min:
        a_min_index = i+1
    elif x == a_max:
        a_max_index = i+1

if a_min >= 0:
    #累積和
    print(n-1)
    for i in range(1,n):
        print(i, i+1)
else:
    if abs(a_min) <= abs(a_max):
        #all positive
        print(2*n-1)
        for i in range(1, n+1):
            print(a_max_index, i)   
        for i in range(1,n):
            print(i, i+1)
    else:
        #all negative
        print(2*n-1)
        for i in range(1, n+1):
            print(a_min_index, i)
        for i in reversed(range(2,n+1)):
            print(i, i-1)



Measured memory_bytes: 3188
import std;

// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}
T[] lreads(T=long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}
void arywrite(T=long)(T[] ary){ary.map!(text).join(' ').writeln;}
void scan(TList...)(ref TList Args){auto line = readln.split;
foreach (i,T;TList){T val=line[i].to!(T);Args[i]=val;}}
void dprint(TList...)(TList Args){debug{auto s=new string[](TList.length);
static foreach(i,a;Args) s[i]=text(a);s.map!(text).join(' ').writeln;}}
alias sread=()=>readln.chomp();enum MOD =10^^9+7;
alias PQueue(T,alias less="a<b") = BinaryHeap!(Array!T,less);
// dfmt on

void main()
{
    long N, K;
    scan(N, K);
    auto A = aryread();
    A[] -= 1;
    long k;
    auto loop = new long[][](N);
    long p;
    while (k < K)
    {
        dprint(k, p);
        if (loop[p].length == 0)
        {
            loop[p] ~= k;
            k++;
            p = A[p];
            continue;
        }
        loop[p] ~= k - loop[p][0];
        dprint(loop[p]);
        long ok = 1;
        long ng = loop[p].length;
        while (1 < ng - ok)
        {
            long m = (ok + ng) / 2;
            if (loop[p][m] <= (K - k))
            {
                ok = m;
            }
            else
            {
                ng = m;
            }
        }
        if (loop[p][ok] <= (K - k))
        {
            k += loop[p][ok];
            continue;
        }
        else
        {
            k++;
            p = A[p];
            continue;
        }
    }
    writeln(p + 1);
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

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

	int64 N;
	cin >> N;
	map<int64, int64> mp;
	vector<int64> a(N);
	REP(i, N) {
	    cin >> a[i];
	    mp[a[i]]++;
	}
	sort(all(a));
	a.erase(unique(all(a)), a.end());
	if (a.size() > 3) {
	    cout << "No" << endl;
	} else if (a.size() == 1) {
	    if (a[0] == 0) {
	        cout << "Yes" << endl;
	    } else {
	        cout << "No" << endl;
	    }
	} else if (a.size() == 2) {
	    if (a[0] == 0 && mp[a[1]] == mp[a[0]] * 2) {
	        cout << "Yes" << endl;
	    } else {
	        cout << "No" << endl;
	    }
	} else {
	    if (mp[a[0]] == mp[a[1]] && mp[a[1]] == mp[a[2]] && (a[0] ^ a[1]) == a[2]) {
	        cout << "Yes" << endl;
	    } else {
	        cout << "No" << endl;
	    }
	}

}


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

#define d7 1000000007
#define fori(n) for( ll i=0 ; i<n; i++)
#define forj(n) for( ll j=0 ; j<n; i++)
//my code discontinue here

//binpow function from cp-algorithms
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

//my code starts from here after discontinued above

int main(){
ll n, k;
cin>>n>>k;
ll w[n], v[n];
fori(n) cin>>w[i]>>v[i];

ll dp[n+1][k+1];

fori(n+1){dp[i][0]=0;}
fori(k+1){dp[0][i]=0;}

for(ll i=1;i<=n;i++){
for(ll j=1;j<=k;j++){
if(w[i-1]>j){dp[i][j]=dp[i-1][j];}
else{
dp[i][j]=max(dp[i-1][j-w[i-1]]+v[i-1], dp[i-1][j]);
}
}
}
cout<<dp[n][k];

return 0;
}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<ll> a(n),x(n);
  ll sum=0;
  rep(i,n){
    cin >> a[i];
    sum+=a[i];
  }
  for(int i=1; i<n-1; i+=2){
    sum-=2*a[i];
  }
  x[0]=sum;
  for(int i=0; i<n-1; i++){
    x[i+1]=2*a[i]-x[i];
  }
  rep(i,n) cout << x[i] << " ";


  return 0;
}


Measured memory_bytes: 2944
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int[] A = nextIntArray1origin(sc, N);

		sc.close();

		ArrayList<int[]> a = new ArrayList<>();
		for (int i = 1; i <= N; i++) {
			a.add(new int[] { i, A[i] });
		}

		Collections.sort(a, (x, y) -> Integer.compare(x[1], y[1]));

		StringBuilder sb = new StringBuilder();
		for (int[] z : a) {
			sb.append(z[0]);
			sb.append(" ");
		}

		out.println(sb.toString().trim());

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray1origin(Scanner sc, int n) {
		int[] result = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 58468