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

int hms2sec(string hms){
    int h = 10*(hms[0]-'0') + (hms[1]-'0');
    int m = 10*(hms[3]-'0') + (hms[4]-'0');
    int s = 10*(hms[6]-'0') + (hms[7]-'0');

    return 3600*h + 60*m + s;
}

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

    while(1){
        int n;
        cin >> n;

        if(n == 0) break;

        const int DAY = 24 * 60 * 60;

        vector<int> imos(DAY+10);
        rep(i, n){
            string fr_str, to_str;
            cin >> fr_str >> to_str;

            int from = hms2sec(fr_str);
            int to = hms2sec(to_str);

            ++imos[from];
            --imos[to];
        }
        int res = 0;
        rep1(i, DAY+10){
            imos[i] += imos[i-1];
            res = max(res, imos[i]);
        }

        cout << res << endl;

    }

    return 0;
}


Measured memory_bytes: 3504
#include <bits/stdc++.h>
#include <string>
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>

#define fir first
#define sec second
#define get(n) scanf("%d",&n);
#define gets(s) string s;cin >> (s);
#define All(s) (c).begin(), (c).end()
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define rep(i, j) for (int (i)=0;(i)<(j);(i)++)
#define repk(i, j, k) for(int (i)=(j);(i)<(k);(i)++)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long int ll;
const ll INF = 10241024;
int N, K;
string S;

void input(){
    cin >> N >> K >> S;
}

void solve(){
    input();
    int score = 0;
    rep(i, N-1){
        if(S[i] == S[i+1]) score++;
    }

    int ans = min(score+2*K, N-1);
    cout << ans << endl;
}
int main(){
    solve();
    return 0;
}

Measured memory_bytes: 512
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################


n , k = map(int , input().split())
arr = list(map(int , input().split()))
arr.sort()
print(sum(arr[:k]))








Measured memory_bytes: 9572
#include <stdio.h>

int main(){
    int r,d,a[11],i;
    scanf("%d %d %d",&r,&d,&a[0]);
    
    for(i=0;i<10;i++){
        a[i+1]=r*a[i]-d;
    }

    for(i=1;i<=10;i++){
        printf("%d\n",a[i]);
    }
    
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>

using namespace std;

string s,t;

int main(){
  cin>>s;
  cin>>t;

  int p = s.size()-t.size();

  int match = 0;
  for(int i = 0;i+t.size()<=s.size();i++){
    int tmp = 0;
    for(int j = 0;j<t.size();j++){
      if(s[j+i] == t[j] ||s[j+i] =='?'){
	tmp++;
      }
    }
    if(tmp >= match){
      match = tmp;
      p = i;
    }
  }
  // cout<<p<<"\t"<<match<<endl;
  if(match==t.size())
    s.replace(p,t.size(),t);
  for(int i = 0;i<s.size();i++){
    if(s[i] == '?')
      s[i] = 'a';
  }
  if((int)s.find(t)!=-1){
    cout<<s<<endl;
  }else{
    cout<<"UNRESTORABLE"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
N = int(input())
s = []
for i in range(N):
  s.append(int(input()))

s.sort()
ans = sum(s)
if ans % 10 == 0:
  fil = list(filter(lambda x: x % 10 != 0, s))
  if len(fil) == 0:
    print(0)
  else:
    print(ans - fil[0])
else:
  print(ans)

Measured memory_bytes: 9056
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;

class in {
  int n;
public:
  in() {}
  in(int n_) : n(n_){};
  template <class T> operator T() { T ret; cin >> ret; return ret; }
  template <class T> operator vector<T>() { vector<T> ret(n); for (int i = 0; i < n; i++) cin >> ret[i]; return ret; }
};

template <std::uint_fast64_t Mod> class modint {
  using u64 = std::uint_fast64_t;
  u64 a;
  friend ostream& operator<<(ostream& os, const modint& m);
public:
  constexpr modint(const u64 x = 0) noexcept : a(x % Mod) {}
  constexpr u64 val() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; }
  constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; }
  constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; }
  constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; }
  constexpr bool operator==(const modint rhs) const noexcept { return modint(*this).val() == rhs.val(); }
  modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Mod) a -= Mod; return *this; }
  modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) a += Mod; a -= rhs.a; return *this; }
  modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Mod; return *this; }
  modint &operator/=(modint rhs) noexcept { u64 exp = Mod - 2; while (exp) { if (exp % 2) *this *= rhs; rhs *= rhs; exp /= 2; } return *this; }
};
const ll mod=(ll)1e9+7;
using mint = modint<mod>;
ostream& operator<<(ostream& os, const mint& m){ return os << m.a; }
//}}}

const int kMaxBit = 64;
int bit[kMaxBit];

int main(){
  int N = in();
  vector<ll> A = in(N);

  mint ans = 0;
  rep(i, N){
    rep(b, kMaxBit){
      bit[b] += ((A[i] >> b) & 1);
    }
  }
  rep(i, N){
    rep(b, kMaxBit){
      if(((A[i] >> b) & 1)){
        ans += (1LL << b) % mod * (N - bit[b]);
      }else{
        ans += (1LL << b) % mod * bit[b];
      }
    }
  }
  ans /= 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define int llint
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define PI 3.1415926535897
#define EPS (1e-10)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


int N, M;
int fact[200010];
int invFact[200010];
MII fNum;


void makeFact(){
	int n = 200000;
	fact[0] = 1;
	repe(i, 1, n) fact[i] = MUL(fact[i-1], i);
	int m = MOD-2;
	int pow = fact[n];
	invFact[n] = 1;
	do {
		if(m&1) invFact[n] = MUL(invFact[n], pow);
		pow = MUL(pow, pow);
	} while(m>>=1);
	repr(i, n, 0) invFact[i] = MUL(invFact[i+1], i+1);
}


void factorize(){
	int n = M;
	repif(i, 2, i*i <= n)
		while(n%i == 0) n/=i, fNum[i]++;
	if(n != 1) fNum[n]++;
}


int comb(int n, int k){
	if(n < k) return 0;
	if(n < 0 || k < 0) return 0;
	return MUL(fact[n], MUL(invFact[k], invFact[n-k]));
}


int solve(){
	int ans = 1;
	for(PII p : fNum){
		int k = p.se;
		ans = MUL(ans, comb(k+N-1, k));
	}
	return ans;
}


signed main(){
	cin >> N >> M;

	makeFact();
	factorize();

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int ratingNow;
  int prformance;
  int ratingTarget;
  cin >> ratingNow;
  cin >> prformance;
  ratingTarget = 2*prformance - ratingNow;
  cout << ratingTarget << endl;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  if (s + t[t.length()-1] == t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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


using namespace std;

typedef long long int llint;
#define abs absolute

struct node
{
    llint x, y, id;
};

struct edge
{
    llint start, end, weight;
};

inline llint absolute (llint a)
{
    return (a > 0) ? a : (- a);
}

inline bool x_asc (node a, node b)
{
    return (a.x < b.x);
}

inline bool y_asc (node a, node b)
{
    return (a.y < b.y);
}

inline bool weight_asc (edge a, edge b)
{
    return (a.weight < b.weight);
}

inline llint ancestor_recursive_search (vector <llint>& parent, llint id)
{
    // find ancestors recursively
    if (parent[id] != id) parent[id] = ancestor_recursive_search(parent, parent[id]);
    return parent[id];
}

int main(int argc, char const *argv[])
{
    llint length; cin >> length;
    vector <node> city (length);
    for (llint i = 0 ; i <= length - 1 ; i++)
    {
        cin >> city[i].x >> city[i].y; city[i].id = i;
    };
    
    // sort by x-diff to compute sides from x-diff

    sort (city.begin(), city.end(), x_asc);
    vector <edge> roads;
    for (llint i = 0 ; i <= length - 2 ; i++)
    {
        edge tmp;
        tmp.start = city[i].id; tmp.end = city[i + 1].id;
        tmp.weight = abs(city[i].x - city[i + 1].x);
        roads.push_back(tmp);
    };

    // sort by Y-diff to compute sides from y-diff

    sort (city.begin(), city.end(), y_asc);
    for (llint i = 0 ; i <= length - 2 ; i++)
    {
        edge tmp;
        tmp.start = city[i].id; tmp.end = city[i + 1].id;
        tmp.weight = abs(city[i].y - city[i + 1].y);
        roads.push_back(tmp);
    };

    // parent record to compute MST

    vector <llint> parent (length);
    for (llint i = 0 ; i <= length - 1 ; i++) parent[i] = i;

    // sort sides for easier computation

    sort(roads.begin(), roads.end(), weight_asc);

    // MST computation from sides formed from both sources (x-diff and y-diff)

    llint out = 0;
    for (edge i : roads)
    {   
        // find both vertices' ancestor(s)
        llint start_vertex_ancestor = ancestor_recursive_search(parent, i.start), end_vertex_ancestor = ancestor_recursive_search(parent, i.end);

        // if they're not identical
        // then add to MST
        if (start_vertex_ancestor != end_vertex_ancestor)
        {
            // add to total weight
            out += i.weight;
            // and rewrite parent record
            parent[end_vertex_ancestor] = start_vertex_ancestor;
        }
    };

    cout << out;
}

Measured memory_bytes: 10864
#include <bits/stdc++.h>
using namespace std;
int a, b, c;
int main() {
    bool flg = false;
    cin >> a >> b >> c;
    if(a == b || b == c || c == a) {
        flg = true;
    }
    if(a == b && b == c) {
        flg = false;
    }

    if(flg) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

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

struct Clothes {
	int a, b, c;
};

int main() {
	int dp[201][200] = {};
	int d, n, mt[200];
	Clothes clothes[200];

	cin >> d >> n;
	REP(i, d) scanf("%d", &mt[i]);
	REP(i, n) scanf("%d %d %d", &clothes[i].a, &clothes[i].b, &clothes[i].c);
	
	REP(i, d - 1) {
		REP(j, n) {
			if (clothes[j].a > mt[i] || clothes[j].b < mt[i]) continue;
			REP(k, n) {
				if (clothes[k].a > mt[i+1] || clothes[k].b < mt[i+1]) continue;
				dp[i+1][k] = max(dp[i+1][k], dp[i][j] + abs(clothes[k].c - clothes[j].c));
			}
		}
	}

	int ans = 0;
	REP(i, n) ans = max(ans, dp[d - 1][i]);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1412
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		long[][]p = new long[n + 1][2];
		for(int i = 0; i < n; i++) {
			long x = scan.nextLong();
			long y = scan.nextLong();
			long[]t = {x, y};
			p[i] = t;
		}
		p[n] = p[0];
		scan.close();
		for(int i = 0; i < n; i++) {
			long s = area(p[(i - 1 + n) % n], p[i], p[i + 1]);
			long t = area(p[i], p[i + 1], p[(i + 2) % n]);
			if(s * t < 0) {
				System.out.println(0);
				System.exit(0);
			}
		}
		System.out.println(1);
	}
	static long area(long[]x, long[]y, long[]z) {
		return (cross(vec(z, x), vec(z, y)));
	}
	static long cross(long[]u, long[]v) {
		return u[0] * v[1] - u[1] * v[0];
	}
	static long[] vec(long[]p1, long[]p2) {
		long[]u = {p2[0] - p1[0], p2[1] - p1[1]};
		return u;
	}
}


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

const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if(n < k) return 0;
  if(n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long n, k, res = 0;
vector<long long> a;

int main() {
  COMinit();
  cin >> n >> k;
  a.resize(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  sort(a.begin(), a.end());

  for(int i = 0; n - i >= k; ++i) {
    res += COM(n - i - 1, k - 1) *
           ((a[n - i - 1] - a[i] + MOD + MOD) % MOD) % MOD;
    res %= MOD;
  }

  cout << res << endl;

}



Measured memory_bytes: 24448
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace AOJ0087
{
    class Program
    {
        private static readonly Dictionary<string, Func<Expression, Expression, Expression>> BinaryOperators =
            new Dictionary<string, Func<Expression, Expression, Expression>>
            {
                {"+", Expression.Add},
                {"-", Expression.Subtract},
                {"*", Expression.Multiply},
                {"/", Expression.Divide}
            };

        static void Main()
        {
            ReadInputs()
                .Select(line => line.Split(' '))
                .Select(operations =>
                {
                    var stack = new Stack<Expression>();
                    foreach (var operation in operations)
                    {
                        if (BinaryOperators.ContainsKey(operation))
                        {
                            var right = stack.Pop();
                            var left = stack.Pop();
                            stack.Push(BinaryOperators[operation](left, right));
                        }
                        else
                        {
                            stack.Push(Expression.Constant(double.Parse(operation)));
                        }
                    }

                    return Expression.Lambda<Func<double>>(stack.Pop()).Compile()();
                })
                .ForEach(Console.WriteLine);
        }

        private static IEnumerable<string> ReadInputs()
        {
            string line;
            while ((line = Console.ReadLine()) != null)
            {
                yield return line;
            }
        }
    }

    public static class EnumerableExtensions
    {
        public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
        {
            foreach (var item in source)
            {
                action(item);
            }
        }
    }
}

Measured memory_bytes: 11572
/* ****TCIITB**** */

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

#define N  100005

int main()
{
	
	io
	ll n,k;
	cin>>n>>k;
	string x;
	cin>>x;
	x[k-1]=char(x[k-1]-'A'+'a');
	cout<<x;

}

Measured memory_bytes: 764
# D - RGB Triplets
N = int(input())
S = input()
r,b,g = 0,0,0
for i in range(N):
    if S[i]=='R':
        r += 1
    elif S[i]=='G':
        g += 1
    else:
        b += 1
ans = r*g*b
for i in range(N):
    for j in range(i+1,N):
        k = 2*j-i
        if k<N and S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans -= 1
print(ans)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
//constant
const long long MOD = 1e9+7;
//const long long MOD = ;
const long long INF_LL = 1e18+3; const int INF_int = 1e9;
//Macro
#define ll long long
#define rep(i,n) for(int i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
//Debuging tools
#define Debug_Output_ALL(a) for(auto itr = a.begin();itr!=a.end();itr++) cout << *itr << " ";cout << endl;
///library
//@brief make vector of primes (meets some requirements) less than a.
template <typename T>
std::vector<T> makeprimes(T a,auto requirement = [](T x){return true;}){
    bool ok[a];
    fill_n(ok,a,true);
    for(T i = 2;i<a;i++) if(ok[i]) for(int j = 2*i;j<a;j+=i) ok[j] = false;
    std::vector<T> ret;
    for(T i = 2;i<a;i++) if(ok[i] && requirement(i)) ret.push_back(i);
    return ret;
}
//DataStructure
int main(){
    int n;
    cin >> n;
    long maxn = 1e5;
    std::vector<long> primes = makeprimes(maxn,[](long a){if(a%5==1) return true;else return false;});
    rep(i,n) cout << primes[i] << " ";
}


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

#define f(i,a,b) for (int i = a; i <b ; i++)

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	clock_t start = clock();
#endif

	int n,m; cin >> n >> m;
	int cnt[n];
	fill(cnt,cnt+n,0);
	f(i,0,m) {
		int a,b; cin>>a>>b;
		cnt[--a]++; cnt[--b]++;
	}
	bool found = 0;
	f(i,0,n) found |= cnt[i]&1;
	cout << (found?"NO":"YES") << endl;

#ifdef LOCAL
	cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
#endif
	
	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    
    int n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    string c,d;
    c ="";
    d ="";
    for(int i=0;i<q;i++)
    {
        char cc,dd;
        cin>>cc>>dd;
        c+=cc;
        d+=dd;
    }
    int l=-1,r=n;
    int mid = l+((r-l)/2);
    int l_max=-1;
    for(int i=0;i<80;i++)
    {
        if(l+1<r)
        {
            mid = l+((r-l)/2);
            int index = mid;
            char val = s[index];
            bool reached = false;
            for(int j=0;j<q;j++)
            {
                if(c[j]==val&&d[j]=='L')
                {
                    index--;
                }
                else if(c[j]==val&&d[j]=='R')
                {
                    index++;
                }
                if(index ==-1)
                {
                    reached=true;
                    break;
                }
                else if (index ==n)
                    break;
                val = s[index];      
            }
            if(reached)
            {
                l = mid;
                l_max = mid;
            }
            else
                r = mid;
        }
        else
        {
            break;
        }
    }

    l=-1,r=n;
    mid = l+((r-l)/2);
    int r_max=n;
    for(int i=0;i<80;i++)
    {
        if(l+1<r)
        {
            mid = l+((r-l)/2);
            int index= mid;
            char val = s[index];
            bool reached = false;
            for(int j=0;j<q;j++)
            {
                if(c[j]==val&&d[j]=='L')
                {
                    index--;

                }
                else if(c[j]==val&&d[j]=='R')
                {
                    index++;
                }
                if(index == n)
                {
                    reached=true;
                    break;
                }      
                else if (index ==-1)
                    break;
                val = s[index];      
            }
            if(reached)
            {
                r = mid;
                r_max = mid;
            }
            else
                l = mid;
        }
        else
        {
            break;
        }
    }
    l_max++;
    r_max--;

    cout<<max(0,r_max-l_max+1);
    return 0;
}

Measured memory_bytes: 1044
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define per(i,a,n) for (int i=(n)-1;i>=(a);i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef long double DB;
mt19937 mrand(random_device{}()); 
const LL mod=1000000007;
int rnd(int x) { return (int)mrand() % x;}
LL powmod(LL a,LL b) { LL res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
LL gcd(LL a,LL b) { return b?gcd(b,a%b):a;}
// head

const int N=111;
int n,x;
int vis[N];
int main() {
	scanf("%d%d",&x,&n);
	rep(i,0,n) {
		int d;
		scanf("%d",&d);
		vis[d]=1;
	}
	int mindiff=100100;
	int ans=0;
	rep(i,-1,102) if (!vis[i]) {
		if (abs(x-i)<mindiff) {
			ans=i;
			mindiff=abs(x-i);
		}
	}
	printf("%d",ans);
}


Measured memory_bytes: 3784
def main():
    s = input()
    k = int(input())

    if s[0] != '1':
        print(s[0])
        exit()

    for i in range(1,len(s)):
        if s[i] != '1':
            break
    else:
        print(1)
        exit()

    if i >= k:
        print(1)
        exit()

    print(s[i])

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
import collections
class UnionFind:
  def __init__(self, n):
    self.par = [i for i in range(n+1)]
    self.rank = [0] * (n+1)

    # 検索
  def find(self, x):
    if self.par[x] == x:
      return x
    else:
      self.par[x] = self.find(self.par[x])
      return self.par[x]

  # 併合
  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if self.rank[x] < self.rank[y]:
      self.par[x] = y
    else:
      self.par[y] = x
      if self.rank[x] == self.rank[y]:
        self.rank[x] += 1

  # 同じ集合に属するか判定
  def same_check(self, x, y):
    return self.find(x) == self.find(y)
n,m = map(int,input().split())
uf = UnionFind(n)
for _ in range(m):
  a,b = map(int,input().split())
  uf.union(a,b)
r = [0 for _ in range(n)]
for i in range(1,n+1):
  r[uf.find(i)-1] += 1
print(max(r))

Measured memory_bytes: 98484
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int N;
    string s;
    cin >> N >> s;
    int L = s.length();
    lli cnt = 0;
    lli r = count(s.begin(), s.end(), 'R');
    lli g = count(s.begin(), s.end(), 'G');
    lli b = count(s.begin(), s.end(), 'B');
    cnt = r * g * b;
    lli cnt2 = 0;
    int k = 0;
    for (int i = 0; i < N - 2; i++)
    {
        for (int j = i + 1; j < N - 1; j++)
        {
            k = 2 * j - i;
            if (k >= 0 && k < N)
            {
                if (s[i] != s[j] && s[j] != s[k] && s[i] != s[k])
                {
                    cnt -= 1;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << i << endl
using namespace std;
const int mod = 1e9+7;
int dp[100001] = {};


int main(){
    int n,m;
    cin >> n >> m;
    REP(i,m){
        int t;
        cin >> t;
        dp[t] = -1;
    }
    dp[0] = 1;

    FOR(i,1,(n+1)){
        if(dp[i] != -1){
             FOR(j,1,3){
                 if(dp[i-j] != -1) dp[i] = (dp[i] + dp[i-j]) % mod;
             }
        }

    }
    //REP(i,n) cout << dp[i] << " ";
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 640
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

l = []
for y in range(H):
    l += [(x, y) for x in list(range(W))[::-1 if y%2 else 1]]

p = []
for i, (x, y) in enumerate(l[:-1]):
    if A[y][x] % 2 == 0:
        continue
    nx, ny = l[i+1]
    p.append((x+1, y+1, nx+1, ny+1))
    A[y][x] -= 1
    A[ny][nx] += 1

print(len(p))
[print(*p_i[::-1]) for p_i in p]


Measured memory_bytes: 49288
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

X = get_int

require 'prime'

count = Prime.each(X-1).to_a.length

puts Prime.take(count+1).last




Measured memory_bytes: 14812
// Aizu Vol-10 1008: What Color Is The Universe?
// 2017.8.19 bal4u@uu

#include <stdio.h>
#include <string.h>

#define HASHSIZ 199999   //299993
typedef struct { int n, c; } HASH;
HASH hash[HASHSIZ + 5], *hashend = hash + HASHSIZ;

int color, cnt;

int lookup(int n)
{
	HASH *p = hash + n % HASHSIZ;
	while (p->n) {
		if (p->n == n) return ++(p->c);
		if (++p == hashend) p = hash;
	}
	p->n = n, p->c = 1;
	return 1;
}

int main()
{
	int n, i, k;

	while (scanf("%d", &n) && n) {
		memset(hash, 0, sizeof(hash)), cnt = 1;
		for (i = 0; i < n; i++) {
			scanf("%d", &k);
			if (lookup(k) == cnt) cnt++, color = k;
		}
		if (--cnt > n / 2) printf("%d\n", color);
		else puts("NO COLOR");
	}
	return 0;
}

Measured memory_bytes: 2180
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL)
    {
      y = x;
      if(z->key < x->key)
	{
	  x = x->left;
	}
      else
	{
	  x = x->right;
	}
    }
  z->parent = y;
  if(y == NIL)
    {
      root = z;
    }
  else
    {
      if(z->key < y->key)
	{
	  y->left = z;
	}
      else
	{
	  y->right = z;
	}
    }
}

void inorder(Node u){
  if(u != NIL)
    {
      inorder(u->left);
      printf(" %d",u->key);
      inorder(u->right);
    }
}
void preorder(Node u){
  if(u != NIL)
    {
      printf(" %d",u->key);
      preorder(u->left);
      preorder(u->right);
    }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  
  return 0;
}



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

int main () {
    bool isStPal;
    string s, t, ss, st;
    cin >> s;
    t = s;
    reverse(begin(t), end(t));
    if (s != t) isStPal = false;
    else {
        ss = s.substr (0,(s.length() - 1) / 2);
        st = ss;
        reverse(begin(st), end(st));
        if (ss != st) isStPal = false;
        else {
            ss = s.substr ((s.length() + 1) / 2, (s.length() - 1) / 2);
            st = ss;
            reverse(begin(st), end(st));
            if (ss != st) isStPal = false;
            else isStPal = true;
        }
    }
    printf("%s\n", isStPal ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b

signed main(){
	ll n,m,k; cin>>n>>m>>k;
  vl a(n+1),b(m+1);
  a[0]=0; b[0]=0;
 rep(i,1,n+1){
   ll x; cin>>x;
   a[i]=x;
  if(i!=0) a[i]+=a[i-1];
 }
  rep(i,1,m+1){
    ll x; cin>>x;
    b[i]=x;
    if(i!=0)b[i]+=b[i-1];
  }
  ll ans=0;
 /* rep(i,1,n+1)cout<<a[i]<<" ";
  cout<<endl;
  rep(i,1,m+1)cout<<b[i]<<" ";
  cout<<endl;*/
 rep(i,0,n+1){
	if(a[i]>k)break;
   ll j=upper_bound(all(b),k-a[i])-b.begin();
  // cout<<"j:"<<j<<endl;
   --j;
   chmax(ans,i+j);
 }
  cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 6428
K = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
N = int(input())

print(K[N - 1])

Measured memory_bytes: 3060
<>;$/=$";@D=(.5,(1)x2e6);($%^=$_)?$P[$%]+=$D[$%]+=$P[$%]*(-${*y=-$%}+($y=$0))%$=:($D[!++$0]*=2)%=$==1e9+7for<>;$D[0]+=$_ for@P;print$D[$%]%$=

Measured memory_bytes: 273668
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    vector<int> water;
    for(int i=0;100*a*i<=f;i++){
        for(int j=0;100*a*i+100*b*j<=f;j++){
            water.push_back(100*a*i+100*b*j);
        }
    }
    vector<int> sugar;
    for(int i=0;c*i<=f;i++){
        for(int j=0;c*i+d*j<=f;j++){
            sugar.push_back(c*i+d*j);
        }
    }
    int bestw=0,bestc=0;
    double best=-1;
    for(int i=0;i<water.size();i++){
        for(int j=0;j<sugar.size();j++){
            if(water[i]+sugar[j]>f)continue;
            if(sugar[j]>e*(water[i]/100.0))continue;
            //cout<<water[i]<<" "<<sugar[j]<<endl;
            if(best<(100.0*sugar[j])/(water[i]+sugar[j])){
                best=(100.0*sugar[j])/(water[i]+sugar[j]);
                bestw=water[i]+sugar[j];
                bestc=sugar[j];
            }
        }
    }
    cout<<bestw<<" "<<bestc<<endl;
    return 0;
}


Measured memory_bytes: 1400
class Solution:
    def main(self):
        s = input()
        t = input()
        loop = 0
        string = s
        for i in range(len(t)):
            if s.find(t[i]) == -1:
                print(-1)
                return
            elif string.find(t[i]) == -1:
                loop += 1
                string = s[s.find(t[i])+1:]
            else:
                string = string[string.find(t[i])+1 :]

        print((loop+1)*len(s) - len(string))
        return

if __name__ == '__main__':
    Solution().main()

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

#define  int        long long int
 #define    sp(x)                 setprecision(x)
#define    bp(x)           __builtin_popcount(x)
 #define  ld         long double
 #define  f(i,j,n)            for(int i = j; i <= n; i++)
#define  r(i,n,j)       for(int i = n; i >= j; i--)
 #define  all(container)       container.begin() , container.end()
#define  sz(container)   (int)container.size()
 #define  ff             first
#define  ss             second
 #define  pii      pair <int , int>
#define  sp(x)       setprecision(x)
 #define  endl    "\n"
#define  mod  1000000007
 #define  pb    push_back
#define  mp    make_pair
 #define  T     int ttt; cin >> ttt; while(ttt--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}

int32_t main()
{
    fast
    int n;
    cin>>n;
    map<string ,int>m;
    m["AC"]=0;
     m["WA"]=0;
      m["TLE"]=0;
       m["RE"]=0;
    string s;
    f(i,1,n)
    {
        cin>>s;
        m[s]++;
    }
    cout<<"AC x "<<m["AC"]<<endl;
     cout<<"WA x "<<m["WA"]<<endl;
      cout<<"TLE x "<<m["TLE"]<<endl;
      cout<<"RE x "<<m["RE"]<<endl;

}

Measured memory_bytes: 3660
a,b=input().split()
c=[]
for i in range(len(b)):
  if b[i]=='.':
    x=i
  else:
    c.append(b[i])
if len(c)<3:
  c.append('0')
d=''.join(c)
if x==2:
  print(int(a)*10)
  exit()
else:
  e=int(a)*int(d)
  e=list(str(e))
  if len(e)<=2:
    print(0)
    exit()
  else:
    e.pop(-1)
    e.pop(-1)
  print(''.join(e))

Measured memory_bytes: 61876
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vectors<decltype(inner)>(x, inner); }
using ll = long long;
using ld =long double;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int W,H;
bool inrange(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define MP make_pair
signed main(){
    string s; cin >> s;
    int ans = 0;
    rep(i,s.size())ans+=s[i]-'0';
    cmax(ans, 9*(s.size()-1)+(s[0] -'1'));
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
long long a , b ;
int main()
{
	cin >> a >> b ;
	if ( a== 0 || ( a==0 && b==0)  ) 
	{
		cout << "Zero" << endl;
		return 0 ;
	}
	else if ( a> 0 ) 
	{
		cout << "Positive" << endl;
		return 0 ;
	}
	else if ( a < 0 && b >= 0 ) 
	{
		cout << "Zero" << endl;
		return 0 ;
	}
	else if ( a < 0 && b < 0 ) 
	{
		if ( (long long)(b-a+1) %2 == 0 ) 
			cout << "Positive" << endl;
		else
			cout << "Negative" << endl;
		return 0 ;
	}

}

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

using db = double;
const db Inf = 1e18L;

struct poi {
	db x, y;
	poi operator -(poi p) {
		return {x - p.x, y - p.y};
	}
	bool operator <(poi p) const {
		return tie(x, y) < tie(p.x, p.y);
	}
	db len2() {
		return x * x + y * y;
	}
};

using vp = vector <poi>;
db solve(poi *p, int l, int r) {
	if(l + 1 == r) return Inf;
	int m = (l + r) / 2; db mx = p[m].x; vector <poi> v;
	db ret = min(solve(p, l, m), solve(p, m, r));
	for(int i = l; i < r; i ++)
		if(poi{p[i].x - mx, 0}.len2() < ret)
			v.push_back(p[i]);
	sort(v.begin(), v.end(), [](poi a, poi b) {
		return tie(a.y, a.x) < tie(b.y, b.x); });
	for(int i = 0; i < v.size(); i ++)
		for(int j = i + 1; j < v.size(); j ++) {
			if(poi{0, v[i].y - v[j].y}.len2() > ret) break;
			ret = min(ret, (v[i] - v[j]).len2());
		}
	return ret;
} // ?????????p[]????????????

const int N = 1e5L + 11;
poi p[N];

int main() {
	ios :: sync_with_stdio(false);
	int n; cin >> n;
	for(int i = 0; i < n; i ++)
		cin >> p[i].x >> p[i].y;
	sort(p, p + n);
	db ans = solve(p, 0, n);
	cout << fixed << setprecision(9) << sqrt(ans) << '\n';
	return 0;
}

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

int n;
vector<int> h(100001);
vector<int> cost(100001);

int ans(int n){
    if (cost[n] != -1)
        return cost[n];
    cost[n] = min(ans(n-1) + abs(h[n] - h[n-1]),
                  ans(n-2) + abs(h[n] - h[n-2]));
    return cost[n];
}

int main(){
    cin>>n;
  	rep(i,n){
        cin >> h[i];
        cost[i] = -1;
    }
    cost[0] = 0;
    cost[1] = abs(h[1] - h[0]);
    cout << ans(n-1) << endl;
}

Measured memory_bytes: 6264
<?php
  # 最初のに合わせて最小値を更新していく方針
  $n = intVal(trim(fgets(STDIN)));
  $first = str_split(trim(fgets(STDIN)));
  $fix = [];
  foreach($first as $k=>$v){
    if(array_key_exists($v, $fix)){
      $fix[$v] += 1;
    }else{
      $fix[$v] = 1;
    }
  }
  for($i = 1; $i < $n; $i++){
     $next = str_split(trim(fgets(STDIN)));
     $next_count_values = array_count_values($next);
     foreach($fix as $k=>$v){
       if(array_key_exists($k, $next_count_values)){
         $fix[$k] = min($fix[$k], $next_count_values[$k]);
       }else{
         unset($fix[$k]);
       }
     }
  }
  ksort($fix);
  $ans = "";
  foreach($fix as $k=>$v){
    for($i=0; $i<$v; $i++){
      $ans .= $k;
    }
  }
  echo $ans . PHP_EOL;
?>

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

using namespace std;
using ll = long long;

ll gcd(ll a, ll b) {
  ll r = 1;
  if (a < b)
    swap(a, b);
  while (r > 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int main(int argc, char const *argv[]) {
  ll n, m;
  cin >> n >> m;
  vector<int> a(n);
  cin >> a[0];
  a[0] /= 2;
  ll mini = a[0];
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    a[i] /= 2;
    ll t0 = gcd(mini, a[i]);
    if ((mini % t0 == 0 && (mini / t0) % 2 == 0) ||
        (a[i] % t0 == 0 && (a[i] / t0) % 2 == 0)) {
      cout << 0 << endl;
      return 0;
    } else {
      mini = (mini / t0) * a[i];
    }
  }

  int ret = 0;

  ret = (m / mini + 1) / 2;
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1e9+7;
ll qpow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1) res=res*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return res%mod;
}
int main(){
	ll n,m,k;
	cin>>n>>m>>k;
	ll t=n*m,p=k,num=1;
	for(int i=1;i<=k;i++){
		num=(num%mod*t%mod*qpow(p,mod-2)%mod)%mod;
		t--,p--;
	}
	ll x=(k*(k-1))/2;
	cout<<(x%mod*(n+m)%mod*num%mod*qpow(3,mod-2)%mod)%mod<<endl;
}

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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll inf=1e9+7;
const ll mod=1e9+7;
const int MAX=1010;
//Ford-Fulkerson
struct edge{
    int to,cap,rev;
};

vector<edge>G[MAX];
vector<int>level(MAX);
vector<int>iter(MAX);

void add_edge(int from,int to,int cap){
    int ts=G[to].size();
    int fs=G[from].size();
    G[from].push_back((edge){to,cap,ts});
    G[to].push_back((edge){from,0,fs});
}

void bfs(int s){
    for(int i=0;i<MAX;i++)level[i]=-1;
    queue<int>q;
    level[s]=0;
    q.push(s);
    while(!q.empty()){
        int v=q.front();
        q.pop();
        for(auto &e:G[v]){
            if(e.cap>0&&level[e.to]<0){
                level[e.to]=level[v]+1;
                q.push(e.to);
            }
        }
    }
}

int dfs(int v,int t,int f){
    if(v==t)return f;
    for(int &i=iter[v];i<G[v].size();i++){
        edge &e=G[v][i];
        if(e.cap>0&&level[v]<level[e.to]){
            int d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s,int t){
    int flow=0;
    while(1){
        bfs(s);
        if(level[t]<0)return flow;
        for(int i=0;i<iter.size();i++)iter[i]=0;
        int f;
        while((f=dfs(s,t,inf))>0){
            flow+=f;
        }
    }
}

signed main(){
    ll h,w;cin>>h>>w;
    vector<string>g(h);
    rep(i,h){
        cin>>g[i];
    }
    ll s=0,t=h+w+1;
    ll sx,sy,tx,ty;
    rep(i,h){
        rep(j,w){
            if(g[i][j]=='S'){
                sx=i,sy=j;
                add_edge(0,i+1,inf);
                add_edge(0,h+j+1,inf);
            }
            if(g[i][j]=='T'){
                tx=i,ty=j;
                add_edge(i+1,h+w+1,inf);
                add_edge(j+h+1,h+w+1,inf);
            }
            if(g[i][j]=='o'){
                add_edge(i+1,h+j+1,1);
                add_edge(h+j+1,i+1,1);
            }
        }
    }
    if(sx==tx||sy==ty){
        cout<<-1<<endl;
        return 0;
    }
    ll ans=max_flow(s,t);
    cout<<ans<<endl;
}

Measured memory_bytes: 4728
#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;
  
  int A =S.size();
  int B =A-1;
  
  if(S.at(B)=='s'){
    cout << S+"es" <<endl;
  }
  else{
    cout << S+"s" <<endl;
  }
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

// 参考: https://www.hamayanhamayan.com/entry/2019/01/12/151211
// 類題: https://yukicoder.me/problems/no/719

const ll maxn=1<<16;
ll dp[maxn];
ll sub[maxn];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  vvll a(n,vll(n));
  rep(i,n) rep(j,n) cin>>a[i][j];
  
  rep(s,1<<n){
    ll cnt=0;
    rep(i,n) if(s>>i&1) {
      irep(j,i+1,n) if(s>>j&1) cnt+=a[i][j];
    }
    sub[s]=cnt;
  }
  // rep(i,1<<n) cout<<sub[i]<<endl;
  
  rep(s,1<<n) for(ll bit=s; bit>=0; bit--){
    bit&=s;
    chmax(dp[s],dp[s-bit]+sub[bit]);
  }
  
  cout<<dp[(1<<n)-1]<<endl;
  
  
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;
const int N=1e5+5;

namespace utils{
	template <class T> inline void apn(T &x,const T y){x>y?x=y:0;}
	template <class T> inline void apx(T &x,const T y){x<y?x=y:0;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	int n=nxi(),c0=0,c1=0,c2=0;
	for(int i=1; i<=n; ++i){
		const int x=nxi();
		if((x&3)==0) ++c2;
		else if((x&1)==0) ++c1;
		else ++c0;
	}
	if(c1) puts(c2>=c0?"Yes":"No");
	else puts(c2>=c0-1?"Yes":"No");
	return 0;
}


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

int main(){
	int A, B, C;
	cin >> A >> B >> C;

	int h1, h2;
	h1 = min(A, B); h2 = max(A, B);

	for(int i = h1; i <= h2; ++i){
		if(i == C){ cout << "Yes" << endl; return 0; }
	}

	cout << "No" << endl;

	return 0;
}


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

using namespace std;

bool isValid(int n, vector<int> &arr){
	while (n > 0) {
		if (binary_search(arr.begin(), arr.end(), n%10)) return false;
		n /= 10;
	}
	return true;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k;
	cin >> n >> k;
	vector<int> arr(k);
	for (int i = 0; i < k; i++) cin >> arr[i];
	
	while(!isValid(n, arr)) n++;
	cout << n << endl;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    String sLast = s.substring(s.length() - 1);
    if(sLast.equals("s")){
      s = s+"es";
    }else{
      s = s+"s";
    }
    System.out.println(s);
  }
}

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

int main(){
    int a,b;
    cin >> a >> b;
    
    const int hour = 24;
    
    if(a+b>=24) cout << a + b - hour;
    else cout << a + b;
}

Measured memory_bytes: 256
from itertools import permutations
n,m=map(int,input().split())
e=[[]for _ in range(n)]
for _ in range(m):
  a,b=map(int,input().split())
  e[a-1]+=[b-1]
  e[b-1]+=[a-1]
def dfs(now,vis):
  vis+=[now]
  if len(vis)==n:return 1
  res=0
  for to in e[now]:
    if to not in vis:
      res+=dfs(to,vis[:])
  return res
print(dfs(0,[]))

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

int main() {
  int N;
  char a,b,c,d;
  cin >>a>>b>>c>>d;
  if (a==b&&b==c) {
    cout << "Yes"<< endl;
  }
  else if (b==c&&c==d){
    cout<<"Yes"<<endl;
  }
  else  {

  cout << "No"<< endl;
}
}

Measured memory_bytes: 256
program alter_altar
  implicit none
  integer :: n, m = 0, l = 1, r
  character(200000) :: s
  read(*,*) n
  read(*,*) s
  r = n
  do
    do while (l <= n .and. s(l:l) == 'R')
      l = l + 1
    end do
    do while (r >= 1 .and. s(r:r) == 'W')
      r = r - 1
    end do
    if (l >= r) exit
    m = m + 1
    s(l:l) = 'R'
    s(r:r) = 'W'
  end do
  write(*,'(i0)') m
end program alter_altar

Measured memory_bytes: 3304