akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(*array)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    ll N;
    cin >> N;
    ll a[N][3];
    REP(i, N) {
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }

    ll dp[N + 1][3];
    REP(i, N + 1) REP(j, 3) dp[i][j] = 0;

    REP(i, N) {
        REP(j, 3) {
            REP(h, 3) {
                if(j != h) chmax(dp[i + 1][j], dp[i][h] + a[i][j]);
            }
        }
    }

    ll ans = 0;
    REP(i, 3) {
        chmax(ans, dp[N][i]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8244
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (n, hp) = get!(usize, i64);
    let mut hp = hp;
    let mut v = Vec::new();
    let mut max_slash = 0;
    for _ in 0..n {
        let tmp = get!(i64, i64);
        if max_slash < tmp.0 {
            max_slash = tmp.0;
        }
        v.push(tmp);
    }
    let mut throw_weapons = Vec::new();
    for i in v.iter() {
        if max_slash < i.1 {
            throw_weapons.push(i.1);
        }
    }
    let mut count = 0;
    throw_weapons.sort_by(|a, b| b.cmp(a));
    for i in throw_weapons.iter() {
        hp -= *i;
        count += 1;
        if hp <= 0 {
            break;
        }
    }
    if hp <= 0 {
        println!("{}", count);
        return;
    }
    count += (hp + (max_slash - 1)) / max_slash;

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


Measured memory_bytes: 8444
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
vector<int>E[1010];
int n,m,b[200020][2];
bool vis[1010],f[200020][2];
int q[1010],h,t,l[1010],r[1010];
int st[1010],tp;
void dfs1(int v,int a[],int w)
{
	vis[v]=1,a[v]=w;
	for(auto u:E[v])if(!vis[u])dfs1(u,a,w);
}
void work(int v)
{
	tp=0;
	for(auto u:E[v])st[++tp]=u;
	memset(vis+1,0,n);vis[v]=1;
	for(int i=1;i<=tp;++i)if(!vis[st[i]])dfs1(st[i],l,i);
	memset(vis+1,0,n);vis[v]=1;
	for(int i=tp;i;--i)if(!vis[st[i]])dfs1(st[i],r,i);
	for(int i=1;i<=m;++i)if(b[i][0]==v)f[i][0]=l[b[i][1]]!=r[b[i][1]];
}
void dfs(int v)
{
	vis[v]=1;
	for(auto u:E[v])if(!vis[u])dfs(u);
}
int main()
{
	scanf("%d %d",&n,&m);
	int x,y;
	for(int i=1;i<=m;++i)scanf("%d %d",&x,&y),E[x].emplace_back(y),b[i][0]=x,b[i][1]=y;
	for(int i=1;i<=n;++i)
	{
		memset(vis+1,0,n);
		dfs(i);
		for(int j=1;j<=m;++j)if(b[j][1]==i)f[j][1]=vis[b[j][0]];
	}
	for(int i=1;i<=n;++i)work(i);
	for(int i=1;i<=m;++i)
		if(f[i][0]!=f[i][1])printf("diff\n");
		else printf("same\n");
	return 0;
}


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

using namespace std;

int main(void) {
  int w, a, b;
  cin >> w >> a >> b;

  if(a + w < b) {
    cout << b - (a + w) << endl;
  }
  else if(b + w < a) {
    cout << a - (b + w) << endl;
  }
  else {
    cout << "0" << endl;
  }
}

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

#define coutv(v) for (int i = 0; i < (v).size(); ++i) cout << v[i] << ' '; cout << endl;
#define coutvv(v) for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cout << v[i][j] << ' '; cout << endl;}
#define debugv(v) {for (int i = 0; i < (v).size(); ++i) cerr << v[i] << ' '; cerr << endl;}
#define debugvv(v) {for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cerr << v[i][j] << ' '; cerr << endl;}}
#define TC int TESTCASE; cin >> TESTCASE; while (TESTCASE--)
typedef long long ll;


int main() {
    vector<int> fact(20);
    fact[0] = 0;
    fact[1] = 1;
    for (int i = 2; i < 15; i++) {
        fact[i] = fact[i-1] * (i);
    }
    int n; cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    int res = 0;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        int cnt = 0;
        for(int j = 0; j < p[i] - 1; j++) {
            if (a[j] == 0) {
                cnt += 1;
            }
        }
        a[p[i] - 1] = 1;
        res += fact[n-(i+1)] * cnt;
    }
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    a.clear();
    a.resize(n);
    int res1 = 0;
    for (int i = 0; i < n; i++) {
        int cnt = 0;
        for(int j = 0; j < (p[i] - 1); j++) {
            if (a[j] == 0) {
                cnt += 1;
            }
        }
        a[p[i] - 1] = 1;
        res1 += fact[n-(i+1)] * cnt;
    }
    cout << abs(res - res1) << endl;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  int ans = 0;
  for(int i = 1; i < n - 1; ++i) {
    vector<int> t;
    t.push_back(p[i]);
    t.push_back(p[i - 1]);
    t.push_back(p[i + 1]);
    sort(t.begin(), t.end());
    if(p[i] == t[1]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)


using namespace std;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int h, w; cin >> h >> w;

	vector<vector<bool>> map(h, vector<bool>(w));
	vector<vector<int>> score(h, vector<int>(w));

	FOR_LT(i, 0, h) {
		FOR_LT(j, 0, w) {
			char c; cin >> c;
			if (c == '#') map[i][j] = true;
		}
	}

	FOR_LT(i, 0, h) {
		FOR_LT(j, 0, w) {
			if (i == 0 && j == 0) {
				if (map[0][0]) score[0][0] = 1;
				continue;
			}
			int cs = INT_MAX;
			if (i != 0) {
				int csu = score[i - 1][j];
				if (map[i - 1][j] != map[i][j] && map[i][j]) {
					csu++;
				}
				cs = min(cs, csu);
			}
			if (j != 0) {
				int csl = score[i][j - 1];
				if (map[i][j - 1] != map[i][j] && map[i][j]) {
					csl++;
				}
				cs = min(cs, csl);
			}
			score[i][j] = cs;
		}
	}

	cout << score[h - 1][w - 1] << endl;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
using P = pair<int, int>;
constexpr array<int, 4> dx = {1, 0, -1, 0};
constexpr array<int, 4> dy = {0, 1, 0, -1};
constexpr int INF = 1234567890;
constexpr int MOD = 1000000000 + 7;
// constexpr int MOD = 998244353;
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 (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int fact(int n) { return n > 1 ? n * fact(n - 1) % MOD : 1; }
int modinv(int a)
{
    int b = MOD, u = 1, v = 0;
    while (b)
    {
        int t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= MOD;
    if (u < 0)
        u += MOD;
    return u;
}
constexpr int modpow(int a, int n)
{
    int rtn = 1;
    while (n > 0)
    {
        if (n & 1)
            rtn = rtn * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return rtn;
}

bool isPrime(int x)
{
    if (x == 1)
        return false;
    if (x == 2)
        return true;
    if (x % 2 == 0)
        return false;
    for (int i = 3; i < sqrt(x); i += 2)
    {
        if (x % i == 0)
            return false;
    }
    return true;
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(10);

    int x;
    cin >> x;

    while (true)
    {
        if (isPrime(x))
        {
            cout << x << endl;
            break;
        }
        x++;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int i;
  string S_i;
  cin>>N;
  for (i=1;i<=N;i++){
    cin>>S_i;
    if(S_i=="Y"){
    cout<<"Four"<<endl;
    break;
  }
    else if (i==N && S_i!="Y" ){
      cout<<"Three"<<endl;
    }
  }
}

Measured memory_bytes: 256
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int c[4][4];

int main() {
  for (int i = 1; i < 4; ++i){
    for (int j = 1; j < 4; ++j) {
      cin >> c[i][j];
    }
  }

  for (int i = 1; i < 4; ++i) {
    for (int j = i+1; j < 4; ++j) {
      if (c[i][1] - c[j][1] != c[i][2] - c[j][2] || c[i][1] - c[j][1] != c[i][3] - c[j][3]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  for (int i = 1; i < 4; ++i) {
    for (int j = i+1; j < 4; ++j) {
      if (c[1][i] - c[1][j] != c[2][i] - c[2][j] || c[1][i] - c[1][j] != c[3][i] - c[3][j]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;
}


Measured memory_bytes: 256
/*
	Created by Faisal Ahmed
*/

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef long double ld;

bool visited[100010];
int p[100010];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	int n, m, pen = 0, ac = 0;
	
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int x;
		string str;
		
		cin >> x >> str;
		
		if(!visited[x]){
			if(str == "WA"){
				p[x]++;
			}
			else{
				ac++;
				visited[x] = true;
			}
		}
	}
	
	for(int i = 0; i <= n; i++){
		if(visited[i]){
			pen += p[i];
		}
	}
	
	cout << ac << " " << pen << endl;
	
	return 0;
} 

Measured memory_bytes: 768
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *AB = map(int, read().split())
    A = AB[: N + 1]
    B = AB[N + 1 :]

    M = sum(A)

    for i in range(N):
        if A[i] > B[i]:
            A[i] -= B[i]
            B[i] = 0
        else:
            B[i] -= A[i]
            A[i] = 0

        A[i + 1] = max(A[i + 1] - B[i], 0)

    print(M - sum(A))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 30912
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
#define MOD int(1e9 + 7)

int main()
{
    long long N;
    set<string> S;

    cin >> N;
    for(long long i = 0; i < N; i++){
        string t;
        cin >> t;
        S.insert(t);
    }

    if(S.size() == 3)
        cout << "Three" << endl;
    else
        cout << "Four" << endl;

}

Measured memory_bytes: 256
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
P = list(map(int, sys.stdin.readline().split()))

A = np.zeros(N, dtype=int)
B = np.zeros(N, dtype=int)
# Ap + Bp が条件を満たすようにする
for i, p in enumerate(P):
    A[p - 1] = i
# A を昇順、B を降順
for i in range(1, N):
    diff = max(A[i - 1] - A[i] + 1, B[i] - B[i - 1] + 1, 0)
    A[i] += diff
    B[i] -= diff
# 調整
A -= A.min() - 1
B -= B.min() - 1

print(*A)
print(*B)


Measured memory_bytes: 21900
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	ll n;
	ll a[100001],b[100001];
	ll min=10000000000000001;

	cin>>n;

	rep(i,n){
		cin>>a[i]>>b[i];
		if(a[i]+b[i]<min){
			min=a[i]+b[i];
		}
	}
	cout<<min<<endl;

	return 0;
}


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

vector<bool> sieve(ll N){
    vector<bool> prime(N+1,true);
    prime[0]=false,prime[1]=false;
    for (ll i = 2; i < N; i++){
        if(!prime[i]) continue;
        for(ll j=i*i;j<=N;j+=i){
            prime[j]=false;
        }
    }
    return prime;
}

int main(){
    ll X; cin>>X;
    vector<bool> prime=sieve(100004);
    for (ll i = X;; i++){
        if(prime[i]){
            cout<<i<<endl;
            return 0;
        }
    }
    
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;


int main(int argc, char* argv[])
{
    int q,h,s,d;
    scanf("%d%d%d%d", &q, &h, &s, &d);

    int tmp=MIN(MIN(4*q,h*2),s);
    int tmp2=MIN(tmp*2,d);

    int n;
    scanf("%d", &n);
    printf("%lld\n", (ll)tmp2*(n/2) + (ll)tmp*(n%2));


    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const double eps=1e-9;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
int N;
int l,r;
int b[20005];
int sim()
{
  int times=0;
  while(times<=10000)
    {
      bool clear=true;
      int height=1;
      for(int i=l;i<=r;i++)
	{
	  if(b[i]==0)
	    {
	      continue;
	    }
	  if(b[i]!=height)
	    {
	      clear=false;
	    }
	  height++;
	}
      if(clear) break;
      int tmp=0;
      //cout << "Before " << l << ' ' << r << endl;
      for(int i=l;i<=r;i++)
	{
	  //cout << b[i] << ' ';
	  if(b[i]>0)
	    {
	      b[i]--;
	      tmp++;
	    }
	}
      //cout << endl;
      for(int i=l;i<=r;i++)
	{
	  if(b[i]>0) 
	    {
	      l=i;
	      break;
	    }
	}
      if(b[r]>0)
	{
	  r++;
	  b[r]=tmp;
	}
      else
	{
	  b[r]=tmp;
	}
      //cout << "After " << l << ' ' << r << endl;
      times++;
      //cout << "Turn " << times << endl;
    }
  if(times>10000)
    {
      return -1;
    }
  else
    {
      return times;
    }
}

int main(void)
{
  while(cin >> N && N)
    {
      int total=0,ans=0;
      l=1,r=N;
      memset(b,0,sizeof(b));
      for(int i=1;i<=N;i++)
	{
	  cin >> b[i];
	  total+=b[i];
	}
      bool can=false;
      for(int i=1;i<=10000;i++)
	{
	  if(i*(i+1)/2==total) can=true;
	}
      if(!can) 
	{
	  cout << -1 << endl;
	  continue;
	}
      else
	{
	  ans=sim();
	}
      cout << ans << endl;
    }
  return 0;
}



Measured memory_bytes: 3156
// AOJ 1026 Hedro's Hexahedron
// 2018.2.2 bal4u@uu

#include <stdio.h>

int main()
{
	long long n, i, k, s, t, ans;

	while(scanf("%lld", &n) && n){
		ans = n << 3;
        s = t = n >> 1;
        for(i = 1, k = 2; i*i < s; i++, k+=2) t += (n+k-1)/k;
        t <<= 1, t -= i*i;
        if (n & 1) t++;
        printf("%lld\n", ans + (t << 3));
	}
	return 0;
}


Measured memory_bytes: 2032
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int c0=0,c1=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='0'){
      c0++;
    }
    if(s[i]=='1'){
      c1++;
    }
  }
  cout << 2*min(c0,c1) << endl;
}

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

int main()
{

	ll n;
	cin>>n;
	ll a[n],b[n];
		
		ll x=0,p[n];
		for(ll j=0;j<n;j++)
		{
			cin>>a[j];
			x+=a[j];
			p[j]=x;
			//cout<<p[j]<<endl;
		}
		
		ll y=0,l[n];
		for(ll j=0;j<n;j++)
		{
			cin>>b[j];
		}
		
		for(ll k=n-1;k>=0;k--)
		{
			y+=b[k];
			l[k]=y;
			//cout<<l[k]<<endl;
		}
		
		ll ans[n];
		
		for(ll o=0;o<n;o++)
		{
			ans[o]=p[o]+l[o];
			//cout<<ans[o]<<endl;
		}
		
		sort(ans,ans+n);
		cout<<ans[n-1]<<endl;

//	ll p[n];
	
	
	
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>

using namespace std;

int main() {
  int n;
  long L[87];
  cin >> n;
  
  L[0] = 2; L[1] = 1;
  for(int i = 2; i <= n; i++) {
    L[i] = L[i-1] + L[i-2];
  }
  cout << L[n] << endl;
}

Measured memory_bytes: 3560
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long lint;

int main() {
  int h, w, n;
  scanf("%d %d %d", &h, &w, &n);
  int init_y, init_x;
  scanf("%d %d", &init_y, &init_x), --init_y, --init_x;
  string s(n, ' '); // out
  string t(n, ' '); // in
  scanf(" %s", &s[0]);
  scanf(" %s", &t[0]);

  int y0 = 0, y1 = h - 1;
  int x0 = 0, x1 = w - 1;
  for (int i = n - 1; i >= 0; --i) {
    int s_dy, s_dx;
    int t_dy, t_dx;
    auto parse_letter = [](char c) -> pair<int, int> {
      if (c == 'L') return {0, -1};
      else if (c == 'R') return {0, +1};
      else if (c == 'U') return {-1, 0};
      else if (c == 'D') return {+1, 0};
      else {
        assert(false);
        return {INT_MIN, INT_MIN};
      }
    };
    tie(s_dy, s_dx) = parse_letter(s[i]);
    tie(t_dy, t_dx) = parse_letter(t[i]);

    auto update_range = [](int &x0, int &x1, int s_dx, int t_dx, int w) {
      if (x0 > x1) return;

      auto inside = [x0, x1, s_dx, t_dx, w](int x) {
        bool can_out = false;
        for (int use_s : {0, 1}) {
          bool can_in = false;
          for (int use_t : {0, 1}) {
            if (0 <= x + use_s * s_dx && x + use_s * s_dx < w &&
                x0 <= x + use_s * s_dx + use_t * t_dx &&
                x + use_s * s_dx + use_t * t_dx <= x1) {
              can_in = true;
            }
          }
          if (!can_in) {
            can_out = true;
          }
        }
        return !can_out;
      };

      int new_x0 = x0, new_x1 = x1;
      while (new_x0 - 1 >= 0 && inside(new_x0 - 1)) --new_x0;
      while (new_x1 + 1 < w && inside(new_x1 + 1)) ++new_x1;
      while (new_x0 <= new_x1 && !inside(new_x0)) ++new_x0;
      while (new_x1 >= new_x0 && !inside(new_x1)) --new_x1;
      x0 = new_x0;
      x1 = new_x1;
    };

    update_range(y0, y1, s_dy, t_dy, h);
    update_range(x0, x1, s_dx, t_dx, w);
  }

  if (y0 <= init_y && init_y <= y1 &&
      x0 <= init_x && init_x <= x1) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }

  return 0;
}


Measured memory_bytes: 640
while True:
    # num_columns: ????£?????????°
    # num_lines: ?¨??£?????????°(???????????????2????´???????????????°)
    # entry: ????????????????????????????§?????????´????????????
    num_columns, num_lines, entry = map(int, input().split())

    if num_columns == 0 and num_lines == 0 and entry == 0:
        break

    lines = []
    for _ in range(num_lines):
        height, p, q = map(int, input().split())
        lines.append((height, p-1, q-1)) # ????????????0?????????????§????????????§???????????????

    # lines??????????????????????????§???????????????????????????????´?????¨??£???????????????\???????????§
    # ??????????????????????????°??????????????????????????????
    lines.sort()
    lines.reverse()
    # ??????2??????????????§???lines????????????????´??????§?????????????????¶

    result = list(range(1, num_columns+1)) # ??????????§????????????´????????¨????????????

    for line in lines:
        height, p, q = line
        
        # ?????????`replace`???p????????¨q?????????????????????
        result[p], result[q] = result[q], result[p]

    for index, element in enumerate(result):
        if element == entry:
            print(index + 1) # ????????????0?????????????§????????????§???????????????
            break
    # print(result.index(entry) + 1) ??§?????????

Measured memory_bytes: 7736
import sys
input = sys.stdin.readline

a = input()

n = int(a)

s = [[0] * 9 for _ in range(9)]

for i in range(1, n+1):
    j = str(i)
    k = int(j[0])
    l = int(j[-1])
    if l != 0:
        s[k-1][l-1] += 1

ans = 0

#print(s)

for i in range(1, 10):
    for j in range(1, 10):
        ans += s[i-1][j-1] * s[j-1][i-1]

print(ans)


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

int main()
{
    ll a,b;
    cin>>a>>b;
    if(a!=1 && b!=1)
        cout<<1;
    else if(a!=2 && b!=2)
        cout<<2;
    else cout<<3;
 return 0;
}


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

int main( ) {
  int A, B;
  cin >> A >> B;
  
  if (A*B % 2 == 0) {
    cout << "No" << endl; // A*B is even number
  } else {
    cout << "Yes" << endl; // A*B is odd number
  }
}

Measured memory_bytes: 256
n=int(input())
s=list(input())
n_W,n_E=0,0
l_W,l_E=[0],[0]
for i in s:
    if i=="W":n_W+=1
    else:n_E+=1
    l_W.append(n_W)
    l_E.append(n_E)
ans=10**9+7
for i in range(n):
    tmp=l_W[i]+l_E[-1]-l_E[i+1]
    if tmp<ans:ans=tmp
print(ans)

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

#define ll long long
#define MAX 1000000
#define eb emplace_back

int main()
{
    ll a[4];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    ll m=(a[2]/2);
    ll n=a[2]-m;
    ll k=a[0]*a[1];
    if(m>n)
    {
        cout<<m*k-n*k;
    }
    else
    {
        cout<<n*k-m*k;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define l first
#define r second

using namespace std;

const int maxn = 2e5 + 1;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0)
        cout << 0;
    else
        cout << min(a * b, min(b * c, a * c));
    return 0;
}


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

int main() {
  int n,k,ans=0; cin>>n>>k;
  vector<int> a(n),b;
  for(int i=0; i<n; i++) cin>>a[i];
  sort(a.begin(),a.end());
  int j=0;
  for(int i=0; i<n; i++) {
    j++;
    if(a[i]!=a[i+1]) {
      b.push_back(j);
      j=0;
    }
  }
  sort(b.begin(),b.end());
  if(b.size()<k) {
    cout<<0;
    return 0;
  }
  for(int i=0; i<b.size()-k; i++) ans += b[i];
  cout<<ans;
}

Measured memory_bytes: 2168
def main():
    N = int(input())
    lists = list(map(int, input().split(' ')))
    min_i = (2 * 10) ** 5 + 1
    cnt = 0
    for item in lists:
        if min_i >= item:
            min_i = item
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24744
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl


namespace atcoder {
	template<typename T>
	T ncr(T left, T right) {
		right = min(left - right, right);
		T ans = 1;
		for (T i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000007;
	const int tenfive = 100000;
}

using namespace atcoder;

int main() {
	int n;
	cin >> n;
	string a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == b[i] && a[i] == c[i]) {

		}
		else if (a[i] == b[i] || c[i] == a[i] || b[i] == c[i]) {
			ans += 1;
		}
		else {
			ans += 2;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
pf={}
m=N
for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        m//=i
if m>1:pf[m]=1

cnt = 0
for k, v in pf.items():
    t = 1
    while v>0:
        v += -1*t
        if v<0:
            break
        cnt += 1
        t+= 1
print(cnt)

Measured memory_bytes: 63488
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vl vector<ll>
#define pl pair<ll,ll>
#define TC int t;cin>>t;while(t--)
#define in(n) ll n;cin>>n;
#define inarr(n) ll n;cin>>n;vector<ll>arr;
#define mod 1000000007
ll dp[1004][1004],h,w;
char arr[1004][10004];
ll solve(int i,int j){
    if(i>=h || j>=w || arr[i][j]=='#') return 0;
    if(i==h-1 && j==w-1) return 1;
    if(~dp[i][j]) return dp[i][j];
    ll r1 = solve(i+1,j);
    ll r2 = solve(i,j+1);
    return dp[i][j]=(r1+r2)%mod;
}
int main(void){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>arr[i][j];
        }
    }
    memset(dp,-1,sizeof(dp));
    solve(0,0);
    cout<<dp[0][0]<<endl;
    return 0;
}

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

int main(){
    
    int n,k;
    cin >> n >> k;
    int a[n+1];
    int pre[n+1];
    pre[0] = 0;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        a[i]++;
        pre[i] = pre[i-1] + a[i];
    }
    double ans=0;
    for(int i=k;i<=n;i++){
        double cur = pre[i] - pre[i-k];
        ans = max(ans,cur);
    }
    ans = ans/2;
    cout << fixed << setprecision(10) << ans ;
    
    return 0;
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  vector<int> v;
  int count = 1;
  for (int i = 1; i < int(s.size()); i++) {
    if(s[i-1] == s[i]){
      count++;
    }else{
      v.push_back(count);
      count = 1;
    }
  }
  v.push_back(count);
  vector<int> res;


  for (int i = 0; i < int(v.size())-1; i+=2) {
    rep(j, v[i]-1) res.push_back(0);
    int l = v[i];
    int r = v[i+1];
    int big = max(l, r);
    if((l + r) % 2 == 0){
      res.push_back((l + r)/2);
      res.push_back((l + r)/2);
    }else if(l < r){
      if((big - 1) % 2 == 0){
        res.push_back((l + r) / 2);
        res.push_back((l + r) / 2 + 1);
      }else{
        res.push_back((l + r) / 2 + 1);
        res.push_back((l + r) / 2);
      }
    }else{
      if((big - 1) % 2 == 0){
        res.push_back((l + r) / 2 + 1);
        res.push_back((l + r) / 2);
      }else{
        res.push_back((l + r) / 2);
        res.push_back((l + r) / 2 + 1);
      }
    }
    rep(j, v[i+1]-1) res.push_back(0);
  }

  rep(i, res.size()) cout << res[i] << ' ';
  cout << endl;


}


Measured memory_bytes: 1480
<?php

fscanf(STDIN, "%s", $s);

$s_arr = str_split($s);
$target = [
    'A',
    'C',
    'G',
    'T',
];

$max = 0;
$count = 0;
foreach ($s_arr as $char) {
    if (in_array($char, $target, true)) {
        ++$count;
        $max = max($max, $count);
    } else {
        $count = 0;
    }
}

echo $max;


Measured memory_bytes: 4728
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n,m = m()

print("Yes" if n == m else "No")



Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

typedef pair<int, int> P;

int main(){
  int N, M, r;
  while(cin >> N >> M){
    if(N == 0 && M == 0) break;
    cin >> r;

    bool record[10010][720];
    memset(record, 0, sizeof(record));
    map<P, int> info;
    
    int t, n, m, s;
    while(r--){
      cin >> t >> n >> m >> s;
      t -= 540;
      
      if(s == 1){
	info[P(m, n)] = t;
      }
      else if(s == 0){
	for(int i = info[P(m, n)] ; i < t ; i++){
	  record[m][i] = true;
	}
	info.erase(P(m, n));
      }
    }
    
    int q, ts, te;
    cin >> q;
    while(q--){
      cin >> ts >> te >> m;
      ts -= 540, te -= 540;
      int ans = 0;
      for(int i = ts ; i < te ; i++){
	if(record[m][i]) ans++;
      }
      cout << ans << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 8244
n = int(input())
Act = []
maxt= 0
for _ in range(n):
    s,t = map(int,input().split( ))
    Act.append([s,t])
    maxt = max(maxt,t)
#print(*Act)
Act.sort()
last = maxt+1
cnt = 0
for i in range(n-1,-1,-1):
    if Act[i][1] <last:
        cnt += 1
        last = Act[i][0]
        #print(last)
print(cnt)



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

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

    vector<int> ans(x,1);

    for(int i=1; i<x; i++){
        for(int j=2; j<=x; j++){
            int v = pow(i,j);
            if(v > x) break;
            ans[i] = v;
        }
    }

    vector<int> ::iterator itr = max_element(ans.begin(),ans.end());

    cout<<*itr<<endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H1, M1, H2, M2, K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  int hour = H2 - H1;
  int min;
  if (M2 < M1) {
    hour--;
    min = 60 + M2 - M1;
  } else {
    min = M2 - M1;
  }
  min += 60 * hour -K;
  cout << min << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



int main() {
	int n, w;
	cin >> n >> w;
	vector<vector<int>> obj(4);
	int w1, v1;
	cin >> w1 >> v1;
	obj[0].emplace_back(v1);
	
	for (int i = 1; i < n; i++) {
		int wi, vi;

		cin >> wi >> vi;
		obj[wi - w1].emplace_back(vi);
	}
	
	for (int i = 0; i < 4;i++) {
		sort(obj[i].begin(), obj[i].end(),greater<int>());
		
	}

	vector<vector<int>> sum(4);
	for (int i = 0; i < 4;i++) {
		vector<int> s(obj[i].size() + 1);
		for (int j = 0; j < obj[i].size();j++) {
			s[j+1] = s[j] + obj[i][j];
		}
		sum[i] = s;
		
	}

	int ans = 0;
	for (int i = 0;i <= obj[0].size();i++) {
		for (int j = 0;j <= obj[1].size();j++) {
			for (int k = 0;k <= obj[2].size();k++) {
				if (1LL *i*w1 +1LL * j * (w1 + 1) +1LL * k * (w1 + 2) > w) {
					break;
				}
				int l = obj[3].size();
				l = min((w - (i * w1 + j * (w1 + 1) + k * (w1 + 2))) / (w1 + 3),l);
				ans = max(ans, sum[0][i] + sum[1][j] + sum[2][k] + sum[3][l]);

			}
		}
	}
	cout << ans << endl;
}





Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i, N, K, A;
    scanf("%d", &N);
    scanf("%d", &K);
    A = 1;
    for ( i = 1; i<= N; i++) {
       if (A < K) {
          A += A;
        } else {
          A += K;
        }
     }
    printf("%d", A);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

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

		n = sc.nextInt();
		while (n != 0) {
			a = new int[n];
			startIndex = 0;
			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
				if (i != 0 && i - startIndex != a[i] - a[startIndex]) {
					if (i - startIndex != 1) {
						System.out.print(a[startIndex] + "-" + a[i - 1] + " ");
					} else {
						System.out.print(a[startIndex] + " ");
					}
					startIndex = i;
				}
				if (i == n - 1) {
					if (i - startIndex != 0) {
						System.out.print(a[startIndex] + "-" + a[i]);
					} else {
						System.out.print(a[startIndex]);
					}
				}
			}
			System.out.println();
			n = sc.nextInt();
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((LL)1e9+7) 
#define INF ((LL)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

int main(){
	int N;
	cin >> N;
	int four=0, two=0, one=0;
	REP(i, N){
		int d;
		cin >> d;
		if(d%4==0)++four;
		else if(d%2==0)++two;
		else ++one;
	}
	if(two)++one;
	if(one>four+1){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
	return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

char *demangle(const char *demangle)
{
    int status;
    return abi::__cxa_demangle(demangle, 0, 0, &status);
}
double dist(int i, int j, vector<pair<double, double>> vec)
{
    double dx = vec[i].first - vec[j].first;
    double dy = vec[i].second - vec[j].second;
    debug(dx);
    debug(dy);

    return pow(dx * dx + dy * dy, 0.5);
}

int main()
{

    int N;
    cin >> N;
    vector<pair<double, double>> vec(N);
    rep(i, N) cin >> vec[i].first >> vec[i].second;
    // rep(i, N)
    // {
    //     cout << vec[i].first << ' ' << vec[i].second << endl;
    // }
    // cout << endl;

    vector<int> a(N);
    rep(i, N) a[i] = i + 1;

    double ans = 0.0, cnt = 0;
    do
    {
        cnt++;
        for (int i = 0; i < N - 1; i++)
        {
            ans += dist(a[i] - 1, a[i + 1] - 1, vec);
        }
    } while (next_permutation(all(a)));
    debug(cnt);
    debug(ans);
    cout << fixed << setprecision(10);
    cout << ans / cnt << endl;
    return 0;
}


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


int main(){
  int n,a,b;
  a = 1;
  b = 1;
  cin >> n;
  int p[n];
  int q[n];
  REP(i,n) cin >> p[i];
  REP(i,n) cin >> q[i];
  int flag[n];
  REP(j,n) flag[j] = 1;
  REP(i,n){
    int cnt = 0;
    flag[p[i]-1] = 0;
    REP(j,p[i]){
      if (flag[j] == 1) cnt++;
    }
    int sum = 1;
    for (int k=1; k<=n-i-1; k++) sum = sum*k;
    a += cnt * sum;
  }
  REP(j,n) flag[j] = 1;
  REP(i,n){
    int cnt = 0;
    flag[q[i]-1] = 0;
    REP(j,q[i]){
      if (flag[j] == 1) cnt++;
    }
    int sum = 1;
    for (int k=1; k<=n-i-1; k++) sum = sum*k;
    b += cnt * sum;
  }

  if (a>b) cout << a-b << endl;
  else cout << b-a << endl;
  return 0;
}


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

class Node {
public:
    bool visited = false;
    int distance;
    int id;
};

class Edge {
public:
    Node *node;
    int distance;
};

typedef vector<Edge> Edges;
typedef vector<Edges> Adjacent;

int N, M;
vector<Node> nodes;
Adjacent adjacent;

bool dfs(Node *node, int distance) {
    if (node->visited) {
        if (node->distance == distance) {
            return true;
        } else {
            return false;
        }
    } else {
        bool okay = true;

        node->visited = true;
        node->distance = distance;

        for (Edge &edge: adjacent.at(node->id)) {
            if (!dfs(edge.node, distance + edge.distance)) {
                okay = false;
            }
        }

        return okay;
    }
}

int main() {
    bool okay = true;

    cin >> N >> M;
    nodes.resize(N + 1);

    for (int i = 1; i <= N; ++i) {
        nodes.at(i).id = i;
    }

    adjacent.resize(N + 1);

    for (int i = 1; i <= M; ++i) {
        Edge e;
        int L, R, D;
        cin >> L >> R >> D;
        e.node = &nodes.at(R);
        e.distance = D;
        adjacent.at(L).push_back(e);
        e.node = &nodes.at(L);
        e.distance = -D;
        adjacent.at(R).push_back(e);
    }

    for (Node &node: nodes) {
        if (!node.visited) {
            if (!dfs(&node, 0)) {
                okay = false;
            }
        }
    }

    cout << (okay ? "Yes" : "No") << endl;
}


Measured memory_bytes: 16896
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_T = 30000;
const int MAX_SIDE = (MAX_T - 1) / 2;

/* typedef */

typedef vector<int> vi;

/* global variables */

bool primes[MAX_SIDE + 1];
vi pnums;
int np;

/* subroutines */

void calc_prime(int max_p) {
  primes[0] = primes[1] = false;
  for (int p = 2; p <= max_p; p++) primes[p] = true;

  for (int p = 2; p * p <= max_p; p++)
    if (primes[p])
      for (int q = p * p; q <= max_p; q += p) primes[q] = false;

  for (int p = 2; p <= max_p; p++)
    if (primes[p]) pnums.push_back(p);

  np = pnums.size();
}

/* main */

int main() {
  calc_prime(MAX_SIDE);

  for (;;) {
    int t;
    cin >> t;
    if (t == 0) break;

    int count = 0;
    int mina = t / 3;
    int maxside = (t - 1) / 2;
  
    for (vi::iterator ait = pnums.begin(); ait != pnums.end(); ait++) {
      int& a = *ait;
      if (a < mina) continue;
      if (a > maxside) break;

      int minb = (t - a) / 2;
      
      for (vi::iterator bit = pnums.begin(); bit != pnums.end(); bit++) {
	int& b = *bit;
	if (b < minb) continue;
	if (b > a) break;

	int c = t - (a + b);
	if (c > 0 && c <= b && primes[c]) {
	  count++;
	}
      }
    }

    cout << count << endl;
  }

  return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n, k; cin >> n >> k;
	set<ll> s;
	zep(i, 0, k){
		ll d; cin >> d;
		zep(j, 0, d){
			ll a; cin >> a;
			s.insert(a);
		}
	}
	print(n-s.size())
	
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    int n;
    cin>>n>>s;
    int count=0;
    for(int i=0;i<n-2;i++){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') count++;
    }
    cout<<count;
}


Measured memory_bytes: 256
#include<iostream>
typedef long long ll;
using namespace std;
ll gcd(ll a, ll b) {
	ll r;
	if (a < b) swap(a, b);
	r = a % b;
	while (r != 0) a = b, b = r, r = a % b;
	return b;
}

int main() {
	ll  a, b,c;
	int cnt = 1;
	cin >> a >> b;
	c = gcd(a, b);
	for (ll i = 2;i*i <= c;i++) {
		if ( c % i== 0) {
			cnt++;
			while (c%i == 0) {
				c /= i;
			}
		}
	}
	if (c!= 1) cnt++;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
#define TEN5 100000 //10^5
#define TEN9 1000000000 //10^9
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    rep1(i,n) {
        string sf = s.substr(0,i);
        string sb = s.substr(i+0,n);
        int sfi = 0, sbi = 0;
        rep(j,sf.length()) {
            int shift = 1;
            shift = shift << (int)(sf[j] - 'a');
            sfi |= shift;
        }
        rep(j,sb.length()) {
            int shift = 1;
            shift = shift << (int)(sb[j] - 'a');
            sbi |= shift;
        }
        bitset<26> f(sfi), b(sbi);
        //cout << f << " " << b << endl;
        f &= b;
        int cnt = 0;
        rep(j,26) {
            bitset<26> base(1);
            base &= f;
            if (base == 1)
                cnt++;
            f >>= 1;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}



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

int main()
{
    long long N, M;
    cin >> N >> M;
    long long minimum = min(N, M);
    long long maximum = max(N, M);
    long long ans;
    if (minimum > 1)
    {
        // N > 1
        // M > 1
        ans = M * N - 2 * (max(0ll, N - 2) + max(0ll, M - 2)) - 4;
    }
    else if (maximum > 1)
    {
        // N == 1
        // M > 1
        ans = maximum - 2;
    }
    else
    {
        // N == 1
        // M == 1
        ans = 1;
    }
    cout << ans << endl;
}


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

int main()
{
    int a,b,c;
    cin >> a;
    cin >> b;
    cin >> c;
    
    if(a+b+c >= 22){
        cout << "bust" << endl;
    }
    else{
        cout << "win" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    // input
    string s;
    cin >> s;
    // output
    int n = s.size();
    vector<int> ans(n);
    int numL = 0, numR = 0;
    for (int i = 0; i < n - 1; i++) {
        if (s[i] == 'R' && s[i + 1] == 'R') {
            ans[i] = 0;
            numR++;
        }
        if (s[i] == 'R' && s[i + 1] == 'L') {
            ans[i] = numR / 2 + 1;
            ans[i + 1] = (numR + 1) / 2 + 1;
            numR = 0;
        }
    }

    for (int i = n - 1; i > 0; i--) {
        if (s[i - 1] == 'L' && s[i] == 'L') {
            ans[i] += 0;
            numL++;
        }
        if (s[i - 1] == 'R' && s[i] == 'L') {
            ans[i - 1] += (numL + 1) / 2;
            ans[i] += numL / 2;
            numL = 0;
        }
    }
    rep(i, n) { printf("%d%c", ans[i], i == n - 1 ? '\n' : ' '); }
    return 0;
}

Measured memory_bytes: 1104
import numpy as np
#S = list(input().strip())
#length = len(S)
#op = np.asarray(S)

def solution():
    S = input()
    N = len(S)
    num = [0] * 2019
    num[0] = 1
    c, ans, dgt = 0, 0, 1
    for i in range(N-1, -1, -1):
        c = (c + int(S[i]) * dgt) % 2019
        dgt *= 10
        dgt %= 2019
        ans += num[c]
        num[c] += 1
        
    print(ans)

solution()



def sample():
    x = -1
    count = 0
    for i in op:
        x += 1
        group = ""
        for j, name in enumerate(op, x):
            group += name
            if int(group) % 2019 == 0:
                count += 1
    print(count)

def checkValue():
    count = 0
    for i in range(length):
        group = ""
        for j in range(i, length):
            group += op[j]
            if int(group) % 2019 == 0:
                count += 1
    print(count)
#checkValue()
    


Measured memory_bytes: 27164
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>
#include <map>

using namespace std;
typedef long long int ll;

int main(){

    ll N, K, Q;
    cin >> N >> K >> Q;
    vector<ll > A(Q);

    for(ll i = 0; i < Q; i++){
        cin >> A[i];
    }

    vector<ll > s(N, K);

    ll sum = 0;
    for(ll i = 0; i < Q; i++){
        s[A[i]- 1]++;
        sum++;
    }

    for(ll i = 0; i < N; i++){
        s[i] -= sum;
        if(s[i] <= 0){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }


} 

Measured memory_bytes: 2176