codeparrot/codecomplex huggingface dataset:
// Problem: 1096_F. Inversion Expectation
// Time complexity: nlogn

import java.math.BigInteger;
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Andy Phan
 */
public class p1096f {
    static long MOD = 998244353;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        BIT invert = new BIT(n+5);
        BIT neg = new BIT(n+5);
        long res = 0;
        int[] arr = new int[n];
        boolean[] has = new boolean[n+1];
        long num1 = 0;
        for(int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            if(arr[i] != -1) {
                res += invert.read(n+5)-invert.read(arr[i]);
                res %= MOD;
                invert.update(arr[i], 1);
                has[arr[i]] = true;
            } else num1++;
        }
        if(num1 == 0) {
            System.out.println(res);
            return;
        }
        for(int i = 1; i <= n; i++) if(!has[i]) neg.update(i, 1);
        long invertNum1 = modInv(num1, MOD);
        res += ((num1*(num1-1))%MOD)*modInv(4, MOD);
        res %= MOD;
        long cnt = 0;
        for(int i = 0; i < n; i++) {
            if(arr[i] == -1) {
                cnt++;
                continue;
            }
            res += (((neg.read(n+5)-neg.read(arr[i]))*cnt)%MOD)*invertNum1;
            res %= MOD;
        }
        cnt = 0;
        for(int i = n-1; i >= 0; i--) {
            if(arr[i] == -1) {
                cnt++;
                continue;
            }
            res += (((neg.read(arr[i]))*cnt)%MOD)*invertNum1;
            res %= MOD;
        }
        System.out.println(res);
    }
    
    //@
    static class BIT {
            int n;
            int[] tree;
            public BIT(int n) {
                    this.n = n;
                    tree = new int[n + 1];
            }

            int read(int i) {
                    int sum = 0;
                    while (i > 0) {
                            sum += tree[i];
                            i -= i & -i;
                    }
                    return sum;
            }

            void update(int i, int val) {
                    while (i <= n) {
                            tree[i] += val;
                            i += i & -i;
                    }
            }
            //$
    }

    
    //@
    // Computes the modular inverse of x
    // Returns 0 if the GCD of x and mod is not 1
    // O(log n)  :  Can be converted to use BigIntegers
    static long modInv(long x, long mod) {
        return (BigInteger.valueOf(x).modInverse(BigInteger.valueOf(mod))).longValue();
    }

    static long modInv(long a, long b, long y0, long y1, long q0, long q1) {
            long y2 = y0 - y1*q0;
            return b == 0 ? y2 : modInv(b, a % b, y1, y2, q1, a / b);
    }
    
    //@
    static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); }
    static long lcm(long a, long b) { return a / gcd(a, b) * b; }


}
// Problem: 924_C. Riverside Curio
// Time complexity: linear
import java.util.*;
import java.io.*;
public class Waw{
    
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i=0;i<n;i++) a[i] = sc.nextLong();
        long[] p = new long[n];
        p[n-1] = a[n-1];
        for(int i=n-2;i>=0;i--){
            if(a[i]<p[i+1]) p[i] = p[i+1]-1;
            else p[i] = a[i];
        }
        long max = p[0];
        long res = p[0] - a[0];
        for(int i=1;i<n;i++){
            if(max < p[i]) max = p[i];
            res += max - a[i];
        }
        System.out.println(res);
    }
}
// Problem: 1179_B. Tolik and His Uncle
// Time complexity: quadratic
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class D {

    private void solve() {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);

        int n = nextInt(), m = nextInt();
        boolean[][] used = new boolean[n + 1][m + 1];

        for (int j = 1; j <= (m + 1) / 2; j++) {
            int x1 = 1, x2 = n;
            for (int i = 1; i <= n; i++) {
                if (x1 <= n && !used[x1][j]) {
                    out.println(x1 + " " + j);
                    used[x1++][j] = true;
                }
                if (x2 > 0 && !used[x2][m - j + 1]) {
                    out.println(x2 + " " + (m - j + 1));
                    used[x2--][m - j + 1] = true;
                }
            }
        }

        out.close();
    }

    public static void main(String[] args) {
        new D().solve();
    }

    private BufferedReader br;
    private StringTokenizer st;
    private PrintWriter out;

    private String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return st.nextToken();
    }

    private int nextInt() {
        return Integer.parseInt(next());
    }

    private long nextLong() {
        return Long.parseLong(next());
    }

    private double nextDouble() {
        return Double.parseDouble(next());
    }
}
// Problem: 608_B. Hamming Distance Sum
// Time complexity: linear
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
	static int check(int temp)
	{
		int count1 = 0; 
    while (temp>0) 
    { 
        if(temp % 2 != 0) 
        count1++; 
        temp/= 2; 
    } 
    return count1;
	}
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc=new Scanner(System.in);
		String a=sc.next();
		String b=sc.next();
		int m=a.length();
		int n=b.length();
		int[] zero=new int[n];
		int[] one=new int[n];
		
		for(int i=0;i<n;i++)
		{
			if(i==0)
			{
				if(b.charAt(i)=='0')
				zero[i]++;
				else
				one[i]++;
			}
			else
			{
				zero[i]=zero[i-1];
				one[i]=one[i-1];
				if(b.charAt(i)=='0')
				zero[i]++;
				else
				one[i]++;
		    }
		}
		

		long res=0;
		for(int i=0;i<m;i++)
		{
		int x=n-m+i;
		if(a.charAt(i)=='0')
		res+=one[x];
		else
		res+=zero[x];
		if(i>0)
		{
			if(a.charAt(i)=='0')
			res-=one[i-1];
			else
			res-=zero[i-1];
		}
		}
		
		System.out.println(res);
	}
}
// Problem: 1036_B. Diagonal Walking v.2
// Time complexity: linear
import java.util.*;
import java.io.*;

public class _1036_B_DiagonalWalkingV2 {

	public static void main(String[] args) throws IOException {
		int Q = readInt();
		while(Q-- > 0) {
			long n = readLong(), m = readLong(), k = readLong();
			if(Math.max(n, m) > k) println(-1);
			else {
				long ans = k;
				if(n%2 != k%2) ans--;
				if(m%2 != k%2) ans--;
				println(ans);
			}
		}
		exit();
	}

	final private static int BUFFER_SIZE = 1 << 16;
	private static DataInputStream din = new DataInputStream(System.in);
	private static byte[] buffer = new byte[BUFFER_SIZE];
	private static int bufferPointer = 0, bytesRead = 0;
	static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	public static String readLine() throws IOException {
		byte[] buf = new byte[64]; // line length
		int cnt = 0, c;
		while ((c = Read()) != -1) {
			if (c == '\n')
				break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}

	public static String read() throws IOException {
		byte[] ret = new byte[1024];
		int idx = 0;
		byte c = Read();
		while (c <= ' ') {
			c = Read();
		}
		do {
			ret[idx++] = c;
			c = Read();
		} while (c != -1 && c != ' ' && c != '\n' && c != '\r');
		return new String(ret, 0, idx);
	}

	public static int readInt() throws IOException {
		int ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (neg)
			return -ret;
		return ret;
	}

	public static long readLong() throws IOException {
		long ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}

	public static double readDouble() throws IOException {
		double ret = 0, div = 1;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();

		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (c == '.') {
			while ((c = Read()) >= '0' && c <= '9') {
				ret += (c - '0') / (div *= 10);
			}
		}

		if (neg)
			return -ret;
		return ret;
	}

	private static void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
		if (bytesRead == -1)
			buffer[0] = -1;
	}

	private static byte Read() throws IOException {
		if (bufferPointer == bytesRead)
			fillBuffer();
		return buffer[bufferPointer++];
	}

	static void print(Object o) {
		pr.print(o);
	}

	static void println(Object o) {
		pr.println(o);
	}

	static void flush() {
		pr.flush();
	}

	static void println() {
		pr.println();
	}

	static void exit() throws IOException {
		din.close();
		pr.close();
		System.exit(0);
	}
}
// Problem: 1019_B. The hat
// Time complexity: logn
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author kessido
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BTheHat solver = new BTheHat();
        solver.solve(1, in, out);
        out.close();
    }

    static class BTheHat {
        PrintWriter out;
        InputReader in;
        int n;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            n = in.NextInt();
            int desiredPair = -1;
            int result = query(1);
            if (result != 0) {
                int l = 2, r = 1 + n / 2;
                while (l < r) {
                    int m = (l + r) / 2;
                    int mRes = query(m);
                    if (mRes == 0) {
                        desiredPair = m;
                        break;
                    } else if (mRes == result) {
                        l = m + 1;
                    } else {
                        r = m;
                    }
                }
            } else {
                desiredPair = 1;
            }
            out.println("! " + desiredPair);
        }

        private int query(int i) {
            int iV = queryValue(i);
            int iN2V = queryValue(i + n / 2);
            if (iV < iN2V) {
                return -1;
            } else if (iV > iN2V) {
                return 1;
            }
            return 0;
        }

        private int queryValue(int i) {
            out.println("? " + i);
            out.flush();
            return in.NextInt();
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine(), " \t\n\r\f,");
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int NextInt() {
            return Integer.parseInt(next());
        }

    }
}
// Problem: 964_A. Splits
// Time complexity: constant

import java.io.PrintWriter;

import java.util.*;
import java.util.Arrays ; 
import java .lang.String.* ;
import java .lang.StringBuilder ;


public class Test{
    static int pos = 0 ; 
    static int  arr[] ; 
  static LinkedList l1 = new  LinkedList() ; 
static void find(int p ,char[]x,int put[],String s){
    int c= 0 ; 
    for (int i = 0; i < s.length(); i++) {
        if(x[p]==s.charAt(i)){
        c++ ; }
    }
    put[p] = c ;  
}
static int mode(int m ,int[]x ){
    int temp = 0 ; 
    for (int i = x.length-1; i >=0; i--) {
        if(x[i]<=m){
            temp= x[i] ; 
           /// break ; 
             return m-temp ; 
             
        }
    }
     return m-temp ; 
}
static int mode2(int m ,int[]x ){
    int temp = 0 ; 
    
    for (int i = x.length-1; i >=0; i--) {
        if(x[i]<=m){
            temp= x[i] ; 
           /// break ; 
             return x[i] ; 
             
        }
    }
     return 0 ; 
}
static int find(int x[],int temp){
    int j = 0 ; 
    for (int i = x.length-1; i >=0; i--) {
        if(x[i]==temp) return j+1 ; 
        j++ ; 
    }
    return -1 ; 
}
static String ch(long[]x,long b){
    for (int i = 0; i < x.length; i++) {
        if(x[i]==b)return "YES" ;
    }
    return "NO" ; 
}

    public static void main(String[] args)  {

        Scanner in = new Scanner(System.in) ;
        PrintWriter pw = new PrintWriter(System.out);   
        long n = in.nextLong() ; 
        long count =1 ; 
        long temp =n/2;
     temp+=count ;
      
       
        System.out.println(temp);
 }               
}
// Problem: 1009_B. Minimum Ternary String
// Time complexity: linear
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner in=new Scanner(System.in);
		String str=in.next();
		int cnt=0;
		for(int i=0;i<str.length();++i) {
			if(str.charAt(i)=='1') {
				++cnt;
			}
		}
		int i=0;
		for(;i<str.length();++i) {
			if(str.charAt(i)=='0') {
				System.out.print("0");
			}
			else if(str.charAt(i)=='2') {
				while(cnt-->0) {//
					System.out.print("1");
				}
				System.out.print("2");
			}
		}
		while(cnt-->0) {
			System.out.print("1");
		}
		in.close();
	}
}
// Problem: 1036_A. Function Height
// Time complexity: constant
import java.util.*;
import java.io.*;
import java.math.*;
import java.awt.geom.*;

public class FunctionHeight {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        long n = sc.nl();
        long k = sc.nl();
        long ans = (n+k-1)/n;
        System.out.println(ans);
    }

    /////////// TEMPLATE FROM HERE /////////////////
    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int ni() {
            return Integer.parseInt(next());
        }

        float nf() {
            return Float.parseFloat(next());
        }

        long nl() {
            return Long.parseLong(next());
        }

        double nd() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}
// Problem: 1190_A. Tokitsukaze and Discard Items
// Time complexity: linear

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class A1 {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        long size = scan.nextLong();
        int numberOfSpecial = scan.nextInt();
        long pageSize = scan.nextLong();

        long[] specialItemsArray = new long[numberOfSpecial];
        for (int i = 0; i < numberOfSpecial; i++) {
            specialItemsArray[i] = scan.nextLong();
        }

        int totalRemoved = 0;
        int step = 0;

        long currentPageIndex = BigDecimal.valueOf(specialItemsArray[0]).divide(BigDecimal.valueOf(pageSize),2, RoundingMode.UP).setScale(0, RoundingMode.CEILING).longValue();
        int specialItemArrayIndex = 1;

        while (specialItemArrayIndex < numberOfSpecial) {
            long pageIndex = BigDecimal.valueOf(specialItemsArray[specialItemArrayIndex] - totalRemoved).divide(BigDecimal.valueOf(pageSize),2,RoundingMode.UP).setScale(0, RoundingMode.CEILING).longValue();
            if (currentPageIndex != pageIndex) {
                step++;
                totalRemoved = specialItemArrayIndex;
                currentPageIndex =  BigDecimal.valueOf(specialItemsArray[specialItemArrayIndex] - totalRemoved).divide(BigDecimal.valueOf(pageSize),2,RoundingMode.UP).setScale(0, RoundingMode.CEILING).longValue();
            }
            specialItemArrayIndex++;
        }


        System.out.println(step + 1);

    }

}
// Problem: 5_D. Follow Traffic Rules
// Time complexity: constant
import java.io.*;

public class n5D
{
    public static void main(String[] args)
    {
        double a = 0, v = 0, l = 0, d = 0, w = 0;
        try
        {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String[] str = br.readLine().split(" ");
            a = Double.parseDouble(str[0]);
            v = Double.parseDouble(str[1]);
            str = br.readLine().split(" ");
            l = Double.parseDouble(str[0]);
            d = Double.parseDouble(str[1]);
            w = Double.parseDouble(str[2]);
        }
        catch(Exception e)
        {
            System.out.println(e);
        }

        double t1, t2, t3, t4, t5, t, D = 0;
        
        if (w > v) w = v;
        t2 = d / v - v / a + w * w / 2 / a / v;
        if (t2 >= 0)
        {
            t1 = v / a; 
            t3 = t1 - w / a;
        }
        else
        {
            if (Math.sqrt(2 * d / a) > (w / a))
            {
                t1 = Math.sqrt((2 * a * d + w * w) / (a * a * 2));
                t3 = t1 - w / a;
            }
            else
            {
                t1 = Math.sqrt(2 * d / a);
                t3 = 0;
            }
            t2 = 0;
        }
        t5 = (l - d - v * v / 2 / a + a * (t1 - t3) * (t1 - t3) / 2) / v;
        if (t5 >= 0) t4 = v / a - (t1 - t3);
        else
        {
            t5 = 0;
            t4 = -t1 + t3 + Math.sqrt((t1 - t3) * (t1 - t3) + 2 * (l - d) / a);
        }
        t = t1 + t2 + t3 + t4 + t5;
        System.out.println(t);
        //System.out.println(t1 + " " + t2 + " " + t3 + " " + t4 + " " + t5);
    }
}
// Problem: 1191_C. Tokitsukaze and Discard Items
// Time complexity: linear
import java.util.*;
import java.io.*;
public class Solution{
    
    public static long page(long p,long k){
        
        return (p-1)/k;
        
    }
    
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        long n = sc.nextLong();
        int m = sc.nextInt();
        long k = sc.nextLong();
        long[] p = new long[m];
        long del = 0;
        long nb = 1;
        int op = 0;
        for(int i=0;i<m;i++) p[i] = sc.nextLong();
        for(int i=1;i<m;i++){
            if(page(p[i]-del,k)!=page(p[i-1]-del,k)){
                
                del += nb;
                nb = 1;
                op++;
                
            }else{
                nb++;
                
            }
        }
        if(nb!=0) op++;
        
        System.out.println(op);
        
    }
    
}
// Problem: 965_A. Paper Airplanes
// Time complexity: constant


import java.io.PrintWriter;

import java.util.*;
import java.util.Arrays ; 
import java .lang.String.* ;
import java .lang.StringBuilder ;


public class Test{
    static int pos = 0 ; 
    static int  arr[] ; 
  static LinkedList l1 = new  LinkedList() ; 
static void find(int p ,char[]x,int put[],String s){
    int c= 0 ; 
    for (int i = 0; i < s.length(); i++) {
        if(x[p]==s.charAt(i)){
        c++ ; }
    }
    put[p] = c ;  
}
static int mode(int m ,int[]x ){
    int temp = 0 ; 
    for (int i = x.length-1; i >=0; i--) {
        if(x[i]<=m){
            temp= x[i] ; 
           /// break ; 
             return m-temp ; 
             
        }
    }
     return m-temp ; 
}
static int mode2(int m ,int[]x ){
    int temp = 0 ; 
    
    for (int i = x.length-1; i >=0; i--) {
        if(x[i]<=m){
            temp= x[i] ; 
           /// break ; 
             return x[i] ; 
             
        }
    }
     return 0 ; 
}
static int find(int x[],int temp){
    int j = 0 ; 
    for (int i = x.length-1; i >=0; i--) {
        if(x[i]==temp) return j+1 ; 
        j++ ; 
    }
    return -1 ; 
}
static String ch(long[]x,long b){
    for (int i = 0; i < x.length; i++) {
        if(x[i]==b)return "YES" ;
    }
    return "NO" ; 
}

    public static void main(String[] args)  {

        Scanner in = new Scanner(System.in) ;
        PrintWriter pw = new PrintWriter(System.out);   
     int k=in.nextInt(), n=in.nextInt(), s=in.nextInt(), p=in.nextInt() ;
     int paper =n/s; 
     if(n%s!=0) paper++ ; 
     paper*=k ; 
     int fin = paper/p ; 
     if(paper%p!=0) fin++ ; 
        System.out.println( fin );
       
       
 }               
}
// Problem: 911_C. Three Garlands
// Time complexity: constant
import java.util.*;
import static java.lang.Math.*;
import java.io.*;

public class SolutionB {
      public static void main(String args[])throws IOException{
              Scanner sc = new Scanner(System.in);
              int a[] = new int[1501];
              for(int i = 0; i < 3; i++){
                     a[sc.nextInt()]++;
              }
              if(a[1] > 0 || a[2] > 1 || a[3] > 2 || (a[4] == 2 && a[2] == 1)){
                     System.out.println("YES");
              }else{
                     System.out.println("NO");
              }
      }
}