akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout << "[" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "]\n"
#define rd() abs((int)rng())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll n, A, B, C;
ll fac[maxn], inv[maxn];
ll pwr(ll a, ll pw)
{
	ll ret = 1;
	while(pw > 0)
	{
		if(pw & 1)
			ret = ret * a % mod;
		a = a * a % mod;
		pw >>= 1;
	}
	return ret;
}
ll modinv(ll a)
{
	return pwr(a, mod - 2);
}
ll choose(int N, int K)
{
	return fac[N] * inv[K] % mod * inv[N - K] % mod;
}
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	cin >> n >> A >> B >> C;
	fac[0] = inv[0] = 1;
	for(ll i = 1; i <= n * 2; i++)
	{
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = modinv(fac[i]);
	}
	ll ab = A + B;
	A *= modinv(ab);
	B *= modinv(ab);
	A %= mod;
	B %= mod;
	ll ans = 0;
	for(ll i = n; i < 2 * n; i++)
	{
		ll ev = choose(i - 1, n - 1) * (pwr(A, n) * pwr(B, i - n) % mod + pwr(B, n) * pwr(A, i - n) % mod) % mod;
		ev = ev * i % mod * 100 % mod * modinv(100 - C) % mod;
		ans = (ans + ev) % mod;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3456
#include <stdio.h>

long long int lcm(long long int a, long long int b){
	long long int x, tmp, r;
 x = a * b;
 
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }

	return x/b;
}

int main(){
	long long int a, b, c, d;
	scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
	long long int i, ans=0, x, y, z;
    
    x = (b-a+1+(a-1)%c)/c;
    y = (b-a+1+(a-1)%d)/d;
    z = (b-a+1+(a-1)%lcm(c,d))/lcm(c,d);
	
	printf("%lld", (b-a+1)-x-y+z);
	
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> perm;

perm mul (perm p, perm q) {
  int n = p.size();
  perm ans (n);
  for (int i = 0; i < n; i++) {
    ans[i] = p[q[i]];
  }
  return ans;
}

perm id (int n) {
  perm ans (n);
  for (int i = 0; i < n; i++) {
    ans[i] = i;
  }
  return ans;
}

perm exp (perm p, ll k) {
  if (k == 0) {
    return id(p.size());
  } else if (k % 2 == 0) {
    perm half = exp(p, k / 2);
    return mul(half, half);
  } else {
    return mul(p, exp(p, k - 1));
  }
}

const int MAX_N = 1e5 + 5;

ll x [MAX_N];
int arr [MAX_N];

ll ids [MAX_N];
ll fds [MAX_N];

ll ans [MAX_N];

int main () {
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;

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

  for (int i = 0; i < n - 1; i++) {
    ids[i] = x[i + 1] - x[i];
  }
  
  int m;
  ll k;
  cin >> m >> k;

  for (int i = 0; i < m; i++) {
    cin >> arr[i];
    arr[i]--;
  }

  perm p = id(n - 1);
  for (int i = m - 1; i >= 0; i--) {
    int u = arr[i];
    int v = u - 1;
    swap(p[u], p[v]);
  }

  p = exp(p, k);
  for (int i = 0; i < n - 1; i++) {
    fds[p[i]] = ids[i];
  }

  ans[0] = x[0];
  for (int i = 1; i < n; i++) {
    ans[i] = ans[i - 1] + fds[i - 1];
  }

  for (int i = 0; i < n; i++) {
    cout << ans[i] << ".0\n";
  }
}


Measured memory_bytes: 36736
#include <stdio.h>
int main(){
  int a, b, d, r;
  double f;
  scanf("%d %d", &a, &b);
  d = a/b;
  r = a%b;
  f = (double)a / (double)b;
  printf("%d %d %f\n", d, r, f);
  return 0;
}

Measured memory_bytes: 1852
N,M = map(int,input().split())
A = list(map(int,input().split()))
import heapq
B = []
for a in A:
    B.append(-a)
heapq.heapify(B)
for i in range(M):
    a = heapq.heappop(B)
    a = (-a)//2
    a = -a
    heapq.heappush(B,a)
print(-sum(B))

Measured memory_bytes: 85084
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
const int maxn=2e5+7;
int p[maxn];
int n;
#define lson o<<1
#define rson o<<1|1
#define Lson L,mid,lson
#define Rson mid+1,R,rson
struct sgt{
    pi mx[maxn<<2];
    pi query(int l,int r,int L=1,int R=n,int o=1)
    {
        if(l>r) return {0x3f3f3f3f,0x3f3f3f3f};
        if(l<=L&&r>=R)
            return mx[o];
        int mid=L+R>>1;
        pi ret={0x3f3f3f3f,0x3f3f3f3f};
        if(l<=mid) ret=min(ret,query(l,r,Lson));
        if(r>mid) ret=min(ret,query(l,r,Rson));
        return ret;
    }
}mx,odd,even;
void build(int L=1,int R=n,int o=1)
{
    if(L==R)
    {
        mx.mx[o].first=p[L];
        mx.mx[o].second=odd.mx[o].second=even.mx[o].second=L;
        odd.mx[o].first=even.mx[o].first=0x3f3f3f3f;
        if(L&1) odd.mx[o].first=p[L];
        else even.mx[o].first=p[L];
        return;
    }
    int mid=L+R>>1;
    build(Lson);
    build(Rson);
    mx.mx[o]=min(mx.mx[lson],mx.mx[rson]);
    odd.mx[o]=min(odd.mx[lson],odd.mx[rson]);
    even.mx[o]=min(even.mx[lson],even.mx[rson]);
}
struct D{
    int l,r,val;
    bool operator<(const D&a)const{
        return val>a.val;
    }
};
D getd(int l,int r)
{
    return D{l,r,(l&1)?odd.query(l,r).first:even.query(l,r).first};
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>p[i];
    build();
    vi ans;
    priority_queue<D> q;
    q.push(D{1,n,odd.query(1,n).first});
    while(!q.empty())
    {
        auto u=q.top();q.pop();
        if(u.l>u.r) continue;
        int L,R;
        if(u.l&1)
        {
            L=odd.query(u.l,u.r).second;
            R=even.query(L,u.r).second;
        }
        else{
            L=even.query(u.l,u.r).second;
            R=odd.query(L,u.r).second;
        }
        ans.push_back(p[L]);
        ans.push_back(p[R]);
        q.push(getd(u.l,L-1));
        q.push(getd(L+1,R-1));
        q.push(getd(R+1,u.r));
    }
    print(ans);
}

Measured memory_bytes: 24496
#include<iostream>
#include<vector>
using namespace std;
typedef long long LL;
 
const int MAX_N=1005;
int n,m;
LL a[MAX_N];
vector<LL> v1,v2;
 
void Build();
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=0;i<n;++i)
		cin>>a[i];
	for(int i=0;i<n;++i)
	{
		LL ss=0;
		for(int j=i;j<n;++j)
		{
			ss+=a[j];
			v1.push_back(ss);
		}
	}
	LL ans=0;
	for(int i=40;i>=0;--i)
	{
		v2.clear();
		LL p=((LL)1<<i);
		for(auto c:v1)
			if(c&p)	v2.push_back(c);
		if(v2.size()>=m){
			ans+=p;
			v1.clear();	v1=v2;
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

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

int n, m, q, a[50], b[50], c[50], d[50];
int ans = 0;
int l[10];


void f(int i, int j) {
	if (i == n) {
		int res = 0;
		rep(i, q) {
			if (l[b[i]] - l[a[i]] == c[i]) res += d[i];
		}
		ans = max(ans, res);
		return;
	}
	for(int k = j; k <= m; k++) {
		l[i] = k;
		f(i+1, k);
	}
}

int main() {
	cin >> n >> m >> q;
	rep(i, q) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--; b[i]--;
	}
	l[0] = 1;
	f(1, 1);
	cout << ans << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, k;
    cin >> n >> k;

    vl d(k);
    rep(i, k) {
        cin >> d[i];
    }

    exrep(x, n, n + 100000) {
        string s = to_string(x);
        ll m = s.size();
        bool ok = true;
        rep(i, m) {
            rep(j, k) {
                if(s[i] - '0' == d[j]) {
                    ok = false;
                }
            }
        }
        if(ok) {
            out(x);
            re0;
        }
    }
    
    re0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  while (true) {
    getline(cin, s);
    if (s == ".") {
      break;
    }
    bool b = [&] {
      string t;
      for (char c : s) {
        if (c == '(' or c == '[') {
          t += c;
        }
        if (c == ')') {
          if (t.empty() or t.back() != '(') {
            return false;
          }
          t.pop_back();
        }
        if (c == ']') {
          if (t.empty() or t.back() != '[') {
            return false;
          }
          t.pop_back();
        }
      }
      return t.empty();
    }();
    cout << (b ? "yes\n" : "no\n");
  }
}



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

int main(){
    int A, B; cin >> A >> B;
    if((A == 1 && B == 2) || (A == 2 && B == 1)){
        cout << 3 << endl;
        return 0;
    }else if((A == 2 && B == 3) || (A == 3 && B == 2)){
        cout << 1 << endl;
        return 0;
    }else{
        cout << 2 << endl;
        return 0;
    }


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
int main() {
	int N,K;

	cin >> N>>K;
	string S;
	cin >> S;

	if (S.at(K-1) == 'A') {
		S.at(K-1) = 'a';
	}
	else if(S.at(K-1) == 'B') {
	S.at(K-1) = 'b';
	}
	else if (S.at(K-1) == 'C') {
		S.at(K-1) = 'c';
	}
	cout << S << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<limits.h>
int main(void)
{
	int n,a[100],min=101,max=-101,min2=INT_MAX,k=0,i,j;
	scanf("%d", &n);
	for(i=0; i<n; i++)
	{
		scanf("%d", &a[i]);
		if(a[i]<min)
		min=a[i];
		if(a[i]>max)
		max=a[i];
	}
	for(i=min; i<=max; i++)
	{
		k=0;
		for(j=0; j<n; j++)
		k+=(a[j]-i)*(a[j]-i);
		if(k<min2)
		min2=k;
	}
	printf("%d\n", min2);
	
	return 0;
}

Measured memory_bytes: 128
#coding : utf-8

import os
import sys

N = int(input())

H = list(map(lambda x: int(x), input().split(" ")))

#print(N)
#print(H)

H.reverse()

#print(H)

res = "Yes"

for i in range(N-1):
	if H[i+1] > H[i]+1:
		res = "No"
		break
	elif H[i+1] == H[i]+1:
		H[i+1] -= 1
	else:
		pass

print(res)




Measured memory_bytes: 14456
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int gcd(int a, int b)
{
  if (a%b==0){
    return(b);
  }
  else{
    return(gcd(b,a%b));
  }
}



int a[1000000];
int b[1000000];
int main(){
  int N,M;
  cin >> N >> M;
  rep(i,M){
    cin >> a[i];
  }
  sort(a,a+M);
  for(int i = 0; i < M-1; i++){
    b[i] = a[i+1] - a[i];
  }
  int ans = 0;
  sort(b,b+M-1,greater<int>());
  for(int i = N - 1; i < M; i++){
    ans += b[i];
    // cout << b[i] << endl;
  }
  cout << ans << endl;
}


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

int main()
{
  string S;
  long K;
  cin >> S >> K;
  int count = 0;
  int renzoku_count = 0;
  bool is_renzoku = false;
  long long ans = 0;
  char start_alphabet = S[0];
  int index = 0;
  int s_index;
  int l_index;

  while (true)
  {
    if (S[index] != start_alphabet)
      break;
    index++;
  }

  ans += index / 2;

  int alphabet_count = index;
  s_index = index;

  index = S.size() - 1;
  while (s_index < index)
  {
    if (S[index] != start_alphabet)
      break;
    index--;
    alphabet_count++;
  }
  l_index = index;
  ans += (S.size() - (l_index + 1)) / 2;

  for (int i = s_index; i < l_index + 1; i++)
  {
    if (S[i] == S[i + 1])
    {
      renzoku_count++;
      is_renzoku = true;
    }
    else if (is_renzoku)
    {
      count += (renzoku_count + 1) / 2;
      is_renzoku = false;
      renzoku_count = 0;
    }
  }

  ans += count * K;
  ans += alphabet_count / 2 * (K - 1);

  if (S.size() == 1)
    ans = K / 2;
  else if (S.size() == s_index)
    ans = S.size() * K / 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
dp = [[0] * (n + 1) for _ in [0, 1]]
dp[0][0] = 0
dp[1][0] = -1 * 10 ** 10
for i in range(n):
    for j in [0, 1]:
        dp[j][i + 1] = max(dp[0][i] + (-1)**j * a[i],
                           dp[1][i] + (-1)**(j + 1) * a[i])
print(dp[0][n])

Measured memory_bytes: 64752
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.HashMap;
import static java.lang.Math.*;

public class Main
{
    String s;
    
    public static void main(String args[])
    {
	new Main().solve();
    }
    
    void solve()
    {
	in();

	out();
    }

    void in()
    {
	Scanner sc = new Scanner(System.in);
	s = sc.next();
    }

    void out()
    {
	int cnt = 0;
	for(int i = 0; i < s.length(); i++) {
	    char c = s.charAt(i);
	    if(c < 'A' || 'Z' < c) cnt++;
	}

	int sl = s.length();
	
	if(s.charAt(0) == 'A' && s.substring(2, sl - 1).indexOf("C") != -1 && sl == cnt + 2)
	    out("AC");
	else
	    out("WA");
	
    }
    
    void out(int n)
    {
	System.out.println(n);
    }

    void out(double n)
    {
	System.out.println(n);
    }

    void out(long n)
    {
	System.out.println(n);
    }
    
    void out(char c)
    {
	System.out.print(c);
    }
    
    void out(String s)
    {
	System.out.println(s);
    }
}


Measured memory_bytes: 22100
using namespace std;
#include<bits/stdc++.h>
#define int long long
#define pb push_back 
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define repa(i,a,b) for (int i=a; i<=b; i++)
#define repd(i,b,a) for (int i=b; i>=a; i--)
#define endl "\n"
//debugging
#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

const int N = 1e+6+5;
int big = 1e+18+3;
int mod = 1e+9+7;

signed main()
{
    IOS;
    
    int n,k;

    cin>>n>>k;

    n%=k;

    cout<<min( n, k-n )<<endl;
    
    
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>

using namespace std;
using llong = long long;
const int MOD=1000000007;


int main(int argc, char**argv){
    // for (int i = 0; i < vvi.size(); i++){
    //     for (int j = 0; j < vvi.front().size(); j++){
    //         cout << vvi[i][j] << endl;
    //     }
    // }
    vector<vector<int> > c = vector<vector<int> >(3, vector<int>(3, 0));
    for (int i = 0; i < 3; i++){
        for (int k = 0; k < 3; k++){
            cin >> c[i][k];
        }
    }
    vector <int> b(3);
    for (int i = 0; i < 3; i++) b[i] = c[0][i];

    vector <int> a;
    a.push_back(0);
    a.push_back(c[1][0]-b[0]);
    a.push_back(c[2][0]-b[0]);

    for (int i = 0; i < 3; i++){
        for (int k = 0; k < 3; k++){
            if (a[i]+b[k] != c[i][k]){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;

    return 0;
}











Measured memory_bytes: 256
lines = STDIN.readlines.map(&:chomp)
n = lines.shift.to_i
v = lines.shift.split(" ").map(&:to_i).sort
puts (1...n).inject(0){|r, i| r += v[i].to_f / 2 ** (n - i)} + v[0].to_f / 2 ** (n - 1)


Measured memory_bytes: 1788
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

using namespace std;
int main() {
	int a, b, t;
	cin >> a >> b >> t;
	cout << b*(t / a) << endl;
	return 0;
}

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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int a,b,c; cin >> a >> b >> c;
	cout << (a==b&&b==c?"Yes":"No") << endl;	
	return 0;
}


Measured memory_bytes: 256
// ABC069B - 

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;

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

	cout << s[0] << s.size() - 2 << s[s.size()-1] << endl;

	return 0;
}


Measured memory_bytes: 256
from operator import mul
from functools import reduce
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
def fctr1(n): 
    f=[]
    c=0
    r=int(n**0.5)
    for i in range(2,r+2):
        while n%i==0:
            c+=1
            n=n//i
        if c!=0:
            f.append([i,c])
            c=0
    if n!=1:
        f.append([n,1])
    return f

n, m = map(int,input().split())
MOD, ans = 10**9+7, 1
c = fctr1(m)
for i in c:
    ans = ans*cmb(i[1]+n-1,n-1)%MOD
print(ans)

Measured memory_bytes: 3688
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include<string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
using namespace std;
long long a,b,n;
long long before,last;
int main()
{
cin>>a>>b>>n;
  if(n<b) cout<<(a*n)/b;
  else
  {
  	before=(a*(b-1))/b;
  	last=(a*n)/b-(n/b)*a;
  	cout<<max(before,last);
  }
    
    
}

Measured memory_bytes: 3588
#include <iostream>
using namespace std;
 
int main() {
  int i,j,n;
  while(1){
    int ans=0;
    cin>>n;
    if (n==0) break;
    int sum=0;
    i=0;
    while(n>sum){
      i++;
      sum=sum+i;
    }
    sum=1;
    for(j=2;j<=i;j++){
      sum=sum+j;
      if((n-sum)%j==0)ans++;
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1160
s = input() #sys.stdin.readlineは最後が改行

from collections import Counter

c = Counter(s)
cm = c.most_common()

if len(c)==1:
    if len(s)==1:
        print('YES')
    else:
        print('NO')
    exit()

if len(c)==2:
    if len(s)==2:
        print('YES')
    else:
        print('NO')
    exit()

if len(c)==3:
    aa = cm[0][1]
    bb = cm[1][1]
    cc = cm[2][1]
    if aa-cc<2:
        print('YES')
    else:
        print('NO')


Measured memory_bytes: 3444
#include "bits/stdc++.h"
using namespace std;

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


int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int a, b;
    cin >> a >> b;
    if (a >= 13) { cout << b << endl; }
    else if (a <= 5) { cout << "0" << endl; }
    else { cout << b / 2 << endl; }

    return 0;
}


Measured memory_bytes: 256
from collections import Counter
from itertools import accumulate

N = int(input())
inputs = [int(i) for i in input().split()]

ans = 0

ruisekiwa = list(accumulate(inputs))
ruisekiwa.sort()
counter_ruiseki = Counter(ruisekiwa)

for key, value in counter_ruiseki.items():
    if key == 0 and value == 1:
        ans += value
        continue
    elif key == 0 and value > 1:
        ans += value
    if value > 1:
        ans += sum(list(range(value)))

print(ans)


Measured memory_bytes: 41472
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define dbg(x) cerr << #x << " = " << x <<endl
#define dbg2(x,y) cerr<< #x <<" = "<< x <<"  "<< #y <<" = "<< y <<endl
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
template<typename T>inline T _min(T A,T B){return A<B?A:B;}
template<typename T>inline T _max(T A,T B){return A>B?A:B;}
template<typename T>inline char MIN(T&A,T B){return A>B?(A=B,1):0;}
template<typename T>inline char MAX(T&A,T B){return A<B?(A=B,1):0;}
template<typename T>inline void _swap(T&A,T&B){A^=B^=A^=B;}
template<typename T>inline T read(T&x){
	x=0;int f=0;char c;while(!isdigit(c=getchar()))if(c=='-')f=1;
	while(isdigit(c))x=x*10+(c&15),c=getchar();return f?x=-x:x;
}
const int N=2e5+7,INF=0x3f3f3f3f;
int n,q,tot;
struct thxorz{
	int u,v,w;
	thxorz(int u=0,int v=0,int w=0):u(u),v(v),w(w){}
	inline bool operator <(const thxorz&A)const{return w<A.w;}
}e[N<<1];
inline int adj(int x){return x==n?0:(~x?x:n-1);}
int minv1[N],minv2[N],edge[N];
int s,tmp,res;
ll ans;
int anc[N];
inline int get_anc(int x){return anc[x]==x?x:anc[x]=get_anc(anc[x]);}
inline void kruskal(){
	sort(e+1,e+tot+1);for(register int i=0;i<n;++i)anc[i]=i;
	for(register int i=1;i<=tot;++i)if(get_anc(e[i].u)^get_anc(e[i].v))anc[get_anc(e[i].u)]=get_anc(e[i].v),ans+=e[i].w;
}

int main(){//freopen("test.in","r",stdin);//freopen("test.ans","w",stdout);
	read(n),read(q);
	memset(minv1,0x3f,sizeof minv1),memset(minv2,0x3f,sizeof minv2),memset(edge,0x3f,sizeof edge);
	for(register int i=1,x,y,c;i<=q;++i)read(x),read(y),read(c),MIN(minv1[x],c),MIN(minv2[y],c),e[++tot]=thxorz(x,y,c);
	tmp=INF;for(register int i=0;i<n;++i)if(MIN(tmp,minv1[i]))s=i;tmp=INF;
	for(register int i=s,cnt=1;cnt<=n;i=adj(i+1),++cnt){if((tmp+=2)>minv1[i]+1)tmp=minv1[i]+1;MIN(edge[i],tmp);}
	tmp=INF;for(register int i=0;i<n;++i)if(MIN(tmp,minv2[i]))s=i;tmp=INF;
	for(register int i=s,cnt=1;cnt<=n;i=adj(i+1),++cnt){if((tmp+=2)>minv2[i]+2)tmp=minv2[i]+2;MIN(edge[i],tmp);}
	for(register int i=0;i<n;++i)e[++tot]=thxorz(i,adj(i+1),edge[i]);
	kruskal();
	return printf("%lld\n",ans),0;
}

Measured memory_bytes: 9984
import bisect
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
A_cum = [0]
B_cum = [0]
A_cum[0] = A[0]
for j in range(len(A)-1):
    A_cum.append(A_cum[j]+ A[j+1])
B_cum[0] = B[0]
for l in range(len(B)-1):
    B_cum.append(B_cum[l] + B[l+1])
for i in range(len(A_cum)):
    k = A_cum[i]
    if k >K:
        break
    b = bisect.bisect(B_cum,K-k)
    check = i+b+1
    if check>ans:
        ans = check
check = bisect.bisect(B_cum,K)
if check>ans:
    ans = check    
print(ans)

Measured memory_bytes: 49068
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>

using namespace std;
typedef long long int ll;

ll n,a[300010],r=0;

int main(){
    scanf("%lld",&n);
    for(int i=0;i<3*n;i++){
        scanf("%lld",&a[i]);
    }
    sort(a,a+3*n,greater<ll>());
    for(int i=0;i<n;i++){
        //printf("%d\n",a[i]);
        r+=a[i*2+1];
    }
    printf("%lld\n",r);
    
}

Measured memory_bytes: 2560
// abc133d: Rain Flows into Dams
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

#define upto(i,s,e,d) for(int i=(s);i<(e);i+=(d))

int main(){
  int n; cin>>n;
  int m0 = 0;
  vi d(n);
  upto(i,0,n,1){
    cin>>d[i];
    if(i%2) m0 -= d[i]; else m0 += d[i];
  }
  cout<<m0;
  upto(i,0,n-1,1) cout<<" "<<(m0 = d[i]*2 - m0);
  cout<<endl;
}

Measured memory_bytes: 1664
function main(input) {
  var N = input[0].split(" ")[0]-0;
  var K = input[0].split(" ")[1]-0;
  var list = input[1].split(" ").map(v=>v-0).sort((a,b)=>b-a);
  var ans = 0;
  for(var i=K;i<list.length;i++){
    ans += list[i];
  }
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').split("\n"))


Measured memory_bytes: 36144
#include <stdio.h>

int main(){

  int n,max,min,i,a;
  long int sum=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){

    scanf("%d",&a);

    if(i==0){ max=a; min=a; }

    if(max<a) max = a;
    if(min>a) min = a;

    sum+=a;
  }

  printf("%d %d %ld\n",min,max,sum);

  return 0;
}


Measured memory_bytes: 2108
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<map>

using namespace std;

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

#define INF 1000000000

int visit[26];

void saiki(int num, int count[26][26]){
	if(visit[num]!=0)return;
	visit[num]=1;
	
	rep(i,26){
		if(count[num][i]>0)saiki(i,count);
	}
}

int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0)break;
		
		int count[26][26]={0};
		int in[26]={0};
		int out[26]={0};
		vector<string> input;
		
		rep(i,n){
			string str;
			cin>>str;
			
			input.push_back(str);
			count[str[0]-'a'][str[str.size()-1]-'a']++;
			in[str[0]-'a']++;
			out[str[str.size()-1]-'a']++;
		}
		
		
		int st=-1;
		rep(i,26){
			rep(j,26){
				if(count[i][j]>0)st=i;
			}if(st!=-1)break;
		}
		
		rep(i,26)visit[i]=0;
		
		saiki(st,count);
		
		bool ans = true;
		rep(i,26){
			if(in[i]!=out[i])ans = false;
			if(in[i]>0 && visit[i]==0)ans=false;
		}
		
		if(ans){
			puts("OK");
		}else{
			puts("NG");
		}
	}
}

Measured memory_bytes: 1960
#include<iostream>
#include<algorithm>
#include<utility>

using namespace std;

typedef long long ll;

const ll INF = 1145141919810893;

int L;
ll A[200000 + 100];

ll dp[200000 + 100][5];//0　偶　奇　偶　0

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

	for (int i = 0; i <= L; i++)for (int j = 0; j < 5; j++)dp[i][j] = INF;
	dp[0][0] = 0;
	for (int i = 0; i <= L; i++) {
		dp[i + 1][0] = dp[i][0] + A[i];
		dp[i + 1][1] = min({ dp[i][0], dp[i][1] }) + (A[i] % 2 ? 1 :(A[i] != 0 ? 0 : 2));
		dp[i + 1][2] = min({ dp[i][0], dp[i][1], dp[i][2] }) + (A[i] % 2 ? 0 : 1);
		dp[i + 1][3] = min({ dp[i][0], dp[i][1], dp[i][2], dp[i][3] }) + (A[i] % 2 ? 1 : (A[i] != 0 ? 0 : 2));
		dp[i + 1][4] = min({ dp[i][0], dp[i][1], dp[i][2], dp[i][3], dp[i][4] }) + A[i];
	}
	cout << min({ dp[L][0], dp[L][1], dp[L][2], dp[L][3], dp[L][4] }) << endl;
	return 0;
}

Measured memory_bytes: 9848
void solve();

int main() {
	solve();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;
typedef pair<int, int> pii;

void solve() {
	string S;
	cin >> S;
	if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3])cout << "Bad" << endl;
	else cout << "Good" << endl;
	return;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    int N,D;
    cin>>N>>D;
    vvi X(N,vi(D));
    for(int i=0;i<N;i++){
        for(int j=0;j<D;j++){
            cin>>X[i][j];
        }
    }
    int ans=0;
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            int sqdist=0;
            for(int k=0;k<D;k++){
                sqdist+=(X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
            }
            int r=round(sqrt(sqdist));
            if(r*r==sqdist)ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <map>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

void solve(vector<int> vv) {
  map<vector<int>, bool> visited;
  queue<vector<int> > Q;
  Q.push(vv);
  while(Q.size()) {
    vector<int> v = Q.front();
    Q.pop();
    if (visited[v]) continue;
    visited[v] = true;
    int n = v.size()-1;
    REP(i,n) {
      if (i) cout << " ";
      cout << v[i];
    }
    cout << endl;
    REP(i,n) {
      if (v[i] > v[i+1]) {
        v[i]--;
        for (int j=i; j<n; ++j) {
          if (v[j] > v[j+1]) {
            vector<int> vv(v);
            vv[j+1]++;
            if (j == n-1)
              vv.push_back(0);
            Q.push(vv);
          }
        }
        v[i]++;
      }
    }
  }
}

int main() {
  int n;
  while(cin >> n, n) {
    vector<int> v(2);
    v[0] = n; v[1] = 0;
    solve(v);
  }
}

Measured memory_bytes: 1544
#include<stdio.h>
int main(void)
{
	int c1,c5,c10,c50,c100,c500,sum;
	scanf("%d",&c1);
	scanf("%d",&c5);
	scanf("%d",&c10);
	scanf("%d",&c50);
	scanf("%d",&c100);
	scanf("%d",&c500);
	sum=c1+(c5*5)+(c10*10)+(c50*50)+(c100*100)+(c500*500);
	if(sum<1000){
		printf("0\n");
	}
	else{
		printf("1\n");
	}
	return 0;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    
    vector<int> p(m);
    vector<string> s(m);
    for(int i = 0; i < m; i++) cin >> p[i] >> s[i];

    vector<bool> ac(n, false);

    int correct = 0;
    int penalty = 0;
    for(int i = 0; i < m; i++) {
        if(ac[p[i]]) continue;
        if(s[i] == "WA") {
            penalty++;
        } else {
            ac[p[i]] = true;
            correct++;
        }
    }

    for(int i = 0; i < m; i++) {
        if(ac[p[i]]) continue;
        if(s[i] == "WA") penalty--;
    }

    cout << correct << " " << penalty << endl;

    return 0;
}

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

int n,s,ans ;

void cal( int i , int sum , int N ){
	if( sum==s && N==0 ){
		ans++;
		return;
	}
	if( i==10 || N==0 ) return;
	
	cal( i+1 , sum , N ) ;
	cal( i+1 , sum+i , N-1 ) ;
}

int main(){
	
	while(1){
		cin >> n >> s ;
		if( n==0 && s==0 ) break;
		
		ans=0;
		
		cal( 0,0,n );
		
		cout << ans << endl ;
	}
	
return 0;
}

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

int main() {
    string s; cin >>s;
    long long ret = 0;
    vector<long long> v(s.size()+1);
    for (int i = 0; i <= s.size(); i++) {v[i]=0;}
    for (int i = 0; i <= s.size(); i++) {if(s[i]=='<'){v[i+1]=max(v[i+1],v[i]+1);}}
    for (int i = s.size(); i >= 0; i--) {if(s[i]=='>'){v[i]=max(v[i],v[i+1]+1);}}
    for (int i = 0; i <= s.size(); i++) ret += v[i];
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 4740
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<long double,long double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<61;
const double pi=acos(-1);
const double eps=1e-10;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

string s;

int main(){
	cin>>s;
	if(s[1]==s[2]&&(s[0]==s[1]||s[3]==s[1])) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
(defun ev (x y z)
  (+ (expt x 2)
     (expt y 2)
     (expt z 2)
     (* x y)
     (* y z)
     (* z x)))

(defun p (x y z)
  (cond ((= x y z) 1)
        ((and (= y z) (/= x y)) 3)
        ((and (= x y) (/= z x)) 3)
        (t 6)))

(defun f (n)
  (let ((c (make-array (list (1+ n)) :initial-element 0)))
    (loop :named x-loop
          :for x :from 1 :to 99
          :do (loop :named y-loop
                    :for y :from x :to (- 123 x)
                    :do (loop :named z-loop
                              :for z :from y :to (- 123 (+ x y))
                              :if (> (ev x y z) n)
                              :do (cond ((= x y z)
                                         (return-from x-loop))
                                        ((= y z)
                                         (return-from y-loop))
                                        (t
                                         (return-from z-loop)))
                              :do (incf (aref c (ev x y z)) (p x y z)))))
    c))

(let* ((n (read))
       (ans (f n)))
  (loop :for x :from 1 :to n
        :do (format t "~A~%" (aref ans x))))



Measured memory_bytes: 24616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
  int N,M;
  cin >> N >> M;

  vector<int>num(M,0);

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

  if(M <= N){
    cout << 0 << endl;
  }

  else{

  sort(num.begin(),num.end());

  vector<int>space(M - 1,0);

  for(int i=0;i<M - 1;i++){
    space[i] = num[i + 1] - num[i];
  }


  sort(space.begin(),space.end());
  int space_total = 0;

  for(int i = M -2;i >= M - N;i--){
    space_total += space[i];
  }

  cout << num[M - 1] - num[0] - space_total << endl;

}
return 0;
}


Measured memory_bytes: 1024
import itertools

n = int(input())
L = list(map(int, input().split()))
cnt = 0
for i, j, k in itertools.combinations(list(range(n)), 3):
    if (L[i] != L[j]) and (L[j] != L[k])and (L[i] != L[k]):
        if (L[i] < L[j] + L[k]) and (L[j] < L[i] + L[k]) and (L[k] < L[i] + L[j]):
            cnt += 1
print(cnt)

Measured memory_bytes: 9068
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1<<20;
int main(){
    int x,y;
    R(x,y);
    W(x*y);
    return 0;
}


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

using namespace std;

int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> m;
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        m.push_back(tmp);
    }
    sort(m.begin(), m.end());
    cout << m.size() + ((x - accumulate(m.begin(), m.end(), 0)) / m[0]) << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<functional>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define INF 200000000

using namespace std;

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

struct OwnVector2
{
	double x, y;
	OwnVector2(double x,double y):x(x),y(y){}
	OwnVector2() :OwnVector2(0, 0) {}
	OwnVector2 operator+(const OwnVector2& v)const
	{
		return OwnVector2(x + v.x, y + v.y);
	}
	OwnVector2 operator-(const OwnVector2& v)const
	{
		return OwnVector2(x - v.x, y - v.y);
	}
	OwnVector2 operator*(const double v)const
	{
		return OwnVector2(x*v, y*v);
	}
	bool operator==(const OwnVector2& v)const
	{
		return abs(x - v.x) <= 0.0000000000001&&abs(y - v.y) <= 0.00000000000001;
	}
	bool operator!=(const OwnVector2& v)const
	{
		return abs(x - v.x) > 0.0000000000001||abs(y - v.y) > 0.00000000000001;
	}

	double dot(const OwnVector2& v)const
	{
		return x*v.x + y*v.y;
	}
	double cross(const OwnVector2& v)const
	{
		return x*v.y - y*v.x;
	}
	double length()const
	{
		return sqrt(x*x + y*y);
	}
	double length2()const
	{
		return x*x + y*y;
	}
};

double CalcMinDistancePointVSSegment(OwnVector2 p1, OwnVector2 p2, OwnVector2 p3)
{
	OwnVector2 p12, p13, p21, p23;
	p12 = p2 - p1; p13 = p3 - p1; p21 = p1 - p2; p23 = p3 - p2;

	if(p12.dot(p13)<0.0)
	{
		return p13.length();
	}

	if (p21.dot(p23) < 0.0)
	{
		return p23.length();
	}

	return abs(p12.cross(p13)) / p12.length();
}

OwnVector2 CalcCrossPoint(OwnVector2 p1, OwnVector2 p2, OwnVector2 p3, OwnVector2 p4)
{
	OwnVector2 p12, p13, p14, p34, p31, p32;
	p12 = p2 - p1; p13 = p3 - p1; p14 = p4 - p1; p34 = p4 - p3; p31 = p1 - p3; p32 = p2 - p3;

	double d, u, v;

	d = p12.cross(p34);

	if (abs(d) <= 0.0000000000001)
	{
		return OwnVector2(INF, INF);
	}

	u = p13.cross(p34) / d;
	v = p13.cross(p12) / d;

	if (u<0.0 || u>1.0)
	{
		return OwnVector2(INF, INF);
	}
	if (v<0.0 || v>1.0)
	{
		return OwnVector2(INF, INF);
	}

	return p1 + p12*u;
}

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

	int q;
	cin >> q;

	for (int i = 0; i < q; i++)
	{
		double x0, x1, x2, x3, y0, y1, y2, y3;
		cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

		OwnVector2 p0(x0, y0), p1(x1, y1), p2(x2, y2), p3(x3, y3);

		OwnVector2 crossPoint = CalcCrossPoint(p0, p1, p2, p3);
		if (crossPoint != OwnVector2(INF, INF))
		{
			printf("%.10lf\n", 0.0);
		}
		else
		{
			double d0, d1, d2, d3;
			d0 = CalcMinDistancePointVSSegment(p0, p1, p2);
			d1 = CalcMinDistancePointVSSegment(p0, p1, p3);
			d2 = CalcMinDistancePointVSSegment(p2, p3, p0);
			d3 = CalcMinDistancePointVSSegment(p2, p3, p1);
			printf("%.10lf\n", min(d0, min(d1, min(d2, d3))));
		}
	}

	return 0;
}


Measured memory_bytes: 3304
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 #998244353
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"
INF = 10**18

def main():
    n = int(ipt())
    base = 10**9
    qs = []
    # Lの最大、Rの最小を求めると同時に、それらが同じセットに入るときのansの最大値を求める
    lma = 0
    li = -1
    ll = 0
    rmi = INF
    ri = INF
    lr = 0
    mal = 0
    for i in range(n):
        l,r = map(int,ipt().split())
        qs.append((l,r))
        d = r-l+1
        f = True
        if l > lma:
            if ll > mal:
                mal = ll
            lma = l
            li = i
            ll = d
            f = False
        elif l == lma and ll > d:
            li = i
            mal = max(mal,ll)
            ll = d
            f = False
        if r < rmi:
            if lr > mal:
                mal = lr
            rmi = r
            ri = i
            lr = d
            f = False
        elif r == rmi and lr > d:
            ri = i
            mal = max(mal,lr)
            lr = d
            f = False
        if f and mal < d:
            mal = d
    ans = mal+max(0,rmi-lma+1)

    # Lの最大値とRの最大値が別のセットに入る場合
    q = []
    for la,ra in qs:
        v = (base-1-max(0,ra-lma+1))*base+max(0,rmi-la+1)
        q.append(v)
    q.sort()
    dp0 = [INF,0]
    dp1 = [0,INF]
    f = False
    for i in q:
        l = base-1-i//base
        r = i%base
        if f:
            dp1[1] = min(dp1[1],r)
            if dp0[0]+r > sum(dp1):
                dp1[0] = dp0[0]
                dp1[1] = r
        f = True
        dp0[0] = min(dp0[0],l)

    # 上二つのうち最大を取る
    print(max(ans,sum(dp1)))
    
    return None

if __name__ == '__main__':
    main()


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

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<vector<int>> cnt(10, vector<int>(10));
    for (int a = 1; a <= n; a++) {
        string s = to_string(a);
        int x = s[0] - '0';
        int y = s[s.size() - 1] - '0';
        cnt[x][y]++;
    }

    long res = 0;
    for (int x = 0; x < 10; x++) {
        for (int y = 0; y < 10; y++) {
            res += 1ll * cnt[x][y] * cnt[y][x];    
        }
    }
    cout << res;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _Ty> static _Ty tp_abs(const _Ty& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _Ty> static _Ty tp_min(_Ty a, _Ty b) {
	return a < b ? a : b;
}
template <class _Ty> static _Ty tp_max(_Ty a, _Ty b) {
	return a > b ? a : b;
}
template<class T> static void getint(T& a) {
	const char* fmt = " %d";
	if (sizeof(T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class T> static void getint(T& a, T& b) {
	const char* fmt = " %d %d";
	if (sizeof(T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class T> static void getint(T& a, T& b, T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static const int EduDp_INF = 1100000000;
static const int MOD_NUM = 1000000007;
static void B_frog2();

#if 1
int main()
{
	B_frog2();
	fflush(stdout);
	return 0;
}
#endif

static void B_frog2()
{
	int N, K;
	getint(N, K);

	std::vector<int> dp(N + 1, 0), cost(N + 1, 0);

	for (int i = 1; i <= N; i++) {
		int c; getint(c);
		cost[i] = c;
	}
	dp[0] = dp[1] = 0;
	dp[2] = tp_abs(cost[1] - cost[2]);

	for (int i = 3; i <= N; i++) {
		int c = EduDp_INF;
		for (int j = 1; j <= K; j++) {
			if (i - j <= 0) break;
			c = tp_min(c, dp[i - j] + tp_abs(cost[i - j] - cost[i]));
		}
		dp[i] = c;
	}
	printf("%d\n", dp[N]);
}


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

int main(void){
    int N,M;
    cin >> N >> M;
    int ans = N;
    for(int i = 0 ; i < M ; i++){
        int tmp;
        cin >> tmp;
        ans -= tmp;
    }
    if(ans < 0) cout << -1 << endl;
    else cout << ans << endl;
    
}

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

typedef long long ll;

const int MAXN = 1e5 + 5;

int N, M;
char s[MAXN], t[MAXN];

int main() {
	scanf("%d%d%s%s", &N, &M, s, t);
	
	for (int i = 0; i < N; i++) 
		if (!((ll)i * M % N) && s[i] != t[(ll)i * M / N]) {
			puts("-1");
			return 0;
		}
		
	printf("%lld\n", (ll)N * M / __gcd(N, M));
	
	return 0;
}

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

int gcd(long long a,long long b,long long c){
  long long l;
  for(long long i=0; i<1000; i++){
    l = a % b;
    if(l == 0)break;
    a = b;
    b = l;
  }
  for(long long j=0; j<1000; j++){
    l = c % b;
    if(l == 0)break;
    c = b;
    b = l;
  }
  return b;
}

int main(){
  long long  n;
  cin >> n;
  long long ans=0;
  for(long long i=1; i<=n; i++){
    for(long long j=1; j<=n; j++){
      for(long long k=1; k<=n; k++){
    ans =  gcd(i,j,k) + ans;
      }
    }
  }
  cout << ans << endl;

}


Measured memory_bytes: 3636
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
S=input()
cnt=0

for i in range(len(S)):
	if i%2==1:
		if S[i]=="L" or S[i]=="U" or S[i]=="D":
			cnt+=1
	if i%2==0:
		if S[i]=="R" or S[i]=="U" or S[i]=="D":
			cnt+=1

if cnt==len(S):
	print("Yes")
else:
	print("No")

Measured memory_bytes: 3064
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>



using namespace std;



int main(){

	int a , b;

	cin>>a>>b;

	if(a%2==0||b%2==0) cout<<"Even"<<endl;

	else cout<<"Odd"<<endl;

	return 0;

	}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

int n;
int res;

int main()
{

  while(cin >> n){
    res = 0;
    rep(a,10) rep(b,10) rep(c,10) rep(d,10) if(a+b+c+d==n) res += 1;
    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 1160