akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
const int MOD=1e9+7;
 
//const int MOD=998244353;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    long long n, mult=1, ans=0;
    cin>>n;
    
    while(n){
        ans+=mult;
        mult*=2;
        n/=2;
    }
    cout<<ans;
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 300000 + 10;
int n[3], p[3], q[3];
long long a[3][N];
bool cmp(long long a, long long b) {return a > b; }
int main() {
	for (int i = 0; i < 3; i++)	p[i] = 1;
	for (int i = 0; i < 2; i++)	scanf("%d", q + i);
	for (int i = 0; i < 3; i++)	scanf("%d", n + i);
	q[2] = n[2];
	priority_queue <long long> pq[3];
	for (int i = 0; i < 3; i++) {
		for (int j = 1; j <= n[i]; j++) {
			scanf("%lld", &a[i][j]);
		}
		sort(a[i] + 1, a[i] + 1 + n[i], cmp);
	}
	long long ans = 0;
	for (int t = 0; t < q[0] + q[1]; t++) {
		int maxv = 0, pos = -1;
		for (int i = 0; i < 3; i++) {
			// printf("i = %d, p = %d, q = %d, a = %lld\n", i, p[i], q[i], a[i][p[i]]);
			if (p[i] <= q[i] && a[i][p[i]] > maxv) {
				maxv = a[i][p[i]];
				pos = i;
			}
		}
		ans += a[pos][p[pos]];
		p[pos]++;
		// printf("pos = %d\n", pos);
	}
	printf("%lld\n", ans);
	
	return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <functional>
using namespace std;

int main() {
	string S; cin >> S;
	for (int i = 0; i < S.size(); i += 2)cout << S[i]; cout << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long int
using namespace std;

signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    //cout<<"I must do it...Yeahhh";
    
    int tt=1;
    //cin>>tt;
    for(int kk=0;kk<tt;kk++)
    {
        int x,y,z;
        cin>>x>>y>>z;
        cout<<z<<' '<<x<<' '<<y;

        //cout<<"Case #"<<kk+1<<": "<<trace<<' '<<r<<' '<<c<<'\n';
    }
    //cerr<<"[Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s]\n";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

/********
*	????¶?????????????????????????????????¨???
*********/


/*********??¢?????´?????????
*	(1)?????£?????????n????????????????????¶?????? ??????4 ?? ?????????13 ???????¬??????????????¨????
*	(2)cards[i][j] ?????¶????????????????????£????????????1???or????????£???????????????0???
*	(3)cards[i][j] ??? false ??????????????????????????????????????????54-n??????
*********/

int main(void){
	int n;	//????????????????????°
	int i,j,k;//???????´?i????¨?????´?j?????????????´?h????????????????´?k; 
			//h=0??????????????????h=1???????????????h=2???????????????h=3????????????
	char h;

	int cards[4][13]={{0},{0}};	//2?¬?????????????????????¶???
	
	
	
		scanf("%d\n", &n);		//?????£????????????????????????????????¶??????1????????\???
	
	for ( i = 0 ; i<n ; i++ ){

			scanf("%c %d\n", &h ,&k);
			if(h == 'S'){				//?????????????????¨???
				cards[0][k-1] = 1;
			}
			else if(h == 'H'){			//??????????????¨???
				cards[1][k-1] = 1;
			}
			else if(h == 'C'){			//??????????????¨???
				cards[2][k-1] = 1;
			}
			else if(h == 'D'){			//??????????????¨???
				cards[3][k-1] = 1;
			}
			else{
			//??????????????\??????
			}
	}

	for( i = 0 ; i< 4 ; i++ ){				//????¶????????????????????????¶??????0????????????
		for(j=0; j<13 ; j++ ){
			if	(cards[i][j] == 0 ){			//?????????????????¨???
				if (i == 0){
					printf("S %d\n", j+1);
				}
				else if(i == 1){
					printf("H %d\n", j+1);
				}
				else if(i == 2){
					printf("C %d\n", j+1);
				}
				else if(i == 3){
					printf("D %d\n", j+1);
				}
				else{
					//??????????????\??????
				}
			}
		}
	}
    return 0;
}

Measured memory_bytes: 1028
s = list(input())

tmp = 0
tmp2 = 0
# 0,1
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] != "0":
            tmp += 1
    else:
        if s[i] != "1":
            tmp += 1
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] != "1":
            tmp2 += 1
    else:
        if s[i] != "0":
            tmp2 += 1
print(min(tmp, tmp2))


Measured memory_bytes: 3956
(require '[clojure.string :as str])

(println
 (apply + (for [line (rest (line-seq (clojure.java.io/reader *in*)))]
            (let [[l r] (as-> line v
                          (str/split v #"\s")
                          (map #(Long/parseLong %) v))]
              (inc (- r l))))))


Measured memory_bytes: 69092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,k;cin >> n >> k;
  if(2*k-1>n){
    cout << -1 << endl;
    return 0;
  }
  vector<int> a(n),b(n),c(n);
  for(int i=0;i<n;i++){
    c[i]=k+2*n+i;
  }
  if(n%2==1){
    ll l=(n+1)/2;
    for(int i=0;i<n;i++){
      if(i<=l-1){
        a[i]=k+2*i;
        b[i]=k+3*l-2-i;
      }
      else{
        a[i]=k+(i-l)*2+1;
        b[i]=k+4*l-3-(i-l);
      }
    }
  }
  else{
    ll l=n/2;
    for(int i=0;i<n;i++){
      if(i<=l-1){
        a[i]=k+2*i;
        b[i]=k+3*l-1-i;
      }
      else{
        a[i]=k+(i-l)*2+1;
        b[i]=k+4*l-1-(i-l);
      }
    }
  }
  for(int i=0;i<n;i++){
    cout << a[i] << " " << b[i] << " " << c[i] << endl;
  }
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
const int N=305;
string s;
int k,dp[N][N][N],ANS;
int main() {
	ios::sync_with_stdio(false);
	
	cin>>s;
	cin>>k;
	
	for (int len=0; len<s.size(); len++)
		for (int l=0; l+len<s.size(); l++) 
			for (int x=0; x<=min(k,len); x++) {
				int r=l+len;
				if (l==r) dp[l][r][x]=1;
				if (l<r) dp[l][r][x]=max(dp[l][r][x],dp[l][r-1][x]);
				if (l<r) dp[l][r][x]=max(dp[l][r][x],dp[l+1][r][x]);
				
				if (l+1==r && s[l]!=s[r] && x) dp[l][r][x]=dp[l][r-1][x-1]+1;
						else 
				if (l+1==r && s[l]==s[r] && !x) dp[l][r][x]=2;
				
				if (r && r-l>1 && s[l]!=s[r] && x) dp[l][r][x]=max(dp[l][r][x],dp[l+1][r-1][x-1]+2);
					else
				if (r && r-l>1 && s[l]==s[r]) dp[l][r][x]=max(dp[l][r][x],dp[l+1][r-1][x]+2);
				
				ANS=max(ANS,dp[l][r][x]);	
			}
	
	cout<<ANS<<endl;
} 

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n,k;cin>>n>>k;
  deque<ll> dq;

  for(int i=0;i<n;i++){
    ll v;cin>>v;
    dq.push_back(v);
  }

  ll res=0;
  for(int l = 0;l<=k;l++){
    for(int r = 0;r<=k;r++){
      if(l+r>k)continue;
      if(l+r>n)continue;

      deque<ll> dq2 = dq;
      priority_queue<int, std::vector<int>, std::greater<int> > pq;
      ll try_v = 0;
      int k_left=0;
      k_left = k - l - r;
      for(int i=0;i<l;i++){
        ll v = dq2.front();dq2.pop_front();
        try_v += v;
        pq.push(v);
      }
      for(int i=0;i<r;i++){
        ll v = dq2.back();dq2.pop_back();
        try_v += v;
        pq.push(v);
      }
      while(k_left-- && pq.size()){
        ll v = pq.top();pq.pop();
        if(v>=0)break;
        try_v -= v;
      }
      res = max(res, try_v);
    }
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (s, t) = readLine()?.split(" ") ?: return
    val (a, b) = readLine()?.split(" ")?.map(String::toInt) ?: return
    val u = readLine() ?: return
    println(
        "${a - if (u == s) {
            1
        } else {
            0
        }} ${b - if (u == t) {
            1
        } else {
            0
        }}"
    )
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i > b; i--)
#define repll(i, a, b) for (ll i = a; i < b; i++)

bool state(int n) {
  if (n % 3 == 0 || n % 5 == 0)
    return false;
  else
    return true;
}

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

  int n;
  cin >> n;

  ll sum = 0;
  rep(i, 1, n + 1) {
    if (state(i))
      sum += i;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.math.*;

public class Main {

    private static Scanner sc;

    public static void main(final String[] args) {
        final Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null)
                br.close();
        }

        public String next() throws IOException {
            if (i < s.length)
                return s[i++];
            String st = br.readLine();
            while (st == "")
                st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }

    private void solve() {
        try {
            int n;
            n = sc.nextInt();
            long a[] = new long[n];
            BigInteger result = BigInteger.ONE;
            for (int i = 0; i < n; i++) {
                a[i] = sc.nextLong();
                if (a[i] == 0) {
                    System.out.println("0");
                    return;
                }
            }
            for (int i = 0; i < n; i++) {
                result = result.multiply(BigInteger.valueOf(a[i]));
                // if(result.divide(BigInteger.valueOf((long)1000000000000000000))>=1) {
                if (result.toString().length()>18 && !result.toString().equals("1000000000000000000")) {
                    System.out.println("-1");
                    return;
                }
            }
            System.out.println(result);

        } catch (

        final Exception e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 61904
#include <stdio.h>

int
main(
    void
)
{
    int n, k;
    scanf("%d%d", &n, &k);

    char s[n + 1];
    scanf("%s", s);

    if ( s[k - 1] == 'A' )
    {
        s[k - 1] = 'a';
    }
    else if ( s[k - 1] == 'B' )
    {
        s[k - 1] = 'b';
    }
    else if ( s[k - 1] == 'C' )
    {
        s[k - 1] = 'c';
    }

    s[n] = '\0';
    printf("%s\n", s);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X,N,Y;
  int M=0;
  cin >> X >> N;
  int A=X;
  int B=X;
  bool E=false;
  bool F=false;
  vector<int>vec(N);
  for (Y=0; Y<N; Y++){
    cin >>vec.at(Y);
    if (vec.at(Y)==X){
      M=1;
    }
  }
  if (M==0){
    cout << X << endl;
  }
  else {
    for (Y=0; Y<100; Y++){
      E=false;
      F=false;
      A-=1;
      B+=1;
      for (int C=0; C<N; C++){
        if (vec.at(C)==A){
          E=true;
        }
      }
      for (int D=0; D<N; D++){
        if (vec.at(D)==B){
          F=true;
        }
      }
      if (E==false){
        break;
      }
      if (F==false){
        break;
      }
    }
    if(E==false){
      cout << A << endl;
    }
    else if(F==false){
      cout << B << endl;
    }
  }
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REPS(i,n) for(int i=1;i<=(int)(n);i++)
using namespace std;
using ll = long long;
using ld = long double;

int main(void) {
    int N;
    cin >> N;
    int P[N], Q[N];
    REP (i, N) {
        cin >> P[i];
        P[i]--;
    }
    REP (i, N) {
        cin >> Q[i];
        Q[i]--;
    }

    int index[N];
    REP (i, N) {
        index[i] = i;
    }
    int a, b, cnt = 0;
    do {
        cnt++;
        bool flg_P = true, flg_Q = true;
        REP (i, N) {
            if (index[i] != P[i]) {
                flg_P = false;
            }
            if (index[i] != Q[i]) {
                flg_Q = false;
            }
        }
        if (flg_P) {
            a = cnt;
        }
        if (flg_Q) {
            b = cnt;
        }
    } while (next_permutation(index, index+N));

    int ans = abs(a-b);
    cout << ans << endl;
}

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

int main(){
    ll N;
    cin >> N;
    map<ll, ll> a;
    rep(i, 0, N){
        ll t;
        cin >> t;
        a[t]++;
    }

    ll ans = 0;
    for(auto aa : a){
        if(aa.second > aa.first) ans += aa.second - aa.first;
        if(aa.second < aa.first) ans += aa.second;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  string N;
  cin >> N;
  
  vector<char> ans;
  for (int i = 0; i < N.size(); i++){
    if(N.at(i) == '0') ans.push_back('0');
    else if(N.at(i) == '1') ans.push_back('1');
    else if(N.at(i) == 'B' && ans.size() != 0) ans.pop_back();
  }

  for (int i = 0; i < ans.size(); i++) cout << ans.at(i);
  cout << endl;
}

Measured memory_bytes: 256
s = input()
ans = "AC"
c = 1
for i in range(0,len(s)):
    if i == 0:
        if s[0] != "A":
            ans = "WA"
            break
    if i >= 2 and i < len(s) -1:
        if s[i] == "C":
            c -= 1
            continue
    if i > 0:
        if not s[i].islower():
            ans = "WA"
if c != 0:
    ans = "WA"
print(ans)


Measured memory_bytes: 3060
#include <array>
#include <iostream>
#include <tuple>
using namespace std;

enum Square {
    BLANK,
    QUEEN,
    KEEP_OUT,
};
using Board = array<array<Square, 8>, 8>;
using Result = tuple<bool, Board>;

Board put_queen(Board b, short r, short c);
Board solve(Board b);
Result solve_rec(Board b, short r);
void print_board(Board b);

int main() {
    short k;
    cin >> k;

    Board b{};
    for (short i = 0; i < k; ++i) {
        short r, c;
        cin >> r >> c;

        b = put_queen(b, r, c);
    }

    print_board(solve(b));
}

Board put_queen(Board b, short r, short c) {
    for (int j = 0; j < 8; ++j)
        if (b[r][j] == BLANK) b[r][j] = KEEP_OUT;
    for (int i = 0; i < 8; ++i)
        if (b[i][c] == BLANK) b[i][c] = KEEP_OUT;
    for (int i = 0; i < 8; ++i)
        for (int j = 0; j < 8; ++j)
            if ((i - j == r - c || i + j == r + c) && b[i][j] == BLANK)
                b[i][j] = KEEP_OUT;
    b[r][c] = QUEEN;
    return b;
}

Board solve(Board b) {
    Result result = solve_rec(b, 0);
    // if (!get<0>(result)) cerr << "no ans" << endl;
    return get<1>(result);
}

Result solve_rec(Board b, short r) {
    if (r == 8) return make_tuple(true, b);

    for (int c = 0; c < 8; ++c)
        if (b[r][c] == QUEEN) return solve_rec(b, r + 1);

    for (int c = 0; c < 8; ++c)
        if (b[r][c] == BLANK) {
            Result result = solve_rec(put_queen(b, r, c), r + 1);
            if (get<0>(result)) return result;
        }
    return make_tuple(false, b);
}

void print_board(Board b) {
    for (short i = 0; i < 8; ++i) {
        for (short j = 0; j < 8; ++j) cout << (b[i][j] == QUEEN ? 'Q' : '.');
        cout << endl;
    }
}


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

int main(){
    int flg[256] = {};
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        flg[s[i]] = 1;
    }
    if((flg['N'] ^ flg['S']) || (flg['E'] ^ flg['W']))cout << "No" << endl;
    else cout << "Yes" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include<vector>
#include<deque>

using namespace std;
#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
void reader(int& x) { int k, m = 0; x = 0; for (;;) { mygc(k); if (k == '-') { m = 1; break; }if ('0' <= k&&k <= '9') { x = k - '0'; break; } }for (;;) { mygc(k); if (k<'0' || k>'9')break; x = x * 10 + k - '0'; }if (m) x = -x; }
void writer(int x, char c) { int s = 0, m = 0; char f[10]; if (x<0)m = 1, x = -x; while (x)f[s++] = x % 10, x /= 10; if (!s)f[s++] = 0; if (m)mypc('-'); while (s--)mypc(f[s] + '0'); mypc(c); }
template<class T> void writerLn(T x) { writer(x, '\n'); }
#define rep(i,n)for(int i=0;i<n;i++)
vector<int>E[100000];
int u[200000], v[200000], r[200000], ans[200000], d[100000]{ 1 }, cnt = 1;
char b[200000], ok[100000]{ 1 };
deque<int>que;

void bfs(int u, int t) {
	que.emplace_back(u);
	while (!que.empty()) {
		int p = que.front(); que.pop_front();
		for (int v : E[p]) {
			if (t) {
				if (d[v] > d[p] && !ok[v]) {
					ok[v] = 1; cnt++; que.emplace_back(v);
				}
			}
			else if (!d[v]) {
				d[v] = d[p] + 1; que.emplace_back(v);
			}
		}
	}
}
int main() {
	int n, m, q; reader(n); reader(m); reader(q);
	rep(i, m) {
		reader(u[i]); reader(v[i]);
		u[i]--; v[i]--;
		E[u[i]].emplace_back(v[i]); E[v[i]].emplace_back(u[i]);
	}
	bfs(0, 0);
	rep(i, m) {
		if (d[u[i]] > d[v[i]])swap(u[i], v[i]);
	}
	rep(i, n)E[i].clear();
	rep(i, q) {
		reader(r[i]); r[i]--;
		b[r[i]] = 1;
	}
	rep(i, m) {
		if (!b[i]) {
			if (d[v[i]] > d[u[i]]) {
				E[u[i]].emplace_back(v[i]);
			}
		}
	}
	bfs(0, 1);
	for (int i = q - 1; i >= 0; i--) {
		ans[i] = n - cnt;
		if (d[v[r[i]]] > d[u[r[i]]] && !ok[v[r[i]]]) {
			E[u[r[i]]].emplace_back(v[r[i]]);
			if (ok[u[r[i]]]) {
				cnt++; ok[v[r[i]]] = 1;
				bfs(v[r[i]], 1);
			}
		}
	}
	rep(i, q)writerLn(ans[i]);
}

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

int main()
{
    long long N, A, B;
    cin >> N >> A >> B;
    
    long long diff = abs(B - A);
    long long result = 0;
    if (diff % 2 == 1) {
        long long distN = N - max(A, B);
        long long dist0 = min(A, B) - 1;
        long long minDist = min(distN, dist0);
        result += minDist + 1;
        diff = diff - 1;
    }
    
    result += diff / 2;
    cout << result;

    return 0;
}

Measured memory_bytes: 888
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        h: usize,
        w: usize,
        mut v: [chars; h]
    }
    for i in 0..h {
        v[i].insert(0, '.');
        v[i].push('.');
    }
    v.insert(0, vec!['.'; w + 2]);
    v.push(vec!['.'; w + 2]);
    for i in 1..h + 1 {
        for j in 1..w + 1 {
            let mut c: u8 = 0;
            for k in i - 1..i + 2 {
                for l in j - 1..j + 2 {
                    if v[k][l] == '#' {
                        c += 1;
                    }
                }
            }
            let ch = if v[i][j] == '#' {
                '#'
            } else {
                (c + '0' as u8) as char
            };
            print!("{}", ch);
        }
        println!("");
    }
}


Measured memory_bytes: 4352
s = input()


sl = list(s)


ans = 101

for i in range(26):
    cur_char = chr(ord('a') + i)

    if not cur_char in sl:
        continue

    sl_cp = sl.copy()

    while not len(set(sl_cp)) == 1:

        for i in range(len(sl_cp)-1):
            if sl_cp[i+1] == cur_char:
                sl_cp[i] = cur_char

        sl_cp.pop()

    ans = min(ans, len(sl) - len(sl_cp))

print(ans)


Measured memory_bytes: 3060
N = int(input())
mod = 1000000007
from collections import Counter
Y = Counter()
for i in range(2, N+1):
    M = i
    for j in range(2,i+1):
        while M % j == 0:
            Y[j] += 1
            M //= j

def product(X):
    res = 1
    for x in X:
        res *= x + 1
        res %= mod
    return res    

ans = product(Y.values())
print(ans)

Measured memory_bytes: 9372
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vll vector <ll>
#define vvi vector <vector <int> >
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 5e5+100;
const ll INF = 1e9;
const ll kek=998244353;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    double q=1;
    for (double i=1;i<n;i++)
        q*=i;
    double sum=0;
    vector <double> x(n),y(n);
    for (int i=0;i<n;i++)
    {
        cin>>x[i]>>y[i];
    }
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<n;j++)
        {
            sum+=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
        }
    }
    cout<<setprecision(40)<<sum/(double)(n);
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] DN = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            if (DN[1] == 100L)
            {
                DN[1]++;
            }
            if (DN[0] == 0)
            {
                Console.WriteLine(DN[1]);
            }
            else if (DN[0] == 1)
            {
                Console.WriteLine(DN[1] * 100L);
            }
            else if (DN[0] == 2)
            {
                Console.WriteLine(DN[1] * 10000L);
            }
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();


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

int main() {
  int N;
  cin >> N;
  vector<double> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];

  double ans = 0;
  for (int i = 0; i < N; i++) {
    ans += 1/A[i];
  }
  printf("%.10lf\n", 1/ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
template<typename T>int o(T x){cout<<x<<endl;return 0;}
int n,m;
vector<int>g[N];
vector<int>du(N,0);
vector<int>depth(N,-1);
vector<pair<int,int> >p;
int main(){
        cin>>n>>m;
        for(int i=1;i<=m;i++){
                int u,v;
                scanf("%d%d",&u,&v);
                g[u].push_back(v);
                g[v].push_back(u);
        }
        if(m&1)return o(-1);
        function<void(int u,int fa)>dfs=[&](int u,int fa){
                depth[u]=depth[fa]+1;
                for(int v:g[u]){
                        if(depth[v]==-1){
                                dfs(v,u);
                        }else{
                                if(depth[v]>depth[u]){
                                        p.emplace_back(u,v);
                                        du[u]++;
                                }
                        }
                }
                if(fa==0)return;
                if(du[u]&1){
                        p.emplace_back(u,fa);
                        du[u]++;
                }else{
                        p.emplace_back(fa,u);
                        du[fa]++;
                }
        };
        depth[0]=0;
        dfs(1,0);
        for(auto x:p)cout<<x.first<<" "<<x.second<<endl;
}

Measured memory_bytes: 14836
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
typedef long long ll;
using namespace std;
//作者：中国江苏南京朱泽齐
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	ll x;
    cin>>x;
    ll ans=x / 11 * 2;
    ll rem=x % 11;
    if(rem!=0 && rem<=6)
	ans++;
    else if(rem!=0)
	ans+=2;
    cout<<ans<<endl;
	//system("pause");
	return 0;
}

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

ll gcd(ll a, ll b){
	if (a == 0) return b;
	return gcd(b  %a, a);
}

ll lcm(ll a, ll b){
	return (a*b) / gcd(a, b);
}

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

	ll n,i,j;
	cin >> n;

	ll ans1;
	for(i=1;;i++)
	{
		if(n <= (26*(pow(26,i) - 1))/25)
		{
			ans1 = i;
			break;
		}
	}



	char s[ans1];
	for(i=1;i<ans1;i++)
	{
		ll z = pow(26,i);	
		ll x = n%z;
		if(i != 1)
		{
			if(x == 0)
			{
				x = z;
			}
			z = pow(26,i-1);
			n-=x;
			x /= z; 
			s[ans1 - i] = (char)('a' + x - 1);
		}
		else
		{
			if(x == 0)
			{
				s[ans1 - i] = 'z';
				n-=26;
			}
			else
			{
				s[ans1 - i] = (char)('a' + x - 1);
				n-=x;
			}
		}	

	}

	ll y = n/pow(26,ans1-1);
	if(y == 0)
		s[0] = 'z';
	else
		s[0] = (char)('a' + y - 1);

	for(i=0;i<ans1;i++)
		cout << s[i];
	cout << endl;
}

Measured memory_bytes: 4052
#include <stdio.h>

long GCD(long a, long b){
  long dividend, divisor;
  if (a >= b) {
    dividend = a;
    divisor = b;
  } else {
    dividend = b;
    divisor = a;
  }
  long remainder;
  while (1) {
    if (divisor == 1) {
      return 1;
    }
    remainder = dividend % divisor;
    if (remainder == 0) {
      break;
    } else {
      dividend = divisor;
      divisor = remainder;
    }
  }
  return divisor;
}

int main(void){

  long k;
  scanf("%ld", &k);
  long sum;
  long sum_a = 0;
  long sum_b = 0;
  long sum_c = 0;
  for (long i = 1; i <= k; i++) {
    for (long j = i+1; j <= k; j++) {
      for (long l = j+1; l <= k; l++) {
        sum_a += GCD(i,GCD(j,l));
      }
    }
  }
  for (long i = 1; i <= k; i++) {
    for (long j = i+1; j <= k; j++) {
      sum_b += GCD(i,j);
    }
  }
  for (long i = 1; i <= k; i++) {
    sum_c += i;
  }
  sum = sum_a*6 + sum_b*6 + sum_c;

  printf("%ld\n", sum);

  return 0;
}

Measured memory_bytes: 1700
using System;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
class Program
{
	static void Main(string[] args)
	{
		const int A = 1;
		const int C = 2;
		const int G = 3;
		const int T = 4;

		int N = int.Parse(Console.ReadLine());

		var dic = new Dictionary<int, BigInteger>();
		
		dic.Add(A, new BigInteger(1));
		dic.Add(C, new BigInteger(1));
		dic.Add(G, new BigInteger(1));
		dic.Add(T, new BigInteger(1));

		for(int i=1; i<N; i++) {
			var temp = new Dictionary<int, BigInteger>();
			
			foreach(KeyValuePair<int, BigInteger> pair in dic){

				for(int ACGT = A; ACGT<=T; ACGT++) {
					int checkValue = (pair.Key * 10 + ACGT) % 10000;
					if(!ContainAGC(checkValue)) {
						if(temp.ContainsKey(checkValue)) {
							BigInteger bi = temp[checkValue];
							bi += pair.Value;
							temp[checkValue] = bi;
						}
						else {
							BigInteger bi = new BigInteger();
							bi += pair.Value;
							temp.Add(checkValue, bi);
						}
					}
				}
			}
			dic = temp;
		}

		BigInteger sum = 0;
		foreach(KeyValuePair<int, BigInteger> pair in dic){
			sum += pair.Value;
		}

		Console.WriteLine(sum%1000000007);
	}


	static bool ContainAGC(int val) {
		if(val/10 == 132) return true; // AGC*
		if(val/100 == 13 && val%10 == 2) return true; // AG*C
		if(val/1000 == 1 && val%100 == 32) return true; // A*GC
		if(val%1000 == 132 || val%1000 == 123 || val%1000 == 312) return true; // *AGC, *ACG, *GAC
		return false;
	}
}

Measured memory_bytes: 17884
#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
int n,a,b,c,l[10],f[10],ans=1e9,x;
void dfs3(int deep,int num,int last,int llast){
	if (num!=0){
		ans=min(ans,abs(llast-a)+abs(last-b)+abs(num-c)+x);
//		cout<<abs(llast-a)+abs(last-b)+abs(num-c)+x<<endl;
	}
	for (int i=deep;i<n;i++)
		if (f[i]==0){
			f[i]=1;
			if (num!=0) x+=10;
			dfs3(i,num+l[i],last,llast);
			if (num!=0) x-=10;
			f[i]=0;
		}
	return ;
}
void dfs2(int deep,int num,int last){
	if (num!=0) dfs3(0,0,num,last);
	for (int i=deep;i<n;i++)
		if (f[i]==0){
			f[i]=1;
			if (num!=0) x+=10;
			dfs2(i,num+l[i],last);
			if (num!=0) x-=10;
			f[i]=0;
		}
	return ;
}
void dfs(int deep,int num){
	if (num!=0) dfs2(0,0,num);
	for (int i=deep;i<n;i++)
		if (f[i]==0){
			f[i]=1;
			if (num!=0) x+=10;
			dfs(i,num+l[i]);
			if (num!=0) x-=10;
			f[i]=0;
		}
	return ;
}
int main(){
	cin>>n>>a>>b>>c;
	for (int i=0;i<n;i++) cin>>l[i];
	dfs(0,0);
	cout<<ans<<endl;
	return 0;
}

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

int digit(int64_t N) {
    string S = to_string(N);
    int digit = S.size();
    return digit;
}

int main()
{
    int64_t N;
    cin >> N;
    int answer = digit(N), current = 0;

    for (int64_t i = 1; i * i <= N; i++) {
        if(N%i == 0) {
            current = digit(N / i);
        }
        answer = min(answer, current);
    }
    cout << answer << endl;
}

Measured memory_bytes: 256
S = input()
k = 1000 
for i in range (len(S)):
    x = y = 0
    for j in range (1, len(S) + 1):
        if S[i] == S[len(S)-j]:
            x = 0
        else:
            x += 1
        y = max(x,y)
    k = min(k,y)
print(k)

Measured memory_bytes: 9044
<?php
fscanf(STDIN,"%d %d",$N,$K);
$result = 0.0;
for($i=1;$i<=$N;$i++){
    $result += (1/$N)*((1/2)**howMultiply($i,$K,0));
}
echo $result;

//$iが$Kを超えるのは2の何乗を掛けたときかを返す
function howMultiply($i,$K,$counter){
  if($i>=$K){
    return $counter;
  }else{
    return howMultiply($i*2,$K,$counter+1);
  }
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll x;
    cin >> x;
    cout << (8 - (x - 400) / 200) << endl;
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h,w;
	cin>>h>>w;
	char a[h][w];
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cin>>a[i][j];
		}
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(a[i][j]=='#')
			{
				if(a[i+1][j]!='#'&&a[i][j-1]!='#'&&a[i][j+1]!='#'&&a[i-1][j]!='#')
				{
					cout<<"No\n";
					return 0;
				}	
			}
		}
	}
	cout<<"Yes\n";
	return 0;
}

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

using namespace std;

int n;
vector<int> G[100100];
bool visit[100100];
vector<int> Path;

bool getP(int idx){

    if(idx==n-1) return true;


    for(int i = 0; i<G[idx].size(); i++){
            if(!visit[G[idx][i]]){
                visit[G[idx][i]]=1;
                if(getP(G[idx][i])){
                    Path.push_back(G[idx][i]);
                    return true;
                }
            }
    }

    return false;

}

int bfs(int idx){

    if(visit[idx]) return 0;
    visit[idx] = 1;

    int ans = 1;
    for(int i = 0; i<G[idx].size(); i++)
        ans+=bfs(G[idx][i]);

    return ans;
}

int main()
{
    cin>>n;

    int a, b;

    memset(visit,0,sizeof visit);


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

    }


    visit[0]=1;
    getP(0);

    Path.push_back(0);
    reverse(Path.begin(),Path.end());
/*
    for(int i = 0; i<Path.size(); i++){
        cout<<Path[i]<<" ";
    }
    cout<<endl;


    queue< vector<int> > Q;
    Q.push(Path);


    while(!Q.empty()){

        Path = Q.front();
        Q.pop();

        int u = Path[Path.size()-1];
        if(u==n-1) break;

        for(int i = 0; i<G[u].size(); i++){
            if(!visit[G[u][i]]){
                Path.push_back(G[u][i]);
                Q.push(Path);
                visit[G[u][i]]=1;
                Path.pop_back();
            }
        }

    }
*/
    memset(visit,0,sizeof visit);

    for(int i = 0; i<Path.size(); i++)
        visit[Path[i]]=1;

    int piv = (Path.size()+1)/2;

    int contF = 0;

    for(int i = 0; i<piv; i++){
        contF++;
        int u = Path[i];

        for(int j = 0; j<G[u].size(); j++)
            contF+=bfs(G[u][j]);

        if(contF>n-contF){
            puts("Fennec");
            return 0;
        }
    }

    if(contF>n-contF){
        puts("Fennec");
    }else{
        puts("Snuke");
    }

    return 0;
}


Measured memory_bytes: 12668
import numpy as np
N,M,C=map(int,input().split())
B=[int(i) for i in input().split()]
count=0
for i in range(N):
  a=[int(val) for val in input().split()]
  if np.dot(a,B)+C>0:
    count+=1
  else:
    pass
print(count)



Measured memory_bytes: 12440
from sys import stdin
import numpy as np

N = int(stdin.readline().rstrip())
MOD =10**9+7
MEMO = [{} for _ in range(N+1)]
ACGT = "ACGT"
ACG = ["ACG","AGC","CAG","ATCG","ACTG","ACCG"]

def acg_check(last4):
  for acg in ACG:
    if acg in last4:
      return False
  return True

def func(length, last3):
  if last3 in MEMO[length]:
    return MEMO[length][last3]
  if length == N:
    return 1

  ans = 0
  for c in ACGT:
    if len(last3)==3:
      if acg_check(last3+c):
        ans += func(length+1,last3[1:]+c)%MOD
    else:
      if acg_check(last3+c):
        ans += func(length+1,last3+c)%MOD
  MEMO[length][last3] = ans
  return ans

print(func(0,"")%MOD)

Measured memory_bytes: 12864
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>

//#include <function>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)


bool isok(int a, int b, int c, int d){
  bool ans = true;
  if ((b == 0 && c == 2 && d == 1) || (b == 0 && c == 1 && d == 2) || (b == 2 && c == 0 && d == 1) || (a == 0 && b == 2 && d == 1) || (a == 0 && c == 2 && d == 1)){
    ans = false;
  }
  return ans;
}

int main() {

  ll MOD = 1e9 + 7;
  int N;
  cin >> N;

  ll dp[110][4][4][4] = {0LL};

  dp[0][3][3][3] = 1;
  for(int i = 0; i < N; i++){
    REP(j, 4){
      REP(k, 4){
        REP(l, 4){

          REP(m, 4){
            if (isok(j, k, l, m)){
              dp[i+1][k][l][m] = (dp[i+1][k][l][m] + dp[i][j][k][l]) % MOD;
            }
          }
        }
      }
    }
  }
  ll ans = 0LL;
  REP(i, 4) REP(j, 4) REP(k, 4){
     ans += dp[N][i][j][k];
     ans %= MOD;
  }
  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<n; i++)
#define out(x) cout << x << endl

int main() {
    int N,K;
    cin >> N >> K;
    vector<int> A(N),bucket(N);
    REP(i,N){
        cin >> A.at(i);
        bucket.at(i) = 0;
    }
    REP(i,N) bucket.at(A.at(i)-1)++;
    sort(bucket.begin(),bucket.end(),greater<int>());
    int sum=0;
    for (int i=0;i<K;i++){
        sum += bucket.at(i);
    }
    out(N-sum);
    return 0;
}

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

using namespace std;

const int MAX_N = 1000;
const int MAX_W = 1000;
int dp[MAX_N + 1][MAX_W + 1];

int main() {
    int id = 1;
    int W, N;
    while (scanf("%d", &W), W) {
        cin >> N;

        int w[MAX_N + 1], v[MAX_N + 1];
        for (int i = 0; i < N; i++) {
            scanf("%d,%d", &v[i], &w[i]);
        }

        for (int i = 0; i <= W; i++) {
            dp[N][i] = 0;
        }

        for (int i = N - 1; i >= 0; i--) {
            for (int j = 0; j <= W; j++) {
                if (j < w[i]) {
                    dp[i][j] = dp[i + 1][j];
                } else {
                    dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
                }
            }
        }

        int max_value = 0, max_weight;
        for (int i = 0; i <= W; i++) {
            if (dp[0][i] <= max_value) continue;
            max_value = dp[0][i];
            max_weight = i;
        }

        printf("Case %d:\n", id++);
        printf("%d\n%d\n", max_value, max_weight);
    }

    return 0;
}


Measured memory_bytes: 7024
def test():
    N, K = map(int, input().split())
    H = list(map(int, input().split()))
    dp = [float('inf')]*N
    dp[0] = 0

    for i in range(1, N):
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i))

    print(dp[-1])

if __name__ == '__main__':
    test()

Measured memory_bytes: 13980
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

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

    set<ll> st;
    
    bool flag = true;
    st.insert(s);
    ll i = 2;
    while(flag){
        if(s&1){
            s = s*3 + 1;
            auto itr = st.find(s);
            if(itr != st.end()){
                cout << i << endl;
                return 0;
            }
            st.insert(s);
        }else{
            s = s/2;
            auto itr = st.find(s);
            if(itr != st.end()){
                cout << i << endl;
                return 0;
            }
            st.insert(s);
        }
        i++;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
using ll = unsigned long long;
const ll mod = 1e9+7;
int main() 
{
    int n, k;
    cin >> n >> k;
    int a[2010] = {};
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    int cntl[2010] = {};
    int cntr[2010] = {};
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < i; j++)
        {
            if (a[i] < a[j]) cntl[i]++;
        }
        for (int j = i+1; j < n; j++)
        {
            if (a[i] < a[j]) cntr[i]++;
        }
        
    }

    ll ans = 0;
   for (int i = 0; i < n; i++)
        {
            ans = (ans + (ll)k*(2*cntl[i])/2%mod+((ll)k*(ll)(k-1))/2%mod*((cntl[i]+cntr[i])%mod)) % mod;
            //ans = (ans + k%mod*(((k-1)%mod*(cntl[i]+cntrs[i]))/2+cntl[i])%mod) % mod;
            //ans = (ans + (ll)k * cntl[i] % mod  + ((ll)k*((ll)k-1)/2) % mod * (cntl[i]+cntr[i]))%mod;
            //ans = (ans + (ll)k * cntl[i] % mod  + ((ll)k*(ll)(k-1)/2) % mod * (cntl[i]+cntr[i]))%mod;
        }

    cout << ans << "\n";
    
    
    
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int INF = 100000000;

ll i,j,k;

int main(){
    ll n;cin>>n;
    vector<ll> a(n);for(i=0;i<n;i++){cin>>a[i];}

    sort(a.begin(),a.end());

    for(i=0;i<n-1;i++){
        if(a[i]+a[i+1]<0){a[i]*=(-1);a[i+1]*=(-1);}
    }

    ll sum=0;
    for(i=0;i<n;i++){
        sum+=a[i];
    }

    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 1024
a,b,c,k = input().split(None, 4)
A = int(a)
B = int(b)
C = int(c)
K = int(k)
X = K - A - B
if K <= A:
    print(K)
elif A < K <= A + B:
    print(A)
else:
    print(A - X)


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

int main() {
  int a;
  cin >> a;
  int b;
  cin >> b;
  int c;
  cin >> c;
  if (a*c <= b) {
    cout << c << endl;
  } else {
    cout << b/a << endl;
  }
}
  

Measured memory_bytes: 256
def make_divisors(n):
    divisors =  float('inf')
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors = min(divisors,i + n//i -2)
    # divisors.sort()
    return divisors


n = int(input())

distance = make_divisors(n)
print(distance)


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

def is_combination_odd(n, r):
    _n = n
    _r = r
    is_odd = True
    while _n > 0 and _r > 0:
        if _n % 0b10 < _r % 0b10:
            is_odd = False
            break
        _n >>= 1
        _r >>= 1
    #print('n: %d, r: %d, is_odd: %d' % (n, r, is_odd))
    return is_odd
    
def is_ans_odd(num_str: str) -> bool:
    is_odd = False
    for i, c in enumerate(num_str):
        is_c_odd = int(c) % 2
        is_odd ^= is_combination_odd(len(num_str)-1, i) & is_c_odd
    return is_odd

def main():
    ans = -1
    table = str.maketrans({'1': '0', '2': '1', '3': '2'})
    a012 = a.translate(table)
    if is_ans_odd(a012):
        ans = 1
    else:
        if '1' in a012:
            ans = 0
        else:
            table = str.maketrans({'2': '1'})
            a01 = a012.translate(table)
            if is_ans_odd(a01):
                ans = 2
            else:
                ans = 0

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 121012
#include<bits/stdc++.h>
using namespace std;
inline long long read()
{
	long long x=0;bool f=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-'){f=1;ch=getchar();break;}ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	if(f) x=-x;return x;
}
const long long N=2000,mod=1000000007;
long long poww(long long a,long long b){long long c=1;while(b){if(b&1) c=c*a%mod;a=a*a%mod;b>>=1;}return c;}
long long n,a[200010],b[200010],dp[4010][4010],jc[8010]={1},inv[8010]={1},ans;
long long C(long long x,long long y){return jc[x]*inv[y]%mod*inv[x-y]%mod;}
int main()
{
	for(long long i=1;i<=8000;i++) jc[i]=jc[i-1]*i%mod;
	inv[8000]=poww(jc[8000],mod-2);
	for(long long i=7999;i>=1;i--) inv[i]=(inv[i+1]*(i+1))%mod;
	n=read();
	for(long long i=1;i<=n;i++)
	{
		a[i]=read(),b[i]=read();
		dp[N-a[i]][N-b[i]]++;//cout<<(N-a[i])<<" "<<(N-b[i])<<" "<<dp[N-a[i]][N-b[i]]<<endl;
	}
	for(long long i=0;i<=2*N;i++)
		for(long long j=0;j<=2*N;j++)
		{
			if(i>0) dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
			if(j>0) dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;//if(dp[i][j])cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
		}
	for(long long i=1;i<=n;i++) ans=(ans+mod+dp[N+a[i]][N+b[i]]-C(2*(a[i]+b[i]),2*a[i]))%mod;
	printf("%lld",ans*inv[2]%mod);
}

Measured memory_bytes: 129152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
	int n;	cin >> n;
  	string s;	cin >> s;
  	string s2;
  	vector<int> si;
  	rep(i,s.size()){
    	int ch = (s.at(i) - 64+n)%26;
      	if(ch == 0) ch = 26;
      	ch += 64;
		char ch2 = ch;
      	s2.push_back(ch2);
    }
  	cout << s2 << endl;
}

Measured memory_bytes: 256
from itertools import accumulate


def binary(N, T):  # 二分探索 # N:探索要素数
    l, r = -1, N
    while r - l > 1:
        if T < b[(l + r) // 2]:  # 条件式を代入
            r = (l + r) // 2
        else:
            l = (l + r) // 2
    return r - 1


n, m, k = map(int, input().split())
a = [0] + list(accumulate(map(int, input().split())))
b = [0] + list(accumulate(map(int, input().split())))

ans = 0
for i, ai in enumerate(a):
    t = k - ai
    if t >= 0:
        j = binary(m + 1, t)
        ans = max(ans, i + j)
print(ans)


Measured memory_bytes: 115316