akhauriyash/Code-Regression huggingface dataset:
import numpy
h,w = map(int, input().split())
l = list()
for i in range(h):
    l.append(list(input()))
l = numpy.array(l)
kari = 0
kari2 = []
for i in range(h):
    for j in range(w):
        if l[i][j] == ".":
            kari += 1
    if kari == w:
        kari2.append(i)
    kari = 0
kari2 = kari2[::-1]
h -= len(kari2)
for i in kari2:
    l = numpy.delete(l, i, 0)
kari2 = []
for i in range(w):
    for j in range(h):
        if l[j][i] == ".":
            kari += 1
    if kari == h:
        kari2.append(i)
    kari = 0
kari2 = kari2[::-1]
for i in kari2:
    l = numpy.delete(l, i, 1)
l = l.tolist()
for i in range(h):
    print(*l[i],sep="")


Measured memory_bytes: 13872
#include<stdio.h>

int main(){
   
  int a[101],n,i,d,sum,k;
  while(1){
sum=0;
scanf("%d",&n);
if(n==0){break;}
  for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
  for(i=n-1;i>0;i--){
    for(k=0;k<i;k++){
      if(a[k]>a[k+1]){d=a[k+1];
a[k+1]=a[k];
 a[k]=d;
 sum=sum+1;}
    }
  }
  
  printf("%d\n",sum);
  }
      return 0;
  }

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;

//最大公約数をユークリッドの互除法を使って求める
int gcd(int a, int b) {
    if(a % b == 0)
    return b;
    return gcd(b, a % b);
}
 
int main() {

    int n,x;
    cin >> n >> x;
    vector<int> v(n);
    rep(i,n)    cin >> v[i];

    int d=abs(v[0]-x);
    for(int i=1;i<n;i++) {
        d=gcd(abs(v[i]-x),d);
    }

    cout<<d<<endl;

 return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> v(n);
    rep(i, n) cin >> v[i];
    ll ans = 0;
    for ( int l = 0; l <= n; ++l ) {
        for ( int r = 0; r <= n; ++r ) {
            if ( l + r > k ) continue;
            if ( l + r > n ) continue;
            priority_queue<ll, vector<ll>, greater<ll>> q;
            ll sum = 0;
            rep(i, l) q.push(v[i]);
            rep(i, r) q.push(v[n-i-1]);
            int d = k - l - r;
            rep(c, d) {
                if ( q.empty() ) break;
                if ( q.top() >= 0 ) break;
                q.pop();
            }
            while(!q.empty()) {
                sum += q.top();
                q.pop();
            }
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <cstring>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll MAX = 55;
mat Com(MAX, vec(MAX));

void com() {
    Rep (i, MAX) {
        Rep (j, MAX) {
            Com[i][j] = 0;
        }
    }
    Com[0][0] = 1;
    for (ll i = 1; i < MAX; i++) {
        Com[i][0] = 1;
        for (ll j = 1; j < MAX; j++) {
            Com[i][j] = Com[i-1][j-1] + Com[i-1][j];
        }
    }
}

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

    cout << fixed << setprecision(10);

    ll N, A, B;
    cin >> N >> A >> B;
    vec v(N);
    Rep (i, N) {
        cin >> v[i];
    }

    sort(v.begin(), v.end());
    double ans = 0;
    for (ll i = N-1; i >= N-A; i--) {
        ans += v[i];
    }

    ans /= A;
    com();

    ll cnt = 0;
    ll choose = 0;
    Rep (i, N) {
        if (v[i] == v[N-A]) {
            cnt++;
            if (i >= N-A) {
                choose++;
            }
        }
    }

    ll check = Com[cnt][choose];
    if (v[N-1] == v[N-A]) {
        for (ll i = 1; i <= B-A; i++) {
            check += Com[cnt][choose+i];
        }
    }

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

Measured memory_bytes: 256
import math

n = int(input())
ans = [0] * (n+1)

f = int(math.sqrt(n)) + 1
for x in range(1, f):
    for y in range(1, f):
        for z in range(1, f):
            v = (x ** 2) + (y ** 2) + (z ** 2) + (x * y) + (y * z) + (z * x)
            if v < n + 1:
                ans[v] += 1
            
for i in range(n):
    print(ans[i+1])

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

int main() {

  int H,W;
  cin >> H >> W;
  vector<vector<char>> a(H,vector<char>(W));
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      cin >> a.at(i).at(j);
    }
  }
  
  vector<bool> row(H,false);
  vector<bool> col(W,false);
  
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      if(a.at(i).at(j) == '#'){
        row.at(i) = true;
        col.at(j) = true;
      }
    }
  }
  
  for(int i = 0; i < H; ++i){
    if(row.at(i)){
      for(int j = 0; j < W; ++j){
      	if(col.at(j)){
          cout << a.at(i).at(j);
        }
      }
      cout << endl;
    }
  }
	
}

Measured memory_bytes: 256
import java.util.Scanner;

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

                int D = scan.nextInt();
                int T = scan.nextInt();
                int S = scan.nextInt();

                if (S*T >= D) {
                	System.out.println("Yes");
                } else {
                	System.out.println("No");
                }

                scan.close();

        }
}

Measured memory_bytes: 35612
n = int(input())
p = list(map(int,input().split()))
int_queue = [i for i in range(1,n+1)]
ans = 0
for j in range(0,n):
  if p[j]-int_queue[j] == 0:
    continue
  else:
    ans += 1
if ans == 2 or ans == 0:
  print("YES")
else:
  print("NO")

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

int main(){
    int a,b,k; cin >> a >> b >> k;
    int p = a,q = b;
    vector<int> ans(2*k);
    int cnt = 0;
    for(int i=0;i<k;i++){
        ans[cnt] = a; a++; cnt++;
        ans[cnt] = b; b--; cnt++;
    }
    sort(ans.begin(),ans.end());
    for(int i=0;i<2*k;i++){
        if(ans[i] != ans[i-1] && ans[i] >= p && ans[i] <= q){
            cout << ans[i] << endl;
        }
    }
}



Measured memory_bytes: 256
K = int(input())
S = input()
N = len(S)
mod = 7 + 10 ** 9
fact = [1] * (N + K + 1)
for i in range(1, N + K + 1): fact[i] = (fact[i-1] * i) % mod
revfact = [1] * (N + K + 1)
revfact[N + K] = pow(fact[N + K], mod - 2, mod)
for i in reversed(range(1, N + K)):
    revfact[i] = ((i + 1) * revfact[i + 1]) % mod

def comb(n, r):
    return (fact[n] * revfact[n-r] * revfact[r]) % mod

def solve():
    ans = 0
    for k in range(K + 1):
        leftMost = pow(26, k, mod) 
        right = (pow(25, K - k, mod) * comb(N + K - k - 1, N - 1)) % mod
        ans += (leftMost * right) % mod
        ans %= mod
    print(ans)


    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 117260
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.flush();
		out.close();
	}
}

class Pair {
	int a[];

}

class TaskB {

	public void solve(int testNumber, InputReader in, PrintWriter pw) {
		int N = in.nextInt();
		long W = in.nextLong();
		int v[] = new int[N];
		long w[] = new long[N];
		int sum = 0;
		for (int i = 0; i < N; i++) {
			w[i] = in.nextLong();
			v[i] = in.nextInt();
			sum += v[i];
		}
		long dp[] = new long[sum + 1];
		Arrays.fill(dp, (long) 1e12);
		dp[0] = 0;
		for (int i = 0; i < N; i++) {
			for (int value_taken = sum - v[i]; value_taken >= 0; value_taken--) {
				dp[value_taken + v[i]] = Math.min(dp[value_taken + v[i]], dp[value_taken] + w[i]);
			}
		}
		int ans = -1;
//		pw.println(Arrays.toString(dp));
		for (int i = 0; i <= sum; i++) {
			if (dp[i] <= W) {
				ans = Math.max(ans, i);
			}
		}
		pw.println(ans);

	}

	int __gcd(int a, int b) {
		if (b == 0)
			return a;
		return __gcd(b, a % b);

	}

	public int getInt(int num) {
		int ret = -1;
		switch (num) {
		case 0:
			ret = 6;
			break;
		case 1:
			ret = 2;
			break;
		case 2:
			ret = 5;
			break;
		case 3:
			ret = 5;
			break;
		case 4:
			ret = 4;
			break;
		case 5:
			ret = 5;
			break;
		case 6:
			ret = 6;
			break;
		case 7:
			ret = 3;
			break;
		case 8:
			ret = 7;
			break;
		case 9:
			ret = 6;
			break;
		}
		return ret;
	}

	public int isPow(long num) {
		int count = 0;
		while (num > 0) {
			num /= 2;
			count++;
		}
		return count;
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

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

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

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

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


Measured memory_bytes: 27068
K,N = map(int,input().split())
A=list(map(int,input().split()))

ans=K
for i in range(N):
    if i == 0:
        dist = A[N-1] - A[0]
    else:
        dist = A[i - 1] + K - A[i]
    
    if ans > dist:
        ans = dist
print(ans)

Measured memory_bytes: 26436
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{
  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    String s;
    String sl[];

    s = r.readLine();
    sl = s.split(" ");

    int n = Integer.parseInt(sl[0]);
    int m = Integer.parseInt(sl[1]);
    int x = Integer.parseInt(sl[2]);

    int a[][] = new int[12][12];
    int c[] = new int[12];

    // Long.parseLong(sl[0]);

    for(int i = 0; i < n; i++)
    {
        s = r.readLine();
        sl = s.split(" ");
    	c[i] = Integer.parseInt(sl[0]);
    	for(int j = 0; j < m; j++)
    	{
    		a[i][j] = Integer.parseInt(sl[1 + j]);
    	}
    }

    int ans = Integer.MAX_VALUE;
    for(int b = 0; b < 1 << 12; b++)
    {
    	int v = 0;
    	int ss[] = new int[12];
        for(int i = 0; i < n; i++)
        {
        	if(((1 << i) & b) > 0)
        	{
    			v += c[i];
        		for(int j = 0; j < m; j++)
        		{
        			ss[j] += a[i][j];
        		}
        	}
        }
        boolean bb = true;
        for(int i = 0; i < m; i++)
        {
        	if(ss[i] < x) bb = false;
        }
        if(bb) {
        	ans = Math.min(v, ans);
        }
    }

    System.out.println(ans == Integer.MAX_VALUE ? -1 : ans);
  }

}

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

long long int N, M;

int main(void) {
  cin >> N >> M;
  long long int H[N];
  long long int A[M], B[M]; 
  for (int i=0; i<N; i++) cin >> H[i];
  for (int i=0; i<M; i++) cin >> A[i] >> B[i];

  long long int LOW[M*2];
  long long int sum = 0;
  for (int i=0; i<M; i++) {
      int a = A[i];
      int b = B[i];
      if(H[a-1] > H[b-1]) {
        LOW[sum] = B[i];
        sum++;
      } else if (H[a-1] == H[b-1]) {
        LOW[sum] = A[i];
        sum++;
        LOW[sum] = B[i];
        sum++;
      } else {
        LOW[sum] = A[i];
        sum++;
      }
  }
  sort(LOW,LOW+sum);
  long long int ans = LOW[0] - 1;
  long long int num = LOW[0];
  for (int i=1; i<sum; i++) {
    if (LOW[i-1] != LOW[i]) {
      num++;
      if (LOW[i] != num) {
      ans += LOW[i] - LOW[i-1] - 1;
      num = LOW[i];
      }
    }
  }
  ans += N - num;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6680
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>

using namespace std;

int main (void)
{
	int n,m;
	
	cin >> n >> m;
	
	if ((n * m) % 2 == 0)
	{
		cout << "Even" << endl;
	}
	else 
	{
		cout << "Odd" << endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private void calc(){
		Scanner scanner = new Scanner(System.in);
		int time =scanner.nextInt();
		
			int hour=time/3600;
			int min =(time-(3600*hour))/60;
			int sec =time-(3600*hour+60*min);
			System.out.print(hour +":"+ min + ":"+sec);
			System.out.println("");
	
	}
	
	public static void main(String[] args) {
		Main cubic =new Main();
		cubic.calc();

	}
}

Measured memory_bytes: 17272
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

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; }

using ll = long long;

ll N, M;

int main()
{
  std::cin >> N >> M;

  std::cout << (1900*M+(N-M)*100)*(1<<M) << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define repd(i, a, b) for (int i = a; i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

int main()
{
    int a, b;
    cin >> a >> b;
    if (a + b >= 10)
        cout << "error" << endl;
    else
        cout << a + b << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define int long long

int32_t main()
{
    int n; cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++) cin>>v[i];
    vector<int> r(n+1,0);
    vector<int> l(n+1,0);
    for(int i=1;i<n;i++)
    {
        l[i]=__gcd(l[i-1],v[i-1]);
        r[n-1-i]=__gcd(r[n-i],v[n-i]);
    }
    int ma=0;
    for(int i=0;i<n;i++)
    {
        if(ma<=__gcd(l[i],r[i]))
        {
            ma=__gcd(l[i],r[i]);
        }
    }
    cout<<ma;
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

struct Point {
    int x;
    int y;
};

const int MAX_SIZE = 1050;

int H, W;
int d[4][2];

std::string S[MAX_SIZE];

char A[MAX_SIZE][MAX_SIZE];

int dist[MAX_SIZE][MAX_SIZE];

const int MAX_DIST = MAX_SIZE * 3; 

int main(int argc, char **argv) {
    std::cin >> H >> W;

    for (int i = 1; i <= H; i++) {
        std::cin >> S[i];
    }

    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            A[i][j] = S[i][j-1];
            dist[i][j] = MAX_DIST;
        }
    }

    d[0][0] =  1; d[0][1] = 0;
    d[1][0] =  0; d[1][1] = 1;
    d[2][0] = -1; d[2][1] = 0;
    d[3][0] =  0; d[3][1] = -1;

    std::queue<std::pair<int, Point>> que;

    //int num = 0;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            if (A[i][j] == '#') {
                Point p;
                p.x = i; p.y = j;
                que.push(std::pair<int, Point>({0, p}));
                //num++;
            }
        }
    }

    while(!que.empty()) {
        std::pair<int, Point> pair = que.front(); que.pop();
        Point p = pair.second;
        if (pair.first < dist[p.x][p.y]) {
            dist[p.x][p.y] = pair.first;
            for (int i = 0; i < 4; i++) {
                Point next;
                next.x = p.x + d[i][0];
                next.y = p.y + d[i][1];
                if (1 <= next.x && next.x <= H && 1 <= next.y && next.y <= W) {
                    que.push(std::pair<int, Point>({pair.first + 1, next}));
                }
            }
        }
    }

    int ret = 0;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            ret = std::max(ret, dist[i][j]);
        }
    }
    
    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 56008
# Middle-Square Method

def middle_square(s, n)
  ss=(s**2).to_s
  ss='0'*(n*2-ss.length)+ss
  ss[n/2..n+1].to_i
end

gets.to_i.times { |i|
  puts "Case #{i+1}:"
  s=gets.to_i
  10.times {
    s=middle_square(s, 4)
    puts s
  }
}

Measured memory_bytes: 6104
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!{
        a: usize,
        b: usize
    }
    println!("{}", (a + b) % 24);
}


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


int main()
{

  int n,m;
  cin>>n>>m;
  int a1 = (n*(n-1))/2;
  int a2 = (m*(m-1))/2;
  cout<<a1+a2;



    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 29)
using namespace std;

int main(){
    int w, h;
    vector<long long> a;
    vector<long long> b;
    long long asum[100005] = {0}, bsum[100005] = {0};
    cin >> w >> h;
    rep(i, w){
        long long inp;
        cin >> inp;
        a.emplace_back(inp);
    }
    rep(i, h){
        long long inp;
        cin >> inp;
        b.emplace_back(inp);
    }

    sort(all(a));
    sort(all(b));
    asum[0] = a[0];
    bsum[0] = b[0];

    range(i,1,w){
        asum[i] = asum[i - 1] + a[i];
    }
    range(i,1,h){
        bsum[i] = bsum[i - 1] + b[i];
    }

    long long  sum = 0;
    rep(i,h){
        long long p = upper_bound(a.begin(), a.end(), b[i]) - a.begin();
        //cout << "p " << p << endl;
        if(p - 1 < 0){
            sum+=w * b[i];
        }else if(p == w){
            sum+=asum[p - 1];
        }else{
            sum+=asum[p - 1];
            sum+=(w - p) * b[i];
        }
        //debug(asum[p - 1]);
        //debug(w - p)
            //cout << sum << endl;
    }
    //debug(sum)
    //debug(asum[w - 1])
    //debug(bsum[h - 1])
    cout << sum + asum[w - 1] + bsum[h - 1] << endl;

}


Measured memory_bytes: 4212
#include <iostream>
#include <string.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
using namespace std;

int main(){
          char str[222];
          cin >> str;
          int n=strlen(str);
          for(int i=n-2;i;i-=2){
                    if(strncmp(str, str+i/2, i/2) == 0){
                              cout << i << endl;
                              return 0;
                    }
          }
          return 0;
}


Measured memory_bytes: 256
<?php
list($h, $n) = array_map('intval', explode(' ', trim(fgets(STDIN))));
for ($i = 0; $i < $n; ++$i) list($a[], $b[]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
$dp = array_fill(0, $h + 1, PHP_INT_MAX);
$dp[0] = 0;
for ($i = 1; $i <= $h; ++$i) {
    for ($j = 0; $j < $n; ++$j) {
        $d = $b[$j] + $dp[max(0, $i - $a[$j])];
        if ($dp[$i] > $d) $dp[$i] = $d;
    }
}
echo $dp[$h];


Measured memory_bytes: 4604
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)
//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
static const int NIL = -1;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

ll gcd3(ll a, ll b){
    if(a == 0 || b == 0)    return 0;
    
    while(1){
        if(b > a)   swap(a, b);
        a = a % b;
        if(!a)  break;
    }
    return b;
}

//最小公倍数(Least Common Multiple)
ll lcm(ll m, ll n){
    //引数に0がある場合は0を返す
    if(m == 0 || n == 0)    return 0;
    
    //lcm = m * n / gcd(m, n)
    return ((m / gcd3(m, n)) * n);
}

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

    cin >> n;
    ll t[n];
    rep(i, n)   cin >> t[i];
    
    
    FOR(i, 1, n){
        t[i] = lcm(t[i - 1], t[i]);
        //cout << t[i] << endl;
    }
    
    cout << t[n - 1] << endl;
}

Measured memory_bytes: 256
import re
import string
import sys
from itertools import product

import numpy as np

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    N = ii()
    S = ii(str)
    K = ii()
    a = S[K - 1]
    for s in string.ascii_lowercase:
        if s == a:
            continue
        S = S.replace(s, "*")
    return S


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 12492
#if 0
????????????????????????????????????
?????¬??????????????????1?????????????????§?????????????????£????????°?????????????????????????????????????????????
????????????????????????for?????????if???????????¨????????§?????????
????????¨???????????°???????????¨???????????????????????¨????????§??????
??±???????????¢?´¢?????????????????????????????\????????????????????????????????????
??\??????c??§??±???????????????????????????????????¨???????????????????????????????????????????????°????????\????????????????????????????????£?????§??????
#endif
#include <iostream>
#include <queue>
using namespace std;
int D[105] = {0};
int V[105];
queue<int> Q[105];
int Ntime=0;
int n,u,k,v;
int d[105] = {0};//start time
int f[105] = {0};//end time
void dfs(int cur) { // cur????¨????
  // cur ????¨??????????????¨????
  Ntime += 1;
  // ???????¢??????¨??¨???
  //cerr << "visiting " << cur << ' ' << Ntime << endl;
  if(D[cur] == 0)
      d[cur] = Ntime;

  for(int dst = 1; dst <= n; dst++) { // ??¨???????????? dst ????????????
    if (D[cur] == 0&&Q[cur].size()>0 && Q[cur].front() == dst && D[dst] == 0) { // cur??????dst??????????????????,dst???????¨??????????
      if(dst != cur && d[dst] == 0)
          dfs(dst);
      Q[cur].pop();
	}
      if(D[cur] == 0&&Q[cur].size()>0 && Q[cur].front() == dst && D[dst] == 1)
          Q[cur].pop();
  }
  // cur ????¨????????????????????¨????
      Ntime += 1;
    if(D[cur] == 0){
        f[cur] =  Ntime;
        D[cur] = 1;}
  // ??¢??°?????????????????????????????? (?????¢??°)
}
int main(){
  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> u >> k;
    V[i] = i;
    for(int j = 1; j <= k; j++){
      cin >> v;
      Q[u].push(v);     
    }
  }

  for(int i = 1; i <= n; i++)
    if(D[i] == 0)
        dfs(V[i]);
  for(int i = 1; i <= n; i++){
    cout << V[i] <<" "<< d[i] <<" "<< f[i] <<endl; 
  }


}

Measured memory_bytes: 3176
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
	char str[2048];
	
	double stack[2048];
	
	while (fgets(str, 2048, stdin) != NULL){
		int len = strlen(str);
		
		int p = 0;
		int m = 10;
		
		while (p < len){
			if (
			(str[p] >= '0' && str[p] <= '9') || 
			(str[p] == '-' && str[p + 1] >= '0' && str[p + 1] <= '9')
			){
				sscanf(&str[p], "%lf", &stack[m++]);
				
				char w[128];
				sscanf(&str[p], "%s", w);
				
				p += strlen(w) + 1;
			}
			
			else {
				switch (str[p]){
					case '+':
					stack[m - 2] += stack[m - 1];
					break;
					
					case '-':
					stack[m - 2] -= stack[m - 1];
					break;
					
					case '*':
					stack[m - 2] *= stack[m - 1];
					break;
					
					case '/':
					stack[m - 2] /= stack[m - 1];
//					break;
				}
				
				m--;
				p += 2;
				
//				printf("%lf\n", stack[m - 1]);
			}
		}
		
		printf("%lf\n", stack[10]);
	}
	
	return 0;
}

Measured memory_bytes: 1096
#include <iostream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;

vector<bool> p(100005,true);
void sieve(void) {
	rep(i, 2, 100005) {
		if (p[i]) {
			rep(j, i + 1, 100005) {
				if (j%i == 0)p[j] = false;
			}
		}
	}

}


int main(void)
{
	int X; cin >> X;
	sieve();
	while (!p[X])X++;
	cout << X << endl;

	return 0;
}

Measured memory_bytes: 384
#include <vector>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;

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

int main(int argc, const char * argv[]) {
    
    ll A, B;
    cin >> A >> B;
    ll C = (A + B) / 2;
    if (abs(A - C) == abs(B - C)) {
        cout << C;
    } else {
        cout << "IMPOSSIBLE";
    }
    
    return 0;
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  int n, m;
  cin >> n >> m;

  vector<int> va(m);
  int sum = 0;
  for (int i = 0; i < m; ++i) {
    cin >> va[i];
    sum += va[i];
  }

  if (sum > n) {
    cout << -1 << '\n';
  } else {
    cout << n - sum << '\n';
  }

  return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    double t, x;
    cin >> t >> x;
    double ans=t/x;
    cout << ans << endl;
}

Measured memory_bytes: 3716
import scala.io.StdIn

object Main extends App {
   val n = StdIn.readLine().toInt
   val a = StdIn.readLine().split(' ').map(_.toInt).sorted(Ordering[Int].reverse).zipWithIndex

   //println(a.mkString(" "))
   println(a.foldLeft(0)((acc, p) => if(p._2 % 2 == 0) acc + p._1 else acc - p._1))
}


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

const int maxn = 1100;
const int maxm = 220000;

int u[maxm], v[maxm];
vector<int> g[maxn];
bool chk[maxn][maxn];
int root;
bool vis[maxn];

namespace SCC {
	const int N = 1100;
	int T, qn;
	int q[N], vis[N];
	vector<int> adj[N], radj[N];
	
	void dfs(int u) {
		vis[u] = 1;
		for (int v : adj[u]) {
			if (!vis[v]) dfs(v);
		}
		q[++qn] = u;
	}
	
	void rdfs(int u) {
		vis[u] = T;
		for (int v : radj[u]) {
			if (!vis[v]) rdfs(v);
		}
	}
	
	void SCC(int n) {
		memset(vis, 0, sizeof(int) * (n + 1));
		qn = 0;
		for (int i = 1; i <= n; i++) if (!vis[i]) dfs(i);
		memset(vis, 0, sizeof(int) * (n + 1));
		for (int i = n; i > 0; i--) if (!vis[q[i]]) ++T, rdfs(q[i]);
	}
};

inline void dfs(int u) {
	vis[u] = true;
	for(auto v : g[u]) {
		if(vis[v]) {
			if(u == root) chk[root][v] = false;
			continue;
		}
		dfs(v);
		if(u == root) chk[root][v] &= true;
		else chk[root][v] = false;
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	for(int i = 0; i < m; ++ i) {
		cin >> u[i] >> v[i];
		g[u[i]].push_back(v[i]);
		SCC::adj[u[i]].push_back(v[i]);
		SCC::radj[v[i]].push_back(u[i]);
	}
	// get SCC
	SCC::SCC(n);
	// check the u -> v edge is the unique way.
	for(int i = 1; i <= n; ++ i) for(int j = 1; j <= n; ++ j) chk[i][j] = true;
	for(int step = 0; step < 2; ++ step) {
		for(int i = 1; i <= n; ++ i) {
			root = i;
			if(step) reverse(g[i].begin(), g[i].end());
			memset(vis, false, sizeof vis);
			dfs(i);
		}
	}
	for(int i = 0; i < m; ++ i) {
		int flag = SCC::vis[u[i]] == SCC::vis[v[i]];
		if(chk[u[i]][v[i]] == flag) cout << "diff\n";
		else cout << "same\n";
	}
	return 0;
}


Measured memory_bytes: 8576
from collections import defaultdict
from collections import deque

n,x,y = map(int,input().split())
graph=[[] for _ in range(n)]

for i in range(1,n+1):
    if i!=x:
        if i == 1:
            graph[i-1].append(i+1)
        elif i == n:
            graph[i-1].append(i-1)
        else:
            graph[i-1].append(i-1)
            graph[i-1].append(i+1)
    else:
        graph[i-1].append(y)
        if i == 1:
            graph[i-1].append(i+1)
        elif i == n:
            graph[i-1].append(i-1)
        else:
            graph[i-1].append(i-1)
            graph[i-1].append(i+1)
k_dic=defaultdict(int)

for i in range(1,n):
    q = deque([[i]])
    prev = [0]*n
    prev[i-1] = 1
    dic=defaultdict(int)
    while q:
        now_l = q.popleft()
        tu = []
        for now in now_l:
            nex = graph[now-1]
            
            for ne in nex:
                if prev[ne-1] == 0:
                
                    tu.append(ne)
                    q.append(tu)
                    prev[ne-1] = 1
                    dic[ne] = dic[now]+1
                    if ne > i:
                        k_dic[dic[ne]] += 1

for i in range(1,n):
    print(k_dic[i])




Measured memory_bytes: 119004
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

ll gcd(ll n,ll m){
  if(n%m==0){
    return m;
  }
  else
    return gcd(m,n%m);
}

int main() {
  ll n,m;
  string s,t;
  cin >> n >> m >> s >> t;
  ll L=n*m/gcd(n,m);
  ll ans=L;
  ll k=gcd(n,m);
  bool a=true;
  rep(i,k){
    if(s[i*n/k]!=t[i*m/k]){
      a=false;
    }
  }
  if(a){
    cout << ans << endl;
  }
  else
    cout << -1 << endl;
}

Measured memory_bytes: 512
#include <stdio.h>

int
main(int argc, char *argv[])
{
    int N;
    int A[20], B[20], C[20];
    int i;
    int safficient=0;

    scanf("%d", &N);
    for (i=0; i<N; i++)
        scanf("%d", A+i);
    for (i=0; i<N; i++)
        scanf("%d", B+i);
    for (i=0; i<N-1; i++)
        scanf("%d", C+i);

    for (i=0; i<N; i++) {
        safficient = safficient + B[A[i]-1];
        if (i>0 && A[i]-A[i-1]==1)
            safficient = safficient + C[A[i-1]-1];
    }
    printf("%d\n", safficient);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
 
#define FOR(i, a, b) for (ll i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (ll i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 100005
int n;
map<ll, ll> ree;

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

    cin >> n;
    F0R(i, n){
        ll x;
        cin >> x;
        ree[x]++;
    }
    if(ree.size() > 3){
        cout << "No\n";
    } else if(ree.size() == 3){
        pll a = *ree.begin(), b=*(++ree.begin()), c=*(++(++ree.begin()));
        //cout << a.f << " " << b.f << " " << c.f << "\n";
        //cout << (a.f ^ b.f ^ c.f) << "\n";
        if(a.s == b.s && a.s == c.s && (a.f^b.f^c.f) == 0){
            cout << "Yes\n";
        } else{
            cout << "No\n";
        }
    } else if(ree.size() == 2){
        pll a = *ree.begin(), b=*(++ree.begin());
        if(a.f == 0 && b.s==2*a.s){
            cout << "Yes\n";
        } else{
            cout << "No\n";
        }
    } else{
        if(ree.begin()->f == 0){
            cout << "Yes\n";
        } else{
            cout << "No\n";
        }
    }

    return 0;
}


Measured memory_bytes: 5120
//kalyanchirla
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
#define int long long
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define csl ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007

int32_t main()
{ 
    csl;

    int n;
    cin >> n;

    int arr[n];
    int sum=0;
    for(int i=0;i<n;i++) cin >> arr[i],sum+=arr[i];

    if(sum%10!=0)
    {
        cout << sum << "\n";
        return 0;
    }
    int p = 0;
    sort(arr,arr+n);
    for(int i=0;i<n;i++)
    {
        p+=arr[i];
        if((sum-arr[i])%10!=0)
        {
            cout << sum-arr[i] << "\n";
            return 0;
        }
        if((sum-p)%10!=0)
        {
            cout << sum-p << '\n';
            return 0;
        }
    }
    cout << 0 << '\n';
}

Measured memory_bytes: 3600
s = input()
n = len(s)

ans = 0

for i in range(n):
    k = 0
    l = 0
    while i + k < n:
        if s[i+k] == 'A' or s[i+k] == 'C' or s[i+k] == 'G' or s[i+k] == 'T':
            k += 1
            l += 1
        else:
            break
    ans = max(ans, l)

print(ans)

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

using namespace std;

const int MAX_N = 1e5 + 5;

int root [MAX_N];
int sz [MAX_N];

int find (int u) {
  if (root[u] != u) {
    root[u] = find(root[u]);
  }
  return root[u];
}

void merge (int u, int v) {
  u = find(u);
  v = find(v);

  if (u != v) {
    sz[v] += sz[u];
    root[u] = v;
  }
}

vector<int> hate [MAX_N];
int ans [MAX_N];

int main () {
  ios::sync_with_stdio(false);

  int n, m, k;
  cin >> n >> m >> k;

  for (int i = 1; i <= n; i++) {
    root[i] = i;
    sz[i] = 1;
  }

  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;

    ans[u]--;
    ans[v]--;

    merge(u, v);
  }

  for (int i = 0; i < k; i++) {
    int u, v;
    cin >> u >> v;

    if (find(u) == find(v)) {
      ans[u]--;
      ans[v]--;
    }
  }

  for (int i = 1; i <= n; i++) {
    cout << ans[i] + sz[find(i)] - 1 << " ";
  }
  cout << endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <cstdlib>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <iomanip>
#define INFTY 30000
using namespace std;

int main(void){
    char b,out;
    cin >> b;
    if (b == 'A') out = 'T';
    if (b == 'T') out = 'A';
    if (b == 'G') out = 'C';
    if (b == 'C') out = 'G';
    cout << out << endl;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<int,int>;

int main()
{
    ll n,m;cin >>n>>m;
    ll sum=0;
    rep(i,m){
        ll a;
        cin >>a;
        sum+=a;
    }
    ll ans;
    if(sum>n)ans=-1;
    else ans=n-sum;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3584
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000009)
	sc.Split(bufio.ScanWords)

	n, k := oneInt(), oneInt()
	vs := scanNums(n)

	ans := -1050000000

	for i := 0; i <= min(n, k); i++ {

		for a := 0; a <= i; a++ {
			for b := 0; b <= min(n, k)-i; b++ {
				//fmt.Printf("a: %d, b: %d\n", a, b)
				got := []int{}
				got = append(got, vs[:a]...)
				got = append(got, vs[n-b:]...)
				got = sortDesc(got)
				//fmt.Printf("%#v\n", got)

				sum := 0
				for j := 0; j < k-(a+b); j++ {
					if len(got) != 0 && got[len(got)-1] < 0 {
						got = got[:len(got)-1]
					}

				}
				for _, v := range got {
					sum += v
				}

				ans = max(ans, sum)
			}
		}

	}
	fmt.Println(ans)

}

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

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

func scanNums(len int) (nums []int) {
	for i := 0; i < len; i++ {
		nums = append(nums, oneInt())
	}
	return nums
}

func scanStrings(len int) (strs []string) {
	for i := 0; i < len; i++ {
		strs = append(strs, oneStr())
	}
	return strs
}

func abs(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

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

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}

func cumSum(nums []int) []int {
	sums := []int{0}

	for i := 0; i < len(nums); i++ {
		sums = append(sums, sums[i]+nums[i])
	}
	return sums
}


Measured memory_bytes: 5504
import java.util.Scanner;
public class Main {
    public static int findMinCost(int[] heights){
        int n = heights.length;
        int min[] = new int[n];
        min[0] = 0;
        min[1] = Math.abs(heights[1]-heights[0]);
        for(int i=2;i<n;i++){
            min[i] = Math.min(Math.abs(heights[i]-heights[i-1])+min[i-1],
                                    Math.abs(heights[i]-heights[i-2])+min[i-2]);
        }
        return min[n-1];
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int heights[] = new int[n];
        for(int i=0;i<n;i++){
            heights[i] = sc.nextInt();
        }
        System.out.println(findMinCost(heights));
    }
}

Measured memory_bytes: 51864
gets
str = Array.new(2)
str[0] = gets.chomp!
str[1] = gets.chomp!

prime = 1000000007

i = 0
type = -1#type -1:initial, type 0: tate , type 1 yoko
sum = 1
while i < str[0].length
   if str[0][i] == str[1][i] then
        if type == -1 then
            sum = sum * 3 % prime
        elsif type == 0 then
            sum = sum * 2 % prime
        elsif type == 1 then
        
        end
        type = 0
        i += 1
    elsif str[0][i] == str[0][i+1] and str[1][i] == str[1][i+1] then
        if type == -1 then
            sum = sum * 6 % prime
        elsif type == 0 then
            sum = sum * 2 % prime
        elsif type == 1 then
            sum = sum * 3 % prime
        end
        type = 1
        i += 2
    end
end
puts sum

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

using namespace std;

int main() {

	int n,k;
	cin >> n >> k;
	int counter = 0;
	int x;
	for (int i = 0; i < n; i++) {
		cin >> x;
		counter += min(x, abs(k - x))*2;
	}
	cout << counter << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int K = sc.nextInt();
		String ABC = sc.next();

		String newS = "" ;
		for(int i = 1 ; i < N + 1; i ++) {
			char c = ABC.charAt(i - 1);
			if( i == K) {
				c = ("" + c).toLowerCase().charAt(0);
			}
			newS = newS + c ;
		}
		// 出力
		System.out.println(newS);

	}

}

Measured memory_bytes: 21844
#!/usr/bin/perl

my ($n,$k) = map { $_ - 0 } split(/\s+/,<STDIN>);
my @aa = map { $_ - 0 } split(/\s+/,<STDIN>);

my @sa = sort { $a <=> $b } @aa;

my $sum1 = 0;
for(my $i=0;$i<$n;$i++){
  $sum1 += $aa[$i];
}

if( $k == 0 ){
  print "$sa[$#sa]\n"; exit(0);
}

my $mx = 10 ** 9;
my $mn = 1;

my $mx_c = &chk($mx);
my $mn_c = &chk($mn);

if( $mn_c < $k ){
  print "1\n"; exit(0);
}

#print "mx,mn_c = $mx_c , $mn_c \n";

while( $mx - $mn > 1 ){
  my $md = int( ($mx + $mn)/2 );
  my $md_c = &chk($md);
  if( $md_c <= $k and $k <= $mn_c ){
    $mx = $md;
    $mx_c = $md_c;
  } else { #( $mx_c <= $k < $md_c ){
    $mn = $md;
    $mn_c = $md_c;
  }
  #print "mx,mn_c = $mx_c , $mn_c \n";
}

if( $mn_c == $k ){
  print "$mn\n";
} elsif( $mx_c == $k ){
  print "$mx\n";
} else {
  #if( $mx_c < $k and $k < $mn_c ){
    print "$mx\n";
  #} elsif( $mn_c < $k ){
  #  print "$mn\n";
  #} else {
  #  print "$mx\n";
  #}
}

exit(0);

sub chk {
  my $v = shift;
  my $s = 0;
  for(my $i=0;$i<$n;$i++){
    my $vv = int((( $v - 1 ) + $aa[$i]) / $v) - 1;
    $s += $vv;
  }
  return $s;
}


Measured memory_bytes: 39736
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll = long long;
int main() {
  string a,b,c;
  cin>>a;
  b="ABC";
  c="ARC";
  if(a==b){
    cout<<c<<endl;
    return 0;
  }
  cout<<b<<endl;
    
  
}


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

int main() {
	int a, b, x = 1, count = 0;
	while (cin >> a >> b, !cin.eof()){
		x = 1;
		count = 0;
		while (a + b>=x) {
			x *= 10;
			count++;
		}
		cout << count << endl;
	}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    string s; cin>>s;
    int q; cin>>q;
    bool turn = false;
    int n = s.size();
    vector<char> add1,add2;
    for(int i = 0 ; i < q ;  i++)
    {
        int t; cin>>t;
        if(t==1)
        {
            turn = !turn;
        }
        else
        {
            int x; cin>>x; x--;
            char c; cin>>c;
            if(!turn)
            {
                if(!x)
                {
                    add1.push_back(c);
                }
                else
                {
                    add2.push_back(c);
                }
            }
            else
            {
                if(x)
                {
                    add1.push_back(c);
                }
                else
                {
                    add2.push_back(c);
                }
            }
        }
    }
    list<char> lister;
    if(turn)
    {
        for(int i = n-1; i >=0; i--)
            lister.push_back(s[i]);
    }
    else
    {
        for(int i = 0 ; i < n ;i ++)
            lister.push_back(s[i]);
    }
    if(!turn)
    {
        int x = add1.size();
        for(int i = 0 ; i < x; i++)
        {
            lister.push_front(add1[i]);
        }
        x = add2.size();
        for(int i = 0 ; i < x ; i++)
        {
            lister.push_back(add2[i]);
        }
    }
    else
    {
         int x = add1.size();
        for(int i = 0 ; i < x; i++)
        {
            lister.push_back(add1[i]);
        }
        x = add2.size();
        for(int i = 0 ; i < x ; i++)
        {
            lister.push_front(add2[i]);
        }
    }
    for(char c : lister)
        cout<<c;
    return 0;
}

Measured memory_bytes: 10236
n=input()
if n%7==0:
    n/=7
def numLen(K): 
      
    # If K is a multiple of 2 or 5 
    if(K % 2 == 0 or K % 5 == 0): 
        return -1
  
    number = 0
  
    len = 1
  
    for len in range (1, K + 1): 
          
        # Instead of generating all possible numbers 
        # 1, 11, 111, 111, ..., K 1's 
        # Take remainder with K 
        number = ( number * 10 + 1 ) % K 
      
        # If number is divisible by k 
        # then remainder will be 0 
        if number == 0: 
            return len
  
    return -1
  
print numLen(n)


Measured memory_bytes: 65708