akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  string S, T;
  int count = 0;
  cin >> S >> T;
  for (int i = 0; i < 3; i++)
  {
    if (S.at(i) == T.at(i))
    {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repr(i, a, b) for (int i = (int)a; i > (int)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 4e18 + 5;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    multiset<int> a;
    rep(i,n){
        int ai;
        cin >> ai;
        a.insert(ai);
    }
    while (m){
        auto itr = a.end();
        itr--;
        int x = (*itr) / 2;
        a.erase(itr);
        a.insert(x);
        m--;
    }
    ll ans = 0;
    for (auto itr = a.begin(); itr != a.end();itr++)
        ans += *itr;
    cout << ans << ENDL;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define ll long long
#define fcout cout << fixed << setprecision(10)
using namespace std;

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << max(max(a*c, a*d), max(b*c, b*d)) << "\n";
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; i++) {
      cin >> A.at(i);
    }
    vector<int> X(1000001);
    for (int a : A){
        X[a] += 1;
    }
    int c = 0;
    for (int a : A){
        X[a] -= 1;
        int q, r;
        bool f = true;
        for (int i = 1; i < int(sqrt(a))+1; i++){
            q = a / i;
            r = a % i;
            if (r == 0){
                if (X[i] != 0 || X[q] != 0){
                    f = false;
                    break;
                }
            }
        }
        c += int(f);
        X[a] += 1;
    }
    cout << c << endl;
}


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


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	string S; cin >> S;
	if (S[0] == S[2]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Programminng
{
    class AOJ_Volume0025
    {
        public static void Main(string[] args)
        {
            while (true)
            {
                string s = Console.ReadLine();
                if (string.IsNullOrEmpty(s)) break;

                string s2 = Console.ReadLine();
                string[] _s = s.Split(' ');
                string[] _s2 = s2.Split(' ');
                int[] a = new int[4];
                int[] b = new int[4];
                int count = 0, count_2 = 0;

                for (int i = 0; i < 4; i++)
                {
                    a[i] = int.Parse(_s[i]);
                    b[i] = int.Parse(_s2[i]);
                }


                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        if (a[i] == b[j])
                        {
                            if (i == j) count++;
                            else count_2++;
                        }
                    }
                }

                Console.WriteLine(count + " " + count_2);

            }
        }
    }
}

Measured memory_bytes: 5600
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int a[110];

int solve() {
    int res = inf;
    int sum;

    for (int t = -100; t <= 100; t++) {
        sum = 0;
        for (int i = 0; i < n; i++)
            sum += (a[i] - t) * (a[i] - t);
        res = min(res, sum);
    }

    return res;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math

# 時針、分針の角度を求める
# 360度
# 分針：1分間 6度 
# 時針：1時間 30度 1分間 0.5度
a, b, h, m = map(int, input().split())

# 時針の角度
h_angle = h * 30 + m * 0.5
# 分針の角度
m_angle = m * 6

# 時針と分針間の角度
angle = h_angle - m_angle

if angle >= 180:
    angle = m_angle + 360 - h_angle

#print(angle)

# 時針、分針の長さと角度で、辺の長さを求める
# 余弦
c = (a * a + b * b - 2 * a * b * math.cos(math.radians(angle))) ** 0.5

print(c)



Measured memory_bytes: 9568
#include <stdio.h>
int main(){
 long a[10000], sum = 0;
 int n, i, max, min, b;
 scanf("%d", &n);
  scanf("%d", &b);
   max = b;
   min = b;
   sum = b;
  for(i=0; i<n-1; i++){
   scanf("%d ", &b);
   a[i] = b;
   sum = sum + b;
   if(max < b){
    max = b;
    }
   if(min > b){
    min = b;
   }
}
 printf("%d %d %ld\n", min, max, sum);

 return 0;
}

Measured memory_bytes: 604
use std::io::{Read, stdin};
use std::str::FromStr;


fn main() {
    let mut n: i64 = read();
    let mut v = Vec::new();
    loop {
        v.push((n % -2).abs());
        if n % -2 == -1{
            n /= -2;
            n += 1;
        }else{
            n /= -2;
        }
        if n == 0{
            break;
        }
    }
    v.reverse();
    for i in v{
        print!("{}", i);
    }
    print!("\n");
}


fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

Measured memory_bytes: 4352
a = gets.strip.split.map(&:to_i)
N = a[0]
K = a[1]
Q = a[2]
A = Q.times.map{gets.to_i}

POINTS = Array.new(N, 0)

A.each do |i|
  POINTS[i-1] += 1
end

POINTS.each do |point|
  if K-Q+point > 0
    puts "Yes"
  else
    puts "No"
  end
end


Measured memory_bytes: 3836
import sys
sys.setrecursionlimit(1000000)
def dfs(u):
    if(dp[u]!=-1):
        return dp[u]
    for i in d[u]:
        if(dp[i]!=-1):
            dp[u]=max(dp[u],dp[i]+1)
        else:
            dp[u]=max(dp[u],dfs(i)+1)
    return max(dp[u],0)
from collections import defaultdict as dd
n,m=map(int,input().split())
d=dd(list)
for i in range(m):
    u,v=map(int,input().split())
    d[u].append(v)
dp=dd(lambda: -1)
mx=0
for i in range(1,n+1):
    if(dp[i]==-1):
        dp[i]=dfs(i)
    mx=max(mx,dp[i])
print(mx)

Measured memory_bytes: 182272
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)

using namespace std;

int main(){
    int x,y=0,t=0;
    cin>>x;
    while(x>y){
        t++;
        y+=t;
    }
    cout<<t<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
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<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  ll k;
  cin >> s >> k;
  ll n = ll(s.size());
  vector<int> v(1, 1);
  for (int i = 1; i < n; i++) {
    if(s[i] == s[i-1]) v[v.size()-1]++;
    else v.push_back(1);
  }
  if(v.size() == 1) cout << (n * k) / 2 << endl;
  else{
    ll res = 0;
    for(auto a : v){
      res += a / 2;
    }
    if(s[0] == s[n-1]){
      v[0] += v[v.size()-1];
      v.pop_back();
    }
    for(auto a : v){
      res += (a / 2) * (k-1);
    }
    cout << res << endl;
  }

}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    long long a,b,c,d,e,f,g,h,p,q,r;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    e=a*c;
    f=a*d;
    g=b*c;
    h=b*d;

    if(e>f)
    {
        p=e;
    }
    else
    {
        p=f;
    }
    if(g>h)
    {
        q=g;
    }
    else
    {
        q=h;
    }
    if(p>q)
    {
        r=p;
    }
    else
    {
        r=q;
    }


    printf("%lld\n",r);

    return(0);




}


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

int main(void)
{
    int N;
    cin >> N;
    vector<int> B(N);
    for (int i = 0; i < N-1; i++) {
        cin >> B[i];
    }

    int s = B[0];
    for (int i = 1; i < N-1; i++) {
        s += min(B[i-1], B[i]);
    }
    s += B[N-2];
    cout << s << endl;
    return 0;
}



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

int main(){
  int N;
  
  cin >> N;
  
  vector<int> A(N);
  for(int i = 0;i < N;i++) cin >> A.at(i);
  
  int ans = A.at(0);
  for(int i = 1;i < N;i++) ans = gcd(ans, A.at(i));
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)                                 //g++ template.cpp -o template.exe
#define zeroes(x) memset(x,0,sizeof(x))                                        //all elements to 0  |  \   \0
#define all(x) (x).begin(), (x).end()
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;







bool sortbysec(const pair<int,int> &a,                         //sorting of elements wrt second
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 

bool sortinrev(const pair<int,int> &a,                   //sorting in descending wrt first 
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
} 
bool sortinrevsec(const pair<int,int> &a,                  //sorting in dsc wrt second
               const pair<int,int> &b) 
{ 
       return (a.second > b.second); 
} 




int main()
{
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif



    
  int n;
  cin>>n;
  

  if(n<30)
    cout<<"No";
  else
    cout<<"Yes";

  



  return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  int tmp;
  map<int, int> amap;
  for(int i=0;i<N;++i) {
    cin>>tmp;
    amap[tmp-1]++;
    amap[tmp]++;
    amap[tmp+1]++;
  }
  int ans = 0;
  for(int i=-1;i<100005;++i) ans = max(ans, amap[i]);
  cout<<ans<<endl;
}



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

constexpr double EPS = 1e-6;

inline double sq(double x) { return x*x; }

struct point {
    double x, y;
    point() {}
    point(double x, double y): x(x), y(y) {}

    point operator + (const point& o) const { return point(x+o.x, y+o.y); }
    point operator - (const point& o) const { return point(x-o.x, y-o.y); }
    point operator * (const double a) const { return point(x*a, y*a); }
    point operator / (const double a) const { return point(x/a, y/a); }
};

double fabs(point a) { return sqrt(a.x*a.x + a.y*a.y); }
double dist(point a, point b) { return fabs(a - b); }

int N;
point P[300];

int solve() {
    int ans = 1;
    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            if (dist(P[i], P[j]) > 2) continue;

            point d = (P[j] - P[i]) / dist(P[i], P[j]);
            point t = (P[i] + P[j]) / 2;
            double k = sqrt(1 - sq(dist(P[i], P[j]) / 2));
            point cs[2] = {t + point(d.y, -d.x) * k, t + point(-d.y, d.x) * k};

            for (point c : cs) {
                int count = 0;
                for (int i = 0; i < N; ++i) {
                    if (dist(c, P[i]) <= 1 + EPS) ++count;
                }
                ans = max(ans, count);
            }
        }
    }

    return ans;
}

int main(void) {
    while (true) {
        cin >> N; if (N == 0) break;
        for (int i = 0; i < N; ++i) cin >> P[i].x >> P[i].y;
        cout << solve() << endl;
    }
    return 0;
}




Measured memory_bytes: 3140
N, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

a.sort()
ans = 0

for i in a:
    if x >= i:
        ans += 1
        x -= i
    else:
        x = 0
        break
        
if x > 0:
    ans -=1
print(ans)

Measured memory_bytes: 9124
# -*- coding: utf-8 -*-
"""
Created on Tue May 12 12:30:35 2020

@author: shinba
"""

s = input()

a = s.count("a")
b = s.count("b")
c = s.count("c")

L = [a,b,c]

L.sort()

if L[2]-L[0] <= 1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3316
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
priority_queue<P> que;
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n>>m;
    rep(i,n)cin>>a[i];
    rep(i,n){
        ll now=a[i]/2;
        now=a[i]-now;
        que.push({now,a[i]});
    }
    rep(i,m){
        P X=que.top();
        que.pop();
        X.se/=2;
        ll now=X.se/2;
        now=X.se-now;
        que.push({now,X.se});
    }
    while(1){
        if(que.empty())break;
        P X=que.top();
        que.pop();
        //Cout(X.se);
        ans+=X.se;
    }
    Cout(ans);
    return 0;
}

Measured memory_bytes: 3188
import math
n = int(input())
a = list(map(int, input().split()))
list.sort(a, reverse = True)
c = math.ceil(n/2)
b = [2]*c + [0]*(n-c)    

b[0] -= 1
if n%2 == 1:
    b[c-1] -= 1

ans = 0
for i in range(n):
    ans += b[i]*a[i]
print(ans)

Measured memory_bytes: 32916
n = int(input())
aa = sorted(list(map(int, input().split())))
if aa[0] == 0:
    print(0)
else:
    ret = 1
    ff = False
    for a in reversed(aa):
        ret *= a
        if ret > 10**18:
            ff = True
            break
    if ff:
        print(-1)
    else:
        print(ret)

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

typedef complex<double> P;

struct C {
  P o;
  double r;
  C() {}
  C(P o, double r) : o(o), r(r) {}
};

const double eps = 1e-8;
const double pi = acos(-1);

bool equals(double a, double b) { return abs(a - b) < eps; }

int isIntersect(C a, C b) {
  double x = a.o.real() - b.o.real();
  double y = a.o.imag() - b.o.imag();
  double s = a.r + b.r;
  double d = x*x + y*y;
  s *= s;
  if(equals(d, s)) return 1;
  if(d > s) return 0;
  double r = abs(a.r - b.r);
  r *= r;
  if(equals(d, r)) return -1;
  if(d > r) return 2;
  return -2;
}

int main(int argc, char *argv[])
{
  int n;
  while (cin >> n) {
    int r[n];
    for (int i = 0; i < n; ++i) {
      cin >> r[i];
    }
    double x[n];
    x[0] = r[0];
    for (int i = 1; i < n; ++i) {
      x[i] = -1e128;
      for (int j = 0; j < i; ++j) {
        double small = max<double>(x[j], r[i]);
        double large = 1e128;
        for (int loop = 1000; loop--; ) {
          double mid = (small + large) / 2.0;
          C a(P(x[j], r[j]), r[j]);
          C b(P(mid,  r[i]), r[i]);
          if (isIntersect(a, b)) small = mid;
          else large = mid;
        }
        x[i] = max(x[i], large);
      }
    }
    double mx = 0;
    for (int i = 0; i < n; ++i) {
      mx = max(mx, x[i] + r[i]);
    }
    printf("%.10lf\n", mx);
  }
  return 0;
}

Measured memory_bytes: 3228
#include<iostream>
#include<vector>
#include<string>
#include<cmath>

using namespace std;

int main() {

	int64_t N, K;
	cin >> N>>K;
	

	N = N % K;

	if (N > abs(N - K)) {
		N = abs(N - K);
	}

	cout << N;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>//万能头真好！
using namespace std;
int n,k,ans;
int main()
{
     cin>>n>>k;//QWQ整个就不用讲了吧
     ans=1;
     for(int i=0;i<n;i++)
    {
        if(ans>k)//一旦大于就累加
        {
            ans+=k;
        }
        else 
        ans*=2;//否则就乘2

    }
    cout<<ans;

    return 0;//完美结局
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <time.h>
#include <stdlib.h>
using namespace std;

	

int main(){
	int count=0,n,ab=0,ca=0,bc=0,len;
	char str[10];
	cin >> n;
	for(int i=0;i<n;i++){
		scanf("%s",str);
		for(len=0;str[len+1]!='\0';len++){
			if(str[len]=='A'&&str[len+1]=='B') count ++;
		}
		if(str[0]=='B'&&str[len]=='A') ab++;
		else if(str[0]=='B') bc++;
		else if(str[len]=='A') ca++;
	}
	if(ab!=0){
		count += (ab-1);
		if(bc>0){
			count++;
			bc--;
		}
		if(ca>0){
			count++;
			ca--;
		}
	}
	if(bc<ca) count +=bc;
	else count += ca;
	printf("%d\n",count);
	return 0;
}
				

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可

const ll INF=1000000000000000000;

signed main(){
    ll R,G,B,N;
    cin>>R>>G>>B>>N;
    ll ans=0;
    for(ll i=0;i*R<=N;i++){
        for(ll j=0;j*G+i*R<=N;j++){
            if((N-(j*G+i*R))%B==0&&(N-(j*G+i*R))>=0) ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static long MOD=1_000_000_007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long ans = (modpow(2, n) - 1 + MOD - comb(n, a)  + MOD - comb(n, b) + MOD) % MOD;
        System.out.println(ans);
    }

    private static long comb(long n, long a){
        long up = 1;
        long down = 1;
        for(int i=0;i<a;i++){
            up *= (n-i);
            up %= MOD;
            down *= (i+1);
            down %= MOD;
        }
        return (up * modinv(down)) % MOD;
    }

    private static long modpow(long a, long b){
        if(b == 1){return a;}
        if(b == 0){return 1;}
        long res = b/2;
        long rem = b%2;
        long p = modpow(a, res) % MOD;
        if(rem == 1){
            return ( ((p*p)%MOD) * a) % MOD;
        }else{
            return (p*p) % MOD;
        }
    }

    private static long modinv(long a){
        return modpow(a, MOD-2);
    }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(m);
  rep(i, 0, m) cin >> b[i];

  int ans = 0;
  rep(i, 0, n) {
    int sum_val = 0;
    rep(j, 0, m) {
      int a;
      cin >> a;
      sum_val += a * b[j];
    }
    if (sum_val + c > 0)
      ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>

struct point
{
  int id;
  int x, y;
  point() = default;
  point(int id, int x, int y): id(id), x(x), y(y) {};
};

struct node
{
  point p;
  node* left = nullptr;
  node* right = nullptr;
};

using tree = node*;
using vector = std::vector<point>;
using iterator = std::vector<point>::iterator;

tree make2Dtree(iterator l, iterator r, int depth)
{
  if (l>=r)
    return nullptr;

  if (depth % 2 == 0)
    {
      std::sort(l, r, [](point a, point b){return a.x < b.x;});
    }
  else
    {
      std::sort(l, r, [](point a, point b){return a.y < b.y;});
    }

  auto mid = l + std::distance(l, r)/2;
  auto new_node = new node;
  new_node->p = *mid;
  new_node->left = make2Dtree(l, mid, depth+1);
  new_node->right = make2Dtree(mid+1, r, depth+1);

  return new_node;
}

void find(tree T, int sx, int tx, int sy, int ty, int depth, vector& ans)
{
  if (T == nullptr) return;


  auto p = T->p;
  if (sx<=p.x && p.x<=tx && sy<=p.y && p.y<=ty)
    {
      ans.push_back(p);
    }

  if (depth%2==0)
    {
      if (p.x>=sx)
        find(T->left, sx, tx, sy, ty, depth+1, ans);
      if (p.x<=tx)
        find(T->right, sx, tx, sy, ty, depth+1, ans);
    }
  else
    {
      if (p.y>=sy)
        find(T->left, sx, tx, sy, ty, depth+1, ans);
      if (p.y<=ty)
        find(T->right, sx, tx, sy, ty, depth+1, ans);
    }
}

int main ()
{
  int n, q, x, y;
  std::cin >> n;
  std::vector<point> points;
  points.resize(n);
  for (int i=0; i<n; ++i)
    {
      // std::cin >> x >> y;
      scanf("%d%d", &x, &y);
      points[i] = point(i, x, y);
    }

  auto T = make2Dtree(points.begin(), points.end(), 0);

  int sx, tx, sy, ty;
  std::cin >> q;
  for (int i=0; i<q; ++i)
    {
      // std::cin >> sx >> tx >> sy >> ty;
      scanf("%d%d%d%d", &sx, &tx, &sy, &ty);
      vector ans;
      find(T, sx, tx, sy , ty, 0, ans);
      std::sort(ans.begin(), ans.end(), [](point a, point b){return a.id < b.id;});
      // std::for_each(ans.begin(), ans.end(), [](auto x){std::cout << x.id << std::endl;});
      std::for_each(ans.begin(), ans.end(), [](auto x){printf("%d\n", x.id);});
      // std::cout << std::endl;
      printf("\n");
    }
}



Measured memory_bytes: 31380
#include<iostream>
using namespace std;
int main(){
  int total1,total2,a,b,c,d;
  cin >> a >> b >> c >> d;
  total1=a+b+c+d;
  cin >> a >> b >> c >> d;
  total2=a+b+c+d;
  if(total1>total2){
    cout << total1 << endl;
  }
  else{
    cout << total2 << endl;
  }
}

Measured memory_bytes: 1160
fun main(args: Array<String>) {
  val N = readLine()!!.toInt()
  val (T,A) = readLine()!!.split(" ").map{it.toDouble()}
  val H = readLine()!!.split(" ").map{it ->
    val ondo = T - (it.toDouble()*0.006)
    Math.abs(A - ondo)
  }
  println(H.indexOf(H.min()) + 1)
}

Measured memory_bytes: 37912
import sys
sys.setrecursionlimit(10**7)
from collections import deque

H,W=map(int,input().split())
dots=H*W
field=[]
for _ in range(H):
    tmp=input()
    dots-=tmp.count("#")
    field.append(tmp)

DX=[1,0,-1,0]
DY=[0,1,0,-1]
dist=[[-1]*W for _ in range(H)]
dist[0][0]=0
que=deque()
que.append([0,0])

while que:
    y,x=que.popleft()
    for dx,dy in zip(DX,DY):
        nx=x+dx
        ny=y+dy
        if nx<0 or nx>=W or ny<0 or ny>=H: continue
        if field[ny][nx]=="#": continue
        if dist[ny][nx]==-1:
            dist[ny][nx]=dist[y][x]+1
            que.append([ny,nx])

score=-1
goal=dist[H-1][W-1]
if goal!=-1:
    score=dots-goal-1
print(score)


Measured memory_bytes: 9340
import java.util.*;

class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        String N = sc.next();
        int d = N.length();
        int sum = 0;
        for (int i = 0; i < d; i++) {
            sum += Integer.parseInt(N.substring(i, i+1));
        }
      	if (sum % 9 == 0) {
        	System.out.println("Yes");
        } else {
          System.out.println("No");
        }

    }
}

Measured memory_bytes: 49984
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF int(1e9+1)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
#define MX (1<<19)
char s[MX];
int N,A,B,C,D;
bool ok(int b,int e){
    FT(b,e)if(s[k]==35&&s[k+1]==35)return 0;
    return 1;
}
bool spc(){
    if(!ok(A,C)||!ok(B,D))return 0;
    FT(B-1,D)if(s[k]^35&&s[k+1]^35&&s[k+2]^35)return 1;
    return 0;
}
int main(void){
    scanf("%d%d%d%d%d%s",&N,&A,&B,&C,&D,s),--A,--B,--C,--D;
    if(A<B&&C>D)return puts(spc()?"Yes":"No"),0;
    puts(!ok(A,C)||!ok(B,D)?"No":"Yes");
    return 0;
}


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

bool q (int x) { 
  if (x == 2 ) {
    return true;  
  }
  if (x % 2 == 0) {
    return false;  
  } 
  else {
    for (int i = 3; i < x/2; i++ ) {
      if (x%i == 0) {
        return false;  
      }  
    }  
    return true;
  }
}

int main () { 
  std::vector<int> q_number;
  for (int i = 2; i < 55555; i++) {
    if (q(i) == true) {
      if (i % 5  == 2 ) {
        q_number.push_back(i);
      }
    }  
  }
  int N;
  std::cin >> N;
  for (int i = 0; i < N; i++) {
    std::cout << q_number[i] << " "; 
  }
  std::cout << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
typedef long long ll;
using namespace std;

ll N,A,B,C;

#define MAX_N 200020
ll inv[MAX_N+10],fac[MAX_N+10],ifac[MAX_N+10];

void setComb(){
  inv[0]=1;inv[1]=1;fac[1]=1;ifac[1]=1;fac[0]=1;ifac[0]=1;
  for(int i=2;i<MAX_N;i++){
    inv[i]=(-MOD/i)*inv[MOD%i]%MOD;
    fac[i]=fac[i-1]*i%MOD;
    ifac[i]=ifac[i-1]*inv[i]%MOD;
  }
  return;
}

ll comb(ll n,ll k){
  if(n<k||n<0||k<0) return 0;
  else return ((fac[n]*ifac[k]%MOD*ifac[n-k]%MOD+MOD)%MOD);
}

ll hcomb(ll n,ll r){
  if(n==0&&r==0) return 1;
  else if(n<0||r<0) return 0;
  else return comb(n+r-1,r);
}


int main(){
  cin>>N>>A>>B>>C;

  setComb();

  int aa=A,bb=B;
  A=A*inv[100]%MOD;
  B=B*inv[100]%MOD;

  vector<ll> a(2*N,0),b(2*N,0),ten(2*N,0);
  a[0]=1;
  b[0]=1;
  ten[0]=1;
  ll hundred=100*inv[aa+bb]%MOD;
  for(int i=1;i<=2*N;i++){
      a[i]=a[i-1]*A%MOD;
      b[i]=b[i-1]*B%MOD;
      ten[i]=ten[i-1]*hundred%MOD;
  }

  ll ans=0;
  for(int i=N;i<=2*N-1;i++){
      ll res=comb(i-1,N-1);
      ll tmp1=a[N]*b[i-N]%MOD;
      ll tmp2=a[i-N]*b[N]%MOD;
      ll tmp=(tmp1+tmp2)%MOD;
      tmp=tmp*i%MOD;

      tmp=tmp*ten[i]%MOD;
      res=res*tmp%MOD;
      
      ans=(ans+res)%MOD;
  }

  ans=ans*inv[100-C]%MOD;
  ans=ans*100%MOD;

  cout<<(ans+MOD)%MOD<<endl;

  return 0;
}


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

struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

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

using intpair = pair<int, int>;

int H, W;
bool is_safe(int x, int y){
    return (0 <= x && x < W)&&(0 <= y && y < H);
}

template<class T> inline bool chmin(T &a, T b) {
    if (a > b) {a = b; return true;}
    return false;
}

int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
bool visited[50][50];
int dist[50][50];

signed main(){
    cin >> H >> W;
    vector<string> field(H);
    rep(i,H) cin >> field[i];
    rep(i,H)rep(j,W){
        dist[i][j]    = INT_MAX;
        visited[i][j] = field[i][j] == '#';
    }
    
    queue<intpair> q;
    q.push({0,0});
    dist[0][0] = 1;
    visited[0][0] = true;
    
    while(!q.empty()){
        auto p = q.front(); q.pop();
        int x = p.first, y = p.second;
        if(x == W-1 && y == H-1) break;
        
        rep(i,4){
            if(!is_safe(x+dx[i], y+dy[i])) continue;
            if(visited[y+dy[i]][x+dx[i]]) continue;
            chmin(dist[y+dy[i]][x+dx[i]], dist[y][x] + 1);
            q.push({x+dx[i], y+dy[i]});
            visited[y+dy[i]][x+dx[i]] = true;
        }
    }
    
    int whites = 0;
    rep(y,H)rep(x,W) if(field[y][x]=='.') whites++;
    
    if(dist[H-1][W-1] == INT_MAX){
        cout << -1 << endl;
    }else{
        cout << whites - dist[H-1][W-1] << endl;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int a[225816];
ll cnt[225816];

int main(void){
	int n,i;
	ll ans = 0ll,tmp;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a[i]; --a[i];
		++cnt[a[i]];
	}
	for(i=0; i<n; ++i){
		ans += cnt[i]*(cnt[i]-1)/2;
	}
	for(i=0; i<n; ++i){
		tmp = cnt[a[i]]*(cnt[a[i]]-1)/2;
		tmp -= (cnt[a[i]]-1)*(cnt[a[i]]-2)/2;
		cout << (ans-tmp) << endl;
	}
	return 0;
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n,i,j,ll,rr,m,ans=0;
  cin>>n;
  vector<int> l(n);
  for(i=0;i<n;i++) cin>>l.at(i);
  sort(l.begin(),l.end());
  for(i=0;i<n-2;i++){
    for(j=i+1;j<n-1;j++){
      ll=j;
      rr=n;
      while(rr-ll>1){
        m=(ll+rr)/2;
        if(l.at(m)<l.at(i)+l.at(j)) ll=m;
        else rr=m;
      }
      ans+=ll-j;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////

typedef struct _ufTree{ 
	typedef long idx_type;
	
	vector<idx_type> par;
	vector<idx_type> rank;

	//n要素で初期化
	void init(idx_type n){
		par.assign(n,0);
		rank.assign(n,0);	
		for(idx_type i=0;i<n;i++) par[i]=i;
	}
	
	//木の根を求める
	idx_type root(idx_type x){
		if(par[x]==x) return x;
		else return par[x]=root(par[x]);
	}
	
	//xとyが同じ集合に属するかを調べる
	bool same(idx_type x,idx_type y){
		return root(x)==root(y);
	}
	
	//xとyの属する集合を併合
	void unite(idx_type x,idx_type y){
		x=root(x);
		y=root(y);
		if(x==y) return;
		if(rank[x]<rank[y]) par[x]=y;
		else{
			par[y]=x;
			if(rank[x]==rank[y]) rank[x]++;
		}
	}
}ufTree;

int main(){
	int n,m;
	cin >> n >> m;
	ufTree uf;
	uf.init(n);

	rep(i,0,m){
		int x,y,z;
		cin >> x >> y >> z;
		x--; y--;
		uf.unite(x , y);
	}

	vector<bool> check(n);
	rep(i,0,n) check[uf.root(i)] = true;
	int ans = 0;
	rep(i,0,n) ans += check[i];

	cout << ans << endl;

	ret 0;
}

Measured memory_bytes: 1792
///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
using namespace std;
#define f first
#define s second
#define PB pop_back 
#define pb push_back
#define mp make_pair
#define int long long
#define y1 y_golabi
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll; 
typedef map<int , int> mii;
typedef pair<int , int> pii; 
typedef map<string , int> msi;
typedef pair<int , string> pis; 
typedef pair<int , pair<int , int> > piii;
const int MAXN = 3e2 + 10;
char ch[MAXN][MAXN];
int n , ans;
bool is_good(int ind , int n)
{
	for(int i = ind , ip = 0 ; ip < n ; i ++ , ip ++ , i %= n)
		for(int j = 0 , jp = ind ; j < n ; j ++ , jp ++ , jp %= n)
			if(ch[i][j] != ch[jp][ip])
				return false;
	return true;
}
int32_t main()
{
	cin >> n;
	for(int i = 0 ; i < n ; i ++)
		for(int j = 0 ; j < n ; j ++)
			cin >> ch[i][j];
	for(int i = 0 ; i < n ; i ++)
		ans += is_good(i , n) * n;
	return cout << ans << endl , 0;
}




Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<iostream>
#include<map>
#include<cstring>
#define INF 1e9+10
using namespace std;
set <int> paper;
int n,x;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&x);
        if(paper.count(x))
            paper.erase(x);
        else
            paper.insert(x);
    }
    printf("%lu",paper.size());
}


Measured memory_bytes: 7692
# editorialを参考に、再帰を使わず実装
N, len_A, len_B, len_C = map(int, input().split())
l = [int(input()) for i in range(N)]

ans = 10 ** 9
pattern = 4 ** N
A = [0] * pattern
B = [0] * pattern
C = [0] * pattern
cost = [0] * pattern
for ite in range(pattern):
    ite_2 = 0
    ite_2 += ite
    A[ite], B[ite], C[ite] = [], [], []
    for j in range(N):
        if ite_2 % 4 == 0:
            A[ite].append(l[j])
        elif ite_2 % 4 == 1:
            B[ite].append(l[j])
        elif ite_2 % 4 == 2:
            C[ite].append(l[j])
        ite_2 = ite_2 // 4
    if len(A[ite]) == 0 or len(B[ite]) == 0 or len(C[ite]) == 0:
        continue
    len_A_magic, len_B_magic, len_C_magic = 0, 0, 0
    for p in A[ite]:
        len_A_magic += p
    for q in B[ite]:
        len_B_magic += q
    for r in C[ite]:
        len_C_magic += r
    cost[ite] += (len(A[ite]) - 1) * 10+abs(len_A-len_A_magic)
    cost[ite] += (len(B[ite]) - 1) * 10+abs(len_B-len_B_magic)
    cost[ite] += (len(C[ite]) - 1) * 10+abs(len_C-len_C_magic)
    if ans > cost[ite]:
        ans = cost[ite]

print(ans)


Measured memory_bytes: 27492
n,m=map(int,input().split())
g=[[] for i in range(1+n)]
v=[0]*(1+n)
for i in range(m):
    a,b=map(int,input().split())
    g[a].append(b)
    g[b].append(a)
v[a]=v[b]=1

def dfs(p):
    path=[]
    while p:
        cur=p.pop()
        path.append(cur)
        v[cur]=1
        flg=True
        for i in g[cur]:
            if v[i]==0:
                p.append(i)
                flg=False
        if flg:
            return path

ans=dfs([a])[::-1]+dfs([b])
print(len(ans))
print(*ans)

Measured memory_bytes: 66244
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end());
#define MIN(vec) *std::min_element(vec.begin(), vec.end());
#define MAXI(vec)                                                              \
  std::distance(vec.begin(), *std::max_element(vec.begin(), vec.end()));
#define MINI(vec)                                                              \
  std::distance(vec.begin(), *std::min_element(vec.begin(), vec.end()));
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define MATMUL(a, b, c)                                                        \
  REP(i, a.size())                                                             \
  REP(j, b[0].size()) REP(k, a[0].size()) c[i][j] += a[i][k] * b[k][j];
#define CLA2(a) REP(i, a.size()) REP(j, a[0].size()) a[i][j] = 0;
#define REV(T) greater<T>()

ll pow_(ll a, ll n) {
  ll x = 1;
  while (n > 0) {
    if (n & 1)
      x = (x * a) % MOD;
    a = (a * a) % MOD;
    n >>= 1;
  }
  return x;
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

ll factorial(int n) {
  ll ans = 1;
  for (int i = 2; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll P(int n, int m) {
  ll ans = 1;
  for (int i = m + 1; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll power(int n, int m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = power(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * power(n, m - 1)) % MOD;
  }
}
ll C(int n, int m) {
  return (P(n, n - m) * power(factorial(m), MOD - 2)) % MOD;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ll N, K, ANS = 0;
  vector<ll> D;
  cin >> N >> K;
  REP(i, K) {
    ll po;
    cin >> po;
    D.push_back(po);
  }
  for (ll i = N; i <= 10 * N; i++) {
    bool ok = true;
    for (ll j = 0; j <= (ll)log10(i); j++) {
      ll po = (i / (ll)pow(10, j)) % 10;
      REP(p, K) {
        if (po == D[p]) {
          p = 100;
          j = 100;
          ok = false;
        }
      }
    }
    if (ok) {
      ANS = i;
      break;
    }
  }
  cout << ANS << endl;

  return 0;
}


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

int N;

int main()
{
	scanf("%d", &N);
	int res = 0;
	for(N--; N; N--)
	{
		for(int d=1; d*d<=N; d++)
		{
			if (N%d == 0)
			{
				res++;
				if (d*d != N) res++;
			}
		}
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define ll long long
#define pi 3.14159265358979
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
const int INF = 1000100100;
 
 
int main(){
    ll n,k,a[2000005],cnt=0,ans=0;
    string s;
    cin>>s;
    k=s.size();
    rep(i,k){
        a[i]=0;
    }
    rep(i,k){
        if(s[i]=='R'){
            cnt++;
        }else{
            a[i-1]+=(cnt+1)/2;
            a[i]+=cnt/2;
            cnt=0;
        }
    }
    for(int i=k-1;i>=0;i--){
        if(s[i]=='L'){
            cnt++;
        }else{
            a[i+1]+=(cnt+1)/2;
            a[i]+=cnt/2;
            cnt=0;
        }
    }
    rep(i,k){
        cout<<a[i];
        if(i<k-1) cout<<" ";
    }
}

Measured memory_bytes: 4560
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    x,y,z,K=map(int,input().split())
    A=sorted(map(int,input().split()),reverse=1)
    B=sorted(map(int,input().split()),reverse=1)
    C=sorted(map(int,input().split()),reverse=1)

    # 1<=i<=x,1<=j<=y,1<=k<=z のうち、ijk<=Kを全て取得する
    from itertools import product
    ind=[]
    for i in range(1,x+1):
        if(i>K): break
        for j in range(1,y+1):
            if(i*j>K): break
            for k in range(1,z+1):
                if(i*j*k>K): break
                ind.append((i-1,j-1,k-1))

    S=[]
    for i,j,k in ind:
        S.append(A[i]+B[j]+C[k])
    S.sort(reverse=1)
    for i in range(K):
        print(S[i])

resolve()

Measured memory_bytes: 61748
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

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

template <class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_mset;

#define FOR(i,a,b) for(int i = a; i < b; i++)
#define F0R(i,a) for(int i = 0; i < a; i++)
#define F0Rd(i,a) for (int i = a - 1; i >=0 ; i--)
#define FORd(i,a,b) for (int i = b - 1; i >= a; i--)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) int((x).size())
#define newl '\n'

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define print(x) cout << x << newl;
#define finish(x) return cout << x << "\n", 0;
#define bug(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _ << " " << 

const int MXN = 2e5 + 5;
//const int MXN = 1e6 + 5;
const ll MOD = 998244353;
const ll INF = 1e9 + 7;



string s;


int main(){ FAST
	//ifstream cin("/Users/konwoo/input.txt");
	//ofstream cout("/Users/konwoo/output.txt");

    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]){
        cout << "Yes" << newl;
    }
    else{
        cout << "No" << newl;
    }








	return 0;
}


Measured memory_bytes: 256
/*input
6
4 2 9 7 1 5
*/
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<ld,ld>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll INF64=4e18;
const int INF=1e6+1;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll sub(ll a,ll b){
    ll x=a-b;
    while(x<0) x+=MOD;
    while(x>MOD) x-=MOD;
    return x;
}
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=(res*a);
        if(res>1e10) return 1e11;
        a=(a*a);
        b>>=1;
    }
    return res;
}
const ll maxn=3005;
const ll maxlg=__lg(maxn)+2;
ll dp[maxn][maxn];
int arr[maxn];
int main(){
    int n;
    cin>>n;
    ll sum=0;
    REP(i,n){
        cin>>arr[i];
        dp[i][i]=arr[i];
        sum+=arr[i];
    }
    for(int i=n-1;i>=0;i--){
        for(int j=i+1;j<n;j++){
            dp[i][j]=max(arr[j]-dp[i][j-1],arr[i]-dp[i+1][j]);
        }
    }
    cout<<dp[0][n-1];
}

Measured memory_bytes: 70016
let x = read_int ()

let rec f a =
  let a' = a * a * a * a * a in

  let rec g b =
    if b = 119 then b
    else
      let b' = b * b * b * b * b in
      if a' - b' = x then b
      else g (b + 1) in

  let b = g ~-119 in
  if b < 119 then a, b
  else f (a + 1)

let () =
  let a, b = f ~-118 in
  Printf.printf "%d %d\n" a b


Measured memory_bytes: 3672
//in the name of allah                
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int t[N];

int main(){
        ios_base::sync_with_stdio(false);cin.tie(NULL);
        int n , c , k;cin >> n >> c >> k;
        for(int i=0 ; i<n ; i++)
                cin >> t[i];        
        sort(t , t+n);
        int mx=0 , ans=0 , last=0;
        for(int i=0 ; i<n; i++){
                if(last == c)
                        mx = 0;
                if(t[i] > mx){
                        mx = t[i] + k;
                        last = 0;
                        ans ++;
                }
                last ++;
        }
        cout << ans << "\n";
        return 0; 
}

Measured memory_bytes: 640
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

input = raw_input().split(" ")
N = int(input[0])
T = int(input[1])

c = []
t = []


for i in range(0, N):
    ct = raw_input().split(" ")
    c.append(int(ct[0]))
    t.append(int(ct[1]))

for i in range(0, len(c)):
    mincost = min(c)
    minindex = c.index(mincost)

    if t[minindex] <= T:
        print mincost
        sys.exit()
    else:
        c.pop(minindex)
        t.pop(minindex)
        if len(c) == 0:
            print 'TLE'
        continue



Measured memory_bytes: 2568