akhauriyash/Code-Regression huggingface dataset:
//C
#include <cassert>
//#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//ここまで標準include

using namespace std;

long aCb(long a, long b) {
	long out = 1;
	for (long i = 1; i <= b; i++) {
		out = out * (a + 1 - i) / i;
	}
	return out;
}

long long gcd(long long a, long long b) {
	long long r = -1;
	if (a < b) {
		swap(a, b);
	}
	while (r != 0) {
		r = a % b;
		if (r == 0) {
			return b;
		}
		else {
			a = b;
			b = r;
		}
	}
}

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

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	cout << min(N * A, B) << endl;
}


Measured memory_bytes: 256
n,m = map(int, input().split())
L = 0
R = 100000
for i in range(m):
    l,r = map(int, input().split())
    L = max(L,l)
    R = min(R,r)
if R - L < 0:
    ans = 0
else:
    ans = R - L + 1
print(ans)

Measured memory_bytes: 3060
program nanagogo
  implicit none
  character(10) :: n, s
  character(1) :: a(3) = (/"7","5","3"/)
  integer :: x, l, m = 0
  read(*,*) n
  l = len_trim(n)
  read(n(1:l),*) x
  call dfs(l)
  write(*,'(i0)') m
contains
  recursive subroutine dfs(i)
    integer, intent(in) :: i
    integer :: v, k
    if (i == 0) return
    do k = 1, 3
      s(i:i) = a(k)
      read(s(i:l),*) v
      if (v <= x .and. check(s(i:l))) m = m+1
      call dfs(i-1)
    end do
  end
  logical function check(s)
    character(*), intent(in) :: s
    logical :: p(3)
    integer :: i
    p = .false.
    do i = 1, len(s)
      p = p .or. s(i:i) == a
    end do
    check = all(p)
  end
end program nanagogo

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, cnt = 0, maxNum = 0, num[200000] = {};
string s[200000] = {};

int main() {
	cin >> n;
	rep(i, n) cin >> s[i];
	stable_sort(s, s + n);
	rep(i, n - 1) {
		if (s[i] == s[i + 1]) {
			cnt++;
		}
		else {
			if (maxNum <= cnt) {
				maxNum = cnt;
				num[i] = cnt;
			}
			cnt = 0;
		}
	}
	if (maxNum <= cnt) {
		maxNum = cnt;
		num[n - 1] = cnt;
	}
	rep(i, n) {
		if (num[i] == maxNum)cout << s[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 15844
import java.util.Scanner;

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

		String s = sc.next();
		String ans = "NO";

		if ("KIHBR".equals(s))
			ans = "YES";

		if ("AKIHBR".equals(s))
			ans = "YES";
		if ("KIHABR".equals(s))
			ans = "YES";
		if ("KIHBAR".equals(s))
			ans = "YES";
		if ("KIHBRA".equals(s))
			ans = "YES";

		if ("AKIHABR".equals(s))
			ans = "YES";
		if ("AKIHBAR".equals(s))
			ans = "YES";
		if ("AKIHBRA".equals(s))
			ans = "YES";
		if ("KIHABAR".equals(s))
			ans = "YES";
		if ("KIHABRA".equals(s))
			ans = "YES";
		if ("KIHBARA".equals(s))
			ans = "YES";

		if ("AKIHABAR".equals(s))
			ans = "YES";
		if ("AKIHABRA".equals(s))
			ans = "YES";
		if ("AKIHBARA".equals(s))
			ans = "YES";
		if ("KIHABARA".equals(s))
			ans = "YES";

		if ("AKIHABARA".equals(s))
			ans = "YES";

		System.out.println(ans);
	}

}


Measured memory_bytes: 23764
nums = list(input())
a, b, c, d = map(int, nums)
if a+b+c+d == 7:
    print('{}+{}+{}+{}=7'.format(a,b,c,d))
elif a+b+c-d == 7:
    print('{}+{}+{}-{}=7'.format(a,b,c,d))
elif a+b-c+d == 7:
    print('{}+{}-{}+{}=7'.format(a,b,c,d))
elif a+b-c-d == 7:
    print('{}+{}-{}-{}=7'.format(a,b,c,d))
elif a-b+c+d == 7:
    print('{}-{}+{}+{}=7'.format(a,b,c,d))
elif a-b+c-d == 7:
    print('{}-{}+{}-{}=7'.format(a,b,c,d))
elif a-b-c+d == 7:
    print('{}-{}-{}+{}=7'.format(a,b,c,d))
else:
    print('{}-{}-{}-{}=7'.format(a,b,c,d))

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vector<ll> x(n), y(n);
  for (int i = 0; i < n; ++i) cin >> x[i] >> y[i];

  auto cal = [&](ll py) {
    bool ret = 0;
    ll px = -1e17;
    for (int i = 0; i < n; ++i) {
      ll dist = x[i] - px, l = y[i], r = y[i] + dist;
      if (l <= py && py <= r)
        ret ^= (dist | (py - l)) == dist;
    }
    return ret;
  };
  ll ans = 0;
  for (int i = 60; i >= 0; --i)
    if (cal(ans | 1LL << i))
      ans |= 1LL << i;
  cout << (ans - (ll)1e17) << '\n';

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    char b;
    cin >> b;
    char ans;
    if (b == 'A')
        ans = 'T';

    if (b == 'T')
        ans = 'A';

    if (b == 'C')
        ans = 'G';

    if (b == 'G')
        ans = 'C';

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3576
MOD=10**9+7
cnt=0; sum=0; prev=nil; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n, k ,q = gsmi
a = q.times.map{gi}.sort

base = k-q
ar = Array.new(n,base)

q.times do |i|
  ar[a[i]-1]+=1
end

n.times do |i|
  can = ar[i]>0
  puts_yesno(can)
end

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

#define MOD 1000000007

int main(){
    int n;
    cin >> n;
    // A C G T
    vector<vector<vector<int>>> s(4, vector<vector<int>>(4, vector<int>(4, 1)));
    s[0][2][1] = 0; // AGC
    s[0][1][2] = 0; // ACG
    s[2][0][1] = 0; // GAC
    for(int m = 3; m < n; m++){
        vector<vector<vector<int>>> st(4, vector<vector<int>>(4, vector<int>(4, 0)));
        for (int i = 0; i < 4; i++){
            for (int j = 0; j < 4; j++){
                for (int k = 0; k < 4; k++){
                    st[j][k][0] += s[i][j][k];
                    st[j][k][3] += s[i][j][k];
                    st[j][k][0] %= MOD;
                    st[j][k][3] %= MOD;
                    // AG?C, A?GC, ?AGC, ?GAC
                    if ((i == 0 & j == 2) | (i == 0 & k == 2) | (j == 0 & k == 2) | (j == 2 & k == 0)){
                        st[j][k][2] += s[i][j][k];
                        st[j][k][2] %= MOD;
                    }
                    // ?ACG
                    else if (j == 0 & k == 1){
                        st[j][k][1] += s[i][j][k];
                        st[j][k][1] %= MOD;
                    }
                    else{
                        st[j][k][1] += s[i][j][k];
                        st[j][k][2] += s[i][j][k];
                        st[j][k][1] %= MOD;
                        st[j][k][2] %= MOD;
                    }
                }
            }
        }
        s = st;
    }
    int ans = 0;
    for (int i = 0; i < 4; i++){
        for (int j = 0; j < 4; j++){
            for (int k = 0; k < 4; k++){
                ans += s[i][j][k];
                ans %= MOD;
            }
        }
    }
    cout << ans << endl;
}


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

void print(int R, int L) {
  for (int r = 0; r < R - 1; r++) {
    cout << 0 << " ";
  }
  cout << (R + 1) / 2 + L / 2 << " ";
  cout << R / 2 + (L + 1) / 2 << " ";
  for (int l = 0; l < L - 1; l++) {
    cout << 0 << " ";
  }
}

int main(void) {
  string S;
  cin >> S;
  int R = 1, L = 0;
  char pre = 'R';
  for (int i = 1; i < S.length(); i++) {
    if (pre == 'L' && S[i] == 'R') {
      print(R, L);
      R = 1;
      L = 0;
    } else if (S[i] == 'L') {
      L++;
    } else if (S[i] == 'R') {
      R++;
    }
    pre = S[i];
  }
  print(R, L);
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int count, N;
  string S, T;
  cin >> S >> T;
  count = 0;
  N = S.size();
  
for (int i = 0; i < N; i++) {
  if(S.at(i) != T.at(i)){
    count++;
   }
}
  cout << count << endl;
}

Measured memory_bytes: 3820
I=lambda:map(int,input().split());F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=(f,F),(f,-F),;H=(F,f),(-F,f),
for i in r(n):*a,c=I();R+=(a,c),;Y+=c,;X+=a
for i in r(m):a,*b=I();H+=(a,b),;X+=a,;Y+=b
def g(X):s=dict(enumerate(sorted(set(X))));return{s[i]:i for i in s},s,len(s)
h,s,K=g(X);w,t,L=g(Y);j=lambda:[[0]*-~K for i in r(L+1)];V=j();U=j();v=j()
for(a,b),c in R:U[w[c]][h[a]]+=1;U[w[c]][h[b]]-=1
for d,(e,f)in H:V[w[e]][h[d]]+=1;V[w[f]][h[d]]-=1
for i in r(L):
 for j in r(K):U[i][j+1]+=U[i][j];V[i+1][j]+=V[i][j]
q=[(h[0],w[0])];v[w[0]][h[0]]=1;a=0
while q:
 x,y=q.pop();a+=(s[x]-s[x+1])*(t[y]-t[y+1])
 for e,f in(-1,0),(1,0),(0,1),(0,-1),:
  c=x+e;d=y+f
  if 1-v[d][c]and U[(f>0)+y][x]*f+V[y][(e>0)+x]*e==0:q+=[(c,d)];v[d][c]=1
print([a,'INF'][a>F])

Measured memory_bytes: 551292
# もらうDPをメモ化再帰にしました的な実装
t = int(input())
for _ in range(t):
    n, a, b, c, d = map(int, input().split())
    memo = {0: 0, 1: d}

    def dfs(n):
        if n in memo.keys():
            return memo[n]

        res1 = n*d
        r = n % 2
        res2 = a+r*d+dfs((n-r)//2)
        if r != 0:
            tmp = a+(2-r)*d+dfs((n+(2-r))//2)
            if tmp < res2:
                res2 = tmp

        r = n % 3
        res3 = b+r*d+dfs((n-r)//3)
        if r != 0:
            tmp = b+(3-r)*d+dfs((n+(3-r))//3)
            if tmp < res3:
                res3 = tmp

        r = n % 5
        res5 = c+r*d+dfs((n-r)//5)
        if r != 0:
            tmp = c+(5-r)*d+dfs((n+(5-r))//5)
            if tmp < res5:
                res5 = tmp

        memo[n] = min(res1, res2, res3, res5)
        return memo[n]

    print(dfs(n))

Measured memory_bytes: 10796
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include<queue>
#include <sstream>
#include <set>
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
using namespace std;
int main(){
    string S;
    cin >>S;

    vector<string> hantei(4);
    hantei = {"dream","dreamer","erase","eraser"};

    REVERSE(S);
    
    REP(i,4){
        REVERSE(hantei[i]);
        
    }
    bool fl = true;
    int i=0;
    while(fl){
        int o=0;
        bool can = false;
        REP(j,4){
            
            string x=hantei[j];
            int size = x.size();
            
            
            string y=S.substr(i,size);
            if(x == y){
                can = true;
                o = size;
            }
        }

        if(can) i+=o;
        else fl = false;

        if(i>=S.size()) break;
    }

    if(fl) cout << "YES" << endl;
    else   cout << "NO"  << endl;


}

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

/*
蟻本片手に学ぶアルゴリズム ~ローリングハッシュ~ - Qiita
https://qiita.com/hirominn/items/80464ee381c8d400725f
*/

#define MOD_BY UINT64_C(4129613490598809767)
#define MULT UINT64_C(2925597417967149787)

uint64_t add(uint64_t a, uint64_t b) {
	uint64_t r = a + b;
	if (r >= MOD_BY) r -= MOD_BY;
	return r;
}

uint64_t sub(uint64_t a, uint64_t b) {
	return b == 0 ? a : add(a, MOD_BY - b);
}

uint64_t mul(uint64_t a, uint64_t b) {
	uint64_t r = 0;
	while (b > 0) {
		if (b & 1) r = add(r, a);
		a = add(a, a);
		b >>= 1;
	}
	return r;
}

struct asumisu {
	int idx;
	uint64_t hash;
};

int hikaku(const void* x, const void* y) {
	struct asumisu a = *(const struct asumisu*)x, b = *(const struct asumisu*)y;
	if (a.hash != b.hash) return a.hash < b.hash ? -1 : 1;
	return a.idx < b.idx ? -1 : a.idx > b.idx;
}

int N;
char S[7777777];

uint64_t mofu[7777777];

struct asumisu nyan[7777777];

int main(void) {
	int yes , no;
	int i;
	if (scanf("%d", &N) != 1) return 1;
	if (scanf("%7777775s", S + 1) != 1) return 1;
	mofu[0] = 1;
	for (i = 1; i <= N; i++) mofu[i] = mul(mofu[i - 1], MULT);
	yes = 0;
	no = N;
	while (yes + 1 < no) {
		int mid = yes + (no - yes) / 2;
		uint64_t hash = 0;
		int nyanSize = 0;
		int start;
		int found = 0;
		for (i = 1; i <= N; i++) {
			hash = add(mul(hash, MULT), (unsigned char)S[i]);
			if (i >= mid) {
				hash = sub(hash, mul((unsigned char)S[i - mid], mofu[mid]));
				nyan[nyanSize].idx = i - mid + 1;
				nyan[nyanSize].hash = hash;
				nyanSize++;
			}
		}
		qsort(nyan, nyanSize, sizeof(*nyan), hikaku);
		for (start = 0, i = 1; !found && i <= nyanSize; i++) {
			if (i >= nyanSize || nyan[start].hash != nyan[i].hash) {
				int j, k;
				for (j = start; !found && j < i; j++) {
					for (k = i - 1; k > j && nyan[j].idx + mid <= nyan[k].idx; k--) {
						if (strncmp(S + nyan[j].idx, S + nyan[k].idx, mid) == 0) {
							found = 1;
							break;
						}
					}
				}
				start = i;
			}
		}
		if (found) yes = mid; else no = mid;
	}
	printf("%d\n", yes);
	return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
string s;
int len,f[100010][15];
int main()
{
    getline(cin,s);
    len=s.length();
    if(s[0]=='?')
        for(int i=0;i<=9;i++)f[0][i]=1;
    else f[0][s[0]-48]=1;
    for(int i=1;i<len;i++)
        for(int j=0;j<=12;j++)
            if(s[i]=='?')
                for(int k=0;k<=9;k++)f[i][(j*10+k)%13]=(f[i][(j*10+k)%13]+f[i-1][j])%mod;
            else f[i][(s[i]-48+j*10)%13]=(f[i][(s[i]-48+j*10)%13]+f[i-1][j])%mod;
    cout<<f[len-1][5];
    return 0;
}

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

using namespace std;
vector<long long> a;
int n, k;
long long s, x;
unordered_set<int> m;

int watering(int l, int r, int height) {
	if (l > r) return 0;

	int maxp=l;
	int minv=a[l];
	for (int i=l+1;i<=r;i++) {
		if (a[i] < minv) {
			minv=a[i];
			maxp=i;
		}
	}

//	cout << l << ' ' << r << ' ' << (minv > height? 1: 0) << endl;

	return (minv > height? minv - height: 0) + watering(l,maxp-1, minv) + watering(maxp+1,r, minv);
}

int main() {
	cin >> n;
	for (int i=1;i<=n;i++) {
		cin >> x;
		a.push_back(x);
	}

	cout << watering(0, n-1, 0);
}



Measured memory_bytes: 256
use proconio::input;

const ASC: [char; 26] = [
    'a', 'b', 'c', 'd', 'e',
    'f', 'g', 'h', 'i', 'j',
    'k', 'l', 'm', 'n', 'o',
    'p', 'q', 'r', 's', 't',
    'u', 'v', 'w', 'x', 'y',
    'z',
];

fn main() {
    input! {
        mut n: u128,
    }
    let mut r = String::new();
    while n > 0 {
        r.insert(0, ASC[((n - 1) % 26) as usize]);
        n = (n - 1) / 26;
//        if n == 1 && r.starts_with('z') {break}
    }
    println!("{}", r);
}


Measured memory_bytes: 2096
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;
const long long P = 1000000007;

long long solve(long long n) {
  int res = 0;
  for(int i = 1; i <= sqrt(n); i++) {
    if(n % i == 0) res += 2;
    if(n % i == 0 && i == sqrt(n)) res--;
  }
  return res;
}

int main() {
  long long n;
  cin >> n;
  long long count = 0;
  for(int i = 1; i < n; i++) {
    count += (n-1)/i;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3672
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>     // pow
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>   // setprecision
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

// long long gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a;
// }

// int binary_search(int key) {
//     int ng = -1;
//     int ok = (int)a.size();
//     while(abs(ok - ng) > 1) {
//         int mid = (ok + ng) / 2;
//         if(isOK(mid, key))
//             ok = mid;
//         else
//             ng = mid;
//     }
//     return ok;
// }

// cout << fixed << setprecision(10);
// vector<vector<int>> vec(H, vector<int>(W))    // int H*W
// int MOD = 1000000007;

int main() {
    string s;
    cin >> s;
    if(s == "AAA" || s == "BBB") {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 888
// B - ATCoder
#include <bits/stdc++.h>
using namespace std;

int main(){
	string T="ACGT", S; cin>>S;
	int maxi = 0, now=0;
	for(int i=0; i<S.size(); ++i){
		now = T.find(S[i]) < T.size()? now+1: 0;
		maxi = max(maxi, now);
	}
	cout<< maxi <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

const int MAX = 10010;

struct P{
  int a,b;
};

void check(int a,int b,P &pr, P &pl,double sq){
  if((double)a/b < sq && (double)a/b > (double)pl.a/pl.b){
    pl.a = a; pl.b = b;
  }
  if((double)a/b > sq && (double)a/b < (double)pr.a/pr.b){
    pr.a = a; pr.b = b;
  }
}

int main(){
  int p,n;
  while(cin >> p >> n,p || n){
    double sq = sqrt(p);
    P pl,pr;
    pl.a = pl.b = 1;
    pr.a = MAX;
    pr.b = 1;
    
    for(int i = 1 ; i <= n ; i++){
      int l,r,m;
      l = 1 ; r = n;
      while(l + 1 < r){
	m = (l + r)/2;
	if((double)m/i < sq)l = m;
	else r = m;
      }
      check(l,i,pr,pl,sq);
      check(m,i,pr,pl,sq);
      check(r,i,pr,pl,sq);
    }
    cout << pr.a << '/' << pr.b << ' ' << pl.a << '/' << pl.b << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String A = sc.nextLine();
    String B = sc.nextLine();
    
    String ans = "";
    if(A.equals(B)){
      ans = "EQUAL";
    }else if(A.length() > B.length()){
      ans = "GREATER";
    }else if(A.length() < B.length()){
      ans = "LESS";
    }else{
      for(int i = 0; i < A.length(); i++){
        char a = A.charAt(i);
        char b = B.charAt(i);
        if(a > b){
          ans = "GREATER";
          break;
        }else if(a < b){
          ans = "LESS";
          break;
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23764
from operator import itemgetter
n, m = [int(i) for i in input().split()]
A = []
for i in range(n):
    A.append([int(j) for j in input().split()])
A = sorted(A, key=itemgetter(0))
cur_drink = 0
cur_cost = 0
for i in range(m):
    if cur_drink < m:
        more_drink = min(m - cur_drink, A[i][1])
        cur_drink += more_drink
        cur_cost += more_drink * A[i][0]
    if cur_drink == m:
        break
print(cur_cost)

Measured memory_bytes: 23604
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main() {
	int n; cin >> n;
	string c; cin >> c;
	vector<int> lw(n + 1), rr(n + 1);
	for (int i = 1; i <= n; ++i) {
		lw[i] = lw[i - 1];
		if (c[i - 1] == 'W') ++lw[i];
	}
	for (int i = n; i > 0; --i) {
		rr[i - 1] = rr[i];
		if (c[i - 1] == 'R') ++rr[i - 1];
	}
	int ans = 1e9;
	for (int i = 0; i <= n; ++i)
		ans = min(ans, max(lw[i], rr[i]));
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5176
/**
*    created: 23.05.2020 13:00:54
**/
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int s;
    cin >> s;
    int m = 1;
    map<int,int> mp;
    mp[s]++;
    while(true) {
        m++;
        if (s % 2 == 0) s /= 2;
        else s = 3 * s + 1;
        if (mp[s]) break;
        else mp[s]++;
    }
    cout << m << endl;
    return 0;
}


Measured memory_bytes: 256
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let v = read_vec::<i32>();
    let x1 = v[0];
    let y1 = v[1];
    let x2 = v[2];
    let y2 = v[3];

    println!("{} {} {} {}",
             x2-(y2-y1), y2+(x2-x1), x1+(y1-y2), y1-(x1-x2));
}


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

int H,W,c[10][10],a,b[11];//b[0]が-1のところ,b[1]が0のところ,,,以下同じ
char kara;
int main(){
        cin>>H>>W;
        for(int i=0;i<10;i++){
                for(int j=0;j<10;j++){
                        cin>>c[i][j];
                }
        }
        for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                        scanf("%d",&a);
                        b[a+1]++;
                }
        }

        int d[11];//0~10
        for(int i=0;i<10;i++){
                d[i]=100000;
        }
        d[1]=0;
        for(int i=0;i<10;i++){
                for(int j=0;j<10;j++){
                        for(int k=0;k<10;k++){
                                if(d[j]>d[k]+c[j][k]){
                                        d[j]=d[k]+c[j][k];
                                }
                        }
                }
        }

        int ans=0;

        ans+=d[0]*b[1];

        for(int i=2;i<=9;i++){
                ans+=d[i]*b[i+1];
        }

        cout<<ans;

        return 0;

}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;

int N;
int freq[401];
int dist[401];

set<vector<int> > res;

int compute_max(){
  for(int i=400;i>=0;i--){
    if(freq[i] > 0) return i;
  }
  return -1;
}

void dfs(int target,vector<int>& points){

  if(target == N){
    vector<int> tmp = points;
    sort(tmp.begin(),tmp.end());

    vector<int> sub;
    for(int i=0;i+1<tmp.size();i++){
      sub.push_back(tmp[i+1]-tmp[i]);
    }
    res.insert(sub);
    return;
  }
  
  int max_pos = compute_max();
  bool isok = true;
  points.push_back(max_pos);
  for(int i=0;i<target;i++){
    if(freq[abs(points[i] - max_pos)] == 0) {
      isok = false;
      for(int j=i-1;j>=0;j--){
        freq[abs(points[j] - max_pos)]++;
      }
      break;
    }
    freq[abs(points[i] - max_pos)]--;
  }

  if(isok){
    dfs(target+1,points);
    for(int i=0;i<target;i++){
      freq[abs(points[i] - max_pos)]++;
    }
  }

  points.pop_back();

  int inv_pos = points[1] - max_pos;
  points.push_back(inv_pos);
  bool isok_inv = true;
  points[target] = inv_pos;
  for(int i=0;i<target;i++){
    if(freq[abs(points[i] - inv_pos)] == 0) {
      isok_inv = false;
      for(int j=i-1;j>=0;j--){
        freq[abs(points[j] - inv_pos)]++;
      }
      break;
    }
    freq[abs(points[i] - inv_pos)]--;
  }

  if(isok_inv){
    dfs(target+1,points);
    for(int i=0;i<target;i++){
      freq[abs(points[i] - inv_pos)]++;
    }
  }

  points.pop_back();
}

int main(){

  while(~scanf("%d",&N)){
    if(N == 0) break;
    res.clear();

    memset(freq,0,sizeof(freq));
    for(int i=0;i < N * (N-1) / 2;i++){
      scanf("%d",&dist[i]);
      freq[dist[i]]++;
    }
    sort(dist,dist + N * (N-1)/2);

    freq[dist[N*(N-1)/2 - 1]]--;
    vector<int> points;
    points.push_back(0);
    points.push_back(dist[N*(N-1)/2 - 1]);
    
    dfs(2,points);
    for(set<vector<int> >::iterator it = res.begin();
        it != res.end();
        it++){
      for(int i=0;i < it->size();i++){
        printf("%s%d",i==0 ? "" : " ",(*it)[i]);
      }
      printf("\n");
    }
    printf("-----\n");
  }
}

Measured memory_bytes: 1228
import math, string, fractions, heapq, re, array, bisect, sys, random, time, copy
import itertools as it
import collections as cl
import functools as ft
import numpy as np


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def calc_lament(a, b):
    return sum([abs(ai - b) for ai in a])


n = int(input())
a = LI()

a = [ai - i for ai, i in zip(a, range(1, n+1))]

b = int(np.median(a))
print(calc_lament(a, b))


Measured memory_bytes: 35608
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)



int main(){ FastIO;

ll n,k;cin>>n>>k;
cout<<min(n%k,k-(n%k));


return 0;
}

Measured memory_bytes: 256
N = input()
zero_one = 0
one_zero = 0

for key, v in enumerate(N):
    if (key+1) % 2 == 1:
        if v == "0":
            zero_one += 1
        elif v == "1":
            one_zero += 1
    elif (key+1) % 2 == 0:
        if v == "0":
            one_zero += 1
        elif v == "1":
            zero_one += 1

print(min(one_zero, zero_one))


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

typedef long long ll;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

ll n, a[100000];

ll aaa(ll flag) {
  ll ans = 0, gou = 0;
  rep(i, 0, n) {
    gou += a[i];
    if(flag && gou >= 0) {
      ans += gou + 1;
      gou = -1;
    }else if(!flag && gou <= 0){
      ans += -gou + 1;
      gou = 1;
    }
    flag = !flag;
  }
  return ans;
}

int main() {
  cin >> n;
  rep(i, 0, n) cin >> a[i];

  cout << min(aaa(true), aaa(false)) << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
n,x,y,t;
main(){
    char a[101],b[101];
    for(scanf("%d",&n);n--;){
        scanf("%s%s",a,b);
        t=strcmp(a,b);
        x+=t>0?3:t==0?1:0;
        y+=t<0?3:t==0?1:0;
    }
    printf("%d %d\n",x,y);
}

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

#define int long long
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define yn(x) ((x) ? "Yes" : "No")

typedef pair <int, int> ii;
typedef pair <int, ii> iii;

const int siz = 2e5 + 10;
const int SIZ = 1e6 + 10;
const int mod = 1e9 + 7;
const int maxx = 2e9;
const int MAXX = 1e18;
const string file = "3";



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

//    freopen ((file + ".inp").c_str(), "r", stdin);
//    freopen ((file + ".out").c_str(), "w", stdout);

    for (int i = 1; i <= 5; i++) {
        int a;
        cin >> a;
        
        if (a == 0) {
            return cout << i << "\n", 0;
        } 
    }

//    cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}


Measured memory_bytes: 3544
def resolve():
    N=int(input())
    A=[int(i) for i in input().split()]
    B=[A[i]-(i+1) for i in range(N)]
    B.sort()
    x=B[(N-1)//2]
    print(sum([abs(i-x) for i in B]))



if __name__ == "__main__":
    resolve()

Measured memory_bytes: 99668
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;


void solve(long long N, std::vector<long long> V, std::vector<long long> C){
    ll ans = 0;
    loop (N, i) {
        if (V[i] > C[i]) ans += V[i] - C[i];
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> V(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&V[i]);
    }
    std::vector<long long> C(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&C[i]);
    }
    solve(N, std::move(V), std::move(C));
    return 0;
}



Measured memory_bytes: 256
import math
n,d = map(int,input().split())
point_list = []
for i in range(n):
    point = list(map(int,input().split()))
    point_list.append(point)
count = 0

for j in range(n):
    distance = math.sqrt(point_list[j][0]**2 + point_list[j][1]**2)
    if distance <= d:
        count += 1

print(count)

Measured memory_bytes: 45468
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		int n = 0;
		Scanner s = new Scanner(System.in);
		String l = s.nextLine();
		
		for (int i = 0; i < 4; i++)
		{
			n = l.charAt(i) == '+' ? n + 1 : n - 1;
		}
		s.close();
		System.out.println(n);
	}
}

Measured memory_bytes: 22612
//
// Created by rajshah9914 on 05/04/20.
//

#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long x,n;
    cin>>x>>n;
//    if(n>=x)
//        cout<<min(n-x,x)<<endl;
//    else
//    {
        long long m=x/n;
        long long mm=m+1;
        cout<<min(abs(m*n-x),abs(mm*n-x))<<endl;
//    }
}

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

 
int main() {
    ll x;
    cin>>x;

    ll a=100;
    ll count=0;
    while(a<x){
        count++;
        a=a*1.01;
    }

    cout<<count<<endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<string> name(N);
    for(int i=0; i<N; i++){
        cin >> name.at(i);
    }
    sort(name.begin(),name.end());
    int maxcount=1;
    int count[N];
    count[0]=1;
    for(int i=1; i<N; i++){
        if(name.at(i).compare(name.at(i-1))==0){
            count[i]=count[i-1]+1;
        }else{
            count[i]=1;
        }
        maxcount=max(maxcount,count[i]);
    }
    for(int i=0; i<N; i++){
        if(count[i]==maxcount){
            cout << name.at(i) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 15104
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int n;
  ll c=0;
  cin>>n;
  vector<int> a(n),b(n);
  for(int i=1;i<=n;i++){
    cin>>a[i-1];
    b[i-1]=a[i-1]-i;
  }
  sort(b.begin(),b.end());
  int bb;
  if(n%2==1){
    bb=b[n/2];
  }else{
    bb=(b[n/2]+b[n/2-1])/2;
  }
  for(int i=0;i<n;i++){
    c+=abs(b[i]-bb);
  }
  cout<<c;
}

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

int main(void){
  
 	string a, b, c; cin >> a >> b >> c;
  	if( a[a.size()-1]==b[0]&&b[b.size()-1]==c[0] ) cout << "YES" << endl;
    else cout << "NO" << endl;
  
  	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

def solve():
    n = II()
    A = LI()

    B = [-1] * n
    for i in range(n, 0, -1):
        # print(i)
        s = 0
        for j in range(i+i, n+1, i):
            # print(f' {j}')
            s ^= B[j-1]
        B[i-1] = A[i-1] ^ s
    # print(B)

    print(sum(B))
    for idx, b in enumerate(B):
        if b: print(idx+1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 7276
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

int main() {
  int k, s;
  scanf("%d %d", &k, &s);
  ll cnt = 0;
  FOR (x, max(0, s - 2*k), k+1) {
    int sum = s - x;
    if (sum < 0) {
      break;
    }
    if (sum <= k) {
      cnt += (sum+1);
    } else {
      cnt += (2*k - sum + 1);
    }
  }
  printf("%lld\n", cnt);

  return 0;
}


Measured memory_bytes: 760
#include <iostream>

#define SIZE 100000

int  N;
long h[SIZE];
long dp[SIZE];


// dp[i] := 足場 i に移動するのにかかる最小コスト
void solve() {
    dp[0] = 0;
    dp[1] = std::abs(h[0] - h[1]);
    for (int i=2; i<N; ++i) {
        dp[i] = std::min( dp[i-1] + std::abs(h[i] - h[i-1]), dp[i-2] + std::abs(h[i] - h[i-2]) );
    }
    std::cout << dp[N-1] << std::endl;
}

int main() {
    std::cin >> N;
    for (int i=0; i<N; ++i) std::cin >> h[i];
    solve();
    return 0;
}

Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i,n,s) for (int i= (int)(n); i >= (int)(s); i--)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    ll k;cin>>k;
    ll s = 7;
    ll m = k;
    ll cnt = 0;
    map<pair<ll,ll>,int> al;
    while (true){
        cnt++;
        s %= k;
        m = (m+s)%k;
        
        if (al[mp(m,s)]==1){
            cout<<-1<<endl;
            return 0;
        }
        al[mp(m,s)] = 1;
        if (m%k==0) break;
        s *= 10;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 66060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n,m,q;
  cin >> n >> m >> q;
  vector<vector<ll>> train(n,vector<ll>(n));
  for(int i = 0;i < n;i++)for(int j = 0;j < n;j++)train[i][j] = 0;
  ll lmin = 0;
  ll rmax = 0;
  lmin = 100000;
  for(int i = 0;i < m;i++){
    ll l,r;
    cin >> l >> r;
    l--,r--;
    lmin = min(lmin,l);
    rmax = max(rmax,r);
    train[l][r]++;
  }
  for(int i = 0;i < q;i++){
    ll l,r;
    cin >> l >> r;
    l--,r--;
    if(l <= lmin && r >= rmax){
      cout << m << endl;
      continue;
    }
    ll res = 0;
    for(int j = l;j <= r;j++){
      for(int k = l;k <= r;k++){
        res += train[j][k];
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 2944
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=100010;
int n,ck=2,suma,sumb,tota,totb,fxor,ans,f[N],siz[N],a[N],b[N],lsha[N],lshb[N];
int find(int x){
	return x==f[x]?x:f[x]=find(f[x]);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
		lsha[i]=a[i];
		suma^=a[i];
	}
	for(int i=1;i<=n;i++){
		scanf("%d",b+i);
		lshb[i]=b[i];
		sumb^=b[i];
		if(a[i]!=b[i])
			ans++;
	}
	if(!ans){
		puts("0");
		return 0;
	}
	++n;
	lsha[n]=a[n]=suma,lshb[n]=b[n]=sumb;
	sort(lsha+1,lsha+n+1);
	sort(lshb+1,lshb+n+1);
	for(int i=1;i<=n;i++){
		if(lsha[i]!=lshb[i]){
			puts("-1");
			return 0;
		}
	}
	tota=unique(lsha+1,lsha+n+1)-(lsha+1);
	for(int i=1;i<=tota;i++)
		siz[f[i]=i]=1;
	for(int i=1;i<=n;i++){
		a[i]=lower_bound(lsha+1,lsha+tota+1,a[i])-lsha,b[i]=lower_bound(lsha+1,lsha+tota+1,b[i])-lsha;
		int fx=find(a[i]),fy=find(b[i]);
		if(fx!=fy){
			f[fx]=fy;
			siz[fy]+=siz[fx];
		}
	}
	if(a[n]==b[n]&&siz[find(a[n])]==1)
		ans++;
	for(int i=1;i<=n;i++){
		int fi=find(i);
		if(i==fi&&siz[fi]>1)
			ans++;
	}
	printf("%d",ans-1);
	return 0;
}

Measured memory_bytes: 4096
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#define long long long
#define LF '\n'
using namespace std;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;


signed main()
{
  cin.tie(nullptr), ios::sync_with_stdio(false);
  int n, q;;
  int a[1005];

  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];

  cin >> q;
  while(q--) {
    int s, m, e;
    cin >> s >> m >> e;
    rotate(a+s, a+m, a+e);
  }

  for (int i = 0; i < n; ++i) {
    cout << a[i] << (i+1 < n ? ' ' : LF);
  }

  return 0;
}




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

#define INF 1234567890
#define ll long long

int T;
int N, M, A, B;

int main()
{
	scanf("%d", &T);
	while(T--)
	{
		scanf("%d %d %d %d", &N, &M, &A, &B);
		printf("%lld\n", floor_sum(N, M, A, B));
	}
	return 0;
}

Measured memory_bytes: 3820
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	class State implements Comparable<State>{
		int pos, cost, tick;

		public State(int pos, int cost, int tick) {
			this.pos = pos;
			this.cost = cost;
			this.tick = tick;
		}

		@Override
		public int compareTo(State arg0) {
			return this.cost - arg0.cost;
		}
	}
	private void doit(){
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if((n|m) == 0) break;
			int [][] pass = new int[n][n];
			int INF = 1 << 24;
			for(int i = 0; i < n; i++){
				Arrays.fill(pass[i], INF);
				pass[i][i] = 0;
			}
			for(int i = 0; i < m; i++){
				int a = sc.nextInt() -1;
				int b = sc.nextInt() -1;
				int cost = sc.nextInt();
				pass[a][b] = cost;
				pass[b][a] = cost;
			}
			
			PriorityQueue<State> open = new PriorityQueue<Main.State>();
			open.add(new State(0, 0, 1));
			int [][] close = new int[n][2];
			for(int i = 0; i < n; i++){
				Arrays.fill(close[i], INF);
			}
			close[0][1] = 0;
			int ans = 1 << 24;
			while(! open.isEmpty()){
				State now = open.poll();
				if(now.pos == n-1){
					ans = now.cost;
					break;
				}
				for(int i = 0; i < n; i++){
					if(i == now.pos) continue;
					if(pass[now.pos][i] == INF) continue;
					int nextcost = now.cost + pass[now.pos][i];
					if(close[i][now.tick] > nextcost){
						open.add(new State(i, nextcost, now.tick));
						close[i][now.tick] = nextcost;
					}
					
					if(now.tick == 0) continue;
					for(int j = 0; j < n; j++){
						if(j == now.pos || j == i) continue;
						if(pass[i][j] == INF) continue;
						if(close[j][0] <= now.cost) continue;
						open.add(new State(j, now.cost, 0));
						close[j][0] = now.cost;
					}
				}
			}
			System.out.println(ans);
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

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

class Main
{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    char C = sc.next().charAt(0);
    switch (C)
    {
      case 'A':
        System.out.println("T");
        break;
      case 'T':
        System.out.println("A");
        break;
      case 'C':
        System.out.println("G");
        break;
      case 'G':
        System.out.println("C");
        break;
    }
  }
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    string a;
    cin >> a;
    string b;
    cin >> b;
    string c;
    cin >> c;
    
    int ans = 0;
    rep(i, n) {
        if (a[i] == b[i] && a[i] == c[i]) {
            ;
        } else if (a[i] == b[i]) {
            ans++;
        } else if (b[i] == c[i]) {
            ans++;
        } else if (a[i] == c[i]) {
            ans++;
        } else {
            ans += 2;
        }
    }
    cout << ans << endl;


    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <sstream>
#include <set>
typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}



using namespace std;
int main(){
   int n, s1=0,s2=0,min_i = 1,tmp;
   cin >> n;
   vector<int> vec(n);
   
   REP(i,n){
       cin >> vec[i];
       s2 += vec[i];
   }
   s2 -= vec[0];

   s1 = vec[0];
    tmp = abs(s1-s2);
    FOR(i,1,n){
        s1 += vec[i];
        s2 -= vec[i];
        if(tmp > abs(s1-s2)){
            tmp = abs(s1-s2);
            min_i = i;
        }

    }


    cout << tmp <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  int F=0;
  cin>>N>>M;
  vector<long long>vec(N);
  vector<bool>ve(N,true);
  vector<vector<int>> v(M, vector<int>(2));
  for(int X=0;X<N;X++){
    cin>>vec.at(X);
  }
  for(int X=0;X<M;X++){
    for(int Y=0;Y<2;Y++){
      cin>>v.at(X).at(Y);
    }
  }
  for(int X=0;X<M;X++){
    if(vec.at(v.at(X).at(0)-1)>=vec.at(v.at(X).at(1)-1)){
      ve.at(v.at(X).at(1)-1)=false;
    }
    if(vec.at(v.at(X).at(0)-1)<=vec.at(v.at(X).at(1)-1)){
      ve.at(v.at(X).at(0)-1)=false;
    }
  }
  for(int X=0;X<N;X++){
    if(ve.at(X)==true){
      F++;
    }
  }
  cout<<F<<endl;
}

Measured memory_bytes: 9596
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(a == 1 && b != 1) printf("Alice\n");
    else if(a != 1 && b == 1) printf("Bob\n");
    else if(a == b) printf("Draw\n");
    else if(a < b) printf("Bob\n");
    else if(a > b) printf("Alice\n");
    return 0;
}


Measured memory_bytes: 256
while True:
    H, W = map(int, input().split())
    if (H, W) == (0, 0):
        break
    a = "#" * W
    b = "#" + "." * (W - 2) + "#\n"
    print(a)
    print(b * (H - 2), end="")
    print(a + "\n")


Measured memory_bytes: 5640