akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    int n;
    cin>>n;
    string x;
    cin>>x;
    int tb = 0  , tw = 0 ;
    for(auto i : x){
        if(i == '#')
            tb++;
        else tw++;
    }
    int mini = tw , bc = 0 , wc = 0;

    for(int i = 0 ; i < n ; i++){
        if(x[i] == '#') bc++;
        else wc++;
        mini = min(mini , bc + tw - wc);
    }
    cout<<mini<<endl;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 3704
import java.util.*;


/**
 * Created by santa on 2016/10/16.
 */

public class Main {

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

        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        int ans = a * 100 + b * 10 + c;
        if(ans % 4 == 0){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }


    }// mainMethod




} // MainClass


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;


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

  int M1, D1, M2, D2;
  cin >> M1 >> D1 >> M2 >> D2;
  if(M1 != M2) cout << 1 << endl;
  else cout << 0 << endl;

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int N = sc.nextInt();
		int[] vals = new int[N];
		for (int i = 0; i < vals.length; i++) {
			vals[i] = sc.nextInt();
		}
		long ans = 0, xor = 0, acum = 0, lastOk = 0;
		for (int i = 0; i < N; i++) {
			xor ^= vals[i];
			acum += vals[i];
			while (xor != acum) {
				xor ^= vals[(int)lastOk];
				acum -= vals[(int)lastOk];
				lastOk++;
			}
			ans += i - lastOk + 1;
		}
		System.out.println(ans);
	}
}


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

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

    string s;   cin >> s;

    if(s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)
#define in(a) scanf("%lld", &(a))
#define in2(a,b) scanf("%lld %lld",&(a),&(b))
#define in3(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c))
#define ind(a) scanf("%lf", &(a))
#define ins(a) scanf("%s", (a))
#define inc(a) scanf("%c", &(a))
#define put(a) printf("%lld\n", (a))
#define putd(a) printf("%.15f\n", (a))
//      puts(a) printf("%s\n", a) 文字はこっち
//your code here!
int main(void){
    ll N, M, a, b, ans[55]={0};
    in2(N, M);
    rep(_, M){
        in2(a, b);
        ans[--a]++;
        ans[--b]++;
    }
    rep(i, N) put(ans[i]);
    return 0;
}


Measured memory_bytes: 128
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item = U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}

fn com2(n: usize, k: usize) -> usize {
    if n < k {
        0
    } else {
        n * (n - 1) / 2
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let A: Vec<usize> = sc.vec(N);
    let mut cnt = HashMap::new();
    for i in 0..N {
        let e = cnt.entry(A[i]).or_insert(0);
        *e += 1;
    }
    let mut com = HashMap::new();
    let mut allcom = 0;
    for (&k, &v) in &cnt {
        let c = com2(v, 2);
        com.insert(k, c);
        allcom += c;
    }
    for i in 0..N {
        let t = cnt.get(&A[i]).unwrap();
        let prev = com.get(&A[i]).unwrap();
        let cur = com2(t-1, 2);
        println!("{}", allcom - (prev - cur));
    }
}


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

#define ll long long
#define mk make_pair
#define pb push_back


using namespace std;


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

   string al = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   int sft; cin >> sft;
   string s; cin >> s;
   
   for(int i = 0; i < s.size(); ++i){
      int d = s[i];
      char nc = (d + sft - 65) % 26 + 65;
      s[i] = nc;
   }

   cout << s;
   return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int X1  = sc.nextInt();
    int X2 = sc.nextInt();
    int X3 = sc.nextInt();
    int X4 = sc.nextInt();
    int X5 = sc.nextInt();
 
    if(X1==0){
	System.out.println("1");
    }else if(X2==0){
	System.out.println("2");     
    }else if(X3==0){
	System.out.println("3");
    }else if(X4==0){
	System.out.println("4");
    }else{        
	System.out.println("5");
	}
}
}

Measured memory_bytes: 35768
#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;
const long long mod=1000000007;
void mat_mul(vector<vector<long long> >& a,vector<vector<long long> >& b,vector<vector<long long> >&c)
{
    long long m=a.size();
    vector<long long>tmp(m);
    vector<vector<long long> >res(m,tmp);
    long long i,j,k;
    for(i=0;i<m;i++)
    {
        for(j=0;j<m;j++)
        {
            res[i][j]=0;
            for(k=0;k<m;k++)
            {
                res[i][j]=(res[i][j]+(a[i][k]*b[k][j])%mod)%mod;
            }
        }
    }
    for(i=0;i<m;i++)
    {
        for(j=0;j<m;j++)
        {
            c[i][j]=res[i][j];
        }
    }
}
void mat_exp(vector<vector<long long> >& base,long long pow,vector<vector<long long> >&fin)
{
    long long m=base.size();
    vector<long long>tmp(m);
    vector<vector<long long> >res(m,tmp);
    long long i,j;
    for(i=0;i<m;i++) res[i][i]=1;
    while(pow>0)
    {
        if(pow&1) mat_mul(res,base,res);
        pow=(pow>>1);
        mat_mul(base,base,base);
    }
    for(i=0;i<m;i++)
        for(j=0;j<m;j++)
            fin[i][j]=res[i][j];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n,k,i,j;
    cin>>n>>k;
    vector<long long>tmp(n);
    vector<vector<long long> >arr(n,tmp);
    for(i=0;i<n;i++) for(j=0;j<n;j++) cin>>arr[i][j];
    mat_exp(arr,k,arr);
    long long ans=0;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
            ans=(ans+arr[i][j])%mod;
    }
    cout<<ans;
}


Measured memory_bytes: 384
def create(month, days):
    for i in range(days):
        day = i+1
        calendar[(month, day)] = week[0]
        week.append(week[0])
        del week[0]
        
week = ['Thursday','Friday','Saturday','Sunday','Monday','Tuesday','Wednesday']
calendar = {}
for i in range(12):
    month = i+1
    if month == 2:
        create(month, 29)
    elif month in (4,6,9,11):
        create(month, 30)
    else:
        create(month, 31)
    
while True:
        month, day = map(int, raw_input().split())
        if month == 0 and day == 0: break
        print calendar[(month, day)]

Measured memory_bytes: 4288
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();

		int first = m/n;
		int answer=1;

		for(int i=first;i>1;i--) {
			if(m%i==0) {
				answer = i;
				break;
			}
		}

		System.out.print(answer);

	}
}


Measured memory_bytes: 23764
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int a;
    int b;
    int k;
    int cnt=0;
    cin>>a>>b>>k;
    for (int i=a;i<=b;i++)
        if (i-a<k || b-i<k) cout<<i<<endl;
    return 0;
}

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

int INF = 2000000000;

int n, ans=-INF, counts=0;
vector<long int> f(200, 0);
vector< vector<int> > p(200, vector<int>(20, 0));

void dfs(int cur, long int v) {
    if (cur==10)
    {
        counts++;
        

        if (v==0) return;

        int sum=0;
        for (int i = 0; i < n; ++i)
            sum += p.at(i).at(__builtin_popcount(f.at(i)&v));

        // if (sum==0)
        // {
        //     cout << n << endl;
        //     cout << bitset<10>(v) << endl<< endl;
        //     for (int i = 0; i < n; ++i)
        //     {
        //         cout << bitset<10>(f.at(i)&v) << endl;  
        //     }
        //     cout << sum << endl;
        //     cout  << endl;
        // }

        ans = max(ans, sum);
        return;
    }

    dfs(cur+1, v|(1<<cur));
    dfs(cur+1, v);
}

int main() {
    cin >> n;
    for (int j = 0; j < n; ++j)
    {
        for (int i = 0; i < 10; ++i) {
            int bit;
            cin >> bit;
            f.at(j) |= (bit<<(9-i));
        }
    }
    for (int j = 0; j < n; ++j) {
        for (int i = 0; i <= 10; ++i) cin >> p.at(j).at(i);
    }

    dfs(0,0);

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
  int N,K,i,j,a,b,c;
  long count;
  char str[100],*p;
  
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  N=atoi(p);
  p=strtok(NULL," \n");
  K=atoi(p);
  
  for(i=K+1,count=0;i<=N;i++){
    a=(i-1)-(K-1);
    b=N/i;
    c=0;
    if(K==0){
      c=N%i-K;
    }else if(N%i>=K){
      c=N%i-(K-1);
    }
    count+=a*b+c;
  }
  
  printf("%ld\n",count);

  return 0;
}

Measured memory_bytes: 128
def generate_map
  single_primes = [2, 3, 5, 7]
  map = []

  1000000.times { |i| map << prime?(i, single_primes) }

  map
end

def prime?(n, single_primes)
  return false if n <= 1
  return true if single_primes.include?(n)
  return false if n % 2 == 0
  return false if single_primes.any? { |sp| n % sp == 0 }

  2.upto((n ** 0.5).to_i) do |i|
    if n % i == 0
      return false
      break
    end
  end

  true
end

map = generate_map
while i = gets
  n = i.to_i
  puts map[0..n].count(true)
end


Measured memory_bytes: 18432
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int i = 1;
        long[]  c = new long[N];
        while(i<=N){
            int cur = in.nextInt();
            c[i-1]= (long)(cur-i);
            i++;
        }
        Arrays.sort(c);
        long ans = 0;
        for(int k=0;k<=(N/2-1);k++){
            ans +=  c[N-1-k]-c[k];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 83520
g=gets.split
x=[0,2,5,3]
y=[0,4,5,1]
gets
while gets
a,b=$_.split.map{|s|g.index s}
n=[*g]
m=->r,d{r.map{|i|n[i]}.rotate(d).map.with_index{|v,i|n[r[i]]=v}}
m[rand(2)>0?x:y,rand(2)>0?1:-1]until g[a]==n[0]&&g[b]==n[1]
puts n[2]
end

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

int		main(void)
{
	int H, W;

	cin >> H >> W;
	vector<string> table(H);
	vector<int> flag_row(H);
	vector<int> flag_column(W);
	for (int i = 0; i < H; i++)
		cin >> table[i];
	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			if (table[i][j] == '#')
			{
				flag_row[i] = 1;
				flag_column[j] = 1;
			}
		} 
	}
	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			if (flag_row[i] == 1 && flag_column[j] == 1)
				cout << table[i][j];
		} 
		if (flag_row[i] == 1)
			cout << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n,m;
	cin>>n>>m;
	vi in(m);
	rep(i,m)cin>>in[i];
	sort(all(in));
	if(m==1)cout<<in[0]-1<<endl;
	else{
		int sum=0;
		rep(i,m-1)sum+=in[i];
		cout<<max(0,in[m-1]-sum-1)<<endl;
	}
}









Measured memory_bytes: 384
#include <stdio.h>
int main() {
  int n,m;
  scanf("%d %d", &n, &m);
  int arrA[n][m] = {{0}};
  int arrB[m] = {0};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) scanf("%d", &arrA[i][j]);
  }
  for (int k = 0; k < m; k++) scanf("%d", &arrB[k]);
  for (int l = 0; l < n; l++) {
    long tmp = 0;
    for (int z = 0; z < m; z++) tmp += (long) arrA[l][z] * (long) arrB[z];
    printf("%ld\n", tmp);
  }
  return 0;
}



Measured memory_bytes: 2756
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    vi a(n);
    rep(i, n) cin >> a[i];
    sort(a.rbegin(), a.rend());
    int ans = 0;
    rep(i, k) ans += a[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
S = {}
for i in range(N):
    s = input()
    if s not in S:
        S[s] = 1
        continue
    S[s] +=1
    

M = int(input())
T = {}
for i in range(M):
    t = input()
    if t not in T:
        T[t] = 1
        continue
    T[t] += 1

ans = 0
for key in S.keys():
    if key not in T:
        ans = max(ans, S[key])
        continue
    ans = max(ans, S[key] - T[key])
print(ans)

Measured memory_bytes: 3064
// Author : Epsilon573
// If it works, don't touch it.

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

const ll mod  = 1e9+7;
const db eps  = 1e-9 ;
const ll maxn = 1e5+1;
const ll inf  = LLONG_MAX;
const ll minf = LLONG_MIN;

#define mp make_pair
#define pb push_back
#define endl "\n"
#define deb(x) cerr << #x << " " << x << endl

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

    ll k; string s;
    cin >> k >> s;

    if(k < s.size()){
        for(ll i=0 ; i<k ; ++i) cout << s[i] ;
            cout << "...";
    }
    else
        cout << s;

    return 0;
} 

Measured memory_bytes: 3656
package main

import (
	"fmt"
	"strings"
)

func main() {
	for {
		var h, w int
		if _, err := fmt.Scan(&h, &w); err != nil {
			panic(err)
		}
		if h == 0 && w == 0 {
			break
		}

		edgeRow := strings.Repeat("#", w) + "\n"
		innerRow := "#" + strings.Repeat(".", w-2) + "#\n"
		rect := edgeRow + strings.Repeat(innerRow, h-2) + edgeRow
		fmt.Println(rect)
	}
}



Measured memory_bytes: 1304
import math

N = int(input())
A = list(map(int, input().split()))

L = [[] for _ in range(N)]
for i in range(N):
    L[A[i]-1].append(i)

com = []
for i in range(N):
    n = len(L[i])
    com.append(n * (n - 1) // 2)
s = sum(com)

for k in range(N):
    ans = s - com[A[k]-1]
    m = len(L[A[k]-1]) - 1
    ans = ans + m * (m - 1) // 2
    print(ans)

Measured memory_bytes: 41692
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int a, b, c;
  cin >> a >> b >> c;
  int m = max(a, max(b, c));
  int sum = a + b + c;
  if(sum % 2 == m % 2) {
    cout << (m * 3 - sum) / 2 << endl;
  } else {
    cout << ((m+1) * 3 - sum) / 2 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<cmath>
#include<functional>
#include<algorithm>
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;



int calc(string s,string t){
	vector<int> p,q;
	rep(i,s.size())if(s[i]=='1')p.push_back(i);
	rep(i,t.size())if(t[i]=='1')q.push_back(i);
	if(p.size()!=q.size())return INF;
	int ans=0;
	rep(i,p.size()){
		ans+=abs(p[i]-q[i]);
	}
	return ans;
}
int main(){
	int n,m;
	string a,b;
	cin>>n>>m;
	rep(i,n){
		char c;
		cin>>c;
		a+=c;
	}
	rep(i,m){
		int p;
		cin>>p;
		rep(j,p){
			b+=i&1?'1':'0';
		}
	}
	int c=calc(a,b);
	rep(i,b.size())b[i]=b[i]=='1'?'0':'1';
	cout<<min(c,calc(a,b))<<endl;;
	return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
#define MOD 1000000007

int wi[2010], bi[2010];
int seg[8192];
ll G[2010][2010][2];
ll arr[2010][2010];

int rsq(int s, int t, int k = 1, int l = 0, int r = 4095) {
	if (t < l || r < s) {
		return 0;
	}
	if (s <= l && r <= t) {
		return seg[k];
	}

	int lv = rsq(s, t, k * 2, l, (l + r) / 2);
	int rv = rsq(s, t, k * 2 + 1, (l + r) / 2 + 1, r);
	return lv + rv;
}

void upd(int x) {
	x += 4096;
	seg[x]++;
	while (x) {
		x /= 2;
		seg[x] = seg[x * 2] + seg[x * 2 + 1];
	}
}

void chmin(ll& x, ll y) {
	x = min(x, y);
}

int main() {
	for (int i = 0;i < 8192;i++)seg[i] = 0;
	int N, a;
	char c;
	cin >> N;

	for (int i = 0;i < 2 * N;i++) {
		cin >> c >> a;
		if (c == 'W') {
			wi[a] = i;
		}
		else {
			bi[a] = i;
		}
	}
	wi[N + 1] = bi[N + 1] = 4032;

	for (int i = 0;i <= N;i++) {
		for (int j = 0;j < 8192;j++)seg[j] = 0;
		for (int j = 1;j <= i;j++) {
			upd(wi[j]);
		}
		for (int j = 0;j <= N;j++) {
			if (j)upd(bi[j]);

			G[i][j][0] = rsq(wi[i + 1], 4095);
			G[i][j][1] = rsq(bi[j + 1], 4095);

			arr[i][j] = LLONG_MAX;
		}
	}

	arr[0][0] = 0;
	for (int i = 0;i <= N;i++) {
		for (int j = 0;j <= N;j++) {
			chmin(arr[i + 1][j], arr[i][j] + G[i][j][0]);
			chmin(arr[i][j + 1], arr[i][j] + G[i][j][1]);
		}
	}
	cout << arr[N][N] << endl;
}

Measured memory_bytes: 94720
#include<stdio.h>
#include<string.h>
char p[500];
int main(){
    int n;
    scanf("%d",&n);
   scanf("%s",p);
   if(n&1)
    printf("No\n");
   else{
    for(int i=0;i<n/2;i++){
        if(p[i]!=p[i+n/2]){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
   }
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
long long gcd(long long a,long long b){
  if(a%b==0)return b;
  else return gcd(b,a%b);
}
int main(){
  long long n,i,a,ans=1;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>a;
    ans=ans/gcd(ans,a)*a;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
using matrix = vector<vector<uint>>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acos(-1);

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

    ld R;
    cin >> R;
    printf("%.10Lf\n", 2 * PI * R);
    return 0;
}


Measured memory_bytes: 3788
/* *>>>>>Anshit_Bhardwaj<<<<<* */
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define f(i, x, n) for(int i = x; i < n; i++)
#define dbg(x) cout << x << endl
#define dbg2(x, y) cout << x << ' ' << y << endl
#define dbg3(x, y, z) cout << x << ' ' << y << ' ' << z << endl
#define mod 1000000007
using namespace std;

int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T, dmax;
    cin >> T >> dmax;
    dmax *= dmax;
    int x, y, cnt = 0;
    while(T--){
        cin >> x >> y;
        if(x*x + y*y <= dmax){
            cnt++;
        }
        
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

void solve(){
    int n,d;
    cin>>n>>d;
    two_sat ts(n);
    vector<int> x(n),y(n);
    fr(i,n) cin>>x[i]>>y[i];
    fr(i,n) fr(j,i){
        if(abs(x[i]-x[j])<d) ts.add_clause(i,false,j,false);
        if(abs(x[i]-y[j])<d) ts.add_clause(i,false,j,true);
        if(abs(y[i]-x[j])<d) ts.add_clause(i,true,j,false);
        if(abs(y[i]-y[j])<d) ts.add_clause(i,true,j,true);
    }
    if(!ts.satisfiable()){
        puts("No");
        return;
    }
    cout<<"Yes"<<'\n';
    auto ans=ts.answer();
    fr(i,n) cout<<(ans[i]?x[i]:y[i])<<'\n';
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
}

Measured memory_bytes: 3804
import scala.io.StdIn.{readInt, readLine};
object Main {
    def main(args: Array[String]): Unit = {
        (0 until readInt).foreach { i =>
            val y = readLine;
            val x = readLine;
            println(longestCommonSubsequence(y, x));
        }
    }
    def longestCommonSubsequence(strY: String, strX: String): Int = {
        val sizeX = strX.length;
        val sizeY = strY.length;
        val arr = Array.ofDim[Int](sizeY + 1, sizeX + 1);
        (1 to sizeY).foreach { y => (1 to sizeX).foreach { x => arr(y)(x) = -1}}
        def go(y: Int, x: Int): Int = {
            val lcs = arr(y)(x);
            if (lcs != -1) {
                lcs;
            } else {
                val lcs1 = go(y - 1, x - 1);
                val lcs2 = go(y - 1, x);
                val lcs3 = go(y, x - 1);
                arr(y)(x) = if (strX(x - 1) == strY(y - 1)) max(lcs1 + 1, lcs2, lcs3) else  max(lcs1, lcs2, lcs3);
                arr(y)(x);
            }
        }
        go(sizeY, sizeX);
    }

    def max(a: Int, b: Int, c: Int): Int = {
        if (a > b)
            if (a > c) a else c;
        else
            if (b > c) b else c;
    }
}


Measured memory_bytes: 124604
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] intArray = new int[n];
        int count = 1;

        for (int i = 0; i < n; i++) {
            intArray[i] = sc.nextInt();
        }

        int min = intArray[0];

        for (int i = 1; i < intArray.length; i++) {
            if (min > intArray[i]) {
                min = intArray[i];
                count++;
            }
        }
        System.out.println(count);
    }

}

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

int main(){
    int n,m,c;
    cin >> n >> m >> c;
    vector<int> b(m);
    for(int i = 0;i < m;i ++){
        cin >> b.at(i);
    }
    vector<vector<int>> a(n,vector<int>(m));
    for(int i = 0;i < n;i ++){
        for(int j = 0;j < m;j ++){
            cin >> a.at(i).at(j);
        }
    }
    int cnt = 0;
    int sum;

    for(int i = 0;i < n;i ++){
        sum = c;
        for(int j = 0;j < m;j ++){
            sum += a.at(i).at(j) * b.at(j);
        }   
        if(sum > 0){
            cnt ++;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
from collections import defaultdict
import sys
input = sys.stdin.readline

m = defaultdict(int)
ac = {}

N, M = list(map(int, input().split()))

pena = 0
for _ in range(M):
    p, s = input().split()
    p = int(p)
    s = s.strip()
    if s == "AC":
        if p not in ac:
            pena += m[p]
            ac[p] = 1
    else:
        if p not in ac:
            m[p] += 1


print("{} {}".format(len(ac.keys()), pena))


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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;

int main() {
    lli a, b;
    cin2(a, b);
    if ((b - 1) % (a - 1) == 0)
        cout << (b-1) / (a-1) << endl;
    else
        cout << (b-1 + a - 2) / (a-1) << endl;
}


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

using namespace std;

signed main() {
	string s; cin >> s;
	int n = s.length() + 1;
	vector<int> a(n, -1);
	for (int i = 0; i < n - 1; ++i) {
		if (s[i] == '>' && s[i + 1] == '<')
			a[i + 1] = 0;
	}
	if (s[n - 2] == '>')
		a[n - 1] = 0;
	for (int i = n - 2; i >= 0; --i) {
		if (a[i] == -1 && a[i + 1] != -1 && s[i] == '>')
			a[i] = a[i + 1] + 1;
	}
	for (int i = 0; i < n - 1; ++i) {
		if (a[i + 1] == -1 && a[i] != -1 && s[i] == '<')
			a[i + 1] = a[i] + 1;
	}
	if (a[0] == -1 && s[0] == '<')
		a[0] = 0;
	for (int i = 0; i < n - 1; ++i) {
		if (s[i] == '<' && a[i] >= a[i + 1])
			a[i + 1] = a[i] + 1;
	}
	//for (auto ai : a) cout << ai << " ";
	//cout << endl;
	cout << accumulate(a.begin(), a.end(), 0LL) << endl;
	return 0;
}

Measured memory_bytes: 2820
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();

		int[] num = new int[n];
		
		for (int i = 0; i < n; i++) {
			num[i] = sc.nextInt();
		}
		
		int max = num[0];
		boolean stair = true;
		
		for (int i = 1; i < n; i++) {
			if(max > num[i]+1) {
				System.out.println("No");
				System.exit(0);
			}
			max = Math.max(max, num[i]);
		}
		System.out.println("Yes");

	}
}


Measured memory_bytes: 49820
n = int(input())
case = ["AC", "WA", "TLE", "RE"]
ac=0;wa=0;tle=0;re=0;
ss = []
for _ in range(n):
        ss.append(input())
for i in ss:
    if i == "AC":
        ac += 1
    elif i == "WA":
        wa += 1
    elif i == "TLE":
        tle += 1
    else:
        re += 1
print(f"{case[0]} x {ac}")
print(f"{case[1]} x {wa}")
print(f"{case[2]} x {tle}")
print(f"{case[3]} x {re}")

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define EPS 1e-12

int main(void) {
  while (true) {
    int r, w, c, rr;
    cin >> r >> w >> c >> rr;
    if (!r && !w && !c && !rr)
      break;
    if (w * c <= r) {
      cout << 0 << endl;
      continue;
    }
    int ans = 0;
    ans += (w * c - r) / rr;
    if ((w * c - r) % rr > 0) ans++;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2988
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;

template<class T> inline void chmin(T& a, const T& b) { if(b < a) a = b; }

constexpr int MAX = 10000;

struct point {
	int x, y;
	point(int x = 0, int y = 0):x(x), y(y){}
};

namespace std {
	template<>
	struct hash<pair<int, int>> {
		inline size_t operator() (const pair<int, int> &p) const {
			return (p.first << 16) | p.second;
		}
	};
}

inline int dist(const point &a, const point &b) {
	const int diff_x = a.x - b.x;
	const int diff_y = a.y - b.y;
	return diff_x * diff_x + diff_y * diff_y;
}

inline unordered_multimap<pair<int, int>, point> make_grid(double width, const vector<point> &points, int n) {
	chmin<int>(n, points.size());
	unordered_multimap<pair<int, int>, point> grid;
	for(int i = 0; i < n; ++i) {
		const int x = points[i].x / width;
		const int y = points[i].y / width;
		grid.insert(make_pair(make_pair(x, y), points[i]));
	}
	return grid;
}

inline int nearest_points(vector<point> points) {
	const int n = points.size();
	if(n <= 1) return 0.0;

	random_shuffle(points.begin(), points.end());
	int ans = dist(points[0], points[1]);
	double width = sqrt(ans);

	unordered_multimap<pair<int, int>, point> grid = make_grid(width, points, 2);

	for(int i = 2; i < n; ++i) {
		const int x = points[i].x / width;
		const int y = points[i].y / width;
		int min_dist = INT_MAX;
		for(int dx = -1; dx <= 1; ++dx) {
			for(int dy = -1; dy <= 1; ++dy) {
				auto range = grid.equal_range(make_pair(x + dx, y + dy));
				while(range.first != range.second) {
					chmin(min_dist, dist(points[i], range.first->second));
					++range.first;
				}
			}
		}

		if(min_dist < ans) {
			ans = min_dist;
			width = sqrt(ans);
			grid = make_grid(width, points, i + 1);
		}
		else {
			grid.insert(make_pair(make_pair(x, y), points[i]));
		}
	}
	return ans;
}

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

	int n;
	cin >> n;

	vector<point> points;
	points.reserve(n);

	for(int i = 0; i < n; ++i) {
		int x, y;
		cin >> x >> y;
		points.emplace_back(x + MAX, y + MAX);
	}

	cout << nearest_points(move(points)) << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 24748
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
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; }
const ll INF = 1e18;

ll n;
vector<ll>t,a;
vector<P>p;
void solve(ll i){
    ll x = p[i-1].first;
    ll y = p[i-1].second;
    ll nt = t[i-1];
    ll na = a[i-1];
    x = (x+nt-1)/nt*nt;
    y = (y+na-1)/na*na;
    if(x/nt==y/na){
        p[i]={x,y};
        return;
    }
    if(x/nt<y/na){
        x = y/na*nt;
        p[i]={x,y};
        return;
    }
    y = x/nt*na;
    p[i]={x,y};
}
int main(){
    cin >> n;
    t.resize(n);
    a.resize(n);
    p.resize(n+1);
    rep(i,n)cin>>t[i]>>a[i];
    p[0]={1,1};
    rep(i,n){
        solve(i+1);
    }
    cout << p[n].first + p[n].second << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var r = ReadSplit();
            var n = r[0].Double();
            var k = r[1].Double();
            var l = new int[18];
            l[0] = 1;
            for (int i = 1; i <= 18; i++)
            {
                l[i] = l[i - 1] * 2;
                if (l[i] > 100000) break;
            }

            double ans = 0;
            for (double i = 1; i <= n; i++)
            {
                var c = 0;
                for (int j = 0; j < l.Length; j++)
                {
                    if (i * l[j] >= k)
                    {
                        c = j;
                        break;
                    }
                }
                ans += 1 / n * Math.Pow(0.5, c);
            }
            WriteRead(ans);
        }


        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }

        private static bool ChangeMin<T>(ref T a, T b) where T : IComparable
        {
            if (a.CompareTo(b) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }

        private static bool ChangekMax<T>(ref T a, T b) where T : IComparable
        {
            if (b.CompareTo(a) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }
    }
}


public static class Extentions
{
    public static int Int(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long Long(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal Decimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double Double(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 13140
import java.io.*;
import java.util.*;

class Main{
	public static void main(String[] args){
		solve();
	}
	public static void solve(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] score = new int[4001];
		for(int i=0;i<n;i++){
			String s = sc.next();
			int counter = 3;
			for(int j=0;j<s.length();j++){
				if(j==1){
					continue;
				}
				a[i] += (int)Math.pow(10,counter)*((int)s.charAt(j)-(int)'0');
				counter--;
			}
		}

		for(int i=0;i<n;i++){
			score[a[i]]++;
		}		

		int now = 0;
		for(int i=0;i<=4000;i++){
			if(score[i]!=0){
				int tmp = score[i] - 1 + 3 * now;
				now += score[i];
				score[i] = tmp; 
			}
		}

		for(int i=0;i<n;i++){
			System.out.println(score[a[i]]);
		}

	}
}



Measured memory_bytes: 75092
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll a, b, c;
    cin >> a >> b >> c;
    if(a < b) (a < c && c < b) ? Yes() : No();
    else (a > c && c > b) ? Yes() : No();
}

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

int main() {
	int X[10];
	for (int i = 0; i < 10; i++) {
		cin >> X[i];
	}
	sort(X, X + 10, greater<int>());
	for (int i = 0; i < 3; i++) {
		cout << X[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
main(){
    string a,b="keyence";
    int x=-1,y=0;
   cin>>a;
   for(int i=0;i<7;i++){
       if(a[i]==b[i]){
       x=i;
       }
       else break;
   }

   for(int i=0;i<6-x;i++){
       if(a[a.size()-i-1]==b[6-i]){
           y++;
       }else{
           break;
       }
   }


//cout<<x<<" "<<y<<endl;
   if(x+y==6)cout<<"YES";
   else cout<<"NO";
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main 
{
	public static void main(String[]args)
	{
		Scanner in=new Scanner(System.in);
	    final int MAX=50;
	    String[] str1=new String[MAX];
	    String[]str2=new String[MAX];
		int n;
		n=in.nextInt();
		for(int i=0;i<n;i++)
		{
			str1[i]=in.next();
			str2[i]=str1[i];
			
		}
		
		BubbleSort(str1,n);
		print(str1,n);
		System.out.println("Stable");
		
		
		
		SelectionSort(str2, n);
		print(str2,n);
		
		if(isStable(str1, str2, n)) {
			System.out.println("Stable");
			
		}else {
			System.out.println("Not stable");
		}
		
		
		
		
		
		
	
	}
	
	static void BubbleSort(String[] str,int n)
	{   
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n-i-1;j++)
			{
				if(str[j+1].charAt(1)<str[j].charAt(1))
				{
					String temp=str[j+1];
					str[j+1]=str[j];
					str[j]=temp;
				}
			}
		}
	}
	
	static void SelectionSort(String[] str,int n)
	{
		boolean flag=false;
		for(int i=0;i<n;i++)
		{
			int min=i;
			for(int j=i;j<n;j++)
			{
				if(str[j].charAt(1)<str[min].charAt(1))
				{
					min=j;
					flag=true;
				}
				
			}
			if(flag)
			{
				String temp=str[i];
				str[i]=str[min];
				str[min]=temp;
			}
			
			
			
		}
	}
	
	static void print(String[]str,int n)
	{
		for(int i=0;i<n;i++)
		{
			System.out.print(str[i]);
			if(i!=n-1)
				System.out.print(" ");
		}
		System.out.println();
	}
	
	static boolean isStable(String[]str1,String[]str2,int n)
	{
		for(int i=0;i<n;i++)
		{
			if(str1[i].charAt(0)!=str2[i].charAt(0))
				return false;
		}
		
		return true;
	}
	
	
	

}

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

using namespace std;

#define ll long long
typedef complex<double> P;

void show(P p) {
  cout << p.real() << ' ' << p.imag() << endl;
}

void koch(P p1, P p2, int n) {
  if(n == 0) return;

  P s = p1 + (p2 - p1) * P(1.0 / 3, .0);
  P t = p1 + (p2 - p1) * P(2.0 / 3, .0);
  P u = s + (t - s) * P(0.5, sqrt(3)/2);

  koch(p1, s, n-1);
  show(s);

  koch(s, u, n-1);
  show(u);
  
  koch(u, t, n-1);
  show(t);

  koch(t, p2, n-1);
}

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

  cout << fixed;
  cout << setprecision(8);

  P p1(0.0, 0.0);
  P p2(100.0, 0.0);

  show(p1);
  koch(p1, p2, n);
  show(p2);
}

Measured memory_bytes: 3224
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

int N;
int A[2][110];
int sum[2][110];

int main () {
  cin >> N;
  for (auto i = 0; i < 2; ++i) {
    for (auto j = 0; j < N; ++j) {
      cin >> A[i][j];
    }
  }
  for (auto i = 0; i < 2; ++i) {
    for (auto j = 0; j < N; ++j) {
      sum[i][j] = A[i][j];
    }
  }
  for (auto j = 0; j < N-1; ++j) {
    sum[0][j+1] += sum[0][j];
  }
  for (auto j = 1; j < N; ++j) {
    sum[1][N-1-j] += sum[1][N-1-j+1];
  }
  int ans = 0;
  for (auto j = 0; j < N; ++j) {
    ans = max(ans, sum[0][j] + sum[1][j]);
  }
  cout << ans << endl;
}


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

#define mp make_pair
#define X first
#define Y second
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FOD(i, a, b) for(int i = a; i >= b; i--)

using namespace std;

typedef long long ll;
typedef pair <int, int> ii;

const int N = 1e3 + 10;
const int MOD = 1e9 + 7;

ll powMod(ll n, ll k){
    if (k == 0)
        return 1;
    ll res = powMod(n, k >> 1);
    res = res * res % MOD;
    if (k & 1)
        res = res * n % MOD;
    return res;
}

int n, a, b, c, d;
ll C[N][N], rev[N], F[N][N];

void init(){
    rev[0] = 1;
    FOR(i, 1, n)
        rev[i] = powMod(i, MOD - 2);
    C[0][0] = 1;
    FOR(i, 1, n){
        C[i][0] = 1;
        FOR(j, 1, i)
            C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> a >> b >> c >> d;
    init();
    F[0][0] = 1;
    FOR(i, 1, n)
        FOR(j, 0, n){
            F[i][j] = F[i - 1][j];
            if (a <= i && i <= b){
                ll cur = 1;
                for(int k = i; k <= j; k += i){
                    cur = cur * C[j - k + i][i] % MOD * rev[k / i] % MOD;
                    if (c <= k / i && k / i <= d)
                        F[i][j] = (F[i][j] + F[i - 1][j - k] * cur) % MOD;
                }
            }
        }

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

Measured memory_bytes: 16128
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) {
		FastReader scan = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		Task solver = new Task();
		int t = 1;
		while(t-->0) solver.solve(1, scan, out);
		out.close();
	}
	
	static class Task {
		static long mod = (long) (1e9+7);
		public void solve(int testNumber, FastReader scan, PrintWriter out) {
			int n = scan.nextInt();
			long k = scan.nextLong(), t = 0;
			long[] before = new long[n], total = new long[n];
			long[] a = new long[n];
			for(int i = 0; i < n; i++) {
				a[i] = scan.nextLong();
			}
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < n; j++) {
					if(a[j] > a[i]) {
						if(j <= i) before[i]++;
						total[i]++;
					}
				}
			}
			for(int i = 0; i < n; i++) {
				long r = k*(k-1)/2;
				long get = add(mult(k,before[i]), mult(r, total[i]));
				t = add(t, get);
			}
			out.println(t);
		}
		
		static long mult(long a, long b) {
			return ((a%mod)*(b%mod))%mod;
		}
		static long add(long a, long b) {
			return (a%mod+b%mod)%mod;
		}
	}
	
	static void shuffle(int[] a) {
		Random get = new Random();
		for(int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}
	
	static void shuffle(long[] a) {
		Random get = new Random();
		for(int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}
	

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		public FastReader(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}

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

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


Measured memory_bytes: 22868