akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
	int a[101],n;
	fill(a,a+101,0);
	while(cin>>n)a[n]++;
	int most = *max_element(a,a+101);
	for(int i=1;i<=100;i++)
		if(a[i]==most)cout<<i<<endl;
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;
 
public class Main {
    
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String s=sc.next();
        int x=0;
        for(int i=0;i<s.length();i++){
            if(s.charAt(i)=='+'){
                x+=1;
            }
            else{
                x-=1;
            }
        }
        System.out.println(x);
    }
}

Measured memory_bytes: 21844
N = int(input())
caps = []
for i in range(5):
    caps.append(int(input()))

bottleneck = min(caps)

if bottleneck >= N:
    print(5)
    exit()

t_start2bn = 0
sepnum = 0
t_bn2goal = 0

for idx,item in enumerate(caps):
    if item == bottleneck:
        t_start2bn = idx
        sepnum = N // bottleneck if N % bottleneck == 0 else + N // bottleneck + 1
        t_bn2goal = 5 - idx
        print(t_start2bn + t_bn2goal + sepnum - 1)
        exit()


Measured memory_bytes: 3060
#include "bits/stdc++.h"

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, b, e) for (i64 i = (b); i <= (e); ++i)
#define repr(i, b, e) for (i64 i = (b); i >= (e); --i)

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;
// }}} End

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  priority_queue<i64, vector<i64>, greater<>> que;
  rep(i, N) {
    int a; cin >> a;
    que.emplace(a);
  }
  vector<pii> vec(M);
  rep(i, M) {
    int b, c; cin >> b >> c;
    vec[i] = pii(c, b);
  }
  sort(all(vec), greater<>());
  for (auto& e : vec) {
    i64 loop = e.second, norm = e.first;
    while (loop--) {
      if (norm > que.top()) {
        que.pop();
        que.emplace(norm);
      }
      else break;
    }
  }
  i64 res = 0;
  while (que.size()) {
    res += que.top();
    que.pop();
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 2676
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <chrono>
#include <string>
#include <bitset>
#include <cassert>
#include <queue>
#include <memory>

//#pragma comment(linker, "/STACK:16777216")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,abm,mmx,avx,avx2,popcnt,tune=native")

using namespace std;

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

#define ll long long
#define ull unsigned long long
//#define double long double
//#define int ll
//#define int ull
//#define int short
//#define int unsigned short
//#define int unsigned int
#define mp make_pair
#define F first
#define S second
#define pii pair<int, int>
#define hash hash228
const int SZ = 1e2 + 4;
const double EPS = 1e-7;
const int mod = 998244353;
const int hashpow = 127;
const int inf = 2e9;

#define kek cout << "kek"

int n, m;
char c[SZ][SZ];

void read() {
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> c[i][j];
        }
    }
}

void solve() {
    vector<vector<int>> d(n, vector<int>(m, inf));
    d[0][0] = 0;
    set<pair<int, pii>> s;
    s.insert(mp(0, mp(0, 0)));

    while (!s.empty()) {
        int x = s.begin()->first;
        pii u = s.begin()->second;
        s.erase(s.begin());

        if (d[u.F][u.S] != x) continue;

        if (u.F < n - 1) {
            if (c[u.F][u.S] == c[u.F + 1][u.S]) {
                if (d[u.F][u.S] < d[u.F + 1][u.S]) {
                    d[u.F + 1][u.S] = x;
                    s.insert(mp(x, mp(u.F + 1, u.S)));
                }
            } else {
                if (d[u.F][u.S] + 1 < d[u.F + 1][u.S]) {
                    d[u.F + 1][u.S] = x + 1;
                    s.insert(mp(x + 1, mp(u.F + 1, u.S)));
                }
            }
        }
        if (u.S < m - 1) {
            if (c[u.F][u.S] == c[u.F][u.S + 1]) {
                if (d[u.F][u.S] < d[u.F][u.S + 1]) {
                    d[u.F][u.S + 1] = x;
                    s.insert(mp(x, mp(u.F, u.S + 1)));
                }
            } else {
                if (d[u.F][u.S] + 1 < d[u.F][u.S + 1]) {
                    d[u.F][u.S + 1] = x + 1;
                    s.insert(mp(x + 1, mp(u.F, u.S + 1)));
                }
            }
        }
    }

    if (c[0][0] == '#') {
        cout << (d[n - 1][m - 1] + 2) / 2 << "\n";
    } else {
        cout << (d[n - 1][m - 1] + 1) / 2 << "\n";
    }
}

signed main() {

#ifdef __LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

//    int t;
//    cin >> t;
//    for (int i = 0; i < t; ++i) {
    read();
    solve();
//    }

    return 0;
}

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

#define scd second
#define fst first
#define pb push_back
#define mkp make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
typedef vector<ll> vlong;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vint> vvint;
typedef vector<vlong> vvlong;
typedef list<int> lint;
typedef list<ll> llong;
typedef list<pii> lpii;
typedef list<pll> lpll;
typedef list<lint> llint;
typedef list<llong> lllong;

ll const LINF=numeric_limits<long long int>::max();
int const INF=numeric_limits<int>::max();

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

ll pow_mod(ll a, ll e, ll m){
	if(e<0) return 0;
	ll res=1;
	while(e){
		if(e&1) res=res*a%m;
		a=a*a%m;
		e>>=1;
	}
	return res;
}

ll inv_mod(ll b, ll m){
	b%=m;
	ll x=0, y=1, r, q, a=m;
	while(b){
		q=a/b;
		r=a%b;
		a=b;
		b=r;
		r=x;
		x=y;
		y=r-q*y;
	}
	x+=m;
	return x%m;
}

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

	int n;
	cin>>n;
	int c1=0, c2=0, c3=0;
	vint cnt(n,0);
	for(int i=0; i<n; i++){
		int v;
		cin>>v;
		if(c1==v){
			c1++;
			if(c2==v){
				if(c3==v){
					cnt[i]=3;
				} else {
					cnt[i]=2;
				}
			} else {
				if(c3==v){
					cnt[i]=2;
				} else {
					cnt[i]=1;
				}
			}
		} else if(c2==v){
			c2++;
			if(c3==v){
				cnt[i]=2;
			} else cnt[i]=1;
		} else if(c3==v){
			c3++;
			cnt[i]=1;
		}

		vint tmp={c1,c2,c3};
		sort(all(tmp));
		c1=tmp[2];
		c2=tmp[1];
		c3=tmp[0];
	}

	ll ans=1, mod=1e9+7;
	for(int i=0; i<n; i++){
		ans=ans*cnt[i]%mod;
	}

	cout<<ans<<endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int abcd = sc.nextInt();
		int a = abcd / 1000;
		int b = abcd / 100 % 10;
		int c = abcd / 10 % 10;
		int d = abcd % 10;
		boolean op1, op2, op3;
		if (a + b + c + d == 7) {
			op1 = op2 = op3 = true;
		} else if (a + b + c - d == 7) {
			op1 = op2 = true;
			op3 = false;
		} else if (a + b - c + d == 7) {
			op1 = op3 = true;
			op2 = false;
		} else if (a + b - c - d == 7) {
			op1 = true;
			op2 = op3 = false;
		} else if (a - b + c + d == 7) {
			op1 = false;
			op2 = op3 = true;
		} else if (a - b + c - d == 7) {
			op1 = op3 = false;
			op2 = true;
		} else if (a - b - c + d == 7) {
			op1 = op2 = false;
			op3 = true;
		} else {
			op1 = op2 = op3 = false;
		}

		System.out.println(a + (op1 ? "+" : "-")
				+ b + (op2 ? "+" : "-")
				+ c + (op3 ? "+" : "-")
				+ d + "=7");

		sc.close();
	}

}


Measured memory_bytes: 21844
import numpy as np

N= int(input())

A=list(map(int,input().split()))
A.sort()

def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)
  

r = 0
for i in A:
  r = gcd(i,r)
print(r)
  

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

int main(){
  string O;
  cin >> O;
  string E;
  cin >> E;
  int o = O.size();
  int e = E.size();
  if(o == e){
    for(int i = 0; i < o; i++){
      cout << O.at(i) << E.at(i); 
    }
    cout << endl;
  }
  else if(o > e){
    for(int i = 0; i < e; i++){
      cout << O.at(i) << E.at(i); 
    }
    cout << O.at(o - 1) << endl;
  }
  else{
    for(int i = 0; i < o; i++){
      cout << O.at(i) << E.at(i);
    }
    cout << E.at(e - 1) << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if (d2 == 1)
    cout << 1 << endl;
  else
    cout << 0 << endl;
  return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int n, m;
double g[100][100];
double dp[100][100];

int main() {
	while (cin >> n >> m, n || m) {
		REP(i, n) REP(j, n) scanf("%lf", &g[i][j]);
		
		memset(dp, 0, sizeof(dp));
		REP(i, n) dp[0][i] = 1.0;
		
		REP(i, m - 1) {
			REP(j, n) {
				REP(k, n) {
					chmax(dp[i + 1][k], dp[i][j] * g[j][k]);
				}
			}
		}
		
		double ans = 0;
		REP(i, n) chmax(ans, dp[m - 1][i]);
		printf("%.2lf\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RREP(i,n) for (int i=n-1;i>=0;i--)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (ll)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int main(){
    IOS();
    string s;
    cin >> s;
    REP (i,SZ(s)) cout << 'x';
    cout << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define N 200

main(){
  char c[N];
  int a[N], top = 0, x, y;

  while(scanf("%s", c) != EOF){
    if(c[0] == '+'){
      top = top - 1;
      x = a[top+1];
      top = top - 1;
      y = a[top+1];
      top++;
      a[top] = x + y;
    }
    else if(c[0] == '-'){
      top = top - 1;
      x = a[top+1];
      top = top - 1;
      y = a[top+1];
      top++;
      a[top] = y - x;
    }
    else if(c[0] == '*'){
      top = top - 1;
      x = a[top+1];
      top = top - 1;
      y = a[top+1];
      top++;
      a[top] = x * y;
    }
    else{
      x = atoi(c); 
      top++;
      a[top] = x;
    }
  }
  printf("%d\n", a[top]);
  return 0;
}

Measured memory_bytes: 548
#include <stdio.h>
#include <string.h>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn=10050;
const int maxe=40414;
const int INF=0x3f3f3f3f;
struct note
{
    int v;
    int d;
    int c;
    int next;
};
note edge[maxe];
int head[maxn];
int cnt;
void init()
{
    memset(head,-1,sizeof(head));
    cnt=0;
}
void addedge(int u,int v,int d,int c)
{
    edge[cnt].v=v;
    edge[cnt].c=c;
    edge[cnt].d=d;
    edge[cnt].next=head[u];
    head[u]=cnt++;
}
int cost[maxn];
int dis[maxn];
bool vis[maxn];
queue<int>q;
void spfa(int s,int n)
{
    while(!q.empty())q.pop();
    for(int i=1; i<=n; i++)
        cost[i]=dis[i]=INF;
    memset(vis,false,sizeof(vis));
    dis[s]=0;
    cost[s]=0;
    vis[s]=true;
    q.push(s);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        vis[u]=false;
        for(int i=head[u]; i!=-1; i=edge[i].next)
        {
            int v=edge[i].v;
            int val=edge[i].d;
            if(dis[v]>dis[u]+val||(dis[v]==dis[u]+val&&cost[v]>edge[i].c))//有多条最短路时，取花费最小的
            {
                dis[v]=dis[u]+val;
                cost[v]=edge[i].c;
                if(!vis[v])
                {
                    q.push(v);
                    vis[v]=true;
                }
            }
        }
    }
}
int main()
{
    int n,m;
    int u,v,d,c;
    while(~scanf("%d%d",&n,&m))
    {
        if(n==0&&m==0) break;
        init();
        for(int i=0; i<m; i++)
        {
            scanf("%d%d%d%d",&u,&v,&c,&d);
            addedge(u,v,c,d);
            addedge(v,u,c,d);
        }
        spfa(1,n);
        int ans=0;
        for(int i=1; i<=n; i++)
            ans+=cost[i];
        printf("%d\n",ans);
    }
    return 0;
}



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

int main()
{	
	int h, w, m = 100000000;
	int a[25][25];

	cin >> h >> w;

	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			cin >> a[i][j];

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int s = 0;
			for (int k = 0; k < h; k++)
				for (int l = 0; l < w; l++)
					s += a[k][l] * min(abs(k - i), abs(l - j));
			m = min(s, m);
		}
	}

	cout << m << endl;

	return 0;
}



Measured memory_bytes: 3108
fun main(args: Array<String>) {
    val (a,b,m) =  readLine()!!.split(' ').map { it.toInt() }

    val aArr =  readLine()!!.split(' ').map { it.toInt() }
    val bArr =  readLine()!!.split(' ').map { it.toInt() }

    val aMin = aArr.min()!!
    val bMin = bArr.min()!!
    var min = aMin + bMin
    repeat(m) {
        val (x,y,c) =  readLine()!!.split(' ').map { it.toInt() }
        val tmp = aArr[x-1] +  bArr[y-1] - c
        if (tmp < min) min = tmp
    }
    println(min)
}


Measured memory_bytes: 99512
#include <bits/stdc++.h>
/*#ifndef LOCAL_RUN
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC optimize("fast-math")
    #pragma GCC target("avx2,tune=native")
#endif*/
#define X first
#define Y second
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

int main()
{
    #ifdef LOCAL_RUN
        freopen("input.txt", "r", stdin);
    //#else
        //freopen("cowcode.in", "r", stdin);
        //freopen("cowcode.out", "w", stdout);
    #endif
	ios::sync_with_stdio(false);
    cin.tie(0);

    int a, b, c;
    cin >> a >> b >> c;
    cout << (b * c >= a ? "Yes" : "No");

    return 0;
}

// 272472LF


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
typedef pair<int,int> pi;
template <typename T> void chmax(T& a, T b) {a = max(a,b);}
template <typename T> void chmin(T& a, T b) {a = min(a,b);}
//#define cerr if (0) cout

int a,b,c,d;

int main() {
	ios_base::sync_with_stdio(0); 
	cin.tie(0);
	cin >> a >> b >> c >> d;
	while (a > 0 || c > 0) {
		c -= b;
		if (a<=0) {
			cout << "No";
			return 0;
		}
		a -= d;
		if (c<=0) {
			cout << "Yes";
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3656
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line[] = br.readLine().split(" ");
		long a = Long.parseLong(line[0]);
		long b = Long.parseLong(line[1]);
		long x = Long.parseLong(line[2]);

		long count = 0;

		long ad = a / x;
		long bd = b / x;

		count = bd - ad;

		if (a % x == 0) {
			count++;
		}

		System.out.println(count);

	}
}


Measured memory_bytes: 23124
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let (A, x, y) = {
        let mut A = vec![];
        let mut x = vec![];
        let mut y = vec![];
        for i in 0..N {
            let a: usize = {
                let mut line: String = String::new();
                std::io::stdin().read_line(&mut line).unwrap();
                line.trim().parse().unwrap()
            };
            A.push(a);
            let (X, Y): (Vec<usize>, Vec<usize>) = {
                let (mut X, mut Y) = (vec![], vec![]);
                for _ in 0..a {
                    let mut line: String = String::new();
                    std::io::stdin().read_line(&mut line).unwrap();
                    let mut iter = line.split_whitespace();
                    X.push(iter.next().unwrap().parse().unwrap());
                    Y.push(iter.next().unwrap().parse().unwrap());
                }
                (X, Y)
            };
            x.push(X);
            y.push(Y);
        }
        (A, x, y)
    };

    let ans = (0..(1 << N)).map(|z| {
        if (0..N).all(|i| (z >> i) & 1 == 0 || (0..A[i]).all(|j| ((z >> (x[i][j] - 1)) & 1) ^ y[i][j] == 0)) {
            format!("{:b}", z).to_string().chars().filter(|&c| c == '1').count()
        } else {
            0
        }
    }).max().unwrap();

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

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

int main()
{
  int n, k;
  cin >> n >> k;
  
  int count = 0;
  n -= k;
  count ++;
  k --;
  
  while (n > 0)
  {
    n -= k;
    count ++;
  }
  
  cout << count;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int g, n, k, f, i;
  scanf("%d%d",&n, &k);
  k--;
  for(i = 0; i < n; i++){
    scanf("%d", &g);
    //printf("%d", g);
    if(g == 1){
      //printf("%d", i);
      break;
    }
  }
  //printf("%d", k);
  int p, l;
  int ps =i % k;
  if(ps == 0){
    p = i / k;
    //printf("%d", 0%2);
  }
  else
  p = i / k + 1;
  int ls = (n-1-i )% k;
  if(ls == 0)
    l = (n-1-i) / k;
  else
    l = (n-1-i) / k + 1;
  g = 0;
  if(ps + ls <= k && ps != 0 && ls != 0)
    g = 1;
  printf("%d\n", p + l - g);
    return 0;
}


Measured memory_bytes: 256
<?php
$n=trim(fgets(STDIN));
$s=trim(fgets(STDIN)) . "END";
$ans=0;
$i=0;
while($i<$n){
  if($s[$i]=="A"){
    if($s[$i+1]=="B"){
      ++$i;
      if($s[$i+1]=="C"){
        ++$i;
        ++$ans;
      }
    }
  }
  ++$i;
}
echo $ans;

Measured memory_bytes: 4728
import math
def min_sufficient_load(w, k):
    return check(w, k, 0, sum(w))

def check(w, k, p1, p2):
    if k==1:
        return p2
    if p2 - p1 == 1:
        if get_trunk_No(w, p1) == k:
            return max(p1,max(w))
        else:
            return max(p2,max(w))
    m = math.ceil((p1+p2)/2)
    trunk_no = get_trunk_No(w,m)
    if trunk_no > k:
        return check(w, k, m, p2)
    else:
        return check(w, k, p1, m)
def get_trunk_No(w,m):
    temp = 0
    trunk_no = 1
    for i in w:
        if temp + i <= m:
            temp += i
            if temp == m:
                trunk_no += 1
                temp = 0
        else:
            trunk_no += 1
            temp = i
    if temp==0:
        trunk_no-=1
    return trunk_no
if __name__=="__main__":
    n,k = map(int,input().split(" "))
    w = []
    for i in range(n):
        w.append(int(input()))
    print(min_sufficient_load(w,k))


Measured memory_bytes: 9580
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define INF_LL 1e18
#define INF 1e9

#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()

using namespace std;

using ll = long long;
using PII = pair<int, int>;

template<typename T>
void chmax(T &a, T &b){
	a = max(a, b);
}

template<typename T>
void chmin(T &a, T &b){
	a = min(a, b);
}

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	ll a[51], b[51], c[51], d[51];
	cin >> N >> M;
	REP(i, N){
		cin >> a[i] >> b[i];
	}
	REP(i, M){
		cin >> c[i] >> d[i];
	}
	REP(i, N){
		int dis = INF, n = -1;
		REP(j, M){
			if(dis > abs(c[j]-a[i])+abs(d[j]-b[i])){
				dis = abs(c[j]-a[i])+abs(d[j]-b[i]);
				n = j;
			}
		}
		cout << n+1 << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

/* respect for nanikaka-senpai */

struct Note {
  const static int ARRV = 0;
  const static int DEPT = 1;
  int time;
  int type;
};

bool operator < (const Note& s, const Note& t ) {
  if( s.time == t.time ) {
    return s.type < t.type;
  }
  return s.time < t.time;
}

int conv ( string t ) {
  return (
    ( ( t[ 0 ] - '0' ) * 10 + t[ 1 ] - '0' ) * 3600 +
    ( ( t[ 3 ] - '0' ) * 10 + t[ 4 ] - '0' ) * 60   +
    ( ( t[ 6 ] - '0' ) * 10 + t[ 7 ] - '0' )
  );
}

int main() {
  while( 1 ) {
    int n;
    cin >> n;
    if( !n ) { return EXIT_SUCCESS; }
    
    vector<Note> v;   
    for( int i = 0; i < n; i++ ) {
      string dept, arrv;
      cin >> dept >> arrv;
      
      Note nd, na;
      nd.time = conv( dept );
      nd.type = Note::DEPT;
      na.time = conv( arrv );
      na.type = Note::ARRV;
      v.push_back( nd );
      v.push_back( na );
    }
    sort( v.begin(), v.end() );
    int len = v.size();
    int trN = 0;
    int trMax = 0;
    for( int i = 0; i < len; i++ ) {
      if( v[ i ].type == Note::DEPT ) {
        trN++;
        trMax = max( trN, trMax );
      } else {
        trN--;
      }
    }
    
    cout << trMax << endl;
  }
}

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

// g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -o 

int main(){
 ll n,k;
 cin>>n>>k;
 ll a[n];
 for(int i=0;i<n;i++){
  cin>>a[i];
 }
 ll r=*max_element(a,a+n);
 ll l=1;
 while(l<r){
  ll mid=l+(r-l)/2;
  ll cuts=0;
  for(int i=0;i<n;i++){
   if(a[i]%mid)
    cuts+=(a[i]/mid);
   else
    cuts+=((a[i]-1)/mid);
  }
  if(cuts>k)
   l=mid+1;
  else{
   r=mid;
  }
  // cout<<l<<" "<<r<<"\n";
 }
 cout<<l<<"\n";
 return 0;
}


Measured memory_bytes: 5032
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll INF = 1000000009;
ll MOD = 1000000007;

ll a[200010];
ll p[200010];
map<ll, ll> mp;

void solve(){

    ll n;
    cin >> n;
    rep(i,n){
        cin >> a[i];
        p[i]=i-a[i];
        mp[p[i]] = mp[p[i]]+1;
        //cout << p[i] << " ";
        //cout << mp[p[i]] << endl;
    }

    ll ans = 0;
    rep(i,n){
        ans += mp[(-1) * (p[i]-2*i)];
        //mp[p[i]] = mp[p[i]]-1;
        //cout << i << " " << ans << endl;
    }

    cout << ans << endl;

}

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


Measured memory_bytes: 29512
#include <stdio.h>

#define N_MAX 100

void trace(int A[], int N) {
  int i;
  printf("%d", A[0]);
  for (i = 1; i < N; i++) {
    printf(" %d", A[i]);
  }
  printf("\n");

}

void InsertionSort(int A[], int N) {
  int i, j, v;

  for(i = 1; i < N; i++) {
    v = A[i];
    j = i - 1;
    while(j >= 0 && v < A[j]) {
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;

    trace(A, N);
  }
}


int main(void) {
  int N, i;
  int A[N_MAX];

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

  trace(A, N);
  InsertionSort(A, N);

  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
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 FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VI a(n), b(n);
    REP(i,n) a[i] = in();
    int ans = 0;
    FOR(i,1,n-1){
        if (a[i] == a[i-1] && b[i-1] == 0){
            ans++;
            b[i] = 1;
        }
    }
    cout<< ans << endl;

    return 0;
}

Measured memory_bytes: 764
#include <iostream>

using namespace std;

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

int main(){
	int n, m;
	cin >> n >> m;
	int l[n], r[n];
	rep(i, m) cin >> l[i] >> r[i];
	int mxl = 1, mnr = n;
	rep(i, m){
		if(mxl < l[i]){
			mxl = l[i];
		}
		if(mnr > r[i]){
			mnr = r[i];
		}
	}
	int ans = mnr - mxl + 1;
	if(ans > 0) cout << ans << endl;
	else cout << 0 << endl;
}	

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
main()
{
	long long n,m;
	cin>>n>>m;
	long long a[m],ac[n],wa[n];
	for(long long i=0;i<n;i++) {
		ac[i]=0;
		wa[i]=0;
	}
	string s[m];
	for(long long i=0;i<m;i++) 
	{
	cin>>a[i];
	cin>>s[i];
}
for(long long i=0;i<m;i++)
{
if(s[i]=="AC") {
	ac[a[i]-1]=1;
}
else if(s[i]=="WA" && ac[a[i]-1]==0) wa[a[i]-1]++;
}
long long x=0,y=0;
for(long long i=0;i<n;i++)
{                         
//	cout<<ac[i]<<" ";
	x+=ac[i];
	if(ac[i]==1) y+=wa[i];
}
cout<<x<<" "<<y;

}

Measured memory_bytes: 8064
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  ll i,j,N,M,a,b,ans=0;
  cin>>N>>M;
  ans=N/M;
  if(M%2){
    cout<<ans*ans*ans<<endl;
    return 0;
  }
  a=N/(M/2)-ans;
  cout<<ans*ans*ans+a*a*a<<endl;
  return 0;
}

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

int main() {
    int n,m,x;
    cin >> n >> m >> x;
    vector<int> a(m);
    for(int i=0;i<m;i++){
        cin >> a.at(i);
    }
    for(int i=0;i<m;i++){
        if(x<a.at(0)){
            cout << 0 << endl;
            break;
        }
        else if(x>a.at(m-1)){
            cout << 0 << endl;
            break;
        }
        else if(x>a.at(i)&&x<a.at(i+1)){
            cout << min(i+1,m-i-1) << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
n = int(input())
rd = []
bl = []
for _ in range(n):
    a, b = map(int,input().split())
    rd.append([a,b])
for _ in range(n):
    c, d = map(int,input().split())
    bl.append([c,d])
bl.sort()
used_r = [0] * n
ans = 0

for i in range(n):
    y = -1
    pair = -1
    for j in range(n):
        if rd[j][0] < bl[i][0] and rd[j][1] < bl[i][1] and rd[j][1] > y and used_r[j] == 0:
            y = rd[j][1]
            pair = j
    if pair != -1:
        used_r[pair] = 1
        ans += 1
print(ans)
        
    

Measured memory_bytes: 3064
import scala.collection.mutable.HashMap
import scala.io.StdIn

object Main extends App {

  val map = HashMap.empty[Int,Int]

  val Array(n, k) = StdIn.readLine.split(" ").map(_.toInt)
  val seq = StdIn.readLine.split(" ").map(_.toInt)

  seq.foreach(i => {
    if(!map.contains(i)) map += i -> 1
    else map += i -> (map(i)+1)
  })

  val s = map.values.toArray.sorted
  val g = math.max(s.size - k, 0)
  val ans = s.take(g).sum
  
  println(ans)
}

Measured memory_bytes: 74224
#include<iostream>
using namespace std;
int main(){
  int e,y;
  cin>>e>>y;
  if(!e){
    if(y<1912)cout<<'M'<<y-1867<<endl;
    else if(y<1926)cout<<'T'<<y-1911<<endl;
    else if(y<1989)cout<<'S'<<y-1925<<endl;
    else cout<<'H'<<y-1988<<endl;
  }
  if(e==1)cout<<y+1867<<endl;
  if(e==2)cout<<y+1911<<endl;
  if(e==3)cout<<y+1925<<endl;
  if(e==4)cout<<y+1988<<endl;
}



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

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

  int n, k;
  cin >> n >> k;
  
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    a[i] = min(a[i], k);
  }
  
  sort(a.begin(), a.end());
  int l = 0,r = n;
  while (l < r) {
  
    int mid = (l + r) / 2;
    bitset<5005> b;
    b[0] = 1;
    for (int j = 0; j < n; ++j) {
      if (j == mid) continue;
      b |= (b << a[j]);
    }

    bool req = 0;
    for (int j = 0; j < k; ++j) {
      if (b[j] && j + a[mid] >= k) req = 1;
    }

    if (req) r = mid;
    else l = mid + 1;
  }

  cout << l << '\n';

}


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

#define pb push_back
#define fi first
#define se second
typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	int n;
	string s;
	cin >> n >> s;
	for (int i = 0; i < s.length(); ++i)
		cout << (char)((s[i] - 'A' + n) % 26 + 'A');
	cout << '\n';
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.*;
import java.util.*;

import static java.util.stream.Collectors.*;
import static java.util.Map.Entry.*;

public class Main {

	public static void main(String[] args) throws IOException {
		FastReader in = new FastReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt();
		int m = in.nextInt();
		if (m%n == 0) {
			out.println(n+m);
		} else {
			out.println(m-n);
		}
		out.flush();
		out.close();

	}

	static class FastReader {
		StringTokenizer st;
		BufferedReader br;

		public FastReader(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public FastReader(FileReader fileReader) {
			br = new BufferedReader(fileReader);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = nextInt();
			}
			return ret;
		}

		public long[] nextIntLong(int n) throws IOException {
			long[] ret = new long[n];
			for (int i = 0; i < n; i++) {
				ret[i] = nextLong();
			}
			return ret;
		}

		
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}

}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  long long sum=0;
  cin>>n;

  for(int i=1; i<=n; i++){
    if(i%3!=0 && i%5!=0){
      sum+=i;
    }
  }

  cout<<sum<<'\n';
  return 0;
}


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

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

Measured memory_bytes: 3628
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli, lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout << (x ? "Yes" : "No") << endl;
#define YES(x) cout << (x ? "YES" : "NO") << endl;
#define out(s) cout << s << endl;
#define Reverse(x) reverse(all(x));
#define Sort(x) sort(all(x));
#define pb(s) push_back(s);
#define sp " "
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(), s.end()
void vout(vi v)
{
    for (lli i = 0; i < v.size(); i++)
        cout << v.at(i) << endl;
}
int main()
{
    cout << std::fixed << std::setprecision(10);
    lli n;
    cin >> n;
    vi a(n), b(n);
    map<lli, lli> c;
    rep(i, n)
    {
        lli an;
        cin >> an;
        if (c.count(an))
        {
            c[an]++;
        }
        else
        {
            c[an] = 1;
        }
        a[i] = an;
    }
    rep(i, n)
    {
        lli bn;
        cin >> bn;
        if (c.count(bn))
        {
            c[bn]++;
            if (c[bn] > n)
            {
                out("No");
                return 0;
            }
        }
        else
        {
            c[bn] = 1;
        }
        b[i] = bn;
    }
    out("Yes");
    Reverse(b);
    lli num = 0;
    rep(i, n)
    {
        if (a[i] == b[i])
        {
            while (b[i] == b[num]||b[i]==a[num])
            {
                num++;
                if(num>n-1){
                    num = 0;
                }
            }
            swap(b[i], b[num]);
        }
    }
    rep(i,n){
        cout << b[i];
        if(i!=n-1){
            cout << sp;
        }
    }
    cout << endl;
}

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

int N;
int A[210];       

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

    int res = 0;

    while (true) 
    {
        bool exist_odd = false;  
        for (int i = 0; i < N; i++) 
        {
            if (A[i] % 2 != 0) 
              exist_odd = true;
        }

        if (exist_odd) break; 
      
        for (int i = 0; i < N; i++) 
        {
            A[i] /= 2;
        }
        res++; 
    }

    cout << res << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int check(int(*)[2], int);
main()
{
        int i, n,(*a)[2];
        scanf("%d", &n);
        a = (int(*)[2])malloc(sizeof(int) * 2 * n);
        for(i = 0; i < n; i++){
                scanf("%d %d", &a[i][0], &a[i][1]);
        }
        printf("%d\n", check(a, n));
        free(a);
}
int check(int (*a)[2], int n)
{
        int i;
        for(i = 0; i < n; i++){
                int vectora[2] = {a[i][0] - a[(i + 1) % n][0],
                                                  a[i][1] - a[(i + 1) % n][1]},
                        vectorb[2] = {a[(i + 2) % n][0] - a[(i + 1) % n][0],
                                                        a[(i + 2) % n][1] - a[(i + 1) % n][1]};
                if((vectora[0] * vectorb[1] -vectora[1] * vectorb[0]) > 0){
                        return 0;
                }
        }
        return 1;
}

Measured memory_bytes: 1856
a,b,x=gets.chomp.split(" ").map(&:to_f)

if x >= a * a * b / 2.0
  puts Math.atan((2.0*a*a*b-2.0*x)/(a*a*a)) * 180.0 / Math::PI
else
  puts 90.0 - Math.atan((2.0*x)/(a*b*b)) * 180.0 / Math::PI
end


Measured memory_bytes: 1788
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			String[] a = new String[n];
			String[] b = new String[m];
			IntStream.range(0, n).forEach(i -> a[i] = scanner.next());
			IntStream.range(0, m).forEach(i -> b[i] = scanner.next());
			boolean found = false;
			main: for (int i = 0; i <= n - m; i++) {
				for (int j = 0; j <= n - m; j++) {
					if (containsAt(a, b, i, j)) {
						found = true;
						break main;
					}
				}
			}
			System.out.println(found ? "Yes" : "No");
		}
	}

	/**
	 * @param a
	 * @param b
	 * @param x
	 * @param y
	 * @return aの[x][y]からのm x mの部分はbと同じかどうか
	 */
	private static boolean containsAt(String[] a, String[] b, int x, int y) {
		int m = b.length;
		for (int i = 0; i < m; i++) {
			if (!a[x + i].substring(y, y + m).equals(b[i])) {
				return false;
			}
		}
		return true;
	}
}


Measured memory_bytes: 28756
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++)
    cin >> x[i];

  int m = 1e9;

  for (int i = 1; i < 100; i++){
    int sum = 0;
    for (int j = 0; j < n; j++){
      sum += (x[j] - i) * (x[j] - i);
    }

    m = min(m, sum);
  }

  cout << m << endl;
  

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <list>
#include <math.h>
#include <map>
using namespace std;
#define REP(i, k, n) for(int i = k;i < n; i++)
#define rep(i, n) REP(i,0,n)
#define ll long long int
int dx[4] = {0,-1,1,0};
int dy[4] = {-1,0,0,1};
#define eps 10e-6
#define mod 1000000007
ll a[100001];
int n;
int main(void){
	string s1;
	string s2;
	cin >> s1 >> s2;
	for(int i = 0; i < s1.size(); i++){
		if(s1[i] != s2[s2.size()-i-1]){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cctype>

using namespace std;
string str;
int p, q, r, pos;

int formula(){
    if (isdigit(str[pos])) {return str[pos++] - '0';}
    if (str[pos] == 'P') {pos++; return p;}
    if (str[pos] == 'Q') {pos++; return q;}
    if (str[pos] == 'R') {pos++; return r;}
    
    int res = 0;
    if (str[pos] == '-') {pos++; return 2 - formula();}
    if (str[pos] == '(') {
        pos++;
        res = formula();
        if (str[pos] == '*') {
            pos++;
            res = min(res, formula());
        }
        else if (str[pos] == '+') {
            pos++;
            res = max(res, formula());
        }
        pos++;
        return res;
    }
}

int main()
{
    while (true) {
        cin >> str;
        if (str == ".") {
            break;
        }
        int cnt = 0;
        for (p = 0; p <= 2; p++) {
            for (q = 0; q <= 2; q++) {
                for (r = 0; r <= 2; r++) {
                    pos = 0;
                    if (formula() == 2) {
                        cnt++;
                    }
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 1188
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>

using namespace std;

int n, k;
vector<vector<int>> book_price;
vector<vector<int>> pricesum;//?????????????????¬????????£???????????§?????????????´???????
int dp[2001][11];//num genre

int main() {
	book_price.resize(10);
	pricesum.resize(10);
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		book_price[b - 1].push_back(a);
	}
	for (int i = 0; i < 10; i++) {
		sort(book_price[i].begin(), book_price[i].end(), greater<int>());//??§?????????????????????
		pricesum[i].push_back(0);
		for (auto j = 0; j < book_price[i].size(); j++) {
			pricesum[i].push_back(book_price[i][j] + j * 2);
			if (j != 0)pricesum[i][j + 1] += pricesum[i][j];//??§?????????????´????????????¨???
		}
	}
	int ct = 0;
	for (int i = 0;;i++) {
		if (pricesum[i].size() == 1) {
			pricesum.erase(pricesum.begin () + i), i--;//????????¨????????????
		}
		ct++;
		if (ct >= 10)break;
	}
	for (int i = 0; i <= k; i++){
		if (i < pricesum[0].size())dp[i][0] = pricesum[0][i];
		else dp[i][0] = dp[i - 1][0];
	}
	for (int i = 0; i < pricesum.size() - 1; i++) {
		for (int j = 0; j <= k; j++) {
			for (int l = 0; l < pricesum[i + 1].size(); l++) {
				if (j + l <= k)dp[j + l][i + 1] = max(dp[j + l][i + 1], dp[j][i] + pricesum[i + 1][l]);
			}
		}
	}
	cout << dp[k][pricesum.size() - 1] << endl;
	return 0;
}

Measured memory_bytes: 3196
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
// const int INF = 2000000000;

const int MAX_V = 200001;

struct edge {
  int to, cost;
};
vector<edge> g[MAX_V];

pair<int, int> dfs(int idx, int parent) {
  pair<int, int> ret(0, idx);
  for (auto &e : g[idx]) {
    if (e.to == parent) {
      continue;
    }
    auto cost = dfs(e.to, idx);
    cost.first += e.cost;
    if (ret.first < cost.first) {
      ret = cost;
    }
  }
  return ret;
}

int tree_diameter() {
  auto p = dfs(0, -1);
  auto q = dfs(p.second, -1);
  return q.first;
}

int N;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(edge{b, 1});
    g[b].push_back(edge{a, 1});
  }

  int d = tree_diameter();
  if (d % 3 == 1) {
    cout << "Second" << endl;
  } else {
    cout << "First" << endl;
  }

  return 0;
}

Measured memory_bytes: 23680
#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,c,d;
  cin >> a >> b >> c >>d;
  bool can = false;
  if(abs(a-b)<=d && abs(b-c)<=d) can =true;
  if(abs(a-c)<=d) can =true;
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

struct UnionFind{
  vector<int> par;
  UnionFind(int N) : par(N){
    for(int i = 0; i < N; i++){
      par[i] = i;
    }
  }
  int root(int x){
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    par[rx] = ry;
  }
  bool same(int x, int y){
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> P(N);
  for(int i = 0; i < N; i++) cin >> P[i];
  
  UnionFind tree(N);
  
  for(int i = 0; i < M; i++){
    int x, y;
    cin >> x >> y;
    tree.unite(x-1, y-1);
  }
  
  int cnt = 0;
  for(int i = 0; i < N; i++){
    if(tree.same(i, P[i]-1)){
      cnt++;
    }
    
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include<math.h>
#include <string.h>
#include <ctype.h>

int main(){
char b[8];
int a[8];
int n,i,j,k,max,min,f;

scanf("%d",&n);
for(i=0;i<n;i++){

for(j=0;j<8;j++){
scanf(" %c ",&b[j]);
a[j]=b[j]-'0';
}

for(j=0;j<7;j++){
for(k=j+1;k<8;k++){
if(a[j]<a[k]){
f=a[k];
a[k]=a[j];
a[j]=f;
}
}
}
max=10000000*a[0]+1000000*a[1]+100000*a[2]+10000*a[3]+1000*a[4]+100*a[5]+10*a[6]+a[7];
min=10000000*a[7]+1000000*a[6]+100000*a[5]+10000*a[4]+1000*a[3]+100*a[2]+10*a[1]+a[0];
f=max-min;
printf("%d\n",f);

}

return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
main(){
  int N,M;
  cin>>N>>M;
  vector<string>A(N);
  for(auto&x:A)cin>>x;
  vector<string>B(M);
  for(auto&x:B)cin>>x;
  for(int y_a=0;y_a<N;++y_a){
    for(int x_a=0;x_a<N;++x_a){
      bool offset_failed=false;
      for(int y_b=0;y_b<M;++y_b){
        if(y_a+y_b>=A.size())offset_failed=true;
        if(offset_failed)break;
        for(int x_b=0;x_b<M;++x_b){
          if(x_a+x_b>=A[y_a+y_b].size())offset_failed=true;
          if(offset_failed)break;
          if(B[y_b][x_b]!=A[y_a+y_b][x_a+x_b])offset_failed=true;
        }
      }
      if(!offset_failed){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
}


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()
{
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    ll ans = ll(1e18)+1;
    for (ll k=0; k<=int(2e5); k+=2) {
        int a_loss = max(x- k/2, 0LL);
        int b_loss = max(y- k/2, 0LL);
        ll tmp = a_loss * a + b_loss * b + k * c;
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256