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

using namespace std;

#define int long long

void solve() {
    vector <pair <int, int> > kek;
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    for (int i = 0; i < a; ++i) {
        int val;
        cin >> val;
        kek.push_back({val, 1});
    }
    for (int i = 0; i < b; ++i) {
        int val;
        cin >> val;
        kek.push_back({val, 2});
    }
    for (int i = 0; i < c; ++i) {
        int val;
        cin >> val;
        kek.push_back({val, 3});
    }
    sort(kek.begin(), kek.end());
    int sum = 0, cl = 0, sumcl = 0, r = 0, g = 0;
    for (int i = kek.size() - 1; i >= 0; --i) {
        if (kek[i].second == 3) {
            ++cl;
            sumcl += kek[i].first;
        }
        if (kek[i].second == 2) {
            if (g < y) {
                sum += kek[i].first;
                ++g;
            }
        }
        if (kek[i].second == 1) {
            if (r < x) {
                sum += kek[i].first;
                ++r;
            }
        }
        //cout << cl << ' ' << r << ' ' << g << '\n';
        if (cl == x + y - r - g) {
            cout << sum + sumcl;
            return;
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 10476
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def conb(n,r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n = inp()
a = inpl()
cnt4 = 0
cnt2 = 0
cnt_ = 0
for i in range(n):
    if a[i]%4 == 0:
        cnt4 += 1
    elif a[i]%2 == 0:
        cnt2 += 1
    else :
        cnt_ += 1
if (cnt4+1 == cnt_ and cnt2 == 0) or cnt4 >= cnt_  or cnt2 == n:
    print('Yes')
else:
    print('No')



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

static const int MAX = 200000;

int main(void){
  int R[MAX], n;

  cin >> n;
  for(int i = 0; i < n; i++) cin >> R[i];

  int maxv = -2000000000;
  int minv = R[0];

  for(int i = 1; i < n; i++){
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
}

Measured memory_bytes: 1940
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <utility>

#include <cassert>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define FOR(i,a,b) for(ll i=(a); i < (b); i++)
#define RFOR(i,a,b) for(ll i=(b)-1; i >= (a); i--)
#define rep(i,n) FOR(i,0,(n))
#define rrep(i,n) RFOR(i,0,(n))

int main() {
	int N;
	cin >> N;
	vector<ll> A(N);
	rep(i,N) {
		cin >> A[i];
		A[i] -= i+1;
	}
	sort(all(A));
	ll res = 1e15;
	for(int i = N/2; i <= N/2+2 && i < N; i++) {
		ll b = A[i];
		ll tmp = 0;
		rep(j,A.size()) {
			tmp += abs(A[j]-b);
		}
		res = min(res,tmp);
	}
	cout << res << endl;
	return 0;
}


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

#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define all(v) v.begin(), v.end()
#define ar array

#define F first
#define S second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pll = pair <ll, ll>;
using ld = long double;

// const int mod = 1e9 + 7;
const int mod = 998244353;
const ll inf = 2e9;
const ll INF = 2e18;
const ld EPS = 1e-7;

const int N = 1e6 + 5;

int p[N];

int a[N];

ll pw (ll a, ll b) {
	ll res = 1;
	for (int i = 0 ; i < b ; ++ i) {
		res = res * a % 2019;
	}
	return res;
}

ll cnt[N];

ll binpow (ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1) (res *= a) %= 2019;
		b >>= 1;
		(a *= a) %= 2019;
	}
	return res;
}

void solve () {
	string s;
	cin >> s;
	int n = s.size();
	ll ans = 0;
	cnt[0] = 1;
	cerr << "output part\n";
	for (int i = 1 ; i <= n ; ++ i) {
		a[i] = s[i - 1] - '0';
		p[i] = (p[i - 1] * 10 + a[i]) % 2019;
		ll cur = (p[i] * binpow (10, n - i + 1)) % 2019;
		ans += cnt[cur];
		// cerr << i << " " << cur << " " << cnt[cur] << "\n";
		cnt[cur]++;
		// pw = (pw * 10) % 2019;
	}
	// ans = 0;
	// for (int i = 1 ; i <= n ; ++ i) {
		// for (int j = i - 1 ; j >= 0 ; -- j) {
			// if ((p[i] * binpow (10, n - i + 1)) % 2019 == (p[j] * binpow (10, n - j + 1)) % 2019) {
				// ++ans;
			// }
			// if (p[i] == (p[j] * binpow (10, i - j)) % 2019) {
				// ++ans;
			// }
		// }
	// }
	cout << ans;
}

int main () {
	ios;
	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
		cout << "\n";
	}
}




Measured memory_bytes: 5336
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m,q;

int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int u,v,w;
		cin>>u>>v>>w;
	}
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
	}
	cin>>q;
	for(int i=0;i<q;i++){
		int t;
		cin>>t;
		for(int j=0;j<t;j++){
			int x,y;
			cin>>x>>y;
		}
		cin>>t;
		for(int j=0;j<t;j++){
			int x;
			cin>>x;
		}
		cout<<-1<<endl;
		string s;
		cin>>s>>t;
		for(int j=0;j<t;j++){
			int x;
			cin>>x;
		}
	}
}

Measured memory_bytes: 1364
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void calc(int[] a) {
    auto b = a.dup;
    b.partialSort!"a > b"(2);

    int x = b[0];
    int y = b[1];
    foreach (e; a) {
        writeln(e == x ? y : x);
    }
}

void main() {
    int n; scan(n);
    int[] a;
    foreach (_; 0..n) a ~= readint;
    calc(a);
}


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

int main(){
  int N, W; cin >> N >> W;
  
  long long dp[100001];
  dp[0] = 0;
  for (int i=1; i<=100000; i++) dp[i] = W+1;

  for (int i=0; i<N; i++){
    int w, v; cin >> w >> v;
    for (int j=100000-v; j>=0; j--){
      if (dp[j] < W){
        dp[j+v] = min(dp[j+v], dp[j]+w);
      }
    }
  }

  for (int i=100000; i>=0; i--){
    if (dp[i] <= W){
      cout << i << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 1024
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N,K=get_i
a=get_i
cnt=0
min(K,50).times do
  imos=[0]*N
  N.times do|i|
      imos[max(i-a[i],0)]+=1
      #imos[i]-=1
      #imos[min(i+1,N-1)]+=1
      imos[i+a[i]+1]-=1 if i+a[i]+1<N
  end
  #imos[N-1]-=1
  #p imos
  #accum=array(N+1,0)
  a[0]=imos[0]
  (N-1).times do|i|
      #accum[i+1]=accum[i]+imos[i]
      #a[i]=accum[i+1]
      a[i+1]=a[i]+imos[i+1]
  end
  cnt+=1
end
puts a.join(" ")

Measured memory_bytes: 84652
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


signed main(){
  int n,f=0,a;
  cin>>n;
  vector<int> b(n);
  rep(i,n){
    cin>>a;
    if(a==0)f++;
    b[a/2]+=1;
  }
  if(n%2==0){
    if(f==0){
      int ans=1;
      rep(i,n/2){
        if(b[i]!=2)ans=0;
        ans*=2;
        ans%=MOD;
      }
      cout<<ans%MOD<<endl;
    }else cout<<0<<endl;
  }else{
    if(f==1){
      int ans=1;
      rep(i,n/2){
        if(i>0&&b[i]!=2)ans=0;
        ans*=2;
        ans%=MOD;
      }
      cout<<ans%MOD<<endl;
    }else cout<<0<<endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
    long long n,ans=1 ;
    scanf ("%lld",&n) ;
    for (int i=1; i<=n; i++) {
        ans*=i;
        while (ans>=1000000007){
            ans-=1000000007 ;
        }
    }
    printf ("%lld\n",ans) ;
	return 0 ;
}

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

#define pb push_back
#define ff first
#define ss second

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

const int MAXN = 1000 + 17;

int n, m, mat[MAXN][MAXN], a, b;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m >> a >> b;
	for (int i = 1; i <= b; i++)
		for (int j = 1; j <= m; j++)
			mat[i][j] = (j > a);
	for (int i = b + 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			mat[i][j] = (j <= a);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++)
			cout << mat[i][j];
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}

ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

int main (){
    ll x,y;
    cin >> x >>y;
    ll z=x+y;
    if(z%3!=0){
        cout << 0 << endl;
        return 0;
    }
    ll a=2*x-y;
    ll b=2*y-x;
    if(!(a%3==0&&b%3==0)){
        cout << 0 <<endl;
        return 0;
    }
    a/=3;
    b/=3;
    if(!(a>=0&&b>=0)){
        cout << 0 <<endl;
        return 0;
    }
    ll c=a+b;
    cout << com(c,a) <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n, y, m, d, ans;
    cin>>n;
    for (int i=0; i<n; i++)
    {
        cin>>y>>m>>d;
        if (y%3==0) ans=21-d+20*(10-m)+(999-y)*590/3;
        else if (y%3==1)
        {
            if (m%2==0) ans=415-d+39*(10-m)/2+590*(997-y)/3;
            else ans=435-d+39*(9-m)/2+590*(997-y)/3;
        }
        else
        {
            if (m%2==0) ans=220-d+39*(10-m)/2+590*(998-y)/3;
            else ans=240-d+39*(9-m)/2+590*(998-y)/3;
        }
        cout<<ans<<'\n';
    }
    return 0;
}



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

int main() {
    int x, y;
    scanf("%d %d", &x, &y);
    for (int c = 0; c <= 100; c++) {
        for (int t = 0; t <= 100; t++) {
            if (c + t == x and (2 * c + 4 * t == y)) {
                puts("Yes");
                return 0;
            }
        }
    }

    puts("No");
}

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

#define read(num) scanf("%d", &num)
#define readll(num) scanf("%lld", &num)
#define read2(num1, num2) scanf("%d%d", &num1, &num2)
#define read3(num1, num2, num3) scanf("%d%d%d", &num1, &num2, &num3)
#define reads(str) scanf("%s", str)
#define readc(ch) scanf("%c", &ch)

#define pb push_back
#define mp make_pair

#define pii pair<int, int>
#define vi vector<int>
#define ll long long


int main()
{
    ll n,m;
    cin>>n>>m;
    ll s=0,x;
    for(int i=0;i<m;i++){
        cin>>x;
        s+=x;
    }
    n-=s;
    if(n<0){
        n=-1;

    }
    cout<<n;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
//#include "atcoder/all"
//using namespace atcoder;
#define int long long
#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 FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;

signed main(){
	int N;
	cin >> N;
	vector<int>a(N);
	REP(i, N) {
		int b, c;
		cin >> b >> c;
		if(b == c) a[i] = 1;
	}
	int ans = 0;
	REP(i, N - 2) {
		if(a[i] && a[i + 1] && a[i + 2]) ans = 1;
	}
	if(ans) out("Yes");
	else out("No");
}

Measured memory_bytes: 3628
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    _ = rl()
    S = input()
    MOD = 10 ** 9 + 7
    
    counter = defaultdict(int)
    for si in S:
        counter[si] += 1
    
    ans = 1
    s = set(S)
    for si in s:
        ans = ans * (counter[si] + 1) % MOD
    ans -= 1
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3444
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;


int main()
{
	string S;
	int n;
	cin >> n >> n >> S;

	S[n - 1] = (char)((S[n - 1] - 'A') + 'a');

	cout << S << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
    int v[3] = {};
    for (int i = 0; i < 3; i++) {
        cin >> v[i];
    }
    cin.ignore();
    
    sort(v, v+3);
    
    for (int i = 0; i < 3; i++) {
        cout << v[i];
        if (i < 2) {
            cout << " ";
        }
    }
    cout << endl;
}

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

int main(){
  int N,M,C; cin >> N >> M >> C;
  vector<int> B(M);
  for(int i = 0; i < M; i++){
    cin >> B[i];
  }
  int ans = 0;
  for(int i = 0; i < N; i++){
    int sum = C;
    for(int j = 0; j < M; j++){
      int a;
      cin >> a;
      sum += a*B[j];
    }
    if(sum > 0) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
s = input()
s = list(s)
even = ["L","U","D","0"]
odd = ['R',"U","D"]

#print(s)
s.insert(0,"0")
for i in range(len(s)):
  #print(s[i])
  if(i%2 == 0):
    if(s[i] not in even):
      print("No")
      exit()
  else:
    if(s[i] not in odd):
      print("No")
      exit()
print("Yes")

Measured memory_bytes: 38384
#include <stdio.h>
int main(void)
{
	int a, b;
	scanf("%d %d", &a, &b);
	if (a < b)
	{
		printf("a < b\n");
	}
	else if (a > b)
	{
		printf("a > b\n");
	}
	else
	{
		printf("a == b\n");
	}
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pair2;
typedef pair<int, pair<int, int> > pair3;
typedef pair<int, pair<int, pair<int, int> > > pair4;
#define MAXN 3013
#define INF 1000000000000000000LL
#define MOD 1000000007LL
#define IINF 1000000000
#define mp make_pair
#define pb push_back
#define remove pop
#define all(x) x.begin(), x.end()



int n;

int t;

pair2 values[MAXN];

int dp[MAXN][MAXN];

pair2 from[MAXN][MAXN];

bool used[MAXN];

int main() {
	if (fopen("FILENAME.in", "r")) {
		freopen("FILENAME.in", "r", stdin);
		freopen("FILENAME.out", "w", stdout);
	}
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);

	cin >> n;

	cin >> t;

	int bestdish = 0;
	for (int i = 0; i < n; i++) {
		cin >> values[i].first >> values[i].second;
		bestdish = max(bestdish, values[i].second);
	}

	sort(values, values + n);

	//First check if it's POSSIBLE to reach a certain time, then add on whatever dish you want at the end. geniosity


	int answer = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < t; j++) {

			if (j + values[i].first < t && dp[i + 1][j + values[i].first] < dp[i][j] + values[i].second) {
				dp[i + 1][j + values[i].first] = max(dp[i + 1][j + values[i].first], dp[i][j] + values[i].second);
				from[i + 1][j + values[i].first] = mp(i, j);
			}

			if (dp[i + 1][j] < dp[i][j]) {
				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
				from[i + 1][j] = mp(i, j);
			}
			
		}
	}


	for (int i = 0; i < t; i++) {
		//backtrack from dp[n][i];

		for (int j = 0; j < n; j++) {
			used[j] = false;
		}

		int cx = n;
		int cy = i;

		while (cx > 0 || cy > 0) {

			pair2 p = from[cx][cy];

			if (cy != p.second) {
				//We took the previous one
				used[p.first] = true;
			}
			cx = p.first;
			cy = p.second;
		}

		int maxUnused = 0;

		for (int j = 0; j < n; j++) {
			if (!used[j]) {

				maxUnused = max(maxUnused, values[j].second);
			}
			used[j] = false;
		}

		answer = max(answer, maxUnused + dp[n][i]);
	}
	cout << answer << endl;
}

//GCD GCD GCD USE GCD IN MATH

Measured memory_bytes: 106496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
mt19937_64 mt(1);//seed
uniform_real_distribution<double> rnd(0.00,1.00);




int main(){
	int n;
	cin >> n;
	set<int> se;
	FOR(i,1,10)FOR(j,1,10){
		if(i*j==n){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
long long gcd(long long a, long long b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
long long lcm(long long a, long long b)
{
   return a * b / gcd(a, b);
}

int main(){
  long long A,B,C,D;
  cin >> A >> B >> C >> D;
  long long E=lcm(C,D);
  long long ans=(B-A+1)-((B/C)-(A/C))-((B/D)-(A/D))+((B/E)-(A/E));
  if(A%C==0){
    ans--;
  }
  if(A%D==0){
    ans--;
  }
  if(A%E==0){
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int g(string s) {
  int n=0;
  for (int i=0; i<s.length(); i++)
    n |= 1<<(s[i]-'a');
  return n;
}
int f(string a, string b) {
  return __builtin_popcount(g(a)&g(b));
}
int main() {
  int n, c=0;
  string s;
  cin >> n >> s;
  for (int i=1; i<n; i++)
    c = max(c, f(s.substr(0, i), s.substr(i, n-i)));
  cout << c << endl;
  return 0;
}

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

int INF = 1e9;

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

  int ans = 0;

  vector<int> a;
  rep(i, N) {
    int ai;
    cin >> ai;
    if (ai <= N)
      a.push_back(ai);
    else
      ans++;
  }

  if (a.size() == 0) {
    cout << ans << endl;
    return 0;
  }

  sort(a.begin(), a.end());
  a.push_back(INF); // dummy

  int prev = 0;
  for (int i = 1; i < a.size(); i++) {
    if (a[i - 1] == a[i])
      continue;
    int n = i - prev;
    int m = a[i - 1];
    if (n < m)
      ans += n;
    if (n > m)
      ans += n - m;
    prev = i;
  }

  cout << ans << endl;
}

Measured memory_bytes: 892
s=list(input())

i=0
j=0
ans=0
z=[]
while i!=len(s)-1:
    try:
        if s[i]=="B" and s[i+1]=="C":
            z.append(1)
            i=i+2

        else:
            if s[i]=="A":
                z.append(2)
                i=i+1

            else:
                z.append(0)
                i=i+1

    except:
      break

ans=0
i=0
r1=0


#print(z)
#ｚ＝判定数列

while i!=len(z):
    if z[i]==2:#"A"
         r1=r1+1

    elif z[i]==1:#"BC"
        ans=ans+r1

    else:#"gomi"
        r1 = 0


    i=i+1
print(ans)


Measured memory_bytes: 6560
#include<vector>
#include<iostream>
#include<array>
#include <iostream>

using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

std::vector<long long> solve_blue_and_red_balls(int n, int k) {
    COMinit();
    vector<long long> ans(k);
    for(int i = 1;i<=k;i++) {
      //cout << "=====" << endl;
      //cout << "n-k+1: " << n-k+1 << " " << " i: " << i << " -> " << COM(n-k+1, i) << endl;
      //cout << "k-1: " << k-1 << " " << " i-1: " << i -1 << " -> " << COM(k-1, i-1) << endl;
      ans[i-1] = (COM(n-k+1, i) * COM(k-1, i-1)) % MOD;
      //cout << "ans " << i << " -> " << ans[i-1] << endl;
      //cout << "=====" << endl;
    }

    return ans;
}

int main() {
    int n, k;
    cin >> n;
    cin >> k;
    vector<long long> ans = solve_blue_and_red_balls(n, k);
    for(int i=0;i<k;i++) {
      cout << ans[i] << endl;
    }
}

Measured memory_bytes: 15604
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}

struct katana{
  int a;
  int b;
};
bool cmp(const katana &a,const katana &b){
  return a.b < b.b;
}

int main()
{
  int N,H,T=0,ma=-1,n,res=0;
  struct katana k[100001];
  cin >> N >> H;
  REP(i,N)
    cin >> k[i].a >> k[i].b;
  sort(k,k+N,cmp);
  REP(i,N){
    if(ma < k[i].a){
      T = i;
      ma = k[i].a;
    }
  }
  n = N-1;
  while(H > 0){
    if(n == T){
      n--;
      continue;
    }
    if(H - k[T].b <= 0){
      res++;
      break;
    }
    
    if(n < 0 || k[n].b <= k[T].a){
      H = H-k[T].b;
      res++;
      if(H <= 0)
        break;
      res += H/k[T].a;
      if(H % k[T].a)
        res++;
      break;
    }else{
      H = H-k[n].b;
      res++;
      n--;
    }
  }
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

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



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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)2e5 + 9;
int a[N], b[N];
bool is[N];

int n;
priority_queue<pii> tf;

void check(int x){
  if(is[x]){
    return ;
  }
  if(b[x] > a[x] && b[x] > b[(x-1+n)%n] + b[(x+1)%n]){
    tf.push(mp(b[x], x));
    is[x] = true;
  }
}

int main(){
  fastIO;
  cin >> n;
  for(int i = 0 ; i < n ; i ++ ){
    cin >> a[i];
  }
  for(int i = 0 ; i < n ; i ++ ){
    cin >> b[i];
  }
  for(int i = 0 ; i < n; i ++ ){
    check(i);
  }
  ll res = 0;
  int idx;
  ll dd;
  while(!tf.empty()){
    idx = tf.top().se;
    tf.pop();
    is[idx] = false;
    dd = b[idx] - a[idx];
    res += dd / (b[(idx+1)%n] + b[(idx-1+n)%n]);
    b[idx] = a[idx] + (dd % (b[(idx+1)%n] + b[(idx-1+n)%n]));
    check((idx-1+n)%n);
    check((idx+1)%n);
  }
  for(int i = 0 ; i < n ; i ++ ){
    if(a[i] != b[i]){
      cout << -1;
      return 0;
    }
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 3192
#include<iostream>
using namespace std;
int a[1000];
int main(){
	long long n;
	cin>>n;
	long long sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	long long m,temp;
	cin>>m;
	for(int i=0;i<m;i++){
		int c,d;
		cin>>c>>d;
		temp=sum;
		cout<<temp-a[c-1]+d<<endl;
	}
	return 0;
} 

Measured memory_bytes: 256
import collections

H, W = map(int, input().split())
s = [input() for _ in range(H)]

sy, sx = 0, 0
gy, gx = H - 1, W - 1

dist = [[-1 for _ in range(W)] for _ in range(H)]

q = collections.deque()
q.append((sy, sx, 0))

while q:
    y, x, d = q.popleft()

    if y < 0 or H <= y or x < 0 or W <= x:
        continue

    if s[y][x] == '#':
        continue

    if dist[y][x] != -1:
        continue

    dist[y][x] = d + 1

    q.append((y + 1, x, d + 1))
    q.append((y - 1, x, d + 1))
    q.append((y, x + 1, d + 1))
    q.append((y, x - 1, d + 1))

if dist[-1][-1] == -1:
    print(-1)
else:
    num_white = sum(block == '.' for row in s for block in row)
    print(num_white - dist[-1][-1])


Measured memory_bytes: 68572
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<cctype>
using namespace std;


int main() {
	string s;
	cin >> s;
	int c = s.size(), t = 0;
	for (int i = 0; i < c - 1; i++) {
		if (s[i] == 'A' && s[i + 1] == 'C')
			t = 1;
	}
	if (t == 1)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
int n, m, q;
int a[51], b[51], c[51], d[51];
int v[11];
int ans = 0;
 
 
int main() {
    string S, T;
    cin >> S >> T;
    rep(i, 0, S.size()) {
        if (S[i] != T[i]){
            cout << "No" <<endl;
            return 0;
        }
    }
   
    
    cout << "Yes" <<endl;
    return 0;
}


Measured memory_bytes: 3640
use std::io::*;
use std::str::FromStr;

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")
}


fn main() {
    let mut s: u32 = read();

    let mut count = 0;

    for _ in 0..3 {
        if s % 10 == 1 {
            count += 1;
        }
        s /= 10;
    }

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


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}

void solve(){
	int k;
	cin>>k;
	vector<int>rem;
	int mk[k];
	memset(mk,0,sizeof(mk));
	mk[7%k]=1;
	int cur=7;
	int ans=1;
	while(1){
		if(cur%k==0){cout<<ans;return;}
		ans++;
		cur=(cur*10+7)%k;
		if(mk[cur]){cout<<-1;return;}
		mk[cur]=1;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 7560
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    ll N, M, K;
    cin >> N >> M >> K;
    vec<ll> A(N), B(M);
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];

    rep(i, N - 1) A[i + 1] += A[i];
    rep(i, M - 1) B[i + 1] += B[i];

    A.insert(A.begin(), 0);
    B.insert(B.begin(), 0);
    A.push_back(1e18 + 7);
    B.push_back(1e18 + 7);

    ll ans = 0;
    rep(i, A.size()) {
        if (A[i] > K) continue;
        ll idx = upper_bound(all(B), K - A[i]) - B.begin();
        --idx;
        ans = max(ans, i + idx);
    }
    cout << ans << endl;
}


Measured memory_bytes: 7916
from sys import stdin


def main() -> None:
    n = int(input())
    dic = set()

    for i in range(n):
        s = next_str()
        dic.add(s)

    print(["Three", "Four"][len(dic) == 4])


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

int main()
{
    int n,m;
    cin >> n >> m;
    ll ans=0;
    REP(i,m){
        int a;
        cin >> a;
        ans+=a;
    }
    if(ans>n){
        cout << -1 << endl;
    }
    else{
        cout << n-ans << endl;
    }
}

Measured memory_bytes: 3632
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
'''
N, M = mi()
x = li2(M)

#dp = dp2(0, 2, N)
dp = [[0, []] for i1 in range(N+1)]


for i in range(M):
    dp[x[i][1]][0] = max(dp[x[i][1]][0], dp[x[i][0]][0] + 1)
    dp[x[i][0]][1].append(x[i][1])
    if dp[x[i][1]][1] != []:
        for a in dp[x[i][1]][1]:
            dp[a][0] = max(dp[x[i][1]][0] + 1, dp[a][0])

print(dp)
print(max([row[0] for row in dp])) 
'''
from collections import deque
N, M = mi()
x = li2(M)

h = [0]*N
adj = [[] for i in range(N)]
for i in range(M):
    x[i][0] -= 1
    x[i][1] -= 1
    h[x[i][1]] += 1
    adj[x[i][0]].append(x[i][1])

zeros = deque([])
ans = []
for i in range(N):
    if h[i] == 0:
        zeros.append(i)
        ans.append(i)

while(zeros != deque()):
    a = zeros.popleft()
    if(adj[a]):
        for b in adj[a]:
            h[b] -= 1
            if h[b] == 0:
                zeros.append(b)
                ans.append(b)

#print(ans)

dp = [0]*N
#print(ans)
#print(adj)
for a in ans:
    #print(dp)
    if adj[a]:
        for b in adj[a]:
            dp[b] = max(dp[a] + 1, dp[b])
#print(dp)
print(dp[ans[-1]])

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

/* constant */

#define MAX_LEN	(5000)
#define MAX_N	(12)

/* global variables */

bool eoks[MAX_LEN][MAX_N];
bool eused[MAX_LEN + 1][1 << MAX_N];

string elms[MAX_N];
int elens[MAX_N];

/* main */

int main() {
  for (;;) {
    int n, m;
    cin >> n >> m;
    if ((n | m) == 0) break;

    for (int i = 0; i < n; i++) {
      cin >> elms[i];
      elens[i] = elms[i].size();
    }

    string text;
    string line;

    for (int i = 0; i < m; i++) {
      cin >> line;
      text += line;
    }
    int tlen = text.size();

    int allbits = (1 << n) - 1;
  
    memset(eoks, false, sizeof(eoks));
    memset(eused, false, sizeof(eused));
  
    for (int pos = 0; pos < tlen; pos++)
      for (int k = 0; k < n; k++)
	if (text.substr(pos, elens[k]) == elms[k]) {
	  eoks[pos][k] = true;
	  eused[pos + elens[k]][1 << k] = true;
	}
    //p eused

    for (int pos = 0; pos < tlen; pos++) {
      for (int bits = 0; bits <= allbits; bits++) {
	if (! eused[pos][bits]) continue;

	for (int k = 0; k < n; k++) {
	  int bk = 1 << k;
	  int posk = pos + elens[k];
	  if (eoks[pos][k] && (bits & bk) == 0 && posk <= tlen)
	    eused[posk][bits | bk] = true;
	}
      }
    }

    int count = 0;
    for (int pos = 0; pos <= tlen; pos++)
      if (eused[pos][allbits]) count++;
  
    cout << count << endl;
  }

  return 0;
}

Measured memory_bytes: 21304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    ll n;
    cin>>n;
    ll ans=0;

    for(ll i=1;i<=n;i++){
        for(ll j=i;j<=n;j+=i){
            ans+=j;
        }
    }

    cout<<ans<<endl;
}

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

int m,n,k,rs[105][105];

int main()
{
    cin>>m>>n>>k;
    int x,u=1,v=1,dir=1;
    for(int i=1;i<=k;i++)
    {
        cin>>x;
        while(x--)
        {
            rs[u][v]=i;
            v+=dir;
            if(v==0)
            {
                u++;
                v=1;
                dir=1;
            }
            else
            if(v==n+1)
            {
                u++;
                v=n;
                dir=-1;
            }
        }
    }
    for(int i=1;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
            cout<<rs[i][j]<<' ';
        cout<<"\n";
    }
}


Measured memory_bytes: 384
def main():
    n = int(input())
    numbers = [int(input()) for i in range(n)]
    count = shellSort(numbers, n)

    print(count)
    [print(i) for i in numbers]

def shellSort(numbers, n):
    count = 0
    m = 1
    g = []
    while m <= n :
        g.append(m)
        m = 3 * m + 1
    g.reverse()
    for h in g:
        count += insertionSort(numbers, n, h)

    print(len(g))
    print(' '.join(map(str, g)))

    return count

def insertionSort(numbers, n, h):
    count = 0
    for i in range(h, n, 1):
        v = numbers[i]
        j = i - h
        while (j >= 0) & (numbers[j] > v):
            numbers[j + h] = numbers[j]
            j -= h
            count += 1

        numbers[j + h] = v

    return count

if __name__ == '__main__':
    main()



Measured memory_bytes: 53200
#include <cstdio>
#define MOD 998244353
typedef long long ll;
inline ll quick_pow(ll a, int n)
{
	ll res = 1;
	while (n)
	{
		if (n & 1)
			res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}
ll fact[1000005], inv[1000005], sig[1000005], val[1000005], sum[1000005];
inline ll C(int n, int m)
{
	if (n < m || m < 0)
		return 0;
	return fact[n] * inv[m] % MOD * inv[n - m] % MOD;
}
inline void init()
{
	const int mx = 1e6;
	fact[0] = inv[0] = sig[0] = 1;
	for (int i = 1; i <= mx; i++)
		fact[i] = fact[i - 1] * i % MOD;
	inv[mx] = quick_pow(fact[mx], MOD - 2);
	for (int i = mx; i; i--)
	{
		inv[i - 1] = inv[i] * i % MOD;
		sig[i] = inv[i] * fact[i - 1] % MOD;
	}
}
void work(int n, int m)
{
	int rem = n;
	for (int i = n + m - 1; i && rem; i--)
	{
		if (i + 1 < rem << 1)
		{
			if (rem-- != n)
				val[i] = (val[i + 1] + C(n + m - i - 2, n - rem - 1) * C(i, rem)) % MOD;
			else
				val[i] = C(i, rem);
		}
		else if (rem != n)
			val[i] = (val[i + 1] - C(n + m - i - 2, n - rem - 1) * C(i, rem - 1)) % MOD;
		else
			val[i] = 0;
		sum[i] += val[i];
	}
}
int main()
{
	// freopen("AGC019-F.in", "r", stdin);
	init();
	int n, m;
	scanf("%d%d", &n, &m);
	work(n, m);
	work(m, n);
	ll cur = C(n + m, n) * (n < m ? m : n) % MOD, ans = cur * sig[n + m] % MOD;
	for (int i = n + m - 1; i; i--)
	{
		(cur -= sum[i]) %= MOD;
		(ans += cur * sig[i]) %= MOD;
	}
	printf("%lld\n", (ans + MOD) * quick_pow(C(n + m, n), MOD - 2) % MOD);
	return 0;
}


Measured memory_bytes: 39168
#include <bits/stdc++.h>
using namespace std;
int a[200010], b[200010];
int main() {
	int n;
  	cin>>n;
	for (int i = 0; i<n; i++) {
		cin >> a[i] >> b[i];
	}
	sort(a, a + n);
	sort(b, b + n);
	if (n & 1) {
		cout << b[n / 2] - a[n / 2] + 1 << endl;
	}
	else {
		cout << b[n / 2] + b[n / 2 - 1] - a[n / 2] - a[n / 2 - 1] + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 5200
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
const int D_MAX_V=302;
const int D_v_size=302;
struct D_wolf{
	long long c;
	int t,r;
	D_wolf(){t=c=r=0;}
	D_wolf(int t1,long long c1,int r1){
		t=t1;c=c1;r=r1;
	}
};
vector<D_wolf>D_G[D_MAX_V];
int D_level[D_MAX_V];
int D_iter[D_MAX_V];

void add_edge(int from,int to,long long cap){
	D_G[from].push_back(D_wolf(to,cap,D_G[to].size()));
	D_G[to].push_back(D_wolf(from,0,D_G[from].size()-1));
}
void D_bfs(int s){
	for(int i=0;i<D_v_size;i++)D_level[i]=-1;
	queue<int> Q;
	D_level[s]=0;
	Q.push(s);
	while(Q.size()){
		int v=Q.front();
		Q.pop();
		for(int i=0;i<D_G[v].size();i++){
			if(D_G[v][i].c>0&&D_level[D_G[v][i].t]<0){
				D_level[D_G[v][i].t]=D_level[v]+1;
				Q.push(D_G[v][i].t);
			}
		}
	}
}
int D_dfs(int v,int t,long long f){
	if(v==t)return f;
	for(;D_iter[v]<D_G[v].size();D_iter[v]++){
		int i=D_iter[v];
		if(D_G[v][i].c>0&&D_level[v]<D_level[D_G[v][i].t]){
			long long d=D_dfs(D_G[v][i].t,t,min(f,D_G[v][i].c));
			if(d>0){
				D_G[v][i].c-=d;
				D_G[D_G[v][i].t][D_G[v][i].r].c+=d;
				return d;
			}
		}
	}
	return 0;
}
long long max_flow(int s,int t){
	long long flow=0;
	for(;;){
		D_bfs(s);
		if(D_level[t]<0)return flow;
		for(int i=0;i<D_v_size;i++)D_iter[i]=0;
		long long f;
		while((f=D_dfs(s,t,inf))>0){flow+=f;}
	}
	return 0;
}
int p[110];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",p+i+1);
	int S=a+a;
	int T=a+a+1;
	long long ks=0;
	for(int i=0;i<a;i++){
		add_edge(i,i+a,inf);
		add_edge(S,i,max(0,p[i+1]));
		add_edge(i+a,T,max(0,-p[i+1]));
		if(p[i+1]>0)ks+=p[i+1];
		for(int j=0;j<a;j++){
			if((i+1)%(j+1)==0){
				add_edge(i,j+a,inf);
			}
		}
	}
	long long ret=max_flow(S,T);
	printf("%lld\n",ks-ret);
}

Measured memory_bytes: 256
from collections import deque
H, W = map(int, input().split())
G = [list(input()) for i in range(H)]
directions = [[0, 1], [1, 0], [0, -1], [-1, 0]]
 
ans=0

for sh in range(H):
  for sw in range(W):
    if G[sh][sw]=="#":
      continue
      
    dist=[[-1]*W for _ in range(H)]
    dist[sh][sw]=0
    #二重[]に注意
    que=deque([[sh,sw]])
    
    while que:
      nh,nw=que.popleft()
      
      for dh,dw in directions:
        
        # 迷路からはみ出す
        if not 0<=nh+dh<=H-1 or not 0<=nw+dw<= W-1:
          continue
         
        # 移動先が通れないマス
        if G[nh+dh][nw+dw]== "#":
          continue
        
        # 探索済み
        if dist[nh+dh][nw+dw]!=-1:
          continue
          
        dist[nh+dh][nw+dw]=dist[nh][nw]+1
        que.append([nh+dh,nw+dw])
      
    ans=max(ans, max([max(d) for d in dist]))
    
print(ans)

Measured memory_bytes: 3316
// Template Headers {{{
#include <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<long long>; using vvll = vector<vll>;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> istream &operator>>(istream &, vector<T> &);
template <class T> ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U> istream &operator>>(istream &, pair<T, U> &);
template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &);
template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : std::numeric_limits<T>::max(); } };
template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } };
template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } };
constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf();
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// }}}
// Preprocessing & "Global" variables {{{
struct Solver {
	const double pi = atan(1) * 4;
	Solver() {}
	int solve();
};
// }}}

int Solver::solve() {
	int a, b, h, m; cin >> a >> b >> h >> m;
	long double angm = 2.0 * pi * m / 60;
	long double angh = 2.0 * pi * (h * 60 + m) / 720;
	long double difang = angm - angh;
	cout << fixed << setprecision(12) << sqrt(a * a + b * b - 2 * a * b * cos(difang)) << endl;
	return 0;
}

// Template Main {{{
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	Solver solver;
	#ifdef JUDGE_MULTI_CASE
		int t; cin >> t; for (int i = 1; i <= t; i++)
	#endif
	solver.solve();
	// cout << "Case #" << i << ": ", solve();
	return 0;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
	for (auto it=v.begin();it!=v.end();++it) is >> *it;
	return is;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto it=v.begin();it!=v.end();) os << *it, os << " \n"[++it==v.end()];
	return os;
}

template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
	return is >> p.first >> p.second;
}

template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) {
	return os << p.first << ' ' << p.second;
}
// }}}

// vim: fdm=marker


Measured memory_bytes: 4184
<?php
$f = fopen( 'php://stdin', 'r' );
$line = fgets($f);
$eve = ' Eve';
$day = (int)$line;
$output = 'Christmas';
for ($i = 1; $i <= (25 - $day); $i++) {
    $output = $output.$eve;
}
echo($output);

Measured memory_bytes: 4604
public class Main {

  private static void solve() {
    int n = ni();
    long d = ni();

    int ret = 0;
    for (int i = 0; i < n; i++) {
      long x = nl();
      long y = nl();
      if (x * x + y * y <= d * d) {
        ret++;
      }
    }
    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 55552
n=input()
l=len(n)
ans=0
if(l%2==0):
  for i in range(1,l,2):
    ans+=10**i-10**(i-1)
else:
  for i in range(1,l-1,2):
    ans+=10**i-10**(i-1)
  ans+=int(n)-(10**(l-1))+1
print(ans)  

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
	char a[4];
	int i = 0;
	bool p;
	
	cin >> a;

	for (i = 0; i < 3; i++)
	{
		if (a[i] == a[i + 1]) {p = false; break;
	}
		else p = true;
	}

	if (p) cout << "Good" << endl;
	else cout << "Bad" << endl;

	return 0;

}

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

int main()
{
    int a, b;
    cin >> a >> b;
    if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }

    return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
using iii = pair<ii, ll>;
#define vt vector
#define pq priority_queue
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define __lcm(a, b) a * b / __fpb(a, b)
const ll MOD = 1e9 + 7;
const ll INF = 2e9;
const ll N = 1e5 + 5;

ll n, capacity;
ll w[N], v[N];
ll dp[105][N];

ll f(ll idx, ll cap) {
    if(cap < 0) return -INF;
    if(idx > n) return 0;
    ll &sol = dp[idx][cap];
    if(sol != -1) return sol;
    return sol = max(f(idx + 1, cap - w[idx]) + v[idx], f(idx + 1, cap));
}

void solve() {
    cin >> n >> capacity;
    for(ll i = 1; i <= n; i++) {
        cin >> w[i] >> v[i];
    }
    memset(dp, -1, sizeof(dp));
    cout << f(1, capacity) << "\n";
}

int main() {
 
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    solve();
    
}

Measured memory_bytes: 85692