akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn=4010,INF=(int)1e9;
vector<int> G[maxn];
char s[maxn];
int sz[maxn],h[maxn],l[maxn];

int ans=INF,n,res;

void dfs(int u,int fa,int dep){
    sz[u]=l[u]=h[u]=0;
    for(auto v: G[u])if(v!=fa){
        dfs(v,u,dep+1);
        sz[u]+=sz[v];
        int tmpl,tmph;
        tmph=h[u]+h[v]+sz[v];
        if(l[u]<=l[v]+sz[v]){
            if(h[u]>=l[v]+sz[v])tmpl=tmph&1;
            else tmpl=l[v]+sz[v]-h[u];
        }
        else {
            if(l[u]<=h[v]+sz[v])tmpl=tmph&1;
            else tmpl=-(h[v]+sz[v]-l[u]);
        }
        l[u]=tmpl;h[u]=tmph;
    }
    if(s[u]=='1'){
        ++sz[u];
        res+=dep;
    }
}
int main(){
    scanf("%d%s",&n,s+1);
    for(int i=1,u,v;i<n;++i){
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    for(int i=1;i<=n;++i){
        res=0;dfs(i,0,0);
        if(l[i]==0)ans=min(ans,res/2);
    }
    if(ans==INF)puts("-1");
    else printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 640
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Map<Integer, Integer> count = new HashMap<>();
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            int a=in.nextInt();
            if (count.containsKey(a)) {
                count.replace(a, count.get(a) + 1);
            } else {
                count.put(a, 1);
            }
        }
        int res = 0;
        for (Map.Entry<Integer, Integer> kv : count.entrySet()) {
            if (kv.getKey() <= kv.getValue()) {
                res += kv.getValue() - kv.getKey();
            } else {
                res += kv.getValue();
            }
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 61520
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;
using P = pair<int,int>;
typedef long long ll;


#define rep(i,n) for (int i=0; i<(n); i++)
//const int INF =1001001001;
const ll BIG = 1e9+7;
const double PI = 3.141592653589793;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> H(n);
    rep(i,n) cin >> H[i];
    sort(H.rbegin(), H.rend());
    ll ans = 0;
    rep(i,n) {
        if(k>0){
            //ans++;
            k--;
            continue;
        }
        ans += H[i];
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  while (true) {
    int n; cin >> n;
    if (n == 0) return;
    vi32 a(n); cin >> a;
    int ans = 1e9;
    rep(i, n) rep(j, n) if (i != j) amin(ans, abs(a[i] - a[j]));
    cout << ans << '\n';
  }
}



Measured memory_bytes: 3148
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		int a,b;
		Scanner scan = new Scanner(System.in);

	    a= Integer.parseInt(scan.next());
	    
	    b= Integer.parseInt(scan.next());
	   
	    if(a<b)
	    {
	    	System.out.println("a < b");
	    }
	    else {
	    	if(a==b) {
	    		System.out.println("a == b");
	    	}
	    	else {
	    		System.out.println("a > b");
	    	}
	    }
	}

}

Measured memory_bytes: 26032
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll a[10010];
int main(){
	int n;
	scanf("%d",&n);
	rep(x,1,1000)if(x*x<=n)rep(y,1,1000)if(x*x+y*y+x*y<=n){
		for(ll z=1;x*x+y*y+z*z+x*y+y*z+z*x<=n;z++)a[x*x+y*y+z*z+x*y+y*z+z*x]++;
	}
	rep(i,1,n+1)printf("%lld\n",a[i]);
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

class UnionFind {
    // 経路圧縮によるrank更新はなし
    public:
        vector<int> rank, par, size; // rank[x]: xの高さ, par[x]: xの親のノード, size[x]: x

    // 初期化
    UnionFind() {}
    UnionFind(int size){
        rank.resize(size, 0);
        par.resize(size, 0);
        rep(i, size) makeSet(i);
    }

    void makeSet(int x){
        par[x] = x;
        rank[x] = 1;
    }

    // 根を再帰的に求める(経路圧縮)
    int findRoot(int x){
        if(x != par[x]){
            par[x] = findRoot(par[x]);
        }
        return par[x];
    }

    // 根が同じかどうか
    bool same(int x, int y){
        return findRoot(x) == findRoot(y);
    }

    //  xとyの木を併合
    bool unite(int x, int y){
        x = findRoot(x);
        y = findRoot(y);
        if(x==y) return false;
        if(rank[x]<rank[y]) swap(x, y);

        // 単純に繋げない場合
        // if(rank[x]==rank[y]) rank[x]++;

        // 単純に一列につなげる場合
        rank[x] += rank[y];


        par[y] = x;
        return true;
    }

    int getRank(int x){
        return rank[findRoot(x)];
    }
};

vector<int> abf[100500], cdf[100500];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind ab = UnionFind(n);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        ab.unite(a, b);
        abf[a].push_back(b);
        abf[b].push_back(a);
    }
    rep(i, k){
        int c, d;
        cin >> c >> d;
        c--; d--;
        cdf[c].push_back(d);
        cdf[d].push_back(c);
    }
    rep(i, n){
        int tmp = ab.getRank(i);
        tmp = tmp - abf[i].size() - 1;
        rep(j, cdf[i].size()){
            if (ab.same(i, cdf[i][j])){
                tmp--;
            }
        }
        cout << max(0, tmp) << ' ';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 12664
#include<bits/stdc++.h>
#define lli long long int
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define ulli unsigned long long int
#pragma GCC target ("sse4.2")
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define time cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";

int main()
{

    fast;

    lli n,d;
    lli cnt=0;
    cin>>n>>d;
    for(lli i=0;i<n;i++)
    {
        lli x,y;
        cin>>x>>y;
        if(d>=sqrt(x*x+y*y))
            cnt++;
    }
    cout<<cnt;





    return 0;


}


Measured memory_bytes: 3684
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num1 = sc.nextInt();
		int num2 = sc.nextInt();
		int num3 = sc.nextInt();
		System.out.print(num3 + " ");
		System.out.print(num1 + " ");
		System.out.print(num2);

	}

}


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

int main(){
  int num=1000;
  string s;
  cin>>s;
  
  for(int i=0;i<s.size()-2;i++){
    int ans=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
    num=min(num,abs(753-ans));
  }
  cout<<num<<endl;
}
    
    


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

typedef long long ll;

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

using namespace std;

int main(){
    int X,Y,A,B,C;
    ll score = 0;
    cin >> X >> Y >> A >> B >> C;
    vector<int> red(A);
    vector<int> gren(B);
    priority_queue<int> none;
    for( int i = 0; i < A ;i++) cin >> red[i];
    for( int i = 0; i < B ;i++) cin >> gren[i];
    for( int i = 0; i < C ;i++){
        int temp ;
        cin >> temp;
        none.push(temp);
    }
    sort(red.begin(),red.end(),greater<>());
    sort(gren.begin(),gren.end(),greater<>());
    for(int i = 0; i < X ; i++){
        none.push(red[i]);
    }
    for(int i = 0 ; i < Y ; i++){
        none.push(gren[i]);
    }
    for(int i = 0 ; i < X + Y ; i++){
        score += none.top();
        none.pop();
    }
    cout << score << endl;
    return 0;
}

Measured memory_bytes: 3188
<?php

fscanf(STDIN, "%d", $N);

$M = 0;
$A = 0;
$R = 0;
$C = 0;
$H = 0;

for ( $i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%s", $s);
    $S = str_split($s);

    if($S[0] == 'M'){
        $M += 1;
    }else if($S[0] == 'A'){
        $A += 1;
    }else if($S[0] == 'R'){
        $R += 1;
    }else if($S[0] == 'C'){
        $C += 1;
    }else if($S[0] == 'H'){
        $H += 1;
    }
}

$count = 0;

if($M > 0){
    $count += 1;
}else{
    //$M = 1;
}
if($A > 0){
    $count += 1;
}else{
    //$A = 1;
}
if($R > 0){
    $count += 1;
}else{
    //$R = 1;
}
if($C > 0){
    $count += 1;
}else{
    //$C = 1;
}
if($H > 0){
    $count += 1;
}else{
    //$H = 1;
}
/*
if($count < 3){
    $num = 0;
}else if($count == 3){
    $num = 1;
}else if($count == 4){
    $num = 4;
}else if($count == 5){
    $num = 10;
}

if($count == 3){
    $NUM = $num * $M * $A * $R * $C * $H;
}else if($count == 4){
    $NUM = $num
}else if($count == 5){
    $NUM = 
}
*/
$NUM = $M*$A*$R + $M*$A*$C + $M*$A*$H + $M*$R*$C + $M*$R*$H
       +$M*$C*$H + $A*$R*$C + $A*$R*$H + $A*$C*$H + $R*$C*$H;

out::println($NUM);

class out {
    public static function println($str = "") {
        echo $str . PHP_EOL;
    }
}



?>


Measured memory_bytes: 3828
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

void solve()
{
	int n,x,t;
	cin>>n>>x>>t;
	int tako=0;
	int time=0;
	while(tako<n){
		tako+=x;
		time+=t;
	}
	cout<<time<<endl;

}

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


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

using namespace std;

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

    vector<double> v(N);

    for (int i = 0; i < N; ++i) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());

    double val = v[0];
    for (int i = 1; i < N; ++i) {
        val = (val + v[i]) / 2;
    }

    cout << val << endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
int main()
{
    FASTINOUT;
    int x;
    ll ans=0;
    cin>>x;
    int a[x+1],b[x+1],c[x];
    for (int i=1;i<=x;i++)
        cin>>a[i];
    for (int i=1;i<=x;i++)
        cin>>b[i];
    for (int i=1;i<x;i++)
        cin>>c[i];
    for (int i=1;i<x;i++){
        if (a[i]+1!=a[i+1])
            ans+=b[a[i]];
        
        else
            ans+=(b[a[i]]+c[a[i]]);
    }
    cout<<ans+b[a[x]]<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
L = list(map(int,input().split()))
A = []
B = []
Q = [0,0]
R = [0,0]
S = [0,0]
T = [0,0]
J = 1
K = 1
for i in range(n):
  if (i%2 == 0):
    A.append(L[i])
  else:
    B.append(L[i])
A.sort()
B.sort()
A.append(-1)
B.append(-1)
for j in range(1,len(A)):
  if (A[j-1] == A[j]):
    J += 1
  else:
    if (J > Q[0]):
      Q[1] = Q[0]
      del Q[0]
      Q.insert(0,J)
      R[1] = R[0]
      del R[0]
      R.insert(0,A[j-1])
      j += J
      J = 1
    elif (Q[0] >= J > Q[1]):
      del Q[1]
      Q.append(J)
      del R[1]
      R.append(A[j-1])
      j += J
      J = 1
    else:
      j += J
      J = 1
for k in range(1,len(B)):
  if (B[k-1] == B[k]):
    K += 1
  else:
    if (K > S[0]):
      S[1] = S[0]
      del S[0]
      S.insert(0,K)
      T[1] = T[0]
      del T[0]
      T.insert(0,B[k-1])
      k += K
      K = 1
    elif (S[0] >= K > S[1]):
      del S[1]
      S.append(K)
      del T[1]
      T.append(B[k-1])
      k += K
      K = 1
    else:
      k += K
      K = 1
if (R[0] != T[0]):
  print(n-Q[0]-S[0])
else:
  print(n-max(S[0]+Q[1],S[1]+Q[0]))

Measured memory_bytes: 13992
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define first F
#define second S

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

int main(void) {
  int i,j;
  string s;
  cin>>s;
  int n;
  cin>>n;
  int ans=0;
  rep(i,n){
    string str;
    cin>>str;
    int len=str.size();
    if(len<s.size())continue;
    str=str+str;
    rep(j,len)
      if(str.substr(j,s.size())==s){
        ans++;
        break;
      }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3148
x, y = map(int, input().split())
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]
if x in a:
    if y in a:
        print('Yes')
    else:
        print('No')
elif x in b:
    if y in b:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 3064
#include <stdio.h>

#define N 10000
#define H 100
#define W 100

void reverse(int n, int *aa) {
	int i, j;

	for (i = 0, j = n - 1; i < j; i++, j--) {
		int tmp;

		tmp = aa[i];
		aa[i] = aa[j];
		aa[j] = tmp;
	}
}

int main() {
	static int aa[10000], bb[10000], cc[100][100];
	int h, w, n, i, j, k;

	scanf("%d%d%d", &h, &w, &n);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	k = 0;
	for (i = 0; i < n; i++)
		for (j = i; j < i + aa[i]; j++)
			bb[k++] = i + 1;
	k = 0;
	for (i = 0; i < h; i++)
		for (j = 0; j < w; j++)
			cc[i][j] = bb[k++];
	for (i = 1; i < h; i += 2)
		reverse(w, cc[i]);
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++)
			printf("%d ", cc[i][j]);
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
#ifdef ONLINE_JUDGE
#define D(...)
#else
#define D(...)cerr<<__LINE__<<":"<<"["<<#__VA_ARGS__<<"]->",P(__VA_ARGS__)
#endif
void P(){cerr<<endl;} 
template<typename H,typename...T>void P(H h,T...t){cerr<<h<<" ";P(t...);}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    string s;cin>>s;
    int ans=100000;
    for(int i=0;i+2<int(s.size());++i){
        ans=min(ans,abs(stoi(s.substr(i,3))-753));
    }
    cout<<ans;

}

Measured memory_bytes: 3676
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(int argc, char **argv)
{
    int H, N;
    cin >> H >> N;
    int A[N], B[N];
    REP(i, N) cin >> A[i] >> B[i];

    ll dp[H + 1];
    dp[0] = 0;
    FOR(i, 1, H + 1) {
        ll m = 1000000000;
        REP(j, N) {
            ll r = i - A[j];
            if (r < 0) r = 0;
            ll c = dp[r] + B[j];
            if (m > c) m = c;
        }
        dp[i] = m;
    }
    cout << dp[H] << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define debug(x) cerr << "\n" \
                      << #x << ": " << x << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define int long long
#define print(x) cout << (x) << endl
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int INF = (1LL << 30);
const ll MOD = 1000000007;



int H, W, K;

// W本
// 1 <= H <= 100
// 1 <= W <= 8
// 1 <= K <= W


// dp[i][j]: i列目を通過した直後，左からj番目の縦棒にいる場合の数
ll dp[102][11] = {};

void solve()
{
  for (int i = 0; i < H; ++i)
  {
    for (int j = 0; j < W; ++j)
    {
      // 2^(W-1) 個探索
      // 2進で1が連続しないようにする
      for (int k = 0; k < (1 << (W - 1)); ++k)
      {
        bool flag = true;
        //端点を共有しない制約
        for (int l = 0; l < W - 2; ++l)
        {
          if (((k >> l) & 1) && ((k >> (l + 1)) & 1))
          {
            flag = false;
          }
        }
        // 全探索
        // 全ての横棒の置き方
        if (flag)
        {
          // 左方向に行ける
          if (j >= 1 && ((k >> (j - 1)) & 1))
          {
            dp[i + 1][j - 1] += dp[i][j];
            dp[i + 1][j - 1] %= MOD;
          }
          // 右方向に行ける
          else if (j <= (W - 2) && ((k >> j) & 1))
          {
            dp[i + 1][j + 1] += dp[i][j];
            dp[i + 1][j + 1] %= MOD;
          }
          // 下に行く
          else
          {
            dp[i + 1][j] += dp[i][j];
            dp[i + 1][j] %= MOD;
          }
        }
      }
    }
  }
}

signed main()
{
  cin >> H >> W >> K;
  dp[0][0] = 1; // 最初
  solve();
  print(dp[H][K-1]);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 int main(){
   int A,B,C;
   cin>>A>>B>>C;
   if(B/A>C){
   cout<<C<<endl;
   return 0;
   }
   else{
   cout<<B/A<<endl;
   return 0;
   }
   }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dbg() cerr << 
#define show(x) (#x) << ": " << (x) <<

using namespace std;

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

  int n; cin >> n;
  vector<pair<int, int>> v(n);
  int max_lft = 0, min_rgt = (int)1e9 + 10, max_len = 0;
  for (auto &p : v) {
    cin >> p.first >> p.second;
    max_lft = max(max_lft, p.first);
    min_rgt = min(min_rgt, p.second);
    max_len = max(max_len, p.second - p.first + 1);
  }
  for (auto &p : v) {
    int l, r; tie(l, r) = p;
    p.first = r - max_lft + 1;
    p.second = min_rgt - l + 1;
  }
  sort(v.begin(), v.end(), [](pair<int, int> a, pair<int, int> b) {
    if (a.first != b.first) return a < b;
    return a > b;
  });
  int ans = max_len + max(0, min_rgt - max_lft + 1);
  int minn = v[0].second;
  for (int i = 1; i < n; ++i) {
    ans = max(ans, minn + v[i].first); 
    minn = min(minn, v[i].second);
  }
  cout << ans << endl;


  cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){fastio
    ll a,b,c,x,y;cin>>a>>b>>c>>x>>y;
    if(a+b<=2*c){
        cout<<a*x+b*y<<endl;
    }else{
        ll ans=0;
        if(x<=y){
            ans+=x*c*2;
            if(b<=2*c){
                ans+=b*(y-x);
            }else{
                ans+=c*2*(y-x);
            }
        }else{
            ans+=y*c*2;
            if(a<=2*c){
                ans+=a*(x-y);
            }else{
                ans+=c*2*(x-y);
            }
        }
        cout<<ans<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 256
def main():
    k = int(input())
    s = input()
    n = len(s)

    def cmb1(n, r, mod):
        if ( r<0 or r>n ):
            return 0
        r = min(r, n-r)
        return g1[n] * g2[r] * g2[n-r] % mod

    mod = 10**9+7
    N = 2*10**6
    fac = [1]*(N+1)
    finv = [1]*(N+1)
    for i in range(N):
        fac[i+1] = fac[i] * (i+1) % mod
    finv[-1] = pow(fac[-1], mod-2, mod)
    for i in reversed(range(N)):
        finv[i] = finv[i+1] * (i+1) % mod

    def cmb1(n, r, mod):
        if r <0 or r > n:
            return 0
        r = min(r, n-r)
        return fac[n] * finv[r] * finv[n-r] % mod

    def power(a, n, mod):
        bi=str(format(n,"b")) #2進数
        res=1
        for i in range(len(bi)):
            res=(res*res) %mod
            if bi[i]=="1":
                res=(res*a) %mod
        return res

    ans = 0
    for i in range(k+1):
        temp = power(25, i, mod)
        temp *= cmb1(i+n-1, n-1, mod)
        temp %= mod
        temp *= power(26, k-i, mod)
        temp %= mod
        ans += temp
    print(ans%mod)

if __name__ == '__main__':
    main()


Measured memory_bytes: 106940
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod  1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int N, ans = 0;
  cin >> N;
  vector<int> dp(N + 1, INT_MAX / 100);

  dp[0] = 0;
  for(int i = 1; i <= N; i++){
    for(int j = 1; j <= i; j *= 6)dp[i] = min(dp[i], dp[i - j] + 1);
    for(int j = 1; j <= i; j *= 9)dp[i] = min(dp[i], dp[i - j] + 1);
  }
  cout << dp[N] << endl;
  return 0;
}


Measured memory_bytes: 640
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		HashMap<String,Integer> t = new HashMap<>();
		String str = "";
		for(int i = 0;i < n;i++){
			str = saori.nextHayami();
			t.put(str, t.getOrDefault(str, 0)+1);
		}
		int m = saori.saori_hayami();
		for(int i = 0;i < m;i++){
			str = saori.nextHayami();
			t.put(str, t.getOrDefault(str, 0)-1);
		}
		int ans = 0;
		for(int num : t.values())ans = Math.max(ans, num);
		System.out.println(ans);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21076
use proconio::input;
use proconio::marker::{Chars, Usize1};

fn main()
{
    input! {
    _n:usize,
    k:Usize1,
    mut s:Chars,
    }

    let ans = s.into_iter().enumerate().map(|(i, c)| {
        if i == k {
            c.to_ascii_lowercase()
        } else {
            c
        }
    }).collect::<String>();
    println!("{}", ans);
}

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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
  
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const ll INF = 10000000000;
ll N, M, L, Q;
ll fuel[305][305];
ll dist[305][305];
ll s[105000], t[105000];
ll A[100000], B[100000], C[100000];

int main() {
    cin >> N >> M >> L;
    for(int i = 1; i <= M; i++) cin >> A[i] >> B[i] >> C[i];
    cin >> Q;
    for(int i = 1; i <= Q; i++) cin >> s[i] >> t[i];

    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            fuel[i][j] = INF;
            dist[i][j] = INF;
        }
        fuel[i][i] = 0;
        dist[i][i] = 0;
    }
    for(int i = 1; i <= M; i++) {
        chmin(fuel[A[i]][B[i]], C[i]);
        chmin(fuel[B[i]][A[i]], C[i]);
    }
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            for(int k = 1; k <= N; k++) {
                chmin(fuel[j][k], fuel[j][i] + fuel[i][k]);
            }
        }
    }
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            if(i == j) continue;
            if(fuel[i][j] <= L) chmin(dist[i][j], 1LL);
        }
    }
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            for(int k = 1; k <= N; k++) {
                chmin(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
    for(int i = 1; i <= Q; i++) {
        if(dist[t[i]][s[i]] < INF) cout << dist[t[i]][s[i]] - 1 <<endl;
        else cout << -1 << endl;
    }
    return 0;
}

        

Measured memory_bytes: 4864
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
ps = []
table = [[0] * (2 * K) for _ in range(2 * K)]
res = 0
ws = 0
for i in range(N):
  u, v, t = input().split()
  u = int(u)
  v = int(v)
  ps.append((u % (2 * K), v % (2 * K), t))
  table[u % (2 * K)][v % (2 * K)] += (-1) ** int(t == "W")
  table[(u + K) % (2 * K)][(v + K) % (2 * K)] += (-1) ** int(t == "W")
  ws += (t == "W")
#print(table)
cs = [[0] * (2 * K + 1) for _ in range(2 * K)]
for i in range(2 * K):
  for j in range(2 * K): cs[i][j + 1] = cs[i][j] + table[i][j]

for i in range(2 * K):
  t = 0
  tres = 0
  for j in range(K): t += cs[j][min(2 * K, i + K)] + cs[j][max(0, i - K)] - cs[j][i] 
  tres = max(tres, t + ws)
  for j in range(2 * K):
    t -= cs[j][min(2 * K, i + K)] + cs[j][max(0, i - K)] - cs[j][i]
    t += cs[(j + K) % (2 * K)][min(2 * K, i + K)] + cs[(j + K) % (2 * K)][max(0, i - K)] - cs[(j + K) % (2 * K)][i]
    tres = max(tres, t + ws)
    #print(tres, t, i, j + 1, j + K)
  res = max(res, tres)
print(res)

Measured memory_bytes: 125276
-- parse "1X3+1X3=X46" === ["1X3" , "1X3" , "X46"]
parse :: String -> [String]
parse xs = case break (== '+') xs of
    (y,ys) -> case break (== '=') (tail ys) of
        (z,zs) -> [y,z,tail zs]

split_impl :: String -> String -> String -> [String]
split_impl _ xs [] = [xs]
split_impl ds xs ys
    | ds == take (length ds) ys = xs : split_impl ds [] (drop (length ds) ys) 
    | otherwise = split_impl ds (xs ++ [head ys]) (tail ys)

split :: String -> String -> [String]
split ds xs = split_impl ds [] xs

join' :: String -> [String] -> String
join' ds = foldr1 ((++) . (++ ds))

replace :: String -> String -> String -> String
replace old new = join' new . split old

toInt :: Int -> String -> Integer
toInt n = read . replace "X" (show n)

check :: String -> Bool
check xs = length xs >= 2 && head xs == 'X'

isOK :: Int -> [String] -> Maybe Int
isOK 0 xs = if any check xs then Nothing else let [x,y,z] = map (toInt 0) xs in if x + y == z then Just 0 else Nothing
isOK n xs = let [x,y,z] = map (toInt n) xs in if x + y == z then Just n else Nothing

solve :: String -> IO ()
solve xs = putStrLn $ maybe "NA" show $ foldr merge Nothing $ map (flip isOK (parse xs)) [0..9]
    where
        merge :: Maybe a -> Maybe a -> Maybe a
        merge Nothing x = x
        merge x _ = x

main :: IO ()
main = getContents
    >>= mapM_ solve . lines

Measured memory_bytes: 4336
#include<stdio.h>
#include<algorithm>
#include<cmath>
using namespace std;
struct point{
    double x, y, z;
    point(){}
    point(double x_,double y_, double z_ = 1.0){
        x=x_,y=y_,z=z_;
    }
    point Cross(const point &p){
        return point(y*p.z-z*p.y,z*p.x-x*p.z,x*p.y-y*p.x);
    }
    point operator +(const point &p)const{
        return point(x+p.x,y+p.y);
    }
    point operator -(const point &p)const{
        return point(x-p.x,y-p.y);
    }
    point To2D(){
        return point(x/z,y/z);
    }
    point operator *(const double &k)const{
        return point(k*x,k*y);
    }
    point Rot(){
        return point(-y,x);
    }
    double SZ(){
        return sqrt(x*x+y*y);
    }
};
double ccw(point a, point b, point c){
    return (b.x-a.x)*(c.y-a.y) - (b.y-a.y)*(c.x-a.x);
}
double Area(point a, point b, point c){
    double t = a.x*b.y-a.y*b.x+b.x*c.y-b.y*c.x+c.x*a.y-c.y*a.x;
    if(t<0)t=-t;
    return t*0.5;
}
void Input(point &p){
    scanf("%lf%lf",&p.x,&p.y);
}
point Seg(point a, point b){
    return point(b.y-a.y,a.x-b.x,a.y*b.x-a.x*b.y);
}
point Move(point a, point b, double d){
    point tp = (b-a).Rot();
    tp = tp * (1.0/ tp.SZ()) * d;
    return Seg(a+tp,b+tp);
}
point Inter(point a, point b){
    point tp = (a.Cross(b)).To2D();
    return tp;
}
bool Pos(double r, point A, point B, point C){
    point t1 = Move(A,B,r), t2 = Move(B,C,r), t3 = Move(C,A,r);
    point P1 = Inter(t1,t2),P2 = Inter(t2,t3),P3=Inter(t3,t1);
    if((P1-P2).SZ()>=r*2)return true;
    if((P2-P3).SZ()>=r*2)return true;
    if((P1-P3).SZ()>=r*2)return true;
    return false;
}
int main(){
    point P1, P2, P3;
    Input(P1);
    Input(P2);
    Input(P3);
    if(ccw(P1,P2,P3)<0)swap(P2,P3);
    double ee = Area(P1,P2,P3) / ((P1-P2).SZ() + (P1-P3).SZ() + (P2-P3).SZ()) * 2, bb = 0.0, mid;
    for(int TT=0;TT<50;TT++){
        mid = (bb+ee)*0.5;
        if(!Pos(mid,P1,P2,P3))ee=mid;
        else bb = mid;
    }
    printf("%.11f\n",(bb+ee)*0.5);
}

Measured memory_bytes: 128
import math

A, B, H, M = list(map(int, input().split()))


zisin = H*30 + (M/60)*30
hunsin = float(M*6)
sa = abs(zisin-hunsin)
sa = min(sa, 360-sa)
sa_pi = sa/180*math.pi

C2 = A**2 + B**2 - 2*A*B*math.cos(sa_pi)
C = math.sqrt(C2)

print(C)

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

using namespace std;

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;


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

  int n; ll y; scanf("%d %lld", &n, &y);

  int max1 = min(n, int(y/10000+1));
  int max2 = min(n, int(y/5000+1));

  for(int i=0;i<=max1;i++){
    for(int j=0;j<=max2;j++){
      if(y == 10000*i+5000*j+1000*(n-i-j)){
        if(n-i-j >= 0){
        cout << i << ' ' << j << ' ' << n-i-j;
        return 0;
        }
      }
    }
  }

  cout << "-1 -1 -1";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
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);
    int A, B;
    cin >> A >> B;
    cout << (A ^ B ^ 1 ^ 2 ^ 3) << endl;

    return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());

		int n=0;

		if(a == b && b == c) {
			n = 1;
		}else if(a == b || b == c || c == a) {
			n = 2;
		}else {
			n = 3;
		}

		System.out.println(n);

	}

}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S;
int nex[101010][2];
int F[101010];
int tmp[3];
ll dp[101010];
ll mo=1000000007;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	N=S.size();
	FOR(i,N-1) if(S[i]==S[i+1]) break;
	if(i==N-1) return _P("1\n");
	
	FOR(i,N) {
		S[i]-='a'-1;
		F[i+1]=(F[i]+S[i])%3;
	}
	nex[N][0]=nex[N][1]=N+1;
	tmp[0]=tmp[1]=tmp[2]=N+1;
	int pn=N;
	for(i=N-1;i>=0;i--) {
		if(i<N-1 && S[i]==S[i+1]) {
			while(pn>i) tmp[F[pn]]=pn, pn--;
		}
		if(S[i]==1) {
			nex[i][0]=i+1;
			nex[i][1]=tmp[(F[i]+2)%3];
		}
		else {
			nex[i][1]=i+1;
			nex[i][0]=tmp[(F[i]+1)%3];
		}
	}
	dp[0]=1;
	FOR(i,N) {
		if(nex[i][0]<=N) (dp[nex[i][0]]+=dp[i])%=mo;
		if(nex[i][1]<=N) (dp[nex[i][1]]+=dp[i])%=mo;
	}
	ll ret=0;
	for(i=1;i<=N;i++) if(F[i]==F[N]) ret+=dp[i];
	cout<<ret%mo<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 2512
#!/usr/bin/env python3
import sys


def solve(N: int, H: "List[int]"):
    ct = 0
    mct = 0
    for i in range(1, N):
        # print(ct)
        if(H[i-1] >= H[i]):
            ct += 1
        else:
            ct = 0
        mct = max(mct, ct)

    print(mct)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, H)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15288
# 解説AC
S = input()
N = len(S)

cnt = [0] * 2019

cnt[0] = 1

ans = 0
e = 1; cur = 0
for s in reversed(S):
    cur = (cur + int(s) * e) % 2019

    ans += cnt[cur]

    e = (e * 10) % 2019
    cnt[cur] += 1

print(ans)

Measured memory_bytes: 9336
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	string s;
	int ans=1;
	cin >>s;
	ll k;
	cin>>k;
	for(int i=0;i<min(k,(ll)s.size()) and ans==1;i++){
		ans=s[i]-'0';
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int n;
	cin>>n;
	priority_queue<int> q;
	vi arr(n);for(int &i:arr)cin>>i,q.PU(i);
	for(int i=0;i<n;i++) {
		if(q.top()==arr[i]){
			q.pop();
			cout<<q.top()<<"\n";
			q.PU(arr[i]);
		}
		else cout<<q.top()<<"\n";
	}
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 5072
import sys

while True:
	h, w = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
	if 0 ==h and 0 == w:
		break
	pa = [ "#", "." ]
	ouput = []
	for i in range( h ):
		for j in range( w ):
			ouput.append( pa[(i+j)%2] )	
		ouput.append( "\n" )	
	print( "".join( ouput ) )

Measured memory_bytes: 4416
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    ans=0
    for i in range(1,int(N**0.5)+1):
        if N%i==0:
            ans=i
    print(max(len(str(ans)),len(str(N//ans))))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
from collections import Counter
n,k=map(int,input().split())
lst=[int(i) for i in input().split()]
L=list(Counter(lst).values())
L.sort()
l=len(L)
ans=0
a=0
if l>k:
  while l>k:
    ans+=L[a]
    l-=1
    a+=1
print(ans)
    

Measured memory_bytes: 32540
#include<math.h>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include <array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
#include<bitset>
//AtCoderC++.cpp

using namespace std;


int main() {
	string S; cin >> S;
	size_t count = pow(2, S.length()-1) - 1; 
	long long answer = 0;
	auto sp = 0;
	while (true) {
		for (size_t i = 1; i < S.length(); i++) {
			if ((count >> (i - 1)) % 2 == 1) {
				answer += stoll(S.substr(sp, i - sp));
//				cout << S.substr(sp, i - sp) << endl;
				sp = i;
			}
		}
		answer += stoll(S.substr(sp));
//		cout << S.substr(sp) << endl;
		sp = 0;
		if (count == 0)break;
		count--;
	}
	cout << answer << endl;
}

Measured memory_bytes: 256
import sys

N,A,B = map(int,input().split(' '))

Count_Blue = 0
if 1<=N<=10**18 and A > 0 and B >= 0 and \
   0< A + B <= 10**18:
    Add_Blue = 1 * A
    Add_Both = Add_Blue + 1 * B

    q = N // Add_Both
    mod = N % Add_Both
    if mod < Add_Blue:
        Count_Blue = (q *Add_Blue) + mod
    else:
        Count_Blue = (q * Add_Blue) + Add_Blue
    print(Count_Blue)
elif A == 0:
    print(Count_Blue)

Measured memory_bytes: 3064
#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>;
const int INF = 1001001001;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int now;
  for(int i = 1; i <= 5; ++i) {
    cin >> now;
    if(now != i) {
      cout << i << endl;
      break;
      
    }
  }
  return 0;
}

Measured memory_bytes: 3640
function f()
    n = parse(Int, chomp(readline()))
    H = map(x -> parse(Int, x), split(chomp(readline()), " "))

    ret = 0
    max = H[1]
    for i in 2:length(H)
        if max <= H[i]
            max = H[i]
            ret += 1
        end
    end
    print(ret+1)
    
end
f()


Measured memory_bytes: 164796
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <cmath>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main(){
  int s,w;
  cin>>s>>w;
  if(w>=s){cout<<"unsafe"<<endl;}
  else{cout<<"safe"<<endl;}
  return 0;
}

Measured memory_bytes: 3620
use std::io::{self, BufRead};

const D: u64 = 1000000007;

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let n: usize = lines.next().unwrap().unwrap().parse().unwrap();
  let xs: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
  let mut ones: Vec<usize> = vec![0; 64];
  for i in 0..64 {
    ones[i] = xs.iter().filter(|x| **x & (1 << i) != 0).count();
  }
  let mut coeffs: Vec<u64> = vec![0; 64];
  coeffs[0] = 1;
  for i in 1..64 {
    coeffs[i] = coeffs[i-1] * 2 % D;
  }
  let mut ans: u64 = 0;
  for i in 0..64 {
    ans = (ans + ((ones[i] as u64 * (n as u64 - ones[i] as u64) % D) * coeffs[i] % D)) % D;
  }
  println!("{}", ans);
}

Measured memory_bytes: 14456
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>

using namespace std;

int main()
{
  string S, T, U;
  int A, B;
  cin >> S >> T >> A >> B >> U;
  if (U == S) {
    A--;
  }
  else {
    B--;
  }

  cout << A << " " << B;
  return 0;
}


Measured memory_bytes: 256
def isok(t):
    cnt = 0
    for i in range(n):
        cnt += max(a[i] - t // f[i], 0)
        if cnt > k:
            return False
    return True 

n,k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort(reverse = 1)
f.sort()
ok = a[0] * f[-1]
ng = -1
bool = True
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if isok(mid):
        ok = mid
    else:
        ng = mid
    #print(ng,mid,ok)
print(ok)


Measured memory_bytes: 119884
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {
	string s="NO";
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b) {
		s = "YES";
	}

	
	cout <<s<< endl;
}


Measured memory_bytes: 256