akhauriyash/Code-Regression huggingface dataset:
import sys
import numpy as np
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())


def main():
    s = input()
    n = len(s)
    k = ii()
    a = set()
    for i in range(1, k+1):
        for j in range(n):
            a.add(s[j:j+i])
    print(sorted(a)[k-1])
    
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 28532
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

n, m = map(int, input().split())

for i in make_divisors(m):
    if i >= n:
        print(m // i)
        break

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

int ctoi(char c) {
    int n = c - '0';
    return n;
}

int pow_int(int x, int n) {
    if (n == 0) {
        return 1;
    }else {
        int y = x;
        for (int i = 0; i < n-1; i++) {
            x *= y;
        }
        return x;
    }
}


int main() {
    long long n, k;
    cin >> n >> k;
    if (n == 0 || k == 1) {
        cout << 0 << endl;
    }else if(n <= k) {
        cout << min(n, llabs(n-k)) << endl;
    }else if(k <= n/2) {
        cout << min(n%k, k-(n%k)) << endl;
    }else {
        n -= k;
        cout << min(n, llabs(n-k)) << endl;
    }
    // long long t = n%k;
    // cout << min(t, k-t);
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1 << 30 - 1;
constexpr long long LLINF = 1LL << 60;
constexpr long long MOD = 1000000007;

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


int main()
{
  int N; 
  cin >> N;
  vector<int> V(N);
  REP(i, N) cin >> V[i];
  REP(i, N) {
    int C;
    cin >> C;
    V[i] -= C;
  }

  cout << accumulate(ALL(V), 0,
      [](int acc, int e) { return acc + max(0, e);}) << endl;

  return 0;
}


Measured memory_bytes: 256
D, G = map(int, input().split())
P = []
C = []
for i in range(D):
    p, c = map(int, input().split())
    P.append(p)
    C.append(c)


def bit_search(A):
    result = []
    for i in range(1 << len(A)):
        output = []
        for j in range(len(A)):
            if ((i >> j) & 1) == 1:
                output.append(A[j])
        result.append(output)

    return result


search_list = bit_search(list(range(D)))
ans = 10 ** 9
for complete_list in search_list:
    score = sum([100 * (i + 1) * P[i] + C[i] for i in complete_list])
    count = sum([P[i] for i in complete_list])
    if score >= G:
        ans = min(ans, count)
    else:
        j_max = max([i for i in range(D) if i not in complete_list])
        required = -(-(G - score) // (100 * (j_max + 1)))
        if required < P[j_max]:
            count += required
            ans = min(ans, count)
print(ans)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
    string s,t;
    cin>>s>>t;
    int ans=0;
    for(int i=0;i<s.size();i++) if(s[i]!=t[i]) ans++;
    cout<<ans<<"\n";
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

    solve();
    return 0;
}

Measured memory_bytes: 3792
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){
  int i;
  int n,m,h,k;
  while(scanf("%d%d%d%d",&n,&m,&h,&k),n||m||h||k){
    pair<int,int> a[1000];
    for(i=0;i<n;++i)
      scanf("%d",&(a[i].second));
    pair<int,int> b[100000];
    for(i=0;i<m;++i)
      scanf("%d%d",&(b[i].second),&(b[i].first));
    sort(b,b+m);
    int c[1000];
    for(i=0;i<n;++i)
      c[i]=i;
    for(i=0;i<m;++i){
      int p=c[b[i].second-1];
      c[b[i].second-1]=c[b[i].second];
      c[b[i].second]=p;
      b[i]=make_pair(c[b[i].second],c[b[i].second-1]);
    }
    for(i=0;i<n;++i)
      a[i].first=c[i];
    sort(a,a+n);
    int sm=0;
    for(i=0;i<k;++i)
      sm+=a[i].second;
    int mn=sm;
    for(i=0;i<m;++i){
      if(b[i].first<k&&b[i].second>=k&&a[b[i].first].second>a[b[i].second].second)
	mn=min(mn,sm-a[b[i].first].second+a[b[i].second].second);
      if(b[i].first>=k&&b[i].second<k&&a[b[i].first].second<a[b[i].second].second)
	mn=min(mn,sm+a[b[i].first].second-a[b[i].second].second);
    }
    printf("%d\n",mn);
  }
  return 0;
}

Measured memory_bytes: 1548
#!/usr/bin/env python3
from scipy.sparse.csgraph import floyd_warshall
INF = float("inf")

h, w = map(int, input().split())
M = [input() for _ in [0]*h]
E = [[0]*h*w for _ in [0]*h*w]
D = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def point(x, y):
    return w * x + y

for i in range(h):
    for j in range(w):
        if M[i][j] == ".":
            for x, y in D:
                I, J = i + x, j + y
                if w > J >= 0 <= I < h and M[I][J] == ".":
                    E[point(i, j)][point(I, J)] = 1

a = floyd_warshall(E)
print(int(a[a != INF].max()))

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

ll n, t_n, t_r, a_n, a_r;
vector<ll> t, a;

ll ceiling(ll x, ll y) {
  if (x % y == 0) {
    return x / y;
  } else {
    return x / y + 1;
  }
}

void ratio_plus() {
  if (t_n > t_r || a_n > a_r) {
    ll t_q, a_q, max_q;
    t_q = ceiling(t_n, t_r);
    a_q = ceiling(a_n, a_r);
    max_q = max(t_q, a_q);
    t_r *= max_q;
    a_r *= max_q;
  }
}

void solve() {
  for (int i = 0; i < n; i++) {
    t_r = t[i];
    a_r = a[i];
    ratio_plus();
    t_n = t_r;
    a_n = a_r;
  }
  cout << t_n + a_n << '\n';
  return;
}

int main() {
  cin >> n;
  t.resize(n);
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> t[i] >> a[i];
  }
  solve();
  return 0;
}

Measured memory_bytes: 256
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    s = input().split()

    for i in s:
        if i == 'Y':
            print('Four')
            return
    
    print('Three')

solve()


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &A[i]);
  }
  sort(A.begin(), A.end(), greater<int>());
  vector<int> bars;
  int cnt = 0;
  for (int i = 0, j = 0; i < N and cnt < 2; i = j) {
    while (j < N and A[j] == A[i] and (j - i) < 4) { ++j; }
    int num = j - i;
    if (num == 4) {
      cnt += 2;
      bars.push_back(A[i]);
      bars.push_back(A[i]);
    }
    else if (num >= 2) {
      ++cnt;
      bars.push_back(A[i]);
    }
  }

  ll ans = 0;
  if (cnt >= 2) {
    ans = 1LL * bars[0] * bars[1];
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef pair<vector<int>,vector<int> > P;
typedef pair<int,int> S;

int w,h,n;
string s[20];
int ax[]={1,-1,0,0,0};
int ay[]={0,0,1,-1,0};

S i2s(int x){
  return S(x/2744,x%2744);
}
int s2i(const S& s){
  //cout<<s.first<<" "<<s.second<<":"<<(s.first<<13)+s.second<<endl;
  return (s.first*2744)+s.second;
}
S p2s(const P& p){
  int y=0,x=0;
  for(int i=n-1;i>=0;i--){
    y=y*14+p.first[i]-1;
    x=x*14+p.second[i]-1;
  }
  return S(y,x);
}

P s2p(const S& s){
  vector<int> y,x;
  int a=s.first,b=s.second;
  for(int i=0;i<n;i++){
    y.push_back(a%14+1);
    x.push_back(b%14+1);
    a/=14;b/=14;
  }
  return P(y,x);
}

int p2i(const P& p){
  return s2i(p2s(p));
}
P i2p(int x){
  return s2p(i2s(x));
}


short m[7530000];
queue<int> q;

vector<int> ys,xs;

int calc(){
  int y=0,x=0;
  for(int i=n-1;i>=0;i--){
    y=y*14+ys[i]-1;
    x=x*14+xs[i]-1;
  }
  return s2i(S(y,x));
}

void dfs(int d,P& p,int xyz){
  if(d==n){
    int abc=calc();
    if(~m[abc]) return;
    m[abc]=m[xyz]+1;
    q.push(abc);
    return;
  }
  for(int k=0;k<5;k++){
    int ny=p.first[d]+ay[k],nx=p.second[d]+ax[k];
    if(ny<0||h<=ny||nx<0||w<=nx) continue;
    if(s[ny][nx]=='#') continue;
    bool f=0;
    for(int j=0;j<d;j++){
      f|=(ys[j]==ny&&xs[j]==nx);
      f|=(ys[j]==p.first[d]&&xs[j]==p.second[d])&&
	 (ny==p.first[j]&&nx==p.second[j]);
    }
    if(f) continue;
    ys.push_back(ny);
    xs.push_back(nx);
    dfs(d+1,p,xyz);
    ys.pop_back();
    xs.pop_back();
  }
}

signed main(){
  while(cin>>w>>h>>n,w||h||n){
    cin.ignore();
    for(int i=0;i<h;i++) getline(cin,s[i]);
    vector<int> yt(n),xt(n);
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	if(islower(s[i][j])){
	  yt[s[i][j]-'a']=i;
	  xt[s[i][j]-'a']=j;
	}
    memset(m,-1,sizeof(m));
    while(!q.empty()) q.pop();
    q.push(p2i(P(yt,xt)));
    m[p2i(P(yt,xt))]=0;
    int ans=-1;
    while(!q.empty()){
      int xyz=q.front();q.pop();
      P p=i2p(xyz);
      //cout<<xyz<<":"<<m[xyz]<<endl;
      //for(int i=0;i<n;i++) cout<<p.first[i]<<" "<<p.second[i]<<endl;
      bool flg=1;
      for(int i=0;i<n;i++)
	flg&=(s[p.first[i]][p.second[i]]=='A'+i);
      if(flg){
	ans=m[xyz];
	break;
      }
      dfs(0,p,xyz);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 18616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    if(s.find('7')!=string::npos)cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

void solve(int a, string s){
    VI b(a+1), w(a+1);

    int tmp = 0;
    w.PB(0);
    REP(i, s.size()) {
        if(s[i] == '#') tmp++;
        w[i+1] = tmp;
    }

    tmp = 0;
    RREP(i, s.size()-1) {
        if(s[i] == '.') tmp++;
        b[i] = tmp;
    }
    b.PB(0);

    int ans = INF;
    REP(i, s.size()) {
        ans = min(ans, w[i] + b[i+1]);
    }

    cout << ans << endl;
}

int main(){
    int a;
    cin >> a;
    string s;
    cin >> s;
    solve(a, s);
    return 0;
}


Measured memory_bytes: 2948
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(int i = a;i < n;i++)
#define LINF (ll)1e17
#define INF 1e9
#define MOD 1e9+7
#define sMOD 1e5
#define fs first
#define sc second


signed main(){
	
	ll n,temp = 1,temp2 = 0,ans = 0;
	cin >> n;
	ll memo[n] = {};
	
	rep(i,0,n){
		if(temp <= temp2){
			temp++;
			temp2 = 0;
			
		}
		memo[i] = temp;
		temp2++;
	}
	
	while(n > 0){
		cout << memo[n-1] << endl;
		n -= memo[n-1];
		
	}
	
	return 0;

}

Measured memory_bytes: 78336
import sys
input = sys.stdin.readline
N = int(input())
act = [tuple(map(int, input().split())) for _ in range(N)]
dp = [[0] * 3 for _ in range(N)]
dp[0][0] = act[0][0]
dp[0][1] = act[0][1]
dp[0][2] = act[0][2]
for i in range(N - 1):
  for j in range(3):
    dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + act[i + 1][j]
print(max(dp[-1]))

Measured memory_bytes: 70620
import heapq

N = int(input())
V = list(map(int, input().split()))

evens = [(0, 0)]*(10**5+1)
odds = [(0, 0)]*(10**5+1)
for i in range(N):
    if (i+1) % 2 == 0:
        evens[V[i]] = (V[i], evens[V[i]][1] + 1)
    else:
        odds[V[i]] = (V[i], odds[V[i]][1] + 1)

evens_top_two = heapq.nlargest(2, evens, key=lambda x: x[1])
odds_top_two = heapq.nlargest(2, odds, key=lambda x: x[1])

if evens_top_two[0][0] != odds_top_two[0][0]:
    print(N - evens_top_two[0][1] - odds_top_two[0][1])
else:
    print(min(N - evens_top_two[0][1] - odds_top_two[1][1],
              N - evens_top_two[1][1] - odds_top_two[0][1]))


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

M = int(input())
t = []
for i in range(M):
    t.append(input())

s_set = list(set(s))
t_set = list(set(t))

ans = 0
for i in range(len(s_set)):
    y = 0
    for j in range(N):
        if s_set[i] == s[j]:
            y += 1
    for k in range(M):
        if s_set[i] == t[k]:
            y -= 1
    if y > ans:
      ans = y

print(ans)

Measured memory_bytes: 9108
from fractions import Fraction

N,K=map(int,input().split())

number = []
count = 0
result_a = 0

for i in range(1,N+1):
    while i <= K-1:
        i *= 2
        count += 1
    count = 2**count
    number.append(count*N)
    count = 0

for j in range(N):
    number[j] = Fraction(1,number[j])

for k in range(N):
    result_a += number[k]

result_b = float(result_a)
print(result_b)

Measured memory_bytes: 18784
#include <bits/stdc++.h>                 // [PRIMES]               1777 ~2^10.80
using namespace std;                     //                       10333 ~2^13.33
using ll=long long;                      // seq 1 128 | factor   100333 ~2^16.61
using vl=vector<ll>;                     //   | grep -v ' .* '  1300111 ~2^20.31
using vvl=vector<vl>;                    //                    10300777 ~2^23.30
using vb=vector<bool>;                   //                   100400999 ~2^26.58
using vs=vector<string>;                 //                  1300400999 ~2^30.28
using pll=pair<ll,ll>;                   //                 10200500333 ~2^33.25
const ll oo =0x3f3f3f3f3f3f3f3fLL;       //                100200400777 ~2^36.54
const double eps=1e-9;                   //               1200300700111 ~2^40.13
#define sz(c) ll((c).size())             //              10200300500777 ~2^43.21
#define all(c) begin(c),end(c)           //             100200300400777 ~2^46.51
#define mp make_pair                     //            1200300400600999 ~2^50.09
#define mt make_tuple                    //           10200300400600111 ~2^53.18
#define pb push_back                     //          100200300400600333 ~2^56.48
#define eb emplace_back                  //         1200300400500800999 ~2^60.06
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main(){
	cin.sync_with_stdio(0);
	// cin.tie(0);

	ll n;
	cin >> n;

	unordered_map<string, pll> anas;

	string s;
	FOR(i,0,n) {
		cin >> s;
		sort(s.begin(), s.end());
		if (!anas.insert({s, {1, 0}}).yy) {
			anas[s] = {anas[s].xx + 1, anas[s].yy + anas[s].xx};
		}
	}

	ll result = 0ll;
	for (auto ele : anas) {
		result += ele.yy.yy;
	}
	cout << result << '\n';
}


Measured memory_bytes: 10660
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        Console.WriteLine(getAns(n, k));
    }
    static long getAns(int n, int k)
    {
        var ans = 0L;
        for (int i = 0; i < n - 1; i++)
        {
            var w1 = ans / (k - 1);
            var w2 = ans % (k - 1);
            ans = k * w1 + w2 + 1;
        }
        return ans;
    }
}



Measured memory_bytes: 17928
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,k;
  cin >> n >> k;
  vector<int64_t> cont(100);
  vector<int64_t> abc(n);
  
  for(int i = 0 ; i < n ; i++){
    int64_t a;
    cin >> a;
    abc.at(i) = a;
    int active = 0;
    while(a > 0){
      if(a&1 == 1){
        cont.at(active)++;
      }
      active++;
      a >>= 1; 
    }
  }

  int64_t cnt = 0;
  int64_t jjj = k;
  
  while(jjj > 0){
    jjj = (jjj>>1);
    cnt++;
  }

  int64_t ans = 0;
  if(k == 0){
    cout << abc.at(0) << endl;
    return 0;
  }
  
  for(int i = 0 ; i < cnt ; i++){
    int64_t jad = 0;
    bitset<50> aaa(k);
    
    for(int j = 0 ; j <= i ; j++){
      if(j == i){
        aaa.set(j,0);
        continue;
      }
      
      if(cont.at(j) > n - cont.at(j)){
        aaa.set(j,0);
      }
      else{
        aaa.set(j,1);
      }
    }
    
    if(aaa.to_ullong() > k){
      continue;
    }
    
    for(int p = 0 ; p < n ; p++){
      bitset<50> ccc(abc.at(p));
      bitset<50> ddd = (aaa^ccc);
      jad += ddd.to_ullong();
    }
    
    ans = max(ans , jad);
  }
  
  cout << ans << endl;
}

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

const double eps = 1e-10;

int dcmp(double x) {
        if(fabs(x) < eps) return 0;
        return x < 0 ? -1 : 1;
}

#define Vector P
struct P {
        double x, y;
        P(double x = 0, double y = 0): x(x), y(y) {}
        P operator + (P b) {return P(x + b.x, y + b.y);}
        P operator - (P b) {return P(x - b.x, y - b.y);}
        P operator * (double b) {return P(x * b, y * b);}
        P operator / (double b) {return P(x / b, y / b);}
        double operator * (P b) {return x * b.x + y * b.y;} // Dot
        double operator ^ (P b) {return x * b.y - y * b.x;} // Cross
        double abs() {return hypot(x, y);}
        P unit() {return *this / abs();}
        P spin(double o) {
                double c = cos(o), s = sin(o);
                return P(c * x - s * y, s * x + c * y);
        }
};

struct Line {
        //ax + by + c = 0
        double a, b, c, theta;
        P pa, pb;
        Line(): a(0), b(0), c(0), theta(0), pa(), pb() {}
        Line(P pa, P pb): a(pa.y - pb.y), b(pb.x - pa.x), c(pa ^ pb), theta(atan2(-a, b)), pa(pa), pb(pb) {}        P projection(P p) {return pa + (pb - pa).unit() * ((pb - pa) * (p - pa) / (pb - pa).abs());}                P reflection(P p) {return p + (projection(p) - p) * 2;}
        double get_ratio(P p) {return (p - pa) * (pb - pa) / ((pb - pa).abs() * (pb - pa).abs());}
        P dis(P p) {return ((pb - pa) ^ (p - pa)) / (pb - pa).abs();} // directed distance
};

struct Circle {
        P c;
        double r;
        Circle(P c, double r = 0): c(c), r(r) {}
};
bool onsegment(P p, P a, P b) {
        return dcmp((a - p) ^ (b - p)) == 0 && dcmp((a - p) * (b - p)) <= 0;
}
bool segment_intersection(P p1, P p2, P p3, P p4) { // end points are not allowed
        return dcmp((p2 - p1) ^ (p3 - p1)) * dcmp((p2 - p1) ^ (p4 - p1)) < 0
                && dcmp((p4 - p3) ^ (p1 - p3)) * dcmp((p4 - p3) ^ (p2 - p3)) < 0;

}

int main() {
        ios_base::sync_with_stdio(false); cin.tie(0);
        int q; cin >> q;
        while(q--) {
                P p0, p1, p2, p3;
                cin >> p0.x >> p0.y >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
                if(segment_intersection(p0, p1, p2, p3) || onsegment(p0, p2, p3) || onsegment(p1, p2, p3) || onsegment(p2, p0, p1)|| onsegment(p3, p0, p1)) cout << 1 << '\n';
                else cout << 0 << '\n';
        }
        return 0;
}


Measured memory_bytes: 3288
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
#define rep(i,n) for(long long i=0;i<n;i++)
int main()
{
    int n,l;
    cin >> n >> l;
    string ww[n];
    rep(i,n) cin >> ww[i];
    sort(ww, ww + n);
    rep(i,n) cout << ww[i];
    return 0;
}

Measured memory_bytes: 256
a, b, c = (int(x) for x in input().split())
list = [a, b, c]

for i in range(2,0,-1):
    for j in range(i):
        if list[j]>list[j+1]:
            list[j], list[j+1] = list[j+1], list[j]
print(list[0],list[1],list[2])


Measured memory_bytes: 5604
#include <iostream>
#include <stack>

int main(){

	std::stack<int> train;
	int buf;

	while(std::cin >> buf){

		if(buf == 0){

			std::cout << train.top() << std::endl;
			train.pop();

		}else{
			train.push(buf);
		}
	}
	return 0;
}	

Measured memory_bytes: 1200
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////

ll po(ll i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}
ll bunbo(ll n){
    return po(n,i_5);
}


#define N 2000004
ll kai[N];
ll kai2[N];
void calc(){
    kai[0]=1;
    kai2[0]=1;
    rep(i,1,N-1){
        kai[i]=mod(kai[i-1]*i);
    }
    kai2[N-1]=po(kai[N-1],i_5);
    for(ll i=N-2;i>=0;i--){
        kai2[i]=mod(kai2[i+1]*(i+1));
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n==0)return 1;
    return mod(mod(kai[n]*kai2[n-k])*kai2[k]);
}

bool comp(l_l a,l_l b){
    return a.fi+a.se<b.fi+b.se;
}



int main(){fastio
    calc();
    ll h,w,n;cin>>h>>w>>n;
    l_l p[n];
    rep(i,0,n-1)cin>>p[i].fi>>p[i].se;
    sort(p,p+n,comp);
    ll dp[n];
    rep(i,0,n-1){
        dp[i]=comb(p[i].fi-1+p[i].se-1,p[i].se-1);
        
        rep(j,0,i-1){
            if(p[i].fi<p[j].fi)continue;
            if(p[i].se<p[j].se)continue;
            Add(dp[i],-dp[j]*comb(-(p[j].fi-p[i].fi+p[j].se-p[i].se),-(p[j].fi-p[i].fi)));
        }
    }
    //rep(i,0,n-1)cout<<dp[i]<<endl;
    ll ans=comb(h+w-2,h-1);
    rep(i,0,n-1){
        Add(ans,-dp[i]*comb(h+w-p[i].fi-p[i].se,h-p[i].fi));
    }
    cout<<mod(ans)<<endl;
    
    return 0;
}


Measured memory_bytes: 31616
#include<bits/stdc++.h>
using namespace std;
map<int,int> M;
int main()
{
  int N;
  cin>>N;
  long long Ans=0;
  for(int i=1;i<=N;i++)
  {
    int X;
    cin>>X;
    Ans+=M[i-X];
    M[X+i]++;
  }
  cout<<Ans<<endl;
  return 0;
}

Measured memory_bytes: 20452
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<map>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;

typedef pair<string,int> psi;

char st[200][200]={0};

int main(void){
	
	A:;
	string str;
	cin>>str;
	
	if(str=="0")return 0;
	
	queue<psi> que;
	que.push(psi(str,0));
	
	map<string,int> memo;
	
	st['r']['b']='g';
	st['b']['r']='g';
	st['r']['g']='b';
	st['g']['r']='b';
	st['g']['b']='r';
	st['b']['g']='r';
	
	int ans = -1;
	while(1){
		if(que.empty()){
			break;
		}
		
		psi u = que.front();
		que.pop();
		
		bool flg = true;
		rep(i,u.first.size()-1)if(u.first[i]!=u.first[i+1])flg=false;
		
		if(flg){
			ans = u.second;
			break;
		}
		
		if(memo[u.first]==1)continue;
		memo[u.first]=1;
		
		rep(i,u.first.size()-1){
			if(u.first[i] == u.first[i+1])continue;
			string copy = u.first;
			char c3 = st[u.first[i]][u.first[i+1]];
			copy[i] = copy[i+1] = c3;
			que.push(psi(copy,u.second+1));
		}
	}
	
	if(ans==-1)printf("NA\n");
	else printf("%d\n",ans);
	
	goto A;
}

Measured memory_bytes: 3408
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B =  [int(input()) for _ in range(N)]

for b in B:
  for i in range(3):
    for j in range(3):
      if A[i][j] == b:
        A[i][j] = 0

for i in range(3):
  if A[i][0] == A[i][1] == A[i][2] == 0:
    print('Yes')
    exit()

  if A[0][i] == A[1][i] == A[2][i] == 0:
    print('Yes')
    exit()
    
if A[0][0] == A[1][1] == A[2][2] == 0:
    print('Yes')
    exit()
 

if A[0][2] == A[1][1] == A[2][0] == 0:
    print('Yes')
    exit()
    
  
print('No')


Measured memory_bytes: 9028
#include <algorithm>
#include <iostream>
#include <cassert>
#include <vector>

using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b) - 1; i >= (a); --i)
#define trav(x, v) for (auto &x : v)

#define sz(x) int((x).size())
#define eb(x...) emplace_back(x)
#define ff first
#define ss second

using ll = int64_t;

const int M = 1e9 + 7;

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

using vi = vector<int>;
using vvi = vector<vi>;

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

	int n; cin >> n; vi f(n), s(n + 1);
	string x; cin >> x;
	f[0] = 1;
	rep(i, 1, n) {
		vi g(n);
		rep(j, 0, i + 1) s[j + 1] = (s[j] + f[j]) % M;
		if (x[i - 1] == '<')
			rep(j, 0, i + 1) g[j] = s[j];
		else
			rep(j, 0, i + 1) g[j] = (s[i + 1] - s[j]) % M;
		swap(f, g);
	}
	int ans = 0;
	trav(z, f) (ans += z) %= M;
	if (ans < 0) ans += M;
	cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    // 入力
    int N;
    cin >> N;

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

    for (int i = N - 1; i > 0; i--) {
        if (H[i - 1] - H[i] == 1) {
            H[i - 1]--;
        } else if (H[i - 1] - H[i] >= 2) {
            cout << "No" << endl;
            return 0;
        }
    }

    // 出力
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

int N, M;
int X[110], A[110];
int pos[110];
int mark[2020];

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

    memset(mark, 0xff, sizeof(mark));
    cin >> N;
    REP(i, N) {
        cin >> X[i];
        --X[i];
        mark[X[i]] = i;
        pos[i] = X[i];
    }
    cin >> M;
    REP(i, M) {
        cin >> A[i];
        --A[i];
        if (~mark[pos[A[i]] + 1]) continue;
        mark[pos[A[i]]] = -1;
        pos[A[i]] = min(2018LL, pos[A[i]] + 1);
        mark[pos[A[i]]] = A[i];
    }
    REP(i, N) cout << pos[i] + 1 << endl;
}


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

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

    int h,w,m;

int main(){
    cin>>h>>w>>m;
    vector<int> yv(h),xv(w);
    int x,y;
    set<pair<int,int>> s;
    rep(i,m){
        cin>>y>>x;
        y--;
        x--;
        s.insert(make_pair(y,x));
        yv[y]++;
        xv[x]++;
    }
    int ymax=*max_element(yv.begin(),yv.end());
    int xmax=*max_element(xv.begin(),xv.end());
    ll ans=xmax+ymax;
    vector<int> yvv,xvv;

    rep(i,h) if(yv[i]==ymax) yvv.push_back(i);
    rep(i,w) if(xv[i]==xmax) xvv.push_back(i);

    for(int y : yvv){
        for(int x : xvv) {
            if(s.count(make_pair(y,x))==0){
                cout<<ans<<endl;
                return 0;
            }
        }
    }
    cout<<ans-1<<endl;
    return 0;

}



Measured memory_bytes: 23680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
namespace IO
{
	template <typename T> inline void read(T &x)
	{
		int f = 1; x = 0; char c = getchar();
		for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
		for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
		x *= f;
	}

	template <typename T> inline void chkmax(T &x, T y) { x = x > y ? x : y; }
	template <typename T> inline void chkmin(T &x, T y) { x = x < y ? x : y; }

	template <typename T> inline void write(T x)
	{
		if (x < 0) putchar('-'), x = -x;
		if (x > 9) write(x / 10);
		putchar(x % 10 + '0');
	}
	template <typename T> inline void writesp(T x) { write(x); putchar(' '); }
	template <typename T> inline void writeln(T x) { write(x); putchar('\n'); }
}
using namespace IO;
const int N = 2e5 + 5;
int n, a[N];
int main(){
	int s = 0;
	read(n);
	for (int i = 1; i <= n; i++) {
		read(a[i]); s ^= a[i];
	}
	for (int i = 1; i <= n; i++) writesp(s ^ a[i]);
	puts("");
  return 0;
}

Measured memory_bytes: 4372
#include<bits/stdc++.h>
using namespace std;
#define int long long

map<int,int> vis;
signed main(){
	int f=1;
	int n;cin>>n;for(int i=1;i<=n;i++){
		int t;cin>>t;vis[t]++;
		if(vis[t]>1){
			f=0;
		}
	}	
	if(f) cout<<"YES";
	else cout<<"NO";
	return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
const ll INF = 1e18;
#define print(x) cout << (x) << endl;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> A(n,0);
    vector<int> B(n,0);
    vector<int> C(n-1,0);
    int Bsum = 0;
    for (int i = 0; i < n; i++) {
        cin >> A.at(i);
    }
    for (int i = 0; i < n; i++) {
        cin >> B.at(i);
        Bsum += B.at(i);
    }
    for (int i = 0; i < n-1; i++) {
        cin >> C.at(i);
    }
    for (int i = 0; i < n-1; i++) {
        if (A.at(i+1) == A.at(i)+1) {
            // cout << Bsum << endl;
            Bsum += C.at(A.at(i)-1);
        }
    }
    cout << Bsum << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    char S; 
    rep(i, N) {
        cin >> S;
        if (S == 'Y') {
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<algorithm>
using namespace std;
char s[210000];
int n,ans;
int main()
{
    scanf("%s",s+1);
    n=strlen(s+1);
    ans=n;
    for(int i=1;i<n;i++)
    {
        if(s[i]!=s[i+1])
            ans=min(ans,max(i,n-i));
    }
    printf("%d\n",ans);
    //system("pause");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<climits>

#define ll long long int
#define llu unsigned long long int
#define N 100001
using namespace std;

vector<int> dp(N,0);
int main(){
	int n,k;
  cin>>n>>k;
  vector<ll> v(n+1);
  for(int i=1;i<n+1;i++){
  cin>>v[i];
  }
  dp[1]=0;
  dp[2]=abs(v[1]-v[2]);
  for(int i=3;i<=n;i++){
    ll m=INT_MAX;
    for(int j=1;j<=k&&i-j>0;j++){
  	ll x=dp[i-j]+abs(v[i]-v[i-j]);
      if(x<m)
        m=x;
    }
    dp[i]=m;
  }
  cout<<dp[n];

return 0;
}

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

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

    int ans = 0, buff = 0;
    bool continue_flag = false;
    
    for (int i = 0;i < s.size();i++)
    {
        if (s[i] == 'A'|| s[i] == 'G' || s[i] == 'C' || s[i] == 'T')
        {
            if (continue_flag) buff++;
            else
            {
                continue_flag = true;
                buff = 1;
            }
        }
        else
        {
            continue_flag = false;
        }
        ans = (ans > buff)? ans : buff;
    }

    cout << ans << endl;
    
    return 0;
}


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

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;

ld const PI = 4*atan((ld)1);

int const N = 5e5 + 7;
int bit[N] = {};
int ans[N] = {};
int color[N] = {};
int last[N] = {}; //last occurence of color i
vector<int> q[N]; // [i][j] i.e. i: right, j: left
vector<int> qidx[N]; //Index for query [i][j]

void add(int x, int val)
{
	while (x < N)
		bit[x] += val, x += (x & -x);
}

int sum(int x)
{
	int res = 0;
	while (x)
		res += bit[x], x -= (x & -x);
	return res;
}

int rangesum(int l, int r) //[l, r]
{
	return sum(r) - sum(l-1);
}

int main()
{
	fastio;

	int n, m;
	int l, r;
	cin >> n >> m;

	for (int i = 1; i <= n; ++i)
		cin >> color[i];

	for (int i = 1; i <= m; ++i)
	{
		cin >> l >> r;
		q[r].pb(l);
		qidx[r].pb(i);
	}

	for (int i = 1; i <= n; ++i)
	{
		if (last[color[i]]) add(last[color[i]], -1);
		add(i, 1);
		last[color[i]] = i;

		for (int j = 0; j < q[i].size(); ++j)
		{
			ans[qidx[i][j]] = rangesum(q[i][j], i);
		}
	}

	for (int i = 1; i <= m; ++i)
		cout << ans[i] << '\n';

	return 0;
}


Measured memory_bytes: 52972
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
#include<deque>

//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)

#define All(a) (a).begin(),(a).end()

//定数
#define INF 1e9
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
template<class T>bool chmax(T &a, const T &b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T>bool chmin(T &a, const T &b) {
	if (a > b) { a = b; return 1; }
	return 0;
}


int main()
{
	int n,k;
	cin >> n >> k;
	char pre;
	cin >> pre;
	int ans = 0;
	int cnt = 1;
	REP(i, n-1) {
		char c;
		cin >> c;
		if (c != pre) {
			cnt++;
		}
		else {
			ans++;
		}
		pre = c;
		//cout << ans << " " << cnt << endl;
	}
	if (cnt == 1) {
		ans = n - 1;
	}
	else if (cnt-k*2>=1) {
		ans += k * 2;
	}
	else {
		ans = n - 1;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=505,maxm=1e6+5;

int main()
{  string s;
cin>>s;
bool flag=1;
int len=s.size();
for(int i=0;i<len-1;i++)
{
    if(s[i+1]==s[i])
    {
        flag=0;
        break;
    }
}
if(flag) cout<<"Good"<<endl;
else cout<<"Bad"<<endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

N, T = map(int, input().split())
*a, = map(int, input().split())
t = defaultdict(int)
m = a[0]
p = 0
ans = 0
for i in range(1, N):
    c = a[i] - m
    if t[m] < c:
        t[m] = c
    if a[i] < m:
        m = a[i]
    if c > p:
        p = c
        ans = 1
    elif c == p:
        ans += 1

print(ans)


Measured memory_bytes: 66668
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    a--,b--,c--,d--;
    string s;
    cin>>s;
    ll t=0;
    if(d<c){
        rep(i,b-1,d-1){
            if(s[i]=='.' && s[i+1]=='.' && s[i+2]=='.')
                t=1;
        }
    }
    else t=1;
    if(t==0) {cout<<"No";return;}
    while(1){
        if(a==c) break;
        else if(s[a+2]=='.' && a+2<=c) a+=2;
        else if(s[a+1]=='.' && a+1<=c) a+=1;
        else{cout<<"No";return;}
    }
    while(1){
        if(b==d) break;
        else if(s[b+2]=='.' && b+2<=d) b+=2;
        else if(s[b+1]=='.' && b+1<=d) b+=1;
        else{cout<<"No";return;}
    }
    cout<<"Yes";
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <string>
#include <vector>

int main()
{
    int N;
    long double tmp, div = 0.0;
    std::cin >> N;
    for (int i = 0; i < N; i++)
    {
        std::cin >> tmp;
        div += (1.0 / tmp);
    }

    std::cout << 1.0 / div << std::endl;

    return 0;
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n;
  cin >> n;
  vector<int> ans(4,0);
  vector<string> st = {"AC","WA","TLE","RE"};
  int i,j;
  rep(i,n)
  {
    string ns;
    cin >> ns;
    rep(j,4)
    {
      if(ns == st[j])
      {
        ans[j]++;
        break;
      }
    }
  }
  rep(j,4)
  {
    cout << st[j] << " x " << ans[j] << "\n";
  }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  ll N, M;
  cin >> N >> M;
  pair<ll, pair<ll, ll>> p[M];
  ll p_ans[M];
  REP(i, M) {
    cin >> p[i].second.first >> p[i].first;
    p_ans[i] = p[i].second.first;

    p[i].second.first--;
    p[i].second.second = i;
  }
  sort(p, p + M);
  vector<ll> ans(M), cnt(N, 0);

  REP(i, M) {
    ll P = p[i].second.first, index = p[i].second.second;
    cnt[P]++;
    ans[index] = cnt[P];
  }

  REP(i, M) {
    cout << setw(6) << setfill('0') << p_ans[i];
    cout << setw(6) << setfill('0') << ans[i] << endl;
  }
  return 0;
}

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

struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))
#define int long long

signed main(){
    int m; cin >> m;
    cout << 48 - m << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int n,m;

int solve(){
  int ans=m;
  int tmp=m;

  while(n--){
    int a,b;
    cin >> a >> b;
    tmp+= a-b;
    ans = max(ans,tmp);
    if(tmp < 0) return 0;
  }
  return ans;
}
int main(){

  cin >> n >> m;

  
  cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
#define int long long
#define all(c) (c).begin(), (c).end()
#define cpresent(c,x) ((c).find(x) != (c).end()) 
#define vpresent(c,x) (find(all(c),x) != (c).end())
#define endl '\n'
#ifdef LOCAL
#include "/home/iggaboi/Desktop/CP/debug.h"
#else
#define debug(x...)
#endif
using namespace std;
 
int n, q;
 
void solve(){
    cin >> n;
    int sum = 0;
    vector<int> freq(100069, 0); 
    for(int i = 0, inp; i < n; ++i){
        cin >> inp;
        freq[inp]++;
        sum += inp;
    }
    cin >> q;
    while(q--){
        int b, c;
        cin >> b >> c;
        sum -= freq[b]*b;
        sum += freq[b]*c;
        freq[c] += freq[b];
        freq[b] = 0;
        cout << sum << endl;
    }
}
 
int32_t main(){
	ios_base::sync_with_stdio(false),cin.tie(nullptr);
	// int t; cin >> t;
	// while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 3952
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
 
from functools import reduce
# from math import *
from fractions import *
H, W = map(int, readline().split())
S = [0 for i in range(H)]
for i in range(H):
    S[i] = readline().decode().strip()

from collections import deque
def bfs(start, H, W):
    INF = 10 ** 9
    dist = [INF] * (H * W)
    q = deque([start])
    dist[start[0] * W + start[1]] = 0
    while q:
        (i, j) = q.popleft()
        d = dist[i * W + j]
        for dy in range(-1, 2):
            for dx in range(-1, 2):
                if dx * dy != 0:
                    continue
                if dx == dy:
                    continue
                if i + dy < 0 or i + dy >= H or j + dx < 0 or j + dx >= W:
                    continue
                if S[i + dy][j + dx] == '#':
                    continue
                if dist[(i + dy) * W + j + dx] != INF:
                    continue
                dist[(i + dy) * W + j + dx] = d + 1
                q.append((i + dy, j + dx))
    return max(x for x in dist if x < INF)

ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        start = (i, j)
        ans = max(ans, bfs(start, H, W))
print(ans)


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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> Pair;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

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

ll N;
vector<string> s;

int main() {
    cin >> N;
    s.resize(N);
    REP(i, N) cin >> s[i];
    ll ans = 0, cona = 0, conb = 0, conab = 0;
    REP(i, N) {
        if(s[i][s[i].length() - 1] == 'A' && s[i][0] == 'B')
            conab++;
        else if(s[i][0] == 'B')
            conb++;
        else if(s[i][s[i].length() - 1] == 'A')
            cona++;
        REP(j, s[i].length() - 1) {
            string t = s[i].substr(j, 2);
            if(t == "AB") ans++;
        }
    }
    if(conab == N || (cona == 0 && conb == 0 && conab > 0)) ans--;
    cout << ans + min(conab + conb, conab + cona) << "\n";
}


Measured memory_bytes: 768
#include<iostream>
using namespace std;
int main()
{
    bool a[50][50], b[50][50], f = 1;
    char c;
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> c;
            a[i][j] = (c == '.' ? 0 : 1);
        }
    }
    for(int i = 0; i < m; i++){
        for(int j = 0; j < m; j++){
            cin >> c;
            b[i][j] = (c == '.' ? 0 : 1);
        }
    }
    for(int ki = 0; ki <= n - m; ki++){
        for(int kj = 0; kj <= n - m; kj++){
            for(int i = 0; i < m; i++){
                for(int j = 0; j < m; j++){
                    if(a[ki + i][kj + j] != b[i][j]){
                        i = m;
                        j = m;
                        f = 0;
                        break;
                    }
                }
            }
            if(f == 1){
                cout << "Yes" << endl;
                return 0;
            }
            f = 1;
        }
        
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256