akhauriyash/Code-Regression huggingface dataset:
import math
n= int(input())

m = math.floor(n/2)
if n>2:
    q = int( n / m )
    lm= m
    s = n - 1
else:
    s = 0

while( m>1 ):
    m = math.floor(n/(q+1))
    r0 = n % ( m + 1 )
    if r0>=q:
        d= r0  - q
        if d%q==0:
            s+= ( m+1+int(d/q) )
    #
    # for next
    q = int( n/m )
    lm= m
#
print( s )


Measured memory_bytes: 3060
N = int(input())

freq = [[ 0 for i in range(9)] for i in range(9)]

for i in range(1,N + 1):
  num = str(i)
  if num[-1] != "0":
    p = int(num[0])
    q = int(num[-1])
    freq[p - 1][q - 1] += 1

ans = 0

for i in range(9):
  for j in range(9):
    A = freq[i][j]
    B = freq[j][i]
    ans += A * B

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
#include <fstream>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FILL(Itr,n) fill((Itr).begin(),(Itr).end(),n)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;


int SaccA[100010];
int SaccB[100010];
int TaccA[100010];
int TaccB[100010];

int SsumA(int l, int r){
    if(l==0)return SaccA[r];
    return SaccA[r] - SaccA[l-1];
}

int SsumB(int l, int r){
    if(l==0)return SaccB[r];
    return SaccB[r] - SaccB[l-1];
}

int TsumA(int l, int r){
    if(l==0)return TaccA[r];
    return TaccA[r] - TaccA[l-1];
}

int TsumB(int l, int r){
    if(l==0)return TaccB[r];
    return TaccB[r] - TaccB[l-1];
}

int main(){

    string S,T; cin>>S>>T;
    int Q; cin>>Q;
    
    REP(i,S.size()){
        if(S[i]=='A'){
            SaccA[i] = 1;
            SaccB[i] = 0;
        }else{
            SaccA[i] = 0;
            SaccB[i] = 1;
        }
    }
    
    REP(i,T.size()){
        if(T[i]=='A'){
            TaccA[i] = 1;
            TaccB[i] = 0;
        }else{
            TaccA[i] = 0;
            TaccB[i] = 1;
        }
    }
    
    REP(i,S.size()-1){
        SaccA[i+1] = SaccA[i+1] + SaccA[i];
        SaccB[i+1] = SaccB[i+1] + SaccB[i];
        TaccA[i+1] = TaccA[i+1] + TaccA[i];
        TaccB[i+1] = TaccB[i+1] + TaccB[i];
    }
    
    REP(kai,Q){
        int a,b,c,d; cin>>a>>b>>c>>d;
        a--; b--; c--; d--;
        int SA = SsumA(a,b)%3;
        int SB = SsumB(a,b)%3;
        REP(i,10){
            if(SA>=2){
                SA-=2;
                SB++;
            }
            if(SB>=2){
                SB-=2;
                SA++;
            }
        }
        
        int TA = TsumA(c,d)%3;
        int TB = TsumB(c,d)%3;
        REP(i,10){
            if(TA>=2){
                TA-=2;
                TB++;
            }
            if(TB>=2){
                TB-=2;
                TA++;
            }
        }
        if((SA==TA)&&(SB==TB))cout<<"YES"<<endl;
        else if((SA==SB)&&(TA==TB))cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 2432
#define _CRT_SECURE_NO_WARNINGS


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <bitset>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstdio>
#include <cstring>

using namespace std;

//#define FAST_ALLOCATOR_MEMORY 1e8
#undef LOCAL
//#include "optimization.h"

vector< pair<int, int> > dir = { {1, 0}, {0, -1}, {-1, 0}, {0, 1} };
const int MX = 20001;

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

#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	string s;
	cin >> s;
	int x, y;
	cin >> x >> y;

	reverse(s.begin(), s.end());
	while (!s.empty() && s.back() == 'F') {
		s.pop_back();
		x--;
	}
	reverse(s.begin(), s.end());

	vector<int> f, sec;
	int now = 0;
	bool is = 1;
	int get = 0;
	s.push_back('T');
	while (now < s.length()) {
		if (s[now] == 'T') {
			if (is)
				f.push_back(get);
			else
				sec.push_back(get);
			is ^= 1;
			get = 0;
		}
		else
			get++;
		now++;
	}
	x = abs(x);
	y = abs(y);
	if (x >= MX || y >= MX) {
		cout << "No";
		return 0;
	}
	bitset<MX> w;
	w[10000] = 1;
	for (int i : f) {
		w = (w << i) | (w >> i);
	}

	bitset<MX> wy;
	wy[10000] = 1;
	for (int i : sec) {
		wy = (wy << i) | (wy >> i);
	}
	if (w[x + 10000] && wy[y + 10000]) {
		cout << "Yes";
	}
	else
		cout << "No";

	return 0;
}

Measured memory_bytes: 384
# 解説AC
N = int(input())
A = [int(i) for i in input().split()]

if sum(A) % (N * (N + 1) // 2) == 0:
    # 操作回数
    k = sum(A) // (N * (N + 1) // 2)
else:
    print("NO")
    exit()

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

flag = True
cnt = 0
for i in range(N):
    if sub[i] < 0 and sub[i] % N == 0:
        cnt += abs(sub[i]) // N
    elif sub[i] != 0:
        flag = False

if flag and k == cnt:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 14480
#include <stdlib.h>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  uint32_t N, K;
  cin >> N >> K;
  double res = 0;
  for (uint32_t i = 1; i <= N; ++i) {
    uint32_t tmp = i;
    double calc = N;
    while (tmp < K) {
      tmp *= 2;
      calc *= 2;
    }
    res += (1 / calc);
  }
  cout << setprecision(12) << res << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

public class Main {

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

  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      String[] lines = in.readLine().split(" ");
      int[] arr = new int[lines.length];
      int k=0;
      for (String s : lines) {
        arr[k++] = Integer.parseInt(s); 
      }
      Arrays.sort(arr);
      int step=0;
      if(arr[2] - arr[1] > 4) {
        for(; arr[1]+4 < arr[2]; step++) {
          arr[1] += 2;
        }
      }
      if(arr[1] - arr[0] > 4) {
        for(; arr[0]+4 < arr[1]; step++) {
          arr[0] += 2;
        }
      }

      Tuple3 t = new Tuple3(arr[0], arr[1], arr[2]);
      t.step = step;

      bfs(t);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }

  private void bfs(Tuple3 t) {
    Deque<Tuple3> que = new ArrayDeque<>();

    que.offer(t);

    Tuple3 cur;
    while(!que.isEmpty()) {
      cur = que.poll();

      if(cur.isEq()) {
        System.out.println(cur.step);
        return;
      }

      if(cur.e[0] < cur.e[1] && cur.e[0] < cur.e[2]) {
        que.offer(new Tuple3(cur.e[0]+2, cur.e[1], cur.e[2]));
        que.peekLast().step = cur.step + 1;
      } else if(cur.e[1] < cur.e[2]) {
        que.offer(new Tuple3(cur.e[0], cur.e[1]+2, cur.e[2]));
        que.peekLast().step = cur.step + 1;
      } else {
        que.offer(new Tuple3(cur.e[0], cur.e[1], cur.e[2]+2));
        que.peekLast().step = cur.step + 1;
      }

      if(cur.e[0] < cur.e[2] && cur.e[1] < cur.e[2]) {
        que.offer(new Tuple3(cur.e[0]+1, cur.e[1]+1, cur.e[2]));
        que.peekLast().step = cur.step + 1;
      } else if(cur.e[1] < cur.e[0] && cur.e[2] < cur.e[0]) {
        que.offer(new Tuple3(cur.e[0], cur.e[1]+1, cur.e[2]+1));
        que.peekLast().step = cur.step + 1;
      } else {
        que.offer(new Tuple3(cur.e[0]+1, cur.e[1], cur.e[2]+1));
        que.peekLast().step = cur.step + 1;
      }
      
    }
  }

  class Tuple3 {
    int[] e;
    int state;
    int step;

    public Tuple3(int a, int b, int c) {
      e = new int[3];
      e[0] = a;
      e[1] = b;
      e[2] = c;
      state = (a*10000) + (b*100) + c;
      step = 0;
    }

    @Override
    public boolean equals(Object obj) {
      if(obj == this) return true;
      if(obj == null) return false;
      if(!(obj instanceof Tuple3)) return false;

      Tuple3 ref = (Tuple3) obj;

      return this.state == ref.state ? true : false;
    }

    public boolean isEq() {
      return (e[0] == e[1]) && (e[1] == e[2]);
    }
  }
}

Measured memory_bytes: 22612
#include <stdio.h>
int main(){
  int x,sum;
  sum=1;
  while(sum!=0){
    sum=0;
    while((x=getchar())!='\n'){
      sum+=x-'0';
    }
    if(sum==0){
      break;
    }
    printf("%d\n",sum);
  }
  return 0;
}

Measured memory_bytes: 2596
import java.util.*;
import java.util.Map.Entry;

import javax.swing.text.Segment;
import javax.xml.ws.WebEndpoint;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main //implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public static void main(String[] args)   throws Exception, IOException{        
        long mod=1000000007;
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        PriorityQueue<Integer> q=new PriorityQueue<>();
        
        int n=sc.nextInt();
        char c[]=sc.getCharSet();
        if(n%2!=0)ret("No");
        
        for (int i = 0; i+c.length/2 < c.length; i++) {
        	db(c[i],c[i+c.length/2]);
			if(c[i]!=c[i+c.length/2])ret("No");
		}

        out.println("Yes");
     	out.flush();
    }
    
    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}


class P {
	int x, y, d;
	P(int  x, int y, int d) {
	  this.x=x;
	  this.y=y;
	  this.d=d;
	}
}

//class P implements Comparable<P>{
//    int a,b;
//    P(int a, int b) {
//    	this.b=b;
//    	this.a=a;
//    }
//
//    public int compareTo(P p){
//        return p.a-a;//des
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() throws IOException{
        return this.nextString().toCharArray();
    }    
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 21972
// 基本テンプレート
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N; cin >> N;

    vector< pair<int, int> > point(N);
    vector<int> ans(N);
    for(int i=0; i<N; i++) point[i].second = i;
    for(int i=0; i<N*(N-1)/2; i++) {
        int A, B, C, D; cin >> A >> B >> C >> D;
        A--; B--;
        if(C == D) {
            point[A].first++;
            point[B].first++;
        }
        else if(C < D) {
            point[B].first += 3;
        }
        else {
            point[A].first += 3;
        }
    }
    sort(point.rbegin(), point.rend());

    int rank = 1, pre = -1;
    for(int i=0; i<N; i++) {
        if(pre < 0) {
            pre = point[i].first;
            ans[ point[i].second ] = rank;
        }
        else if(pre == point[i].first) {
            ans[ point[i].second ] = rank;
        }
        else {
            rank = i+1;
            ans[ point[i].second ] = rank;
        }
        pre = point[i].first;
    }

    for(int i=0; i<N; i++) cout << ans[i] << endl;
    return 0;
}



Measured memory_bytes: 3084
#include <stdio.h>
int N;

void Process(int A[ ], int n){
	int i;
	for(i=0;i<n-1;i++)
		printf("%d ",A[i]);
	printf("%d\n",A[i]);
}

void InsertionSort(int A[ ], int n){
	int i,j,v;
	for(i=1;i<n;i++){
		v = A[i];
		j = i - 1;
		/*for(j = i; j > 0 && A[j-1] > v; j--)
			A[j] = A[j-1];
		A[j] = v;*/
		while(j>=0 && A[j]>v){
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = v;
		Process(A, N);

	}
}



int main(void){
	int i;
	scanf("%d",&N);
	int A[100];
	for(i=0;i<N;i++)
		scanf("%d",&A[i]);
	Process(A, N);
	InsertionSort(A, N);
	
	
	return 0;


}

Measured memory_bytes: 1796
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
    
n=I()
a=LI()
ans=0
pre=None
for i in a:
    if pre==None:
        pre=i
        c=1
        continue
    if i==pre:
        c+=1
    else:
        ans+=c//2
        c=1
    pre=i
ans+=c//2
print(ans)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

template<class Monoid>
class SegmentTree{
private:
  using T = typename Monoid::T;
  const size_t n;
  vector<T> d;

  void build(){
    for(size_t b = n - 1; b > 0; b--) d[b] = Monoid::op(d[b << 1], d[b << 1 | 1]);
  }

public:
  SegmentTree(size_t n)
    : n(n), d(2 * n, Monoid::identify()) {}

  template<typename InputItr>
  SegmentTree(InputItr first, InputItr last)
    : n(distance(first, last)), d(2 * n, Monoid::identify()){
    copy(first, last, next(d.begin(), n));
    build();
  }

  /* set one value */
  void modify(size_t k, T v){
    for(d[k += n] = v; k > 1; k >>= 1) d[k >> 1] = Monoid::op(d[k], d[k ^ 1]);
  }

  /* return [l, r) value */
  T query(size_t l, size_t r){
    T res {Monoid::identify()};
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l&1) res = Monoid::op(res, d[l++]);
      if (r&1) res = Monoid::op(res, d[--r]);
    }
    return res;
  }
  
  void dump(){
    FOR(i, n, 2 * n) cout << i - n << ": " << d[i] << endl;
  }
};

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

template<typename U = int>
struct RGQ{
  using T = U;
  static T op(const T& a, const T& b){ return gcd(a, b); }
  static constexpr int identify(){ return 0; }
};

int main() {
  int n; cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];

  SegmentTree<RGQ<>> tree(a.begin(), a.end());

  int ans = 0;
  REP(i, n){
    int tmp = gcd(tree.query(0, i), tree.query(i+1, n));
    ans = max(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main() {

    long long n, k;
    cin >> n >> k;

    if (k > n) {
        k = n;
    }

    long long a[n];

    for (long long i = 0; i < n; ++i) {
        cin >> a[i];
    }

    sort(a, a + n);

    reverse(a, a + n);

    for (long long i = 0; i < k; ++i) {
        a[i] = 0;
    }

    long long ans = 0;
    for (long long i = 0; i < n; ++i) {
        ans += a[i];
    }

    cout << ans;



    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll A,B,N;
  cin>>A>>B>>N;
  ll x=N;
  if(N>=B-1){
    x=B-1;
  }
    ll ans = A*x/B-A*(x/B);
    cout<<ans<<endl;
  
  
}
    
  
  


Measured memory_bytes: 3556
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define error(args...) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}
string slow(string s) {
    int i = 0;
    int d = 1;
    LL count = 0;
    while(i >= 0 && i < s.size()) {
        count++;
        if(s[i] == 'A') {
            s[i] = 'B';
            d *= -1;
        } else {
            s[i] = 'A';
        }
        i += d;
    }
    error(count);
    return s;
}
string solve(string s, int K) {
    int N = s.size();
    vector<int> state(N);
    REP(i, N) state[i] = (s[i] == 'B' ? 1 : 0);
    int i = 0;
    int b = 0;
    REP(_, K) {
        if(state[i] ^ b) { // B
            i = (i == N-1 ? 0 : i+1);
            b ^= 1;
        } else {
            state[i] ^= 1;
        }
    }
    string res;
    for(int d = 0; d < N; d++) {
        int idx = (i + d) % N;
        res += (state[idx] ^ b ? "B" : "A");
    }
    return res;
}
int main(){
    iostream_init();
    int N, K;
    cin >> N >> K;
    string s;
    cin >> s;
    const int MAX_ITER = 1e9 + 10;
    if(K > MAX_ITER) {
        cout << ((K - MAX_ITER) % 2 == 0 ? solve(s, MAX_ITER) : solve(s, MAX_ITER-1)) << endl;
    } else {
        cout << solve(s, K) << endl;
    }
    return 0;
}



Measured memory_bytes: 1944
// AUTHOR:: MOHAMMAD FAISAL
#include<bits/stdc++.h>
using namespace std;

int main()
{
  
  int target;
  cin >> target ;
  int l,r;
  cin >> l >> r;
  int flag = true;
  for(int i=l;i<=r;i++){
    if(i%target==0){
      flag = false;
      break;
    }
  }
  
 (flag) ? cout<<"NG" : cout<<"OK";
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back




int main(){
  

  int n;
  cin>>n;
  string s;
  cin>>s;
  
  ll cntr=0;
  ll cntg=0;
  ll cntb=0;
  
  rep(i,n){
    if (s.at(i)=='R'){
      cntr++;
    }
    else if (s.at(i)=='G'){
      cntg++;
    }
    else {
      cntb++;
    }
  }
  
  ll answer=cntr*cntg*cntb;
  
  for (int i=0;i<n;i++){
    for (int j=i+1;2*j-i<n;j++){
      int k=2*j-i;
      if (s.at(i)=='R' and s.at(j)=='G' and s.at(k)=='B'){
        answer--;
      }
      if (s.at(i)=='R' and s.at(j)=='B' and s.at(k)=='G'){
        answer--;
      }      
      if (s.at(i)=='G' and s.at(j)=='R' and s.at(k)=='B'){
        answer--;
      }
      if (s.at(i)=='G' and s.at(j)=='B' and s.at(k)=='R'){
        answer--;
      }      
      if (s.at(i)=='B' and s.at(j)=='G' and s.at(k)=='R'){
        answer--;
      }      
      if (s.at(i)=='B' and s.at(j)=='R' and s.at(k)=='G'){
        answer--;
      }   
    }
  }
  
  cout<<answer<<endl;
  
  
  
}




















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

int main() {
  string s;
  cin >> s;
  int q;
  cin >> q;
  while (q--) {
    string op;
    int a, b;
    cin >> op >> a >> b;
    if (op == "replace") {
      string p;
      cin >> p;
      string head(s.begin(), s.begin() + a);
      string tail(s.begin() + b + 1, s.end());
      s = head + p + tail;

    } else if (op == "reverse") {
      reverse(s.begin() + a, s.begin() + b + 1);
    } else if (op == "print") {
      copy(s.begin() + a, s.begin() + b + 1, ostream_iterator<char>(cout, ""));
      cout << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3240
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
	
const long long INF = 7+(1e+18);
typedef long long Weight;
struct Edge {  //src:辺の始点,dst:辺の終点,weight:辺の重さ
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : //辺は重さが重いものを"小さい"と定義する
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

//引数 g:隣接リスト,s:始点,dist:各頂点までの距離が入る,prev:最短路木の親頂点が入る
//戻値 なし
void shortestPath(const Graph &g,int s,vector<Weight> &dist,vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q;
  Q.push(Edge(-2, s, 0));
  while(!Q.empty()) {
    Edge e = Q.top(); Q.pop();
    if (prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    for(auto f=g[e.dst].begin();f!=g[e.dst].end();f++){
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
}
//-----------------
int main()
{ 
    while(true){
        int i, j, k, V;
        int u, v;
        Weight c;
        if(!(cin >> V))break;
        Graph g(V);    //頂点数vの空隣接リストgを生成
        for(i=0; i<V; i++){
            cin >> u >> k;
            for(j=0; j<k; j++){
                cin >> v >> c;
                g[u].push_back(Edge(u, v, c));    //隣接リストgにsからtに向かう重さwの辺を追加
            }
        }
        vector<Weight> dist;
        vector<int> prev;
        shortestPath(g,0,dist,prev);
        for(i=0; i<V; i++){
            cout << i << " " << dist[i] << endl;
        }
    }
  
    return 0;
}



Measured memory_bytes: 3212
# https://atcoder.jp/contests/abc079/tasks/abc079_c

from itertools import product


S = input()
R = []


for p in product(*((0,1),)*3):
    res = S[0]
    for i, s in enumerate(S[1:]):
        if p[i]:
            res = res + "+" + s
        else:
            res = res + "-" + s
    if eval(res) == 7:
        print(res + "=7")
        exit()



Measured memory_bytes: 61984
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i< n; i++){
        cin >> a[i];
    }
    if(n%2==0){
        for(int i = 0; i< n; i++){
            if(i % 2 == 0) b[n/2+i/2] = a[i];
            else b[n/2-(i+1)/2] = a[i];
        }
    }else{
        for(int i = 0; i< n; i++){
            if(i % 2 == 0) b[n/2-i/2] = a[i];
            else b[n/2+(i+1)/2] = a[i];
        }
    }
    for(int i = 0; i< n; i++){
        cout << b[i] << " ";
    }
    cout << endl;
    return 0;
}

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

using namespace std;

int main()
{
	string o, e;
	cin >> o >> e;
	for (int i = 0; i < e.size(); i++)
		cout << o[i] << e[i];
	if (o.size() != e.size())
		cout << o[o.size() - 1];
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
	vector<int> kon(5);
	rep(i, 5) {
		cin >> kon[i];
	}
	int k;
	cin >> k;
	int count = 0;
	rep(i, 5) {
		rep(j, 5) {
			if (kon[i] - kon[j] > k) {
				count ++;
			}
		}
	}
	if (count > 0) {
		cout << ":(" << endl;
	}
	else {
		cout << "Yay!" << endl;
	}
}
		


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1 << 21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// abc 142d
ll gcd(ll a, ll b){
    if(a<b) swap(a, b);
    if(b==0) return a;
    return gcd(b, a%b);
}

vector<pair<ll, ll>> factorize(ll n){
    vector< pair<ll, ll>> res;
    // nが変化していく
    for(ll i=2; i*i<=n; ++i){
        if(n%i) continue;
        res.emplace_back(i, 0);
        while(n%i==0){
            n/=i;
            res.back().second++;
        }
    }
    if(n != 1) res.emplace_back(n, 1);
    return res;
}

int main(){
    ll a, b;
    cin >> a >> b;
    ll gcdd = gcd(a, b);
    ll ans = factorize(gcdd).size();
    cout << ans+1 << endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextInt64() int64 {
	i, err := strconv.ParseInt(io.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}


func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func intMin(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func intMax(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func b2i(b bool) int {
	if b {
		return 1
	}
	return 0
}

type Int64s []int64
func (f Int64s) Len() int {
	return len(f)
}
func (f Int64s) Less(i, j int) bool {
	return f[i] < f[j]
}

func (f Int64s) Swap(i, j int) {
	f[i], f[j] = f[j], f[i]
}

func stdUnique(a *[]string) {
	j := 0
	for i := range *a {
		if i > 0 && (*a)[i-1] == (*a)[i] {
			continue
		}
		(*a)[j] = (*a)[i]
		j++
	}

	*a = (*a)[:j]
}

func solve(io *Io) {
	s := io.Next()
	k := io.NextInt()

	v := make([]string, 0)
	for i := range s {
		for j := 1; j <= k; j++ {
			if i + j > len(s) {
				break
			}
			v = append(v, s[i:i+j])
		}
	}

	sort.Strings(v)
	stdUnique(&v)
	io.PrintLn(v[k-1])
}

func main() {
	io := NewIo()
	defer io.Flush()

	solve(io)
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
const long long INF = INT64_MAX;

#define REP(i, n) for(ll i=0;i<n;i++)
#define WHOLE(v) (v).begin(), (v).end()
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse((v).rbegin(), (v).rend())
#define FOLDL(src, dst, lambda) partial_sum((src).begin(), (src).end(), (dst).begin(), lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum((src).begin(), (src).end(), (dst).begin(), lambda);INV(dst)
#define CUMSUML(src, dst) FOLDL(src, dst, [](auto a, auto b) {return a+b;})
#define CUMSUMR(src, dst) FOLDR(src, dst, [](auto a, auto b) {return a+b;})
#define ACCUM(v, d0, lambda) accumulate((v).begin(), (v).end(), d0, lambda)
#define SUM(v, d0) ACCUM(v, d0, [](auto a, auto b) {return a+b;})
#define DESC(v) sort((v).rbegin(), (v).rend())
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);v.erase(unique(v.begin(), v.end()), v.end())
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

void solve() {
    str s;
    cin >> s;
    vll S(s.size()), T(s.size()), U(s.size());
    for(int i = 0; i < s.size(); i++) {
        S[i] = (s[i] == '0' ? 0 : 1);
        T[i] = i % 2;
        U[i] = (i + 1) % 2;
    }
    ll v1 = 0, v2 = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] != T[i]) v1++;
        if(S[i] != U[i]) v2++;
    }
    cout << min(v1, v2) << endl;
}

int main() {
    FIO;
    solve();
    return 0;
}


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

int main() {
    int n;
    ll X = 0 , x = 0 , ans = 1000000000000000000;
    cin >> n;
    vector <ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        X += a[i];
    }
    for(int i = 0; i < n; i++){
        x += a[i];
        if(i + 1 < n){
           ans = min(ans , abs(X - 2 * x));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4844
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}




const int INF = INT_MAX;
struct SegmentTree {
private:
    int n;
    vector<int> node;

public:
    SegmentTree(vector<int> v) {
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, INF);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = min(node[2*i+1], node[2*i+2]);
    }

    void update(int x, int val) {
        x += (n - 1);
        node[x] = val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = min(node[2*x+1], node[2*x+2]);
        }
    }

    int getmin(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return INF;
        if(a <= l && r <= b) return node[k];

        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};
int main() {
    int n,q;
    cin >> n >> q;
    vector<int>a(n,INF);
    SegmentTree seg(a);
    rep(i,q) {
        int c,x,y;
        cin >> c >> x >> y;
        if(c==0) seg.update(x,y);
        else cout << seg.getmin(x,y+1) << endl;
    }
}




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

int main(){
	int n;
	float ans;
	cin >> n;
	if(n%2 == 0){
		ans = 0.5;
	}
	else if(n%2 == 1){
		ans = (float)(n+1)/2/n;
	}

	cout << ans;
	return 0;
}


Measured memory_bytes: 256
# import bisect
# from collections import Counter, defaultdict, deque, namedtuple
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n, k = list(map(int,ipti().split()))
    s = list(input())
    s[k-1] = s[k-1].lower()
    print(''.join(s))

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include<stdio.h>
#include<string.h>
char s[100];
int S[55];
int main(){
	scanf("%s",s);
	int flag;
	int t = strlen(s);
	memset(S,0,sizeof(S));
	for(int i = 0;i < t;i++){
		if(s[i]=='a') S[0]++;
		if(s[i]=='b') S[1]++;
		if(s[i]=='c') S[2]++;
		if(s[i]=='d') S[3]++;
		if(s[i]=='e') S[4]++;
		if(s[i]=='f') S[5]++;
		if(s[i]=='g') S[6]++;
		if(s[i]=='h') S[7]++;
		if(s[i]=='i') S[8]++;
		if(s[i]=='j') S[9]++;
		if(s[i]=='k') S[10]++;
		if(s[i]=='l') S[11]++;
		if(s[i]=='m') S[12]++;
		if(s[i]=='n') S[13]++;
		if(s[i]=='o') S[14]++;
		if(s[i]=='p') S[15]++;
		if(s[i]=='q') S[16]++;
		if(s[i]=='r') S[17]++;
		if(s[i]=='s') S[18]++;
		if(s[i]=='t') S[19]++;
		if(s[i]=='u') S[20]++;
		if(s[i]=='v') S[21]++;
		if(s[i]=='w') S[22]++;
		if(s[i]=='x') S[23]++;
		if(s[i]=='y') S[24]++;
		if(s[i]=='z') S[25]++;
	}
	for(int j = 0;j <= 25;j++){
		if(S[j]>1){
			flag = 1;
			printf("no\n");
			break;
		}
		else{
			flag = 0;
		}
	}
	if(flag == 0){
		printf("yes\n");
	}
}

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

int main() {
  int n,first,second,third,point,out;
  string str;
  cin >> n;
  for(int i=0;i<n;i++) {
    point = 0;
    out = 0;
    first = 0;
    second = 0;
    third = 0;
    while(cin >> str) {
      //     cout << str << endl;                                                    
      if(str == "HIT") {
        if(third == 1) {
          third = 0;
          point++;
        }
        if(second == 1) {
          second = 0;
          third = 1;
        }
        if(first == 1) {
          second = 1;
        }
        first = 1;
      }
      else if(str == "OUT") {
        out++;
        if(out == 3) break;
      }
      else if(str == "HOMERUN") {
        point += 1 + first + second + third;
        first = 0;
        second = 0;
        third = 0;
      }
    }
    cout << point << endl;
  }

}

Measured memory_bytes: 0
while True:
	m, f, r = map(int,input().split())
	if m == -1 and f == -1 and r == -1:
		break
	
	MF = m + f
	
	if m == -1 or f == -1:
		print("F")
	elif MF >= 80:
		print("A")
	elif MF >= 65:
		print("B")
	elif MF >= 50:
		print("C")
	elif MF >= 30:
		if r >= 50:
			print("C")
		else:
			print("D")
	else:
		print("F")

	

Measured memory_bytes: 7672
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>

#define REP(i, s, e) for (ll i = s; i < e; ++i)

using namespace std;
using ll = long long;
using ld = long double;

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

    int N;
    cin >> N;

    vector<int> A(N);
    REP(i, 0, N) cin >> A[i];

    ll result = 0;
    REP(i, 0, N)
    {
        REP(j, i + 1, N)
        {
            ll sub = abs(A[i] - A[j]);
            result = sub > result ? sub : result;
        }
    }

    cout << result << endl;

    return 0;
}


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

int main()
{
	char s[256], p[128];
	int i, slen, plen;

	scanf("%s", s);
	scanf("%s", p);
	slen = strlen(s);
	plen = strlen(p);

	for(i = 0; i < slen; ++i)
	{
		s[i + slen] = s[i];
	}
	s[2 * slen] = '\0';

	for(i = 0; i < slen; ++i)
	{
		if(strncmp(s + i, p, plen) == 0)
		{
			break;
		}
	}

	printf("%s\n", (i < slen) ? "Yes" : "No");
	return 0;
}


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

int main() {
  int N;
  string s;
  cin >> N;
  for(int i; i < N;i++){
    cin >> s;
    if (s == "Y"){
      cout << "Four" << endl;
      break;
    }
    if (i == N - 1){
      cout << "Three" << endl;
    }
  }
}

Measured memory_bytes: 256
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func main() {
	heighs := make([]int, 10)
	for i := range heighs {
		heighs[i] = nextInt()
	}
	sort.Sort(sort.Reverse(sort.IntSlice(heighs)))
	for i := 0; i < 3; i++ {
		fmt.Println(heighs[i])
	}
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int n;
  cin>>n;
  set<string> s;
  rep(i,n){
    string x;
    cin>>x;
    s.emplace(x);
  }
  cout<<(s.size()==3?"Three":"Four")<<endl;

}

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

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

int main()
{
    int ans = 0;
    rep(i, 4){
        char tmp;
        cin >> tmp;
        if(tmp == '+'){
            ans++;
        }else{
            ans--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }
int a,b,c;
int main(){
	cin>>a>>b>>c;
	if (a==b&&b!=c){
		puts("Yes"); return 0;
	}
	if (c==b&&b!=a){
		puts("Yes"); return 0;
	}
	if (a==c&&b!=c){
		puts("Yes"); return 0;
	}
	puts("No");
    return 0;
}


Measured memory_bytes: 256
/* 

	 - If you fail to prepare, you are prepared to fail.	

	(C) Mark Spitz

*/

#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define S second
#define F first
#define all(x) (x).begin(), (x).end()

using namespace std;

using ll = long long;

const bool dbg_flg = 1;
#define NAME(x) #x
#define debug if (dbg_flg) cerr

const int inf = 1e9 + 7;
const int MAXN = 1e5 + 5;

ll x;


void solve() {
	cin >> x;

	for (ll i = 0; i * i * i <= x; i++) {
		ll a = pow(i, 5);
		ll b = a - x;

		bool neg = 0;

		if (b < 0) {
			neg = 1;
			b = -b;
		}

		for (ll j = 0; j * j * j <= b; j++) {
			if (pow(j, 5) == b) {
				if (neg == 0) cout << i << ' ' << j;
				else cout << i << ' ' << -j;
				return;
			}
		}	
	}	
}

int main() {
	
	//~ freopen(".in", "r", stdin);
	//~ freopen(".out", "w", stdout);
	
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cout.tie(NULL);

	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
	}

	return 0;
}

Measured memory_bytes: 4204
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    cin>>a>>b;
    if(a==1){
        a=14;
    }
    if(b==1){
        b=14;
    }
    if(a>b){
        cout<<"Alice"<<endl;
    }else if(a<b){
        cout<<"Bob"<<endl;
    }else{
        cout<<"Draw"<<endl;
    }
}


Measured memory_bytes: 256
puts ($<.map{|l|(n=l.to_i)<1?0:(a=[]
n.times{|c|n,x,_,y=gets.split;a<<[-x.to_i*3-y.to_i,c,n]}
a.sort.map{|s,c,n|[n,-s]*?,}<<"")}-[0])*$/

Measured memory_bytes: 6108
#include <stdio.h>
#include <math.h>

int main(void){
    
    double x1,y1,x2,y2,ln;
    
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    
    ln=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
    
    printf("%f\n",sqrt(ln));
   
   
    return 0;
    
}


Measured memory_bytes: 2064
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,sum,a[200002],pref[200002];
int main(){
//freopen("text.in.txt","r",stdin);
cin>>n;
for(ll k=1;k<=n;k++){
    cin>>a[k];
    sum+=a[k];
    pref[k]=pref[k-1]+a[k];
}
ll ans=LONG_LONG_MAX;
for(int k=1;k<n;k++){
    ll a1=pref[k],a2=abs(sum-pref[k]);
    ans=min(ans,abs(a2-a1));
}
cout<<ans;
return 0;
}


Measured memory_bytes: 3328
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String inputString = sc.nextLine();
        int s = Integer.valueOf(inputString);
        if(s==4 || s==2 || s==1 ) {
            System.out.println("4");
            return;
        }
        int lastNumber = s;
        int i = 2;
        while(true) {
            int thisNumber = function(lastNumber);
            if(thisNumber==4) {
                System.out.println(i+3);
                break;
            }
            lastNumber = thisNumber;
            i++;
        }
    }

    private static int function(int n) {
        if(n%2==0){
            return n/2;
        }else{
            return 3*n+1;
        }

    }

}

Measured memory_bytes: 22868
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
    int n,m,x,a[110],count1 = 0,count2 = 0;
    cin >> n >> m >> x;
    for(int i = 0;i < m;i++){cin >> a[i];}
    sort(a,a + m);
    for(int i = x;i < n;i++)
    {
        for(int j = 0;j < m;j++)
        {
            if(a[j] == i){count1++;}
        }
    }
    for(int i = x;0 < i;i--)
    {
        for(int j = 0;j < m;j++)
        {
            if(a[j] == i){count2++;}
        }
    }
    cout << min(count1,count2) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
using namespace std;

set<int> divisorList(int n) {
    set<int> div;
    for (int i = 1; i <= n; i++) {
        if (n % i == 0){
            div.insert(i);
            if (i * i != n)
                div.insert(n / i);
        }
    }
    return div;
}

set<int> commonDivList(int a, int b) {
    set<int> aDiv = divisorList(a);
    set<int> bDiv = divisorList(b);
    set<int> res;
    set_intersection(aDiv.begin(), aDiv.end(),
            bDiv.begin(), bDiv.end(),
            inserter(res, res.end()));
    return res;
}

int main() {
    int a, b, k;
    cin >> a >> b >> k;

    set<int> divList = commonDivList(a, b);
    map<int, int> result;

    // auto itr = divList.rbegin();
    auto itr = divList.end();
    for (int i = 0; i < divList.size(); i++) {
        --itr;
        result[i] = *itr;
        // itr++;
    }

    cout << result[k - 1] << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  ll k, n;
  cin >> k >> n;
  vll a(n);
  rep(i,n) cin >> a[i];
  vll b(n);
  rep(i,n-1) b[i] = (a[i+1] - a[i]);
  b[n-1] = (k-a[n-1]) + a[0];
  ll ans = (ll)0;
  rep(i,n) ans = max(ans,b[i]);
  cout << k-ans << endl;
  return 0;
}

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

using namespace std;
#define ll long long 
#define rint register int
#define gc() getchar()
inline int read(int r=0,int s=0,int c=gc()){for(;c<48||c>57;s=c,c=gc());for(;c>=48&&c<=57;(r*=10)+=c-48,c=gc());return s^'-'?r:-r;}
ll N, M; int main(){N = read(), M = read(); if(N==1&&M==1) return puts("1"),0; N>M?swap(N,M),0:0; if(N==1) return printf("%d\n",M-2),0; cout << max(N-2,0ll)*max(M-2,0ll) << endl; return 0;}

Measured memory_bytes: 256
// Problem : D. Omkar and Bed Wars
// Contest : Codeforces - Codeforces Global Round 10
// URL : https://codeforces.com/contest/1392/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize(2)
#include<iostream>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <cstring>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <map>
#include <unordered_map>
#include <vector> 
#include <bitset>
#include <cctype>
#include <set>
#include <stack>
#include <queue>
#include <fstream>
#include <numeric>
#include <random>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MAXN = 200005;
const int MAXM = 20500;
const int MOD = 1e9+7;

#define MP make_pair
#define INF 0x3f3f3f3f
#define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template <typename T> inline T min(T a, T b, T c) { return min(min(a, b), c); }
#define mst(X,Y) memset(X,Y,sizeof(X)) 
#define rep(i, a, n) for (int i=(a); i<=(n); i++)
#define per(i, a, n) for (int i=(a); i>=(n); i--)
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>void debug_out(Head H, Tail... T) { cerr << " " << to_string(H);    debug_out(T...);}


ll a[MAXN];
int main()
{closeSync;
#ifdef DEBUG
	//freopen("C:/Users/86159/Desktop/input.txt", "r", stdin);
	//freopen("C:/Users/86159/Desktop/output.txt", "w", stdout);
#endif
	int n;
	cin>>n;
	rep (i,1,n)
		cin>>a[i];
	ll ans = 0;
	rep (i,2,n)
	{		
		if (a[i] < a[i-1])
		{
			ans += a[i-1] - a[i];
			a[i] = a[i-1];
		}
	}
	cout<<ans<<endl;
	//cerr << "Time:" << clock() - c1 << "ms" <<endl;
    return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define l_ength size
#define ws meow
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int sbrett[2048][2048];
int wbrett[2048][2048];
int ss[2048][2048];
int ws[2048][2048];

int fss( int bx, int by, int ax, int ay ){
	return ss[bx][by]-ss[ax][by]-ss[bx][ay]+ss[ax][ay];
}
int fws( int bx, int by, int ax, int ay ){
	return ws[bx][by]-ws[ax][by]-ws[bx][ay]+ws[ax][ay];
}

int main(){
	int n, k; cin >> n >> k;
	int sanz = 0, wanz = 0;
	for( int i = 0; i < n; ++i ){
		int x, y; cin >> x >> y;
		char c; cin >> c;
		if( c == 'B' ){
			++sbrett[x%(2*k)+1][y%(2*k)+1];
			++sanz;
		} else {
			++wbrett[x%(2*k)+1][y%(2*k)+1];
			++wanz;
		}
	}
	for( int j = 0; j <= 2*k; ++j ){
		for( int i = 0; i < 2*k; ++i ){
			ss[i+1][j] = ss[i][j] + sbrett[i+1][j];
			ws[i+1][j] = ws[i][j] + wbrett[i+1][j];
		}
	}
	for( int j = 0; j <= 2*k; ++j ){
		for( int i = 0; i < 2*k; ++i ){
			ss[j][i+1] = ss[j][i] + ss[j][i+1];
			ws[j][i+1] = ws[j][i] + ws[j][i+1];
		}
	}
	int ans = 0;
	for( int i = 0; i < k; ++i ){
		for( int j = 0; j < k; ++j ){
			int sum = 0;
			int x1 = i, y1 = j, x2 = i+k, y2 = j+k;
			sum += fss(x2, y2, x1, y1) + fss(x1, y1, 0, 0) + fss(x2, 0, 2*k, y1) + fss(x1, 2*k, 0, y2) + fss(2*k, 2*k, x2, y2);
			sum += (wanz) - ( fws(x2, y2, x1, y1) + fws(x1, y1, 0, 0) + fws(x2, 0, 2*k, y1) + fws(x1, 2*k, 0, y2) + fws(2*k, 2*k, x2, y2) );
			ans = max(ans, sum);
		}
	}
	for( int i = 0; i < k; ++i ){
		for( int j = 0; j < k; ++j ){
			int sum = 0;
			int x1 = i, y1 = j, x2 = i+k, y2 = j+k;
			sum += fws(x2, y2, x1, y1) + fws(x1, y1, 0, 0) + fws(x2, 0, 2*k, y1) + fws(x1, 2*k, 0, y2) + fws(2*k, 2*k, x2, y2);
			sum += (sanz) - ( fss(x2, y2, x1, y1) + fss(x1, y1, 0, 0) + fss(x2, 0, 2*k, y1) + fss(x1, 2*k, 0, y2) + fss(2*k, 2*k, x2, y2) );
			ans = max(ans, sum);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 65792
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long ll;

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

int main() {

    ll N,A,B;
    cin >> N >> A >> B;
    ll out = A*N;
    if(B<out) out = B;
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256