akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)

int main(void){
    string s;
    cin >> s;
    int n = s.size();
    rep(i,n){
        if (s[i] == '?') {
            s[i] = 'D';
        }
    }
    cout << s << endl;
    return 0;
}


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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> void chmax(T& a,const T& b){if(a < b) a = b;}
template<typename T> void chmin(T& a,const T& b){if(b < a) a = b;}
typedef long long ll;

int N;
string S;

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

	cin >> S;
	N = S.size();

	int ans = 0,cnt = 0;
	FOR(i,0,N){
		if(S [i] == 'T'){
			cnt++;
		}
		else{
			cnt--;
		}
		chmax(ans,cnt);
	}

	cout << ans * 2 << endl;

	return 0;
}


Measured memory_bytes: 1228
#include <stdio.h>

const int ROOM_NUM = 10;
const int FLOOR_NUM = 3;
const int HOUSE_NUM = 4;

struct OfficialHouse{ int rooms[FLOOR_NUM][ROOM_NUM]; };

void printOfficialHouse(OfficialHouse *oh, int N){
  for(int i=0; i<N; i++){
    for(int j=0; j<FLOOR_NUM; j++){
      for(int k=0; k<ROOM_NUM; k++){
        printf(" %d",oh[i].rooms[j][k]);
      }
      printf("\n");
    }
    if(i != N-1) printf("####################\n");
  }
}

int main(){

  int n;
  scanf("%d", &n);

  OfficialHouse officialHouses[HOUSE_NUM];
  for(int i=0;i<HOUSE_NUM;i++){
    for(int j=0;j<FLOOR_NUM;j++){
      for(int k=0;k<ROOM_NUM;k++){
        officialHouses[i].rooms[j][k] = 0;
      }
    }
  }

  int b,f,r,v;
  for(int i=0;i<n;i++){
    scanf("%d",&b);
    scanf("%d",&f);
    scanf("%d",&r);
    scanf("%d",&v);
    b -= 1; f -= 1; r -= 1;
    officialHouses[b].rooms[f][r] += v;
    if(officialHouses[b].rooms[f][r] < 0 ){
      officialHouses[b].rooms[f][r] = 0;
    } else if(officialHouses[b].rooms[f][r] > 9){
      officialHouses[b].rooms[f][r] = 9;
    }
  }

  printOfficialHouse(officialHouses, HOUSE_NUM);


  return 0;
}



Measured memory_bytes: 2760
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
typedef long long ll;


int main()
{
    int n,flag=0;
    scanf("%d",&n);
    ll a[n];
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
        if(a[i]==0)
        {
            flag=2;
        }
    }

    ll ans=1;
    int i=0;

    while(flag==0&&i<n)
    {
        if(a[i]>1000000000000000000/ans)
        {
            flag=1;
        }
        else
        {
            ans=ans*a[i];
            i=i+1;
        }
    }

    if(flag==1)
    {
        printf("-1\n");
    }
    else if(flag==2)
    {
        printf("0\n");
    }
    else
    {
        printf("%lld\n",ans);
    }

    return 0;
}

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


bool done[100010];
vector<int> gs[100010];
set< pair<int,int> > es;
vector<int> dbg;
int dfs(int s,int t,int k){
	dbg.push_back(t);
	int tot = 0;
	if( k == 0 ){
		if( s != t and !es.count({s,t}) ){
			es.insert({s,t});
			es.insert({t,s});
			gs[s].push_back(t);
			gs[t].push_back(s);
			tot = 1;
		}
	}else{
		auto w = gs[t];
		for( auto e : w ){
			tot += dfs(s,e,k-1);
		}
	}
	dbg.pop_back();
	return tot;
}

int color[100010];

bool dfs2(int x,int c){
	if( color[x] != -1 ){
		if( color[x] != c ){
			return false;
		}
		return true;
	}
	color[x] = c;
	for( auto e : gs[x] ){
		if( !dfs2(e,!c) ) return false;
	}
	return true;
}

long long sol2(long long  N,long long  M){
	memset(color,-1,sizeof(color));
	if( dfs2(0,0) ){
		long long w = count(color,color+N,1);
		long long b = count(color,color+N,0);
		return w * b - M;
	}else{
		return N * (N-1) / 2 - M;
	}
}

void solve(long long N, long long M, vector<long long> A, vector<long long> B){
	for(int i = 0 ; i < M ; i++){
		gs[A[i]-1].push_back(B[i]-1);
		gs[B[i]-1].push_back(A[i]-1);
		es.insert({A[i]-1,B[i]-1});
		es.insert({B[i]-1,A[i]-1});
	}
	/*
	int ans = 0;
	while(1){
		int sub = 0;
		for(int i = 0 ; i < N ; i++){
			sub += dfs(i, i, 3);
		}
		if(sub==0)break;
		ans += sub; 
	}
	
	
	cout << ans << " " << sol2(N,M) << endl;
	*/
	cout << sol2(N,M) << endl;
}

int main(){	
	long long M;
	long long N;
	scanf("%lld",&N);
	scanf("%lld",&M);
	vector<long long> B(M-1+1);
	vector<long long> A(M-1+1);
	for(int i = 0 ; i <= M-1 ; i++){
		scanf("%lld",&A[i]);
		scanf("%lld",&B[i]);
	}
	solve(N, M, A, B);
	return 0;
}


Measured memory_bytes: 18944
def main():
    H, W = map(int, input().split())
    A = [list(input()) for i in range(H)]
    right = [[0] * W for _ in range(H)]
    left = [[0] * W for _ in range(H)]
    upper = [[0] * W for _ in range(H)]
    under = [[0] * W for _ in range(H)]

    num_max_loc = 0

    for i in range(H):
        tmp_num = 0
        for j in range(W):
            if A[i][j] == "#":
                tmp_num = 0
            else:
                tmp_num += 1
                left[i][j] = tmp_num

    for i in range(H):
        tmp_num = 0
        for j in range(W-1, -1, -1):
            if A[i][j] == "#":
                tmp_num = 0
            else:
                tmp_num += 1
                right[i][j] = tmp_num

    for i in range(W):
        tmp_num = 0
        for j in range(H):
            if A[j][i] == "#":
                tmp_num = 0
            else:
                tmp_num += 1
                upper[j][i] = tmp_num

    for i in range(W):
        tmp_num = 0
        for j in range(H-1, -1, -1):
            if A[j][i] == "#":
                tmp_num = 0
            else:
                tmp_num += 1
                under[j][i] = tmp_num

    for i in range(H):
        for j in range(W):
            tmp_sum = (
                left[i][j] + right[i][j] + upper[i][j] + under[i][j] - 3)
            num_max_loc = max(num_max_loc, tmp_sum)

    print(num_max_loc)


if __name__ == '__main__':
    main()


Measured memory_bytes: 359324
using System;

namespace ABC045A{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            var A = sr.Next<int>();
            var B = sr.Next<int>();
            var H = sr.Next<int>();

            Console.WriteLine((A + B) * H / 2);
            //---------------------------------
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];
        private readonly System.IO.StreamReader _sr = new System.IO.StreamReader(Console.OpenStandardInput());

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = _sr.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var ret = new T[x];
            for(var i = 0; i < x; ++i) ret[i] = Next<T>();
            return ret;
        }

        public T[][] Next<T>(int y, int x){
            var ret = new T[y][];
            for(var i = 0; i < y; ++i) ret[i] = Next<T>(x);
            return ret;
        }
    }
}

Measured memory_bytes: 3032
import java.io.BufferedReader;
import java.io.InputStreamReader;

public final class Main {
	public static void main(String[] args) throws java.lang.Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] s = br.readLine().split(" ");
		int n = Integer.parseInt(s[0]);
		int k = Integer.parseInt(s[1]);
		Solver sol = new Solver();
		System.out.println(sol.solve(n, k));
	}

}

class Solver {

	long solve(int n, int k) {

		return (long) (Math.pow((k - 1), (n - 1)) * k);

	}

}


Measured memory_bytes: 20948
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <utility>
#define INF 1000000000
using namespace std;
typedef pair<int, int> pa;
typedef pair<int, pa> pp;

int M, N;
int ary[100][100], dp[100][100];
bool tay[100][100];
int dxy[5] = { 0,1,0,-1,0 };

int dfs(int dis,int y, int x) {
	tay[y][x] = true;
	int res = dis;
	for (int i = 0; i < 4; i++) {
		int yy = y + dxy[i];
		int xx = x + dxy[i + 1];
		if (1 <= yy&&yy <= N && 1 <= xx&&xx <= M && (!tay[yy][xx]) && (ary[yy][xx])) {
			res = max(res, dfs(dis + 1, yy, xx));
		}
	}
	tay[y][x] = false;
	return res;
}

int solve(int y, int x) {
	if (ary[y][x] == 0) {
		return 0;
	}
	for (int i = 1; i <= N; i++) fill(tay[i], tay[i] + M + 1, false);
	return dfs(1, y, x);
}


int main() {
	while (true) {
		cin >> M >> N;
		if (M == 0 && N == 0) break;
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= M; j++) {
				cin >> ary[i][j];
				dp[i][j] = INF;
			}
		}
		int res = 0;
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= M; j++) {
				res = max(res,solve(i, j));
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

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

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

	vector<int> a(n);

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

	vector<int> cp(a);
	sort(cp.rbegin(), cp.rend());

	for (int i = 0; i < n; i++) {
		int ans = cp[0];
		if (cp[0] == a[i]) {
			ans = cp[1];
		}
		cout << ans << endl;
	}	
}


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

int main(){
  string S;
  cin >> S;
  if(S.at(1)=='B'){
    cout << "ARC" << endl;
  }
  else{
    cout << "ABC" << endl;
  }
}


Measured memory_bytes: 3612
#include <iostream>
 
using namespace std;
 
int main(void){
  int A,B,C,D;
  cin >> A >> B >> C >> D;

  while(1){
    C -= B;
    if(C <= 0){
      cout << "Yes" << endl;
      break;
    }
    A -= D;
    if(A <= 0){
      cout << "No" << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 3624
import java.util.*

fun main(args: Array<String>) {
//    val sc = Scanner(System.`in`)

    val S = Array(3) { ArrayDeque(readLine()!!.toCharArray().toList()) }

    var current = S[0].poll()

    while(true) {
        current = when (current) {
            'a' -> {
                if (S[0].isEmpty()) {
                    println("A")
                    return
                }
                S[0].poll()
            }
            'b' -> {
                if (S[1].isEmpty()) {
                    println("B")
                    return
                }
                S[1].poll()
            }
            'c' -> {
                if (S[2].isEmpty()) {
                    println("C")
                    return
                }
                S[2].poll()
            }
            else -> throw IllegalStateException("")
        }
    }

}

Measured memory_bytes: 34020
#include <cstdio>
#include <string.h>
#include <vector>

int main()
{
    int K, N;
    scanf("%d %d", &N, &K);

    std::vector<double> data( N );

    for (int i = 0; i < N; ++i)
    {
        int d;
        scanf("%d", &d);
        data[i] = d;

        // 期待値 = ((d + 1) / 2);
        data[i] = (data[i] + 1.0) / 2.0;
    }

    double current = 0.0;

    int i = 0;
    // K まで進む
    for (; i < K; ++i)
    {
        current += data[i];
    }
    double max = current;

    // 最初を減らして、最後を追加し、比較する
    for (; i < N; ++i)
    {
        current -= data[i - K];
        current += data[i];
        if (max < current)
        {
            max = current;
        }
    }

    printf("%f\n", (float)max);
}


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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }

inline bool ok(string &s, char c) {
    for(int i = 0; i < s.size(); i++) {
        if (s[i] != c) return false;
    }
    return true;
}

void solve() {
    string s;
    cin >> s;
    int n = s.size();
    
    int ans = 100000;
    for(auto &&c: s) {
        string now = s;
        int cnt = 0;
        while(!ok(now, c)) {
            string s_(now.size() - 1, ' ');
            for(int i = 0; i + 1 < now.size(); i++) {
                if (now[i] == c || now[i + 1] == c) {
                    s_[i] = c;
                } else {
                    s_[i] = now[i];
                }
            }
            now = s_;
            cnt++;
        }
        ans = min(ans, cnt);
    }
    
    cout << ans << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

namespace abc119d
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = ReadIntList();
            var r = S[0];
            var D = S[1];
            var x = S[2];

            for (int i = 0; i < 10; i++)
            {
                x = r * x - D;
                Console.WriteLine(x);
            }

#if DEBUG
            Console.ReadKey();
#endif
        }

        private static bool IsRange(int a, int from, int to) => (from <= a && a <= to);
        private static int ReadInt() => int.Parse(Console.ReadLine());
        private static List<int> ReadIntList() => Console.ReadLine().Split().Select(int.Parse).ToList();
        private static double ReadDouble() => double.Parse(Console.ReadLine());
        private static List<double> ReadDoubleList() => Console.ReadLine().Split().Select(double.Parse).ToList();
        private static long ReadLong() => long.Parse(Console.ReadLine());
        private static List<long> ReadLongList() => Console.ReadLine().Split().Select(long.Parse).ToList();
        private static List<int> Int2Digits(int a) => a.ToString().ToCharArray().Select(_ => int.Parse(_.ToString())).ToList();
        private static int BinarySearch<Type>(IReadOnlyList<Type> s, Type target) // target 以下の最大要素のインデックスを返す
            where Type : IComparable
        {
            var lower = 0;
            var upper = s.Count - 1;
            while (upper - lower > 1)
            {
                var mid = lower + (upper - lower) / 2;
                if (s[mid].CompareTo(target) <= 0)
                {
                    lower = mid;
                }
                else
                {
                    upper = mid;
                }

            }
            return lower;
        }
    }
}


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


int main() {
  const double pi = acos(-1);
  double a, b, h, m;
  cin >> a >> b >> h >> m;

  double hour_angle = (h * 60 + m) / 720 * 2 * pi;
  double minute_angle = m / 60 * 2 * pi;

  double x1 = a * cos(hour_angle);
  double y1 = a * sin(hour_angle);
  double x2 = b * cos(minute_angle);
  double y2 = b * sin(minute_angle);

  cout << fixed << setprecision(12) << sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)) << endl;
  // cout << hypot(x1 - x2, y1 - y2) << endl;
}


Measured memory_bytes: 4132
#include <cstdio>
#include <algorithm>
using namespace std;

const int INF = 1<<30;

int main(){
    int n, cost[9999], dum[2][10010], *dp[2];
    fill(dum[0], dum[0]+10010, INF);
    fill(dum[1], dum[1]+10010, INF);
    dp[0] = dum[0]+5005;
    dp[1] = dum[1]+5005;
    scanf("%d", &n);
    for(int x = 0; x < n-1; x++){
        scanf("%d", cost+x);
    }
    dp[0][1] = 0;
    for(int x = 0; x < n-1; x++){
        for(int y = -n/2; y <= n/2; y++){
            dp[-~x&1][y+1] = min(dp[x&1][y], dp[x&1][-y]+cost[x]);
        }
    }
    printf("%d\n", dp[-~n&1][0]);
    return 0;
}

Measured memory_bytes: 1140
import copy

h,w,k = map(int,input().split())
s = [input() for _ in range(h)]

s1 = [[0]*(w+1) for _ in range(h)]
s12 = [[0]*(w+1) for _ in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == '1':
            s1[i][j+1] = s1[i][j] + 1
        else:
            s1[i][j+1] = s1[i][j]

for i in range(h):
    for j in range(w+1):
        if i == 0:
            s12[i][j] = s1[i][j]
        else:
            s12[i][j] = s12[i-1][j] + s1[i][j]

li = []
ans = 10**10

def make_list():
    global li, h
    if len(li) != h - 1:
        li.append(0)
        make_list()
        li.pop(-1)
        li.append(1)
        make_list()
        li.pop(-1)
    else:
        hantei()

def hantei():
    global li, ans
    tmp = li.count(1)
    tmp_1 = -1
    s2 = []
    s3 = []
    for i in range(h-1):
        if li[i] == 1:
            if tmp_1 == -1:
                s2.append(s12[i])
                tmp_1 = i
            else:
                for j in range(w+1):
                    s3.append(s12[i][j] - s12[tmp_1][j])
                s2.append(s3)
                tmp_1 = i
                s3 = []
    if tmp_1 == -1:
        s2.append(s12[-1])
    else:
        for j in range(w+1):
            s3.append(s12[-1][j] - s12[tmp_1][j])
        s2.append(s3)

    tmp_2 = 0
    for i in range(w+1):
        for j in range(len(s2)):
            if s2[j][i] - s2[j][tmp_2] > k:
                tmp += 1
                tmp_2 = i - 1
                if s2[j][i] - s2[j][tmp_2] > k:
                    tmp += 10**5
                break

    ans = min(ans, tmp)

make_list()

print(ans)


Measured memory_bytes: 45276
#include<stdio.h>

int main(){
int a,b,c = 0;
	scanf("%d %d",&a,&b);
	for(int i=0;i<2;i++){
		if(a<=b){
			c+=b;
			b--;
		}
		else{
			c+=a;
			a--;
		}
	}
	printf("%d\n", c);
	return 0;
}

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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define all(a) a.begin(),a.end()
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    vc t;
    rp(i,s.size()){
        t.pb(s.at(i));
    }
    sort(all(t));
    rp(i,t.size()-1){
        if(t.at(i)==t.at(i+1)){
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    return 0;
}


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

int main(){
  long long n,k;
  cin>>n>>k;
  long long cnt=0;
  vector<pair<long long,long long>>a(n);
  for(long long i=0;i<n;i++)cin>>a[i].first>>a[i].second;
  sort(a.begin(),a.end());
  for(long long i=0;i<n;i++){
    cnt+=a[i].second;
    if(k-1<cnt){
      cout<<a[i].first<<endl;
      return 0;
    }
  }
  return 0;
}
    

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll a,b;
  cin >> a >> b;
  cout << a*b << endl;
}

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

int main(){
  long long int N;
  cin >> N;
  
  long long int ans=1;
  for(long long int i=1; i<=sqrt(N); ++i){
    if(N%i==0){
      ans = i+(N/i)-2;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{   
	int l1,l2,i,j,k,t,m;
   	char S[100],T[50];
   	scanf("%s",S);
   	scanf("%s",T);
   	l1=strlen(S);
   	l2=strlen(T);
   	for(i=l1-1;i>=0;i--)
	{
			for(j=i,m=0;j<i+l2;j++,m++) 
			{
				if(S[j]=='?'||S[j]==T[m])
				continue;
				else
				break;
			} 
			if(j==i+l2)
			{
				for(k=i,m=0;k<i+l2;k++,m++)
				{
					S[k]=T[m];  
				}
				for(k=0;k<l1;k++)
				if(S[k]=='?')
					S[k]='a';
				printf("%s",S);
				return 0;
			}
	}
	printf("UNRESTORABLE\n");
	return 0;
}


Measured memory_bytes: 128
N, H, D = map(int,input().split())
MOD = 10**9 + 7
 
fact = [1]
fact_cum = [0]
for i in range(1,N+1):
  fact.append((fact[-1]*i)%MOD)
  fact_cum.append((fact_cum[-1] + fact[-1])%MOD)
 
ap = [0] * (H+1)
ap_cum = [0] * (H+1)
ap[0] = 1
ap_cum[0] = 1
 
for n in range(1,H+1):
  x = ap_cum[n-1]
  if n > D:
    x -=ap_cum[n-D-1]
  x *= fact_cum[N]
  x %= MOD
  ap[n] = x
  ap_cum[n] = (ap_cum[n-1] + x)%MOD
 
 
ans = ap[H]
ans *= fact[N]
ans %= MOD
ans *= pow(fact_cum[N],MOD-2,MOD)
ans %= MOD
 
print(ans)

Measured memory_bytes: 161356
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define en "\n"
#define LL long long
#define ITER(i,a) for( typeof(a.begin()) i=a.begin();i!=a.end();i++)
#define mod 1000000007
#define mpp make_pair
#define mes(a,b) memset((a),(b),sizeof((a))
typedef map<int,int> MI;
typedef pair<int,int>   PI;
typedef vector<int> VI;
int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string a,b;
    cin>>a>>b;
    int ans=0,k=0,r=0;
    ans=1000000007;
    int l=a.size();
    int p=b.size();
    for(int i=0;i<=l-p;i++)
    {
        k=0;
        r=0;
        for(int j=i;j<i+p;j++)
        {
            if(a[j]==b[r])
            k=k+0;
            else
            k++;
            
            r++;
        }
        if(k<ans)
        ans=k;
        
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ysf (1000000007)

int a[3005],f[3005],n,k,tot,ans;

inline int qpow(int a,int b){
  int ans=1;
  while (b){
    if (b&1) ans=1LL*ans*a%ysf;
    if (b>>=1) a=1LL*a*a%ysf;
  }
  return ans;
}

int main(){
  std::cin>>n>>k;
  for (int i=1;i*i<=n;++i){
    if (n%i) continue; a[++tot]=i;
    if (i*i!=n) a[++tot]=n/i;
  }
  std::sort(a+1,a+tot+1);
  for (int i=1;i<=tot;++i){
    f[i]=qpow(k,(a[i]+1)>>1);
    for (int j=1;j<i;++j)
      if (!(a[i]%a[j])) f[i]-=f[j],f[i]<0?f[i]+=ysf:0;
    ans=(ans+1LL*f[i]*(a[i]&1?a[i]:a[i]/2))%ysf;
  }
  std::cout<<ans; return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        int r = Integer.parseInt(sc.next());
        int g = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());

        int rgb = r*100 + g*10 + b;

        if (rgb % 4 == 0)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}

Measured memory_bytes: 21588
#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;

// ×Ö·û×ªÊý×Ö
int CharToInt(char s[]) {
    int ans = 0, i = 0;
    while (s[i] != '\0') {
        ans = ans * 10 + s[i] - '0';
        i++;
    }
    return ans;
}

int main() {
    char s[1000];
    int a, b;
    stack<int> S;

    while(scanf("%s",s)!=EOF){
            if (s[0] == '+') {
                b = S.top(); S.pop();
                a = S.top(); S.pop();
                S.push(a + b);
            }else if (s[0] == '-') {
                b = S.top(); S.pop();
                a = S.top(); S.pop();
                S.push(a - b);
            }else if (s[0] == '*') {
                b = S.top(); S.pop();
                a = S.top(); S.pop();
                S.push(a * b);
            }else {
                S.push(CharToInt(s));
            }
    }
    printf("%d\n", S.top());

    return 0;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);

    // cout << 1.0 / 2 << endl;
    
    int n, m, d; cin >> n >> m >> d;

    // 隣り合う二項はm-1個ある
    // (a, b)並んでいた場合の期待値を求めて、それをm-1倍する

    double ans = 0.0;

    double e = 0.0;

    if (d == 0) {
        e = double(1.0) / n;
    } else {
        e = double(2.0);
        ll n2 = ll(n) * n;
        e *= (n-d);
        e /= n2;
    }
    cout << e * (m-1) << endl;
    return 0;
}

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

 
int main(){
  
  ll n,k;
  //double keta;
  cin>>n>>k;
  double value = log(n) / log(k);
  cout<<int(value)+1<<endl;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint a,b,v,w,t;
    cin >> a>>v>>b>>w>>t;
    lint d = abs(b - a);
    if (v * t >= w * t + d){
        cout << "YES" << "\n";
    }else{
        cout << "NO"
             << "\n";
    }
    return 0;
}

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

const int SIZE = 50100;
bool isP[SIZE];
  
int main(){
	fill(isP, isP+SIZE+1, true);
	for(int i = 2; i <= SIZE; i++){
		if(isP[i]){
			for(int j = i*2; j <= SIZE; j += i){
				isP[j] = false;
			}
		}
	}

	int n;

	while(cin >> n){
		for(int i = n-1; i >= 2; i--){
			if(isP[i]){
				cout << i << " ";
				break;
			}
		}
		for(int i = n+1; i <= SIZE; i++){
			if(isP[i]){
				cout << i << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N;
    cin >> N;
    string S,T;
    cin >> S >> T;
    string ans = S.substr(0,1) + T.substr(0,1);
    for (int i = 1; i < N; i++){
        ans += S.substr(i,1) + T.substr(i,1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
// Rustで競技プログラミングの入力をスッキリ記述するマクロ
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8

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

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

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

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

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

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

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

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

fn main() {
  input! {
      n: usize
  };
  println!("{}", n * (n - 1) / 2);
}


Measured memory_bytes: 4352
h,w=map(int,input().split())
s=set()
a=[]
from collections import deque
q=deque([])
for i in range(h):
    tmp=list(input())
    a.append(tmp)
    for j in range(w):
        if tmp[j]=="#":
            q.append((i,j,0))

ans=0
ll=[[0,1],[0,-1],[1,0],[-1,0]]
while q:
    x,y,v=q.popleft()
    ans=max(ans,v)
    for i,j in ll:
        if 0<=x+i<h and 0<=y+j<w and a[i+x][j+y]==".":
            a[i+x][j+y]="#"
            q.append((i+x,j+y,v+1))

print(ans)





Measured memory_bytes: 158940
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;

struct SideLine{
	int h;
	int l;
	int r;
};
bool myless(const SideLine& l, const SideLine& r) { return r.h < l.h; }
bool mygreater(const SideLine& l, const SideLine& r) { return r.h > l.h; }

int main(void) {
	int peoNum, sideLineNum, design;
	while (cin >> peoNum >> sideLineNum >> design, peoNum) {
		if (sideLineNum == 0) {
			cout << design << endl;
			continue;
		}

		vector<SideLine> lines(sideLineNum);
		for (int li = 0; li < sideLineNum; li++) {
			cin >> lines[li].h >> lines[li].l >> lines[li].r;
		}

		sort(lines.begin(), lines.end(), myless);

		int nowLine = design;
		for (int li = 0; li < sideLineNum; li++) {
			if (lines[li].l == nowLine) {
				nowLine = lines[li].r;
			}else if (lines[li].r == nowLine) {
				nowLine = lines[li].l;
			}
		}
		
		cout << nowLine << endl;
	}

	return 0;
}

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


int main()
{
    int N, M;
    cin >> N >> M;

    int ans = 0;
    if (N >= 2)
    {
        ans += N * (N - 1)/2;
    }
    if ( M >= 2){
        ans += M * (M - 1)/2;
    }
    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

int main() {
    int H,W; cin>>H>>W;
    string S;

    vector<int> cnt(26,0);
    for (int i = 0; i < H; ++i) {
        cin>>S;
        for(char c:S) cnt[c-'a']++;
    }

    int four=(H/2)*(W/2),one=(H%2)*(W%2);
    int two=H*W-four-one;

    for (int i = 0; i < 26; ++i) {
        int tmp=cnt[i]/4;
        four-=tmp;
        cnt[i]-=tmp*4;
    }

    if(four>0){
        cout<<"No"<<endl;
        return 0;
    }

    int oddcnt=0;
    for (int i = 0; i < 26; ++i) {
        oddcnt+=(cnt[i]%2);
    }

    if(oddcnt==one){
        cout<<"Yes"<<endl;
        return 0;
    }

    cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
clock_t t=clock();
namespace my_std{
	using namespace std;
	#define pii pair<int,int>
	#define fir first
	#define sec second
	#define MP make_pair
	#define rep(i,x,y) for (int i=(x);i<=(y);i++)
	#define drep(i,x,y) for (int i=(x);i>=(y);i--)
	#define go(x) for (int i=head[x];i;i=edge[i].nxt)
	#define templ template<typename T>
	#define sz 101001
	typedef long long ll;
	typedef double db;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
	templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
	templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
	templ inline void read(T& t)
	{
		t=0;char f=0,ch=getchar();double d=0.1;
		while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
		while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
		if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
		t=(f?-t:t);
	}
	template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
	char __sr[1<<21],__z[20];int __C=-1,__zz=0;
	inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
	inline void print(register int x)
	{
		if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
		while(__z[++__zz]=x%10+48,x/=10);
		while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
	}
	void file()
	{
		#ifdef NTFOrz
		freopen("a.in","r",stdin);
		#endif
	}
	inline void chktime()
	{
		#ifdef NTFOrz
		cout<<(clock()-t)/1000.0<<'\n';
		#endif
	}
	#ifdef mod
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
	ll inv(ll x){return ksm(x,mod-2);}
	#else
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
	#endif
//	inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;

int n;
int a[sz],b[sz];
pii w[sz<<1];ll sum[sz<<1];
int p1[sz],p2[sz];

int main()
{
	file();
	read(n);
	rep(i,1,n) read(a[i],b[i]),w[i*2-1]=MP(a[i],i),w[i*2]=MP(b[i],i);
	sort(w+1,w+n+n+1);
	int x;
	rep(i,1,n+n) x=w[i].sec,p2[x]=p1[x],p1[x]=i,sum[i]=sum[i-1]+w[i].fir;
	ll s1=0,s2=0;
	rep(i,1,n) s1+=a[i],s2+=b[i];
	ll ans=min(s1,s2);
	rep(i,1,n)
	{
		int j=n;
		while (j-(p1[i]<=j)-(p2[i]<=j)<n) ++j;
		ll cur=sum[j]; 
		if (p1[i]<=j) cur-=w[p1[i]].fir;
		if (p2[i]<=j) cur-=w[p2[i]].fir;
		chkmin(ans,cur);
	}
	cout<<ans;
	return 0;
}


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

#define INF 1LL << 60
#define pb push_back
#define loop_type int
#define REP(i, n) for (loop_type i = 0; i < (loop_type)(n); i++)
#define REPR(i, b, e) for (int i = (b); i <= (e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

ll X, Y, Z, K, A[1005], B[1005], C[1005];
vector<ll> res;

int main() {
    cin.tie(0);
    cin >> X >> Y >> Z >> K;
    REP(i, X) cin >> A[i];
    REP(i, Y) cin >> B[i];
    REP(i, Z) cin >> C[i];
    sort(A, A+X, greater<ll>());
    sort(B, B+Y, greater<ll>());
    sort(C, C+Z, greater<ll>());

    REP(i, X) {
        REP(j, Y) {
            REP(k, Z) {
                if ((i + 1) * (j + 1) * (k + 1) <= K)
                    res.pb(A[i] + B[j] + C[k]);
                else
                    break;
            }
        }
    }
    sort(res.begin(), res.end(), greater<ll>());
    REP(i, K) {
        cout << res[i] << "\n";
    }

    return 0;
}


Measured memory_bytes: 1400
import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    A = [[] for _ in range(N)]
    for i in range(N):
        for _ in range(inputInt()):
            A[i].append(inputIntList())
    ret = 0
    for i in range(2 ** N):
        bits = [i >> j & 1 for j in range(N)]
        for i, a in enumerate(A):
            if bits[i] == 0:
                continue
            for x, y in a:
                # print(bits, bits[x - 1], y)
                if bits[x - 1] == y:
                    continue
                break
            else:
                continue
            break
        else:
            ret = max(ret, sum(bits))
    return ret


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


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	int N, M, K; cin >> N >> M >> K;
	vector<int64> A(N), B(M);
	for (int i = 0; i < N; ++i) cin >> A[i];
	for (int i = 0; i < M; ++i) cin >> B[i];
	int64 t = 0;
	int ans = 0;
	int j = M;
	for (int i = 0; i < M; ++i) t += B[i];
	//しゃくとり法
	//Aの本をN冊分時間を加算したいので、iはNまでループさせる
	for (int i = 0; i < (N + 1); ++i) {
		//jは指している本を諦めた状態、j冊分の本を読んだことを意味する
		//Ex.j = 2 (2番目の本を諦め、0,1番目の本を読んだ状態)
		while (j > 0 && t > K) {
			--j;
			t -= B[j];
		}	
		//t > Kのまま、j = 0(諦めるBの本がない状態)となった場合は詰みなので終了する
		if (t > K) break;
		ans = max(ans, i + j);
		//配列外参照を防ぐ
		if (i == N) break;
		//次はAの本を1冊読んだ時間を加算していく
		t += A[i];
	}
	cout << ans << endl;
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 6376
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string S;
    cin >> S;
    if(S.at(2)==S.at(3)&&S.at(4)==S.at(5)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	A := sc.nextIntSlice(N)
	count := make(map[int]bool)
	s, e := 1, 399
	for i := 0; i < 8; i++ {
		for _, v := range A {
			if s <= v && v <= e {
				count[i] = true
			}
		}
		if i == 0 {
			s += 399
		} else {
			s += 400
		}
		e += 400
	}
	over := 0
	for _, v := range A {
		if 3200 <= v {
			over++
		}
	}

	fmt.Fprintln(wtr, max(1, len(count)), len(count)+over)
	wtr.Flush()
}


Measured memory_bytes: 640
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

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

		int n = scan.nextInt();
		Set<String> set = new HashSet<String>();
		for (int i = 0; i < n; i++) {
			String op = scan.next();

			if ("insert".equals(op)) {
				set.add(scan.next());
			} else if ("find".equals(op)) {
				if (set.contains(scan.next())) {
					System.out.println("yes");
				}
				else {
					System.out.println("no");
				}
			}
		}

		scan.close();

	}

}

Measured memory_bytes: 268316
def main():
	n,k = map(int, input().split())
	r,s,p = map(int,input().split())
	t = list(input())
	t_winer = [ '' for _ in range(n)]
	t_point = [ 0 for _ in range(n)]
	
	for i in range(n):
		if t[i] == 'r':
			t_winer[i] = 'p'
			t_point[i] = p
		elif t[i] == 's':
			t_winer[i] = 'r'
			t_point[i] = r
		else:
			t_winer[i] = 's'
			t_point[i] = s
	for i in range(k,n):
		if t_winer[i-k] == t_winer[i]:
			t_winer[i] = '-'
			t_point[i] = 0
	print(sum(t_point))

if __name__ == '__main__':
	main()

Measured memory_bytes: 5560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<ll, ll>;

P sub(ll h, ll w){
    if(h % 2 == 0 || w % 2 == 0) return P(h*w/2, h*w/2);
    if(h > w) swap(h, w);
    ll l = w / 2;
    return P(h * l, h * (w - l));
}

int main(){
    ll H, W;
    cin >> H >> W;
    ll ans = H * W;
    for(ll h = 1; h <= H - 1; ++h){
        vector<ll> a(3);
        a[0] = h * W;
        auto p = sub(H - h, W);
        a[1] = p.first; a[2] = p.second;
        sort(ALL(a));
        ans = min(ans, a[2] - a[0]);
    }
    for(ll w = 1; w <= W - 1; ++w){
        vector<ll> a(3);
        a[0] = w * H;
        auto p = sub(W - w, H);
        a[1] = p.first; a[2] = p.second;
        sort(ALL(a));
        ans = min(ans, a[2] - a[0]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import deque


L = list(input().strip())
que = deque(L)
Q = int(input())
flip = False
for i in range(Q):
    q = list(map(str, input().split()))
    if len(q) == 1:
        flip = not flip
    else:
        t, f, c = q
        if flip is False and f == '1':
            que.appendleft(c)
        if flip is False and f == '2':
            que.append(c)
        if flip is True and f == '1':
            que.append(c)
        if flip is True and f == '2':
            que.appendleft(c)

if flip:
    que.reverse()

print(''.join(que))


Measured memory_bytes: 9452
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	int n; cin >> n;
	int cnt[8] = {}; int rest = 0;
	rep(i, n) {
		int a;
		cin >> a;
		rep(j, 8) {
			if (a < 400 * (j + 1)) {
				cnt[j]++; break;
			}
			if (j == 7)rest++;
		}
	}
	int mi = 0; 
	rep(i, 8) {
		if (cnt[i])mi++;
	}
	int ma = mi + rest;
	if (mi == 0)mi++;
	cout << mi << " " << ma << endl;
	return 0;
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let s: Vec<char> = iter.next().unwrap().chars().collect();

    let ans = s
        .split(|c| !"AGCT".contains(&c.to_string()))
        .map(|x| x.len())
        .max()
        .unwrap();

    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int value_num = sc.nextInt();
		int[] values = new int[value_num];
		for (int i = 0; i < value_num; i++) {
			values[i] = sc.nextInt();
		}
		printArray(values);

		for (int out_i = 1; out_i < value_num; out_i++) {
			int in_i = out_i - 1;
			int subjectOfSort = values[out_i];
			while (in_i >= 0 && values[in_i] > subjectOfSort) {
				values[in_i + 1] = values[in_i];
				in_i--;
			}
			values[in_i + 1] = subjectOfSort;
			printArray(values);
		}
	}
	public static void printArray(int[] array) {
		for (int print_i = 0; print_i < array.length; print_i++) {
			if (print_i != 0) {
				System.out.print(" ");
			}
			System.out.print(array[print_i]);
		}
		System.out.print("\n");
	}
}


Measured memory_bytes: 33884
mod=10 ** 9 + 7

n, a, b = map(int, input().split())

def power(x,n):
    if n==0:
        return 1
    elif n%2==0:
        half=power(x,n//2)
        return half**2 %mod
    else:
        half=power(x,(n-1)//2)
        return  half**2 * x %mod

def binomial(n,k):
    x=1
    y=1
    for i in range(k):
        x=x*(n-i)%mod
        y=y*(i+1)%mod
    return x*power(y,mod-2)%mod

ans=(power(2,n)-1 - binomial(n,a) -binomial(n,b))%mod

print(ans)

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

int selectionSort(int A[], int N) {
        int minj,cnt = 0;

        for (int i=0;i<N;i++) {
        minj = i;
        for (int j=i+1;j<N;j++) {
        if (A[j] < A[minj])
        minj = j;
        }
        if (i != minj) {
        swap(A[i],A[minj]);
        cnt++;
        }
        }
        return cnt;
}

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

        cnt = selectionSort(A,N);
        for (int i=0;i<N;i++)
        { if (i) cout << " ";
          cout << A[i];
        }
        cout << endl;
        cout << cnt << endl;

        return 0;
}

Measured memory_bytes: 3036
#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;
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};

vector<int> sieve_of_eratosthenes(){
    int MAX = 55556;
    vector<int> is_prime(MAX, 1);
    is_prime[0] = is_prime[1] = 0;
    for(int i=2; i<MAX; ++i){
        if(!is_prime[i]) continue;
        for(int j=i*2; j<MAX; j+=i) is_prime[j] = 0;
    }

    return is_prime;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> is_prime = sieve_of_eratosthenes();
    vector<int> primes;
    rep(i, 55556){
        if (is_prime[i]){
            if (i%5==1) primes.push_back(i);
        }
    }
    rep(i, n){
        cout << primes[i] << ' ';
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

struct Edge{
  int to,cost;
  Edge(int t,int c):to(t),cost(c){};
};

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n,m,r;
  cin>>n>>m>>r;
  std::vector<int> dest;
  for(int i=0;i<r;i++){
    int tmp;
    cin>>tmp;
    dest.push_back(tmp);
  }
  std::vector<Edge> node[201];
  for(int i=0;i<m;i++){
    int a,b,c;
    cin>>a>>b>>c;
    node[a].push_back(Edge(b,c));
    node[b].push_back(Edge(a,c));
  }
  const int INF=INT32_MAX/3;
  int mincost[201][201]={};
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      if(i==j){
        mincost[i][j]=0;
      }else{
        mincost[i][j]=INF;
      }
    }
  }
  for(int i=1;i<=n;i++){
    for(auto e:node[i]){
      mincost[i][e.to]=e.cost;
    }
  }

  for(int k=1;k<=n;k++){
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
        mincost[i][j]=std::min(mincost[i][j],mincost[i][k]+mincost[k][j]);
      }
    }
  }

  int result=INT32_MAX;
  std::sort(dest.begin(), dest.end());
  do{
    int tmp_result=0;
    for(int i=1;i<r;i++){
      tmp_result+=mincost[dest[i-1]][dest[i]];
    }
    result=std::min(result,tmp_result);
  }while(std::next_permutation(dest.begin(),dest.end()));

  cout<<result<<endl;


  return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main()
{
		string s;
  cin>>s;
  int max=0,c=0;
  	for(int i=0;i<s.length();i++)
    {
		if(s[i]=='A'||s[i]=='T'||s[i]=='G'||s[i]=='C')
          c++;
      	else
          c=0;
      if(c>max)
        	max=c;
    }
 	cout<<max;
}


Measured memory_bytes: 256
import java.util.Scanner

/**
 * Created by sonetsuyoshi on 2015/12/16.
 */

object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt
  val a = Array.fill(n)(sc.nextLong)

  run()

  def run(): Unit = {
    val s = a.sum
    val c = n.toLong * (n + 1) / 2

    if(s % c != 0) {
      println("NO")
      return
    }

    val k = s / c

    val d = for(i <- 0 until n) yield a((i + 1) % n) - a(i)

    if(d.exists(x => x > k || (k - x) % n != 0)) println("NO")
    else println("YES")
  }
}

Measured memory_bytes: 55896