akhauriyash/Code-Regression huggingface dataset:
import sys
readline = sys.stdin.readline
from collections import deque
directions = ((-1, 0), (1, 0), (0, -1), (0, 1))

def main():
    H, W = map(int, readline().rstrip().split())
    mat = [list(readline().rstrip()) for _ in range(H)]

    start = []
    for h in range(H):
        for w in range(W):
            if mat[h][w] == '#':
                start.append((h, w))
    
    res = 0
    que = deque(start)
    while que:
        next_que = []
        while que:
            h, w = que.popleft()
            for dh, dw in directions:
                if not (0 <= h+dh < H and 0 <= w+dw < W):
                    continue
                if mat[h+dh][w+dw] == '#':
                    continue
                mat[h+dh][w+dw] = '#'
                next_que.append((h+dh, w+dw))

        res += 1
        que = deque(next_que)

    print(res - 1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 134224
using System;
using System.Collections.Generic;

namespace AtCoder.Company.SoundHound
{
    class c
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Trim();
            var spl = line.Split(' ');
            var n = double.Parse(spl[0]);
            var m = double.Parse(spl[1]);
            var d = double.Parse(spl[2]);
            if (d == 0)
            {
                Console.WriteLine((m - 1) / n);
            }
            else
            {
                Console.WriteLine(2 * (n - d) / n * (m - 1) / n);
            }
        }
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <array>
#include <climits>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef long double LD;


const ll MOD = 10e9 + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = 10e5;
const LD EPS = 10e-7;
const LD PI = 3.14159265359;

int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };

int main() {
	int a[3],ans=0;
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if (a[0] % 2 == a[1] % 2) {
		ans += (a[1] - a[0]) / 2;
		ans += a[2] - a[1];
	}
	else {
		if (a[0] % 2 == a[2] % 2) {
			a[0]++; a[2]++;
			ans++;
			
		}
		else {
			a[1]++; a[2]++;
			ans++;
		}
		ans += (a[1] - a[0]) / 2;
		ans += a[2] - a[1];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void p(vector<char> A){rep(i,A.size()){cout << A[i];}cout << endl;}

int main(){
    int n;
    cin >> n;
    vector<int> a(3*n);
    rep(i,3*n) cin >> a[i];
    sort(a.begin(),a.end(),greater<int>());
    ll ans = 0;
    rep(i,2*n){
        if (i%2 != 0){ans += a[i];}
    }
    cout << ans;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX=3e3+10;
string A,B;
ll N,M;
ll dp[MAX][MAX];
int solve(int i,int j)
{
    if(i>=N||j>=M)return 0;
    if(dp[i][j]!=-1)return dp[i][j];
    int ans=0;
    if(A[i]==B[j]){
        ans =  1+solve(i+1,j+1);
    }
    else{
        ans = max(solve(i+1,j),solve(i,j+1));
    }
    return dp[i][j]=ans;
}
void path(int i,int j)
{
    if(i>=N||j>=M)return;
    if(A[i]==B[j]){
        cout<<A[i];
        path(i+1,j+1);
    }
    else{
        if(solve(i+1,j)==dp[i][j]){
            path(i+1,j);
        }
        else if(solve(i,j+1)==dp[i][j]){
            path(i,j+1);
        }
    }
}
int main ()
{
    memset(dp,-1,sizeof dp);
    cin >> A >> B;
    N = A.size();
    M = B.size();
    solve(0,0);
    path(0,0);
    return 0;
}





Measured memory_bytes: 71296
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int d;
int c[27];
int s[366][27];
int calc(vector<int> t){
    int last[26]={};
    vector<int> ret(d);
    int ans=0;
    for(int i=0; i<d; i++){
        ans+=s[i][t[i]];
        last[t[i]]=i+1;
        for(int j=0; j<26; j++){
            ans-=c[j]*(i+1-last[j]);
        }
        ret[i]=ans;
    }
    return ans;
}
mt19937 mt(334);

int main()
{
    cin>>d;
    for(int i=0; i<26; i++) cin>>c[i];
    for(int i=0; i<d; i++) for(int j=0; j<26; j++) cin>>s[i][j];
    vector<int> t(d);
    
    int last[26]={};
    for(int i=0; i<d; i++){
        int kmx=0, mx=-1e9;
        for(int k=0; k<26; k++){
            int sum=s[i][k];
            int myon=last[k];
            last[k]=i+1;
            for(int j=0; j<26; j++){
                sum-=c[j]*(i+1-last[j]);
            }
            last[k]=myon;
            if(mx<sum) kmx=k, mx=sum;
        }
        t[i]=kmx;
        last[kmx]=i+1;
    }

    uniform_int_distribution<> rndk(0, d-2);
    clock_t start = clock();
    int ans=calc(t);
    while((double)(clock()-start)/CLOCKS_PER_SEC<1.9){
        int k;
        k=rndk(mt);
        int pr=t[k], q=t[k+1], ansp=ans;
        ans-=s[k][pr];
        ans+=s[k][q];
        ans-=s[k+1][q];
        ans+=s[k+1][pr];
        int last[2]={};
        for(int i=0; i<d; i++){
            if(t[i]==pr) last[0]=i+1;
            else if(t[i]==q) last[1]=i+1;
            ans+=c[pr]*(i+1-last[0]);
            ans+=c[q]*(i+1-last[1]);
        }
        swap(t[k], t[k+1]);
        last[0]=last[1]=0;
        for(int i=0; i<d; i++){
            if(t[i]==pr) last[0]=i+1;
            else if(t[i]==q) last[1]=i+1;
            ans-=c[pr]*(i+1-last[0]);
            ans-=c[q]*(i+1-last[1]);
        }
        if(ansp>ans){
            swap(t[k], t[k+1]);
            ans=ansp;
        }
    }
    for(int i=0; i<d; i++){
        cout<<t[i]+1<<endl;
    }
	return 0;
}


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

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

    long long m, d;
    cin >> m >> d;

    long long ans = 0;
    for(int i = 1; i <= m; i++){
        for(int j = 10; j <= d; j++){
            int a = j % 10;
            int b = j / 10;
            if(a < 2 or b < 2) continue;
            if(a * b == i){
                ans++;
                //cout << i << ' ' << a << ' ' << b << endl;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

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

    return 0;
}


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

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) begin(v), end(v)
#define fi first
#define se second

const int N = 302 * 2;

vector<ii> dir[2];
int n, d1, d2;
bool inside(int x, int y) {
  return 0 <= x and x < n and 0 <= y and y < n;
}
int col[2][N][N], vis[N][N];
int layer;

void dfs(int x, int y) {
  vis[x][y] = 1;
  for(ii d : dir[layer]) {
    int xx = x + d.fi;
    int yy = y + d.se;
    if(inside(xx, yy) && !vis[xx][yy]) {
      col[layer][xx][yy] = col[layer][x][y] ^ 1;
      dfs(xx, yy);
    }
  }
}

int sq(int x) { return x * x; }
int dist2(ii a, ii b) {
  return sq(a.fi - b.fi) + sq(a.se - b.se);
}

int main(int argc, char const *argv[])
{
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  cin >> n >> d1 >> d2;
  n *= 2;
  for(int i = -n+1; i < n; ++i) {
    for(int j = -n+1; j < n; ++j) {
      if(i*i + j*j == d1) {
        dir[0].emplace_back(i, j);
      }
      if(i*i + j*j == d2) {
        dir[1].emplace_back(i, j);
      }
    }
  }

  for(layer = 0; layer < 2; layer++) {
    memset(vis, 0, sizeof vis);
    for(int i = 0; i < n; ++i) {
      for(int j = 0; j < n; ++j) {
        if(!vis[i][j]) {
          dfs(i, j);
        }
      }
    }
  }
  vi cnt(4);
  for(int i = 0; i < n; ++i) {
    for(int j = 0; j < n; ++j) {
      cnt[(col[1][i][j] << 1) | (col[0][i][j])]++;
    }
  }
  ii opt = {-1, 0};
  for(int i = 0; i < 4; ++i) {
    opt = max(opt, {cnt[i], i});
  }
  int c0 = opt.se & 1;
  int c1 = opt.se >> 1 & 1;
  vector<ii> S;
  for(int i = 0; i < n; ++i) {
    for(int j = 0; j < n; ++j) {
      if(col[0][i][j] == c0 && col[1][i][j] == c1) {
        S.emplace_back(i, j);
      }
    }
  }
  while((int)S.size() > n * n / 4) S.pop_back();
  for(ii& p : S) {
    cout << p.fi << ' ' << p.se << '\n';
  }
  return 0;
  for(int i = 0; i < (int)S.size(); ++i) {
    for(int j = i+1; j < (int)S.size(); ++j) {
      int x = dist2(S[i], S[j]);
      assert(x != d1 and x != d2);
      /*if(!(x != d1 and x != d2)) {
        cout << ">#$%" << endl;
        cout << S[i].fi << ' ' << S[i].se << endl;
        cout << S[j].fi << ' ' << S[j].se << endl;
        exit(0);
      }*/
    }
  }
  return 0;
}

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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T>ostream &operator<<(ostream &o,const pair<T, T>&p)
{o<<"("<<p.first<<", "<<p.second<<")";return o;}

int main(void){
    int a, b;
    cin >> a >> b;
    string s, t;
    s = "";
    t = "";
    for(int i = 0; i < b; i++){
        s += to_string(a);
    }
    for(int i = 0; i < a; i++){
        t += to_string(b);
    }
    if(s < t) cout << s << endl;
    else cout << t << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

bool is_prime(int64_t x) {
  for(int64_t i = 2; i * i <= x; i++) {
    if(x % i == 0) return false;
  }
  return true;
}

int main(void){
    int x;
    cin >> x;
    while(1){
        if(is_prime(x)){
            cout << x;
            return 0;
        }else x++;
    }

}

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

int stack[500];
int idx = 0;

int pop() {
    return stack[--idx];
}

void push(int n) {
    stack[idx++] = n;
}

int main (void) {
    int n, a, b;
    char s[100];

    while (scanf("%s", s) != EOF) {

        switch (s[0]) {
            case '+':
                a = pop();
                b = pop();
                push(a + b);
                break;
            case '-':
                a = pop();
                b = pop();
                push(b - a);
                break;
            case '*':
                a = pop();
                b = pop();
                push(a * b);
                break;
            default:
                push(atoi(s));
                break;
        }
    }

    printf("%d\n", pop());

    return 0;
}

Measured memory_bytes: 1760
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl
#define eadd(a,b) encode[(a)] = (b)
#define dadd(a,b) decode[(a)] = (b)

int main() {
    map<char, string> encode;
    map<string, char> decode;
    eadd(' ',"101");
    eadd('\'',"000000");
    eadd(',',"000011");
    eadd('-',"10010001");
    eadd('.',"010001");
    eadd('?',"000001");
    eadd('A',"100101");
    eadd('B',"10011010");
    eadd('C',"0101");
    eadd('D',"0001");
    eadd('E',"110");
    eadd('F',"01001");
    eadd('G',"10011011");
    eadd('H',"010000");
    eadd('I',"0111");
    eadd('J',"10011000");
    eadd('K',"0110");
    eadd('L',"00100");
    eadd('M',"10011001");
    eadd('N',"10011110");
    eadd('O',"00101");
    eadd('P',"111");
    eadd('Q',"10011111");
    eadd('R',"1000");
    eadd('S',"00110");
    eadd('T',"00111");
    eadd('U',"10011100");
    eadd('V',"10011101");
    eadd('W',"000010");
    eadd('X',"10010010");
    eadd('Y',"10010011");
    eadd('Z',"10010000");
    
    dadd("00000",'A');
    dadd("00001",'B');
    dadd("00010",'C');
    dadd("00011",'D');
    dadd("00100",'E');
    dadd("00101",'F');
    dadd("00110",'G');
    dadd("00111",'H');
    dadd("01000",'I');
    dadd("01001",'J');
    dadd("01010",'K');
    dadd("01011",'L');
    dadd("01100",'M');
    dadd("01101",'N');
    dadd("01110",'O');
    dadd("01111",'P');
    dadd("10000",'Q');
    dadd("10001",'R');
    dadd("10010",'S');
    dadd("10011",'T');
    dadd("10100",'U');
    dadd("10101",'V');
    dadd("10110",'W');
    dadd("10111",'X');
    dadd("11000",'Y');
    dadd("11001",'Z');
    dadd("11010",' ');
    dadd("11011",'.');
    dadd("11100",',');
    dadd("11101",'-');
    dadd("11110",'\'');
    dadd("11111",'?');
    
    string s;
    while(getline(cin,s)) {
        string enc = "";
        REP(i,s.size()) {
            enc += encode[s[i]];
        }
        switch (enc.size() % 5) {
            case 1:
                enc += "0000";
                break;
            case 2:
                enc += "000";
                break;
            case 3:
                enc += "00";
                break;
            case 4:
                enc += "0";
                break;
            default:
                break;
        }
        string dec = "";
        for(int i = 0; i < enc.size(); i+=5) {
            string five = "";
            five += enc[i];
            five += enc[i+1];
            five += enc[i+2];
            five += enc[i+3];
            five += enc[i+4];
            //cout << five << endl;
            dec += decode[five];
        }
        cout << dec << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1204
def resale n, v, c
  ans = 0
  n.times do |i|
    if v[i] > c[i]
      ans += v[i] - c[i]
    end
  end
  ans
end

n = gets.to_i
v = gets.split(' ').map{|x| x.to_i}
c = gets.split(' ').map{|x| x.to_i}
puts resale(n, v, c)


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

int main(){
    int N;
    int A;
    int i=0;
    int cnt=0;
    
    scanf("%d",&N);
    scanf("%d",&A);
    
    N = N % 500;
    if(N <= A){
        printf("Yes\n");
        return 0;
    }
    
    printf("No\n");
    
    return 0;
}

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

ll INF = 1e+18;
int iINF = 1e9;

int 
main()
{
  int N; cin >> N;
  vector<ll> arr(5);
  rep(i, 0, N){
    string tmp; cin >> tmp;
    char ini = tmp[0];
    if(ini == 'M') arr[0] += 1;
    if(ini == 'A') arr[1] += 1;
    if(ini == 'R') arr[2] += 1;
    if(ini == 'C') arr[3] += 1;
    if(ini == 'H') arr[4] += 1;
  }

  ll ans = 0;
  rep(i, 0, 3){
    rep(j, i + 1, 4){
      rep(k, j + 1, 5){
        ans += arr[i] * arr[j] * arr[k];
      }
    }
  }

  cout << ans << endl;

}

Measured memory_bytes: 3584
class queue:
    def __init__(self):
        self.V = []
        self.T = []
    def isEmpty(self):
        return len(self.V) == 0
    def enqueue(self,lis):
        self.T.append(lis[0])
        self.V.append(int(lis[1]))
    def dequeue(self):
        title = self.T[0]
        value = self.V[0]
        self.T = self.T[1:len(self.T)]
        self.V = self.V[1:len(self.V)]
        return [title,value]
n,q = list(map(int,input().split()))
time = 0
Q = queue()
totalT = 0
for i in range(n):
    arg = input().split()
    totalT += int(arg[1])
    if int(arg[1]) <= q:
        time += int(arg[1])
        print(f"{arg[0]} {time}")
    else:
        time += q
        Q.enqueue([arg[0],int(arg[1])-q])
    
while time<totalT:
    l = Q.dequeue()
    if l[1]<=q:
        time += l[1]
        print(f"{l[0]} {time}")
    else:
        time += q
        Q.enqueue([l[0],int(l[1])-q])


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

using namespace std;
int main(){

  int N;
  vector<int> vC, vV;
  int c,v;
  cin >> N;
  vC.reserve(N);
  vV.reserve(N);


  for(int i = 0; i < N; ++i){
    cin >> v;
    vV.push_back(v);
  }

  for(int i = 0; i < N; ++i){
    cin >> c;
    vC.push_back(c);
  }

  int ans = 0;
  int prf;;//profit
  for(int i = 0; i < N; ++i){
    prf = vV.at(i) - vC.at(i);
    if(prf > 0) ans += prf;
  }

  cout << ans << endl;;

  return 0;
}

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

int gcd(int p, int q){
  int r = p%q;
  if(r == 0){
    return q;
  }else{
    return gcd(q,r);
  }
}

int main(){
  int K;
  cin >> K;
  long long sum = 0;
  for(int a = 1; a < K+1; a++){
    for(int b = 1; b < K+1; b++){
      for(int c = 1; c < K+1; c++){
        sum += gcd(gcd(a,b),c);
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int n,x,a[100001] = {};
  cin >> n >> x;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  ll cnt = 0;
  for(int i = 0; i < n-1; i++){
    ll sum = a[i] + a[i+1];
    ll crr = 0;
    if(sum > x) {
      crr = sum - x;
      if(a[i+1] >= crr){
        a[i+1] -= crr;
      }else{
        a[i] -= crr-a[i+1];
        a[i+1] = 0;
      }
      cnt += crr;
    }
  }
  cout << cnt << endl;
}

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

int main(int argc, char** argv)
{
  int h, n;
  cin >> h >> n;
  
  for (int i = 0; i < n; i++) {
    int a; cin >> a;
    h -= a;
  }
  cout << (h <= 0 ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long N = Long.parseLong(sc.next());
        int count = 0;
        long x = N;
        long res = 0;
        while(x != 0){
            x /= 2;
            count++;
        }
        for(int i=0;i<count;i++){
            res += (long)Math.pow(2,i);
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 24916
#include <iostream>

using namespace std;

int main() {
  while (true) {
    int H, W;
    cin >> H >> W;
    if (H == 0 && W == 0) {
      break;
    }

    for (int i = 0; i < H; ++i) {
      for (int j = 0; j < W; ++j) {
        if (i == 0 || i == H-1) {
          cout << "#";
        } else {
          if (j == 0 || j == W-1) {
            cout << "#";
          } else {
            cout << ".";
          }
        }
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}


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

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

    if(a>=k){
        cout<<k<<endl;
    }
    else if(a+b>=k){
        cout<<a<<endl;
    }else{
        cout<<a-(k-a-b)<<endl;
    }
    return 0;
}

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

char s[10];
bool flag = 0;
 
int main()
{
	scanf("%s", s);
	if(s[0] == s[1] && s[1] == s[2])	flag = 1;
	if(s[1] == s[2] && s[2] == s[3])	flag = 1;
	if(flag)	printf("Yes\n");
	else printf("No\n");
}

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

#define PI 3.141592

int main(){
  long double d1,d2,e1,e2;

  while(1){
    cin>>d1>>e1>>d2>>e2;

    if(d1==-1&&d2==-1&&e1==-1&&e2==-1) break;

    long double d = acos(sin(d1*PI/180)*sin(d2*PI/180)
			 + cos(d1*PI/180)*cos(d2*PI/180)*cos((e1-e2)*PI/180) );

    cout<<floor(d*6378.1+0.5)<<endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int a =0,b=0,c=0,d=0;
    for(int i=0;i<n;i++){
      string s;
      cin>>s;
      if(s == "AC")
        a++;
      if(s == "WA")
        b++;
      if(s == "TLE")
        c++;
      if(s == "RE")
        d++;
    }
    cout<<"AC x "<<a;
    cout<<"\nWA x "<<b;
    cout<<"\nTLE x "<<c;
    cout<<"\nRE x "<<d;
    return 0;
}


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

int main() {

    vector<int> num(3);
    for (int i=0; i<3; ++i) {
        cin >> num[i];
    }
    sort(num.begin(), num.end());
    reverse(num.begin(), num.end());
    int d = num[0] - num[1];
    int e = num[0] - (num[2] + d);
    int res = e / 2 + d;
    if (e % 2 != 0) res += 2;

    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define IO() freopen("palindrome.in","rw",stdin)
#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e6+9, M = (1<<31), OO = 0x3f3f3f3f;
int arr[N];
int main()
{
  int n,k,q;
  scanf("%d%d%d",&n,&k,&q);
  for(int i=0;i<n;++i) arr[i]=k;
  for(int i=0;i<q;++i)
  {
    int x;
    scanf("%d",&x);
    arr[x-1]++;
  }
  for(int i=0;i<n;++i)
  {
    if((arr[i]-q)>0) printf("Yes\n");
    else printf("No\n");
  }
  #ifdef _LOCAL_DEFINE
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}

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

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll minus=0;
    bool allplus=false;
    ll abs_tot=0;
    ll abs_min = pow(10,9);
    for(int i=0; i<n; i++){
        cin >> a.at(i);
        if(a.at(i)==0)allplus=true;
        if(a.at(i)<0)minus++;
        abs_tot += abs(a.at(i));
        abs_min=min(abs_min, abs(a.at(i)));
    }
    if(minus%2==0) allplus=true;
    if(allplus) cout << abs_tot << endl;
    else cout << abs_tot - 2*abs_min << endl;

}


Measured memory_bytes: 4052
#include <iostream>

using namespace std;

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

int main() {
  int n, r;
  cin >> n;
  rep(i,9) {
    r = (i+1) * 111;
    if(n <= r) break;
  }
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a[4], b[4];
	int i, j;
	int hit, blow;
	
	
	while (scanf("%d%d%d%d", &a[0], &a[1], &a[2], &a[3]) != EOF){
		scanf("%d%d%d%d", &b[0], &b[1], &b[2], &b[3]);
		
		hit = 0;
		blow = 0;
		
		for (i = 0; i < 4; i++){
			if (a[i] == b[i]){
				hit++;
			}
			else {
				for (j = 0; j < 4; j++){
					if (a[i] == b[j]){
						blow++;
					}
				}
			}
		}
		
		printf("%d %d\n", hit, blow);
	}
	
	return (0);
}

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

using namespace std;

#define limit int(1e5 + 101)
int arr[ limit ];
int dn[ limit ];

int answer(int n, int k) {
	fill(dn, dn + limit, int(1e9));
	dn[ 0 ] = arr[ 0 ];

	for(int i = 1; i < n; i++) {
		for(int j = 0; j < k; j++) {
			dn[ i + j ] = min(dn[ i + j ], dn[ i - 1 ] + abs(arr[ i - 1 ] - arr[ i + j ]));
		}
		//dn[ i + 1 ] = min(dn[ i + 1 ], dn[ i - 1 ] + abs(arr[ i - 1 ] - arr[ i + 1 ]));
	}

	return (dn[ n - 1 ] - dn[ 0 ]);
}

int main() {
	int n, k;
	scanf("%i%i", &n, &k);

	for(int i = 0; i < n; i++) {
		scanf("%i", &arr[ i ]);
	}

	printf("%i", answer(n, k));
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<28

int graph[210][210];
int R, r[10];

int dfs(int q, int b, int ri){
  if(q == R) return  0;
  int ret = INF;
  for(int i = 0;i < R;i++){
    if((b & (1 << i)) == 0){
      ret = min(ret, dfs(q+1, b | (1 << i), i) + graph[r[ri]][r[i]]);
    }
  }

  return ret;
}

int main(){
  for(int i = 0;i < 210;i++){
    for(int j = 0;j < 210;j++){
      if(i != j) graph[i][j] = INF;
      else graph[i][j] = 0;
    }
  }

  int n, m;
  cin >> n >> m >> R;
  for(int i = 0;i < R;i++){
    cin >> r[i];
  }

  int a, b, c;
  for(int i = 0;i < m;i++){
    cin >> a >> b >> c;
    graph[a][b] = c;
    graph[b][a] = c;
  }

  for(int i = 1;i <= n;i++)
    for(int j = 1;j <= n;j++)
      for(int k = 1;k <= n;k++)
        graph[j][k] = min(graph[j][k], graph[j][i] + graph[i][k]);

  int ans = INF;
  for(int i = 0;i < R;i++){
    ans = min(ans, dfs(1,(1 << i),i));
  }
  cout << ans << endl;
  return 0;

}

Measured memory_bytes: 384
import itertools
a=[]
for i in range(5):
    a.append(int(input()))
out=sum(a)+50
ls = list(itertools.permutations(range(5)))
for i in ls:
    t=0
    for j in i:
        if t%10 != 0:
            t+=10-t%10
        t+=a[j]
    if t <=out:
        out=t
print(out)

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

int main(){
    char s[100001];
    int i;
    int len;
    int count = 0;
    int a;
    scanf("%s",&s);

    len = strlen(s);
    for(i=1;i<len;i++){
        if(s[i]==s[i-1]){
            count++;
            if(s[i]=='0'){
                s[i]='1';
            }else{
                s[i]='0';
            }
        }
    }
    printf("%d",count);
}

Measured memory_bytes: 256
use std::io;
use std::str::FromStr;
use std::cmp::max;

fn input_tuple() -> (u64, u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1], vec[2])
}

fn main() {
    let (a, b, c) = input_tuple();
    let max_dist = max(max(a, b), c);
    if a == max_dist {
        println!("{}", b * c / 2);
    } else if b == max_dist {
        println!("{}", a * c / 2);
    } else {
        println!("{}", a * b / 2);
    }
}


Measured memory_bytes: 4352
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int A, B, C, D, E, F;

int W[3030];
int S[3030];

int main() {
	
	cin >> A >> B >> C >> D >> E >> F;
	W[0] = S[0] = 1;
	rep(i, 3001) if (W[i]) {
		if (i + 100 * A <= F) W[i + 100 * A] = 1;
		if (i + 100 * B <= F) W[i + 100 * B] = 1;
	}

	rep(i, 3001) if (S[i]) {
		if (i + C <= F) S[i + C] = 1;
		if (i + D <= F) S[i + D] = 1;
	}

	int v = 0, s = 0;

	rep(x, 3001)rep(y, 3001)if (W[x] && S[y]) {
		if (x / 100 * E < y) continue;
		if (x + y > F)continue;
		if (y*v >= s*(x + y))s = y, v = x + y;
	}

	cout << v << " " << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;

int main(){

	ll n, a[10000], b[10000], x=0, y=0;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	for(int i=0; i<n; i++){
		cin >> b[i];
	}
	for(int i=0; i<n; i++){
		if(a[i]>b[i]){
			x+=a[i]-b[i];
		} else if(a[i]<b[i]){
			y+=(b[i]-a[i])/2;
		}
	}
	if(y>=x){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF 1<<30

int main(void){
	int i=0,n,cnt=1,ans,sz;
	bool flag=true;
	string s;
	cin >> s;
	n = s.length();
	ans = INF;
	for(i=1; i<n; i++){
		if(s[i] != s[i-1]){
			flag = false;
			ans = min(ans,max(n-i,i));
		}
	}
	if(flag){
		ans = n;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
N = int(input())
# N < 10 ^ 5
A = [0] + [int(x) for x in input().split()] + [0]
# cost = | a - b |

c = 0 
for i in range(0, N+2):
    c += abs(A[i] - A[i-1])
   
# i, i+1, i+2
for i in range(0, N):
    a1, a2, a3 = A[i], A[i+1], A[i+2]
    d = 0
    if   a1 <= a2 <= a3:
        d = 0
    elif a1 <= a3 <= a2: # 1 3 2
        d = abs(a2 - a3)*2
    elif a2 <= a1 <= a3:
        d = abs(a1 - a2)*2
    elif a2 <= a3 <= a1:
        d = abs(a2 - a3)*2
    elif a3 <= a1 <= a2:
        d = abs(a1 - a2)*2
    elif a3 <= a2 <= a1:
        d = 0
    print(c-d)


Measured memory_bytes: 14040
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 510;

int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};

int main() {
	fast_cin();
	int n; cin >> n;
	vector<int> p(n * n);
	for (auto& i : p) {
		cin >> i;
	}
	vector<vector<int>> cost(n + 2, vector<int>(n + 2, 0)), occ = cost;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			cost[i][j] = min(min(i - 1, n - i), min(j - 1, n - j));
			occ[i][j] = true;
		}
	}
	int ans = 0;
	for (auto& id : p) {
		int i = (id - 1) / n + 1;
		int j = (id - 1) % n + 1;
		ans += cost[i][j];
		occ[i][j] = 0;
		queue<pii> q;
		q.push({i, j});
		while (!q.empty()) {
			tie(i, j) = q.front();
			q.pop();
			for (int d = 0; d < 4; ++d) {
				int x = i + dx[d];
				int y = j + dy[d];
				if (x < 1 or x > n or y < 1 or y > n) {
					continue;
				} else if (cost[i][j] + occ[i][j] < cost[x][y]) {
					cost[x][y] = cost[i][j] + occ[i][j];
					q.push({x, y});
				}
			}
		}
	}
	cout << ans << '\n';
}

Measured memory_bytes: 6108
a_line = input()
a_line = list(a_line)
#print(a_line)
b_line = input()
b_line = list(b_line)

c_line = input()
c_line = list(c_line)

end = 0
turn = "a"

while(end == 0):
    if turn=="a":
        if len(a_line) == 0:
            end = "A"
        else:
            temp = a_line[0]
            del a_line[0]
            #print(a_line)
            turn = temp
        
        
    elif turn=="b":
        if len(b_line) == 0:
            end = "B"
        else:
            temp = b_line[0]
            del b_line[0]
            #print(b_line)
            turn = temp    
    
    else:
        if len(c_line) == 0:
            end = "C"
        else:
            temp = c_line[0]
            del c_line[0]
            #print(b_line)
            turn = temp    
        
        
print(end)        

Measured memory_bytes: 9084
#include <iostream> 

using namespace std;

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

    int p[N+10];
    int max = 0;
    for (int i=0; i<N; ++i) {
        cin >> p[i];
        if (max < p[i]) max = p[i];
    }

    int tmp = 0;
    int sum;
    for (int i=0; i<N; ++i) {
        tmp += p[i];
    }
    sum = tmp - max/2;

    cout << sum << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

template<typename T> class Dijkstra {
public:
	struct edge{
		int to; T cost;
	};
	vector<vector<edge> > G;
	vector<T> d;
	int V;
	using pti = pair<T,int>;
	Dijkstra(int node_size){
		V = node_size;
		G.resize(V),d.resize(V,numeric_limits<T>::max());
	}
	//無向グラフの場合
	void add_edge(int u,int v,T cost){
		G[u].pb((edge){v,cost}),G[v].pb((edge){u,cost});
	}
	void solve(int s){
		priority_queue<pti,vector<pti>,greater<pti> > que;
		d[s] = 0;
		que.push(pti(0,s));
		while(!que.empty()){
			pti p = que.top();
			que.pop();
			int v = p.second;
			if(d[v] < p.first) continue;
			for(auto& w : G[v]){
				if(d[w.to] > d[v] + w.cost){
					d[w.to] = d[v] + w.cost;
					que.push(pti(d[w.to],w.to));
				}
			}
		}
	}
};

const ll INIT = 1000000000000000LL;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,s,t;
    cin >> n >> m >> s >> t;
    --s,--t;
    Dijkstra<ll> dj1(n),dj2(n);
    rep(i,m){
        int u,v,a,b;
        cin >> u >> v >> a >> b;
        dj1.add_edge(u-1,v-1,a),dj2.add_edge(u-1,v-1,b);
    }
    dj1.solve(s), dj2.solve(t);
    multiset<ll> st;
    vector<ll> vec(n);
    rep(i,n){
        vec[i] = INIT - dj1.d[i] - dj2.d[i];
        st.insert(vec[i]);
    }
    rep(i,n){
        cout << *(--st.end()) << "\n";
        st.erase(st.find(vec[i]));
    }
    return 0;
}


Measured memory_bytes: 23552
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+3;
string s,p,x;
//vector<int>v;
//map<int,int>mp;

int main()
{
    ft
    int t,i,j,n,m,l,r;
    cin>>s>>p>>n>>m>>x;
    if(x==s)
    {
        n--;
    }
    if(x==p)
    {
        m--;
    }
    cout<<n<<" "<<m<<"\n";
    return 0;
}



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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define maxn 1e5
#define PI 3.141592653589793
#define int long long int
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int mpow(int N, int P, int M) //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0)
    {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}
int binsearch(int n) //二分探索
{
    int l = -1;
    int r = maxn + 1;
    while (abs(r - l) > 1)
    {
        int mid = (r + l) / 2;
        if (true)
        {
            l = mid;
        }
        else
        {
            r = mid;
        }
    }
    return l;
}
signed main()
{
    int a, b, x;
    cin >> a >> b >> x;
    int V = a * a * b;
    double area = (double)x / a;
    bool boundary = false;
    if (area <= (double)a * (double)b / 2)
    {
        boundary = true;
    }
    if (boundary)
    {
        double limit = area * 2 / b;
        cout << fixed << setprecision(10) << 90 - (atan2(limit, b) * 180 / PI) << endl;
    }
    else
    {
        double y = 2 * area / a - b;
        y = b - y;
        cout << fixed << setprecision(10) << 90 - (atan2(a, y) * 180 / PI) << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
    long long int n,a[100009],c[100009]= {0},i,count=0,x=1;
    scanf("%lld",&n);
    for(i=0; i<n; i++)
    {
        scanf("%lld",&a[i]);
        c[a[i]]++;
    }

    if(n%2==1)
    {
        if(c[0]!=1)
        {
            x=0;
        }
        else
        {
            for(i=0; i<n; i++)
            {
                if(a[i]!=0&&c[a[i]]!=2)
                {
                    x=0;
                }
            }
        }
    }
    else if(n%2==0)
    {
        if(c[0]!=0)
        {
            x=0;
        }
        else
        {
            for(i=0; i<n; i++)
            {
                if(a[i]!=0&&c[a[i]]!=2)
                {
                    x=0;

                }
            }
        }
    }
        for(i=1; i<=n/2; i++)
        {
            x=x*2;
            x=x%1000000007;
        }
        printf("%lld\n",x);
    return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;

int n;
int arr[N][2];
void solve(){
    for(int i = 0; i < n - 2; i++){
        if(arr[i][0] == arr[i][1] && arr[i + 1][0] == arr[i + 1][1] && arr[i + 2][0] == arr[i + 2][1]){
            cout << "Yes";
            return;
        }
    }
    cout << "No";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    while(t--) {
        cin >> n;
        for(int i = 0; i < n; i++)
            cin >> arr[i][0] >> arr[i][1];
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
alias route = Tuple!(long, "From", long, "To");
long bignum = 1_000_000_007;

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    auto s = sread();
    long first_C, first_F;
    foreach (i,e; s)
    {
        if(!first_C && e == 'C')
            first_C = i + 1;
        if(e == 'F')
            first_F = i + 1;
    }
    if(first_C && first_F)
    {
        if(first_C < first_F)
        {
            writeln("Yes");
            return;
        }
    }
    writeln("No");
}

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

using namespace std;

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

    cin >> s;

    if(s.at(2) == s.at(3) && s.at(4) == s.at(5)) printf("Yes\n");
    else printf("No\n");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

struct UnionFind {
    UnionFind() {}
    UnionFind(int n) {
        resize(n);
    }
    
    void resize(int n) {
        par.resize(n, -1);
    }
    
    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    
    bool merge(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (par[rx] > par[ry]) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }
    
    bool is_same(int x, int y) {
        return (root(x) == root(y));
    }
    
    int size(int x) {
        return -par[root(x)];
    }
    
private:
    vector<int> par;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    map<int, bool> used;
    set<int> cnt;
    int ans = 0;
    rep(i, m) {
        int x, y, z;
        cin >> x >> y >> z;
        x--; y--;
        uf.merge(x, y);
        used[x] = true;
        used[y] = true;
    }
    rep(i, n) {
        if (used[i]) {
            cnt.insert(uf.root(i));
        }
        else {
            ans++;
        }
    }
    ans += sz(cnt);
    // printf("nu=%d, cnt=%d\n", sz(used), sz(cnt));
    cout << ans << endl;
    return 0;
}


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

bool ok(string s) {
  if (s[0] == '0') {
    return s.length() == 1;
  }

  ll v = 0;
  REP(i, 0, s.length()) {
    v = v * 10 + (s[i] - '0');
  }
  return 1 <= v && v <= 255;
}

int main(void) {
  string S;
  cin >> S;

  ll ans = 0;
  REP(i, 1, S.length()) REP(j, i + 1, S.length()) REP(k, j + 1, S.length()) {
    if (ok(S.substr(0, i)) && ok(S.substr(i, j - i)) && ok(S.substr(j, k - j)) && ok(S.substr(k, S.length() - k))) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3208
import sys

H, W = map(int, input().split())
l = []
for i in range(H):
  l.append(list(input()))

for i in range(H):
  for j in range(W):
    c=0
   
    if l[i][j]=="#":
      pass
   
    else:
      # 左上
      if 0<i and 0<j and l[i-1][j-1]=='#':
        c+=1
      # 上
      if 0<i and l[i-1][j]=='#':
        c+=1
      # 右上
      if 0<i and j<W-1 and l[i-1][j+1]=='#':
        c+=1
      # 左
      if 0<j and l[i][j-1]=='#':
        c+=1
      # 右
      if j<W-1 and l[i][j+1]=='#':
        c+=1
      # 左下
      if i<H-1 and 0<j and l[i+1][j-1]=='#':
        c+=1
      # 下
      if i<H-1 and l[i+1][j]=='#':
        c+=1
      # 右下
      if i<H-1 and j<W-1 and l[i+1][j+1]=='#':
        c+=1
        
              # 地雷隣接数を記載
      l[i][j]=str(c)

# 出力
for i in range(H):
  print(''.join(l[i]))

Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
 
int const N = 1234;
 
long long f[N];
int c[N][4];
long long dp[1<<4];
int can[42];
long long cr[N][4];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 4; j++) {
      scanf("%d", c[i] + j);
    }
    
    
    for (int rot = 0; rot < 4; rot++) {
      long long z = 0;
      for (int e = 0; e < 4; e++) {
        z = z * 1000 + c[i][(e + rot) & 3];
      }
      cr[i][rot] = z;
    }
  }
  
  long long ans = 0;
  for (int first = 0; first < n; first++) 
  {
    for (int back = first + 1; back < n; back++) 
    {
      for (int rb = 0; rb < 4; rb++) 
      {
        for (int i = 0; i < 4; i++) 
        {
          f[i] = c[first][(i + 1) & 3];
          f[i] = f[i] * 1000 + c[first][i];
          f[i] = f[i] * 1000 + c[back][(-i + rb + 1) & 3];
          f[i] = f[i] * 1000 + c[back][(-i + rb) & 3];
        }
        memset(dp, 0, sizeof(dp));
        dp[0] = 1;
        for (int i = first + 1; i < n; i++) 
        {
          if (i == back) continue;
          for (int j = 0; j < 4; j++) 
          {
            can[j] = 0;
            for (int rot = 0; rot < 4; rot++) 
            {
              if (f[j] == cr[i][rot]) 
              {
                ++can[j];
              }
            }
          }
          
          dp[15] += dp[14] * can[0];
          dp[15] += dp[13] * can[1];
          dp[15] += dp[11] * can[2];
          dp[15] += dp[7] * can[3];
          dp[14] += dp[12] * can[1];
          dp[14] += dp[10] * can[2];
          dp[14] += dp[6] * can[3];
          dp[13] += dp[12] * can[0];
          dp[13] += dp[9] * can[2];
          dp[13] += dp[5] * can[3];
          dp[12] += dp[8] * can[2];
          dp[12] += dp[4] * can[3];
          dp[11] += dp[10] * can[0];
          dp[11] += dp[9] * can[1];
          dp[11] += dp[3] * can[3];
          dp[10] += dp[8] * can[1];
          dp[10] += dp[2] * can[3];
          dp[9] += dp[8] * can[0];
          dp[9] += dp[1] * can[3];
          dp[8] += dp[0] * can[3];
          dp[7] += dp[6] * can[0];
          dp[7] += dp[5] * can[1];
          dp[7] += dp[3] * can[2];
          dp[6] += dp[4] * can[1];
          dp[6] += dp[2] * can[2];
          dp[5] += dp[4] * can[0];
          dp[5] += dp[1] * can[2];
          dp[4] += dp[0] * can[2];
          dp[3] += dp[2] * can[0];
          dp[3] += dp[1] * can[1];
          dp[2] += dp[0] * can[1];
          dp[1] += dp[0] * can[0];
        }
        ans += dp[15];
      }
    }
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 256