akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using static System.Console;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        int[] NM = ReadLineParseIntArray();
        int N = NM[0];
        int M = NM[1];
        int[] dp = new int[N];
        Queue<int> zeroDegrees = new Queue<int>();
        List<int>[] Gragh = new List<int>[N];
        int[] dig = new int[N];
        for (int i = 0; i < N; i++)
            Gragh[i] = new List<int>();
        for(int i = 0; i < M; i++)
        {
            int[] xy = ReadLineParseIntArray();
            xy[0]--;
            xy[1]--;
            Gragh[xy[0]].Add(xy[1]);
            dig[xy[1]]++;
        }

        for(int i = 0; i < N; i++)
        {
            if (dig[i] == 0)
                zeroDegrees.Enqueue(i);
        }
        while(zeroDegrees.Count != 0)
        {
            int v = zeroDegrees.Dequeue();
            foreach (var nv in Gragh[v])
            {
                dig[nv]--;
                if (dig[nv] == 0)
                {
                    zeroDegrees.Enqueue(nv);
                    dp[nv] = Max(dp[nv], dp[v] + 1);
                }
            }
        }
        int ans = 0;
        for (int i = 0; i < N; i++)
            ans = Max(ans, dp[i]);
        WriteLine(ans); 
    }
    static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray();
}

Measured memory_bytes: 29568
# 各条件の入力
list32 = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2,
          1, 5, 1, 2, 1, 14, 1, 5, 1, 5,
          2, 2, 1, 15, 2, 2, 5, 4, 1, 4,
          1, 51]
K = int(input())

# 答えの出力
print(list32[K-1])



Measured memory_bytes: 2940
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T1, class T2>bool chmax(T1& a, const T2& b) { return a < b ? a = b, 1 : 0; }
template<class T1, class T2>bool chmin(T1& a, const T2& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

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

    int ans = 0;
    for (int i = 1; i <= N; ++i) {
        string s = to_string(i);
        if (s.size() % 2 == 1) ans++;
    }

    write(ans);
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int x;
cin>>x;
double arr[x],sam=0;
     for(int i=0;i<x;i++)
     {
        cin>>arr[i];
     }


     for(int i=0;i<x;i++)
     {
         sam+=1/arr[i];

     }
     cout.precision(16);
cout<<1/sam;

return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
//#define ll long long
#define pb push_back
#define x first
#define ld long double
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) a.begin(),a.end()

using namespace std;

using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, ans = 0;
    string s, last, cur;
    cin >> s;
    n = (int)s.length();
    bool ok = false;
    for (int i = 0; i < n; i++) {
        if (last.empty()) {
            last = s[i];
            cur.clear();
            ++ans;
            continue;
        }
        string y = cur; y += s[i];
        if (last == y) {
            cur += s[i];
            continue;
        }
        else {
            last = cur + s[i];
            cur.clear();
            ++ans;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 720
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author ExplodingFreeze
 */

#include <iostream>
#include <fstream>

#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define int long long
#define f(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
using pii=std::pair<int,int>;

using namespace std;

class AFiftyFifty {
public:
	void solve(std::istream& in, std::ostream& out) {
		map<int,int> s;
		char x;
		f(i,0,4)
		{
			in >> x;
			s[x]++;
		}
		if(s.size()==2)
		{
			auto it=s.begin();
			auto it2=it;
			it2++;
			if(it->second==2&&it2->second==2)
				out << "Yes\n";
			else
				out << "No\n";
		}
		else
			out << "No\n";
	}
};


int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	AFiftyFifty solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;

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

  long long ans = 0;
  int n;
  cin >> n;
  map<int, int> cnt;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    ans += cnt[x - i];
    ++cnt[-x - i];
  }
  cout << ans;

  return 0;
}


Measured memory_bytes: 20672
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  map<int,int> mp;
  rep(i,n){
    mp[a[i]]++;
    mp[a[i]+1]++;
    mp[a[i]-1]++;
  }
  int ans=0;
  for(auto c:mp){
    chmax(ans,c.second);
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 5120
n, m, l = map(int, input().split())
A = [[] for a in range(n)]
B = [[] for b in range(m)]
C = [[0 for c in range(l)] for d in range(n)]
for a in A:
    a += list(map(int, input().split()))
for b in B:
    b += list(map(int, input().split()))
for k,x in enumerate(C):
    for y in range(l):
        for z in range(m):
            C[k][y] += A[k][z]*B[z][y]
for x in C:
    for k,y in enumerate(x):
        if k == l-1:
            print(y)
        else:
            print(y,end=" ")




Measured memory_bytes: 7080
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static final int MOD = 1000000007;

	static int add(int a, int b) {
		int res = a + b;
		return res >= MOD ? res - MOD : res;
	}

	static int sub(int a, int b) {
		int res = a - b;
		return res < 0 ? res + MOD : res;
	}

	static int mul(int a, int b) {
		int res = (int) ((long) a * b % MOD);
		return res < 0 ? res + MOD : res;
	}

	static void solve() throws Exception {
		int n = scanInt(), a = scanInt(), b = scanInt();
		if (a < b) {
			int t = a;
			a = b;
			b = t;
		}
		System.err.println(a + " " + b);
		int dyn1[] = new int[n + 2];
		dyn1[0] = 1;
		for (int i = 1; i <= n + 1; i++) {
			int v = dyn1[i - 1];
			for (int j = i - b - 1; j >= 0; j--) {
				v = add(v, dyn1[j]);
			}
			dyn1[i] = v;
		}
		int res1[] = new int[n + 1];
		int res2[] = new int[n + 1];
		int res1g[] = new int[n + 1];
		int res2g[] = new int[n + 1];
		res1[0] = res2[0] = 1;
		for (int i = 0; i <= n; i++) {
			for (int j = 1; i + j <= n; j++) {
				int cres2[] = j >= a ? res2g : res2;
				cres2[i + j] = add(cres2[i + j], mul(res1[i], dyn1[j - 1 + (i == 0 ? 1 : 0) + (i + j == n ? 1 : 0)]));
				res2g[i + j] = add(res2g[i + j], mul(res1g[i], dyn1[j - 1 + (i == 0 ? 1 : 0) + (i + j == n ? 1 : 0)]));
			}
			for (int j = 1; j < b && i + j <= n; j++) {
				res1[i + j] = add(res1[i + j], res2[i]);
				res1g[i + j] = add(res1g[i + j], res2g[i]);
			}
		}
//		System.err.println(Arrays.toString(dyn1));
//		System.err.println(Arrays.toString(res1));
//		System.err.println(Arrays.toString(res2));
		out.print(add(res1g[n], res2g[n]));
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

Measured memory_bytes: 27792
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type BC [][]int

func (b BC) Len() int {
	return len(b)
}

func (b BC) Less(i, j int) bool {
	return b[i][1] > b[j][1]
}

func (b BC) Swap(i, j int) {
	b[i], b[j] = b[j], b[i]
}

func main() {
	var n, m int
	fmt.Scan(&n)
	fmt.Scan(&m)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		a[i], _ = strconv.Atoi(scanner.Text())
	}
	sort.Ints(a)

	bc := make(BC, m)
	for i := 0; i < m; i++ {
		scanner.Scan()
		b, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		c, _ := strconv.Atoi(scanner.Text())
		bc[i] = []int{b, c}
	}
	sort.Sort(bc)

	var j int
	for i := 0; i < m; i++ {
		b := bc[i][0]
		c := bc[i][1]

		for k := 0; k < b; k++ {
			if j+k < n && c > a[j+k] {
				a[j+k] = c
			} else {
				var sum int64
				for _, v := range a {
					sum += int64(v)
				}
				fmt.Println(sum)
				return
			}
		}
		j = j + b
	}

	var sum int64
	for _, v := range a {
		sum += int64(v)
	}
	fmt.Println(sum)
}


Measured memory_bytes: 6912
#include <cstdio>  
#include <cstring>  
#include <algorithm>  
#include <queue>  
#include <iostream>  
#include <string>  
#include <cmath>  
#include <vector>  
#include <set>  
#include <map>  
#include <bitset>  
#include <stack>  
using namespace std;  
  
#define REP(i,n) for ( int i=1; i<=int(n); i++ )    
#define MP make_pair  
#define PB push_back  
#define SZ(x) (int((x).size()))  
#define ALL(x) (x).begin(), (x).end()  
#define X first  
#define Y second  
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }  
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }  
  
typedef long long LL;  
typedef long double LD;  
const int INF = 0x3f3f3f3f;
typedef pair<int, int> pii;
const int N = 10;
int c[N * 2];
pii p[N * 2];
char str[N * 2];
int main() {
	int n, m;
	cin >> n >> m;
	bool flag = 0;
	for(int i = 1; i <= n; i ++) {
		scanf("%s", str);
		for(int j = 0; str[j]; j ++) {
			if(str[j] == '#') {
				c[i + j] ++;
				if(c[i + j] > 1) flag = 1;
				p[i + j] = pii(i, j);
			}
		}
	}
	if(flag) puts("Impossible");
	else {
		for(int i = 2; i <= n + m - 1; i ++) {
			int val = abs(p[i].X - p[i - 1].X) + abs(p[i].Y - p[i - 1].Y);
			if(val != 1) flag = 1;
		}
		if(flag) puts("Impossible");
		else puts("Possible");
	}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back

using namespace std;
typedef long long int ll;

ll f(ll a[], ll n, ll b){
	ll r = 0;
	for (ll i = 0; i < n; ++i)
	{
		r += abs(a[i]-(i+1)-b);
	}
	return r;
}

int main(void){
	// #ifndef JUDGE
	// freopen("in.txt", "r", stdin);
	// #endif
	fast;
	ll n; cin >> n;
	ll a[n];
	for (int i = 0; i < n; ++i){
		cin >> a[i];
	}
	ll l = -1e9-1, r = 1e9+1;
	while (r-l>1){
		ll m = (l+r)/2;
		if (f(a, n, m) < f(a, n, m+1)) r = m;
		else l = m;
	}
	cout << f(a, n, l+1) << '\n';
}

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

int main(){
  long long N; cin >> N;
  
  if(N < 2 || N%2 == 1){
    cout << 0 << endl;
    return 0;
  }
  

  long long ans = 0;
  long long fivecount = 10;
  
  while(fivecount <= N){
    ans += N/fivecount;
    fivecount *= 5;  
  }
  
  cout << ans;
  

}

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

int N , M ;
int x , y ;
int table[11][2][2] ;
int Line[11][2]  ;
int dr[4][2] = {
	{ 0 , 1 } ,
	{ 1 , 0 } ,
	{ 0 , -1 } ,
	{ -1 , 0 }
} ;

int Dir( int a , int b ){
	if( a > b ) return 1 ;
	else if( a < b ) return -1 ;
	else return 0 ;
}

void Origin_Line(){
	cin >> M ;
	for( int i=0 ; i<M ; i++ ) cin >> Line[i][0] >> Line[i][1] ;
	
	for( int i=1 ; i<M ; i++ ){
		for( int j=0 ; j<4 ; j++ ){
			if( dr[j][0] == Dir( Line[i][0] , Line[i-1][0] ) &&
				dr[j][1] == Dir( Line[i][1] , Line[i-1][1] ) ){
					table[i][0][0] = j ;
					table[i][1][0] = max( abs(Line[i][0]-Line[i-1][0]) , abs(Line[i][1]-Line[i-1][1]) ) ;
					break ;
			}
		}
	}
	for( int i=M-2 ; i>=0 ; i-- ){
		for( int j=0 ; j<4 ; j++ ){
			if( dr[j][0] == Dir( Line[i][0] , Line[i+1][0] ) &&
				dr[j][1] == Dir( Line[i][1] , Line[i+1][1] ) ){
					table[M-i-1][0][1] = j ;
					table[M-i-1][1][1] = max( abs(Line[i][0]-Line[i+1][0]) , abs(Line[i][1]-Line[i+1][1]) ) ;
					break ;
			}
		}
	}
	
}

bool Check_Line(){
	int m ;
	cin >> m ;
	for( int i=0 ; i<m ; i++ ) cin >> Line[i][0] >> Line[i][1] ;
	
	if( M != m ) return 0 ;
	
	for( int k=0 ; k<4 ; k++ ){
		int cnt = 0 , t[11][2] = {} ;
		for( int i=1 ; i<m ; i++ ){
			for( int j=0 ; j<4 ; j++ ){
				if( dr[(j+k)%4][0] == Dir( Line[i][0] , Line[i-1][0] ) &&
					dr[(j+k)%4][1] == Dir( Line[i][1] , Line[i-1][1] ) ){
						t[i][0] = j ;
						t[i][1] = max( abs(Line[i][0]-Line[i-1][0]) , abs(Line[i][1]-Line[i-1][1]) ) ;
						break ;
				}
			}
		}
		for( int i=1 ; i<m ; i++ ){
			if( t[i][0] == table[i][0][0] && t[i][1] == table[i][1][0] ) cnt++ ;
		}
		if( cnt == M-1 ) return true ;
	}
	
	for( int k=0 ; k<4 ; k++ ){
		int cnt = 0 , t[11][2] = {} ;
		for( int i=m-2 ; i>=0 ; i-- ){
			for( int j=0 ; j<4 ; j++ ){
				if( dr[(j+k)%4][0] == Dir( Line[i][0] , Line[i+1][0] ) &&
					dr[(j+k)%4][1] == Dir( Line[i][1] , Line[i+1][1] ) ){
						t[i+1][0] = j ;
						t[i+1][1] = max( abs(Line[i][0]-Line[i+1][0]) , abs(Line[i][1]-Line[i+1][1]) ) ;
						break ;
				}
			}
		}
		for( int i=1 ; i<m ; i++ ){
			if( t[i][0] == table[i][0][1] && t[i][1] == table[i][1][1] ) cnt++ ;
		}
		if( cnt == M-1 ) return true ;
	}
	
	return false ;
}

main(){
	
	while( cin >> N  , N ){
		Origin_Line() ;
		
		for( int ans=1 ; ans<=N ; ans++ ){
			if( Check_Line() ) cout << ans << endl ;
		}
		cout << "+++++" << endl ;
	}
	
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const LL INF = (1ll<<31)-1;

class SegT{
private:
  int dat[2 * (1 << 17) - 1]; // = 131072
  int NN;

public:
  SegT(int n_){
	NN = 1;
	while(NN < n_) NN <<= 1;
	for(int i=0;i<2*NN-1;++i) dat[i] = INF;
  }

  // dat[idx] = a, 0-indexed
  void update(int idx, int a){
	idx += NN - 1;
	dat[idx] = a;
	while(idx > 0){
	  idx = (idx - 1) / 2;
	  dat[idx] = min(dat[idx*2+1], dat[idx*2+2]);
	}
  }

  // calc min of [a,b)
  int query(int a, int b, int k, int l, int r){
	// no intersect
	if(r <= a || b <= l) return INF;

	// completely contain
	if(a <= l && r <= b) return dat[k];
	else{
	  int vl = query(a, b, k*2+1, l, (l+r)/2);
	  int vr = query(a, b, k*2+2, (l+r)/2, r);
	  return min(vl, vr);
	}
  }
  int query(int a, int b){
	return query(a, b, 0, 0, NN);
  }
};

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

  int N, Q;
  cin >> N >> Q;
  SegT seg(N);
  while(Q--){
	int c, x, y;
	cin >> c >> x >> y;
	if(c == 0)
	  seg.update(x, y);
	else
	  cout << seg.query(x,y+1) << endl;
  }

  return 0;
}

Measured memory_bytes: 4196
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int N; cin>>N;
  string S; cin>>S;
  vector<int> W(N+2,0);
  REP(i,N) {
    W[i+1] = W[i];
    if(S[i] == '.') W[i+1]++;
  }
  int ans = 0;
  // 全部黒ににする                                                                
  ans =	W[N];
  //  cout << ans << endl;                                                               
  for(int i = 1; i <= N; i++) {
    int tmp1 = i - W[i];
    int	tmp2 = W[N] - W[i];
    ans	= min(ans, tmp1+tmp2);
    //    cout << i << " " << ans << " " << tmp1 << " " << tmp2  << endl;                
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 1412
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
  vector<int> a;
  int ptr=0;
  int tmp;
  while(cin>>tmp) a.push_back(tmp);
  stable_sort(a.begin(),a.end(),greater<int>());
  for(int i=0;i<a.size();++i) cout<<a[i]<<(i==a.size()-1?"":" ");
  cout<<endl;
  return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<int>;

#define rep(i, n)  for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define Sort(a)    sort(a.begin(), a.end())
#define gSort(a)   sort(a.begin(), a.end(), greater<int>())
#define pout(n, a) cout << fixed << setprecision(n) << (a)
#define Cast(dig, n) static_cast<std::bitset<(dig)>>(n)

const int INF = 2147483647;
const ll  MOD = 1000000007;

int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    ll ans = 0;

    if(a <= k) {
        ans += a;
        k -= a;
    }else {
        ans += k;
        cout << ans;
        return 0;
    }

    if(b <= k) {
        k -= b;
    }else {
        cout << ans;
        return 0;
    }

    if(c <= k) {
        ans -= c;
        k -= c;
    }else {
        ans -= k;
        cout << ans;
        return 0;
    }

    cout << ans;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main()
{
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<char>> field(h, vector<char>(w));
    P start;
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            cin >> field[i][j];
            if(field[i][j] == 'S') start = P(i, j);
        }
    }
    queue<P> que;
    int dis = min(start.first, start.second);
    dis = min(dis, min(h-1-start.first, w-1-start.second));
    if(dis == 0)
    {
        cout << 0 << endl;
        return 0;
    }
    que.push(start);
    vector<vector<int>> d(h, vector<int>(w, -1));
    d[start.first][start.second] = 0;
    vector<int> dx = {1, 0, -1, 0};
    vector<int> dy = {0, -1, 0, 1};
    while(!que.empty())
    {
        P p = que.front();
        que.pop();
        int x = p.first;
        int y = p.second;
        dis = min(dis, min(x, y));
        dis = min(dis, min(h-1-x, w-1-y));
        if(d[x][y] == k) continue;
        for(int i = 0; i < 4; i++)
        {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx >= 0 && nx < h && ny >= 0 && ny < w && field[nx][ny] == '.' && d[nx][ny] == -1)
            {
                que.push(P(nx, ny));
                d[nx][ny] = d[x][y] + 1;
            }
        }
    }
    if(dis == 0) cout << 1 << endl;
    else cout << (dis-1) / k + 2 << endl;
}


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(const T x,const T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD=1e9+7;
const int MAX=1e5+100;

int main() {
  int A,B;cin>>A>>B;
  FOR(i,1,4) {
    if (i!=A && i!=B) {
      OUT(i);
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
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; }

int main(){
  int k;
  string s;
  cin >> k;
  cin >> s;
  if(s.size() <=k)
    cout << s << endl;
  else {
    s= s.erase(k);
    s += "...";
    cout << s << endl;
  }
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(void){
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a <= k){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
    return 0;
}


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

int main(){
   int N;
   cin >> N;
   vector<int> H(N);
   for (int i=0; i<N; i++){
      cin >> H.at(i);
   }
   bool flag = true;
   int max = 0;
   for (int i=0; i<N-1; i++){
      if (H.at(i+1) >= H.at(i)){
         if (H.at(i)-1 >= max){
            max = H.at(i)-1;
         } else{
            max = H.at(i);
         }
      } else if (H.at(i+1) >= H.at(i)-1){
         if (H.at(i)-1 >= max){
            max = H.at(i)-1;
         } else{
            flag = false;
         }
      } else{
         flag = false;
      }
   }

   if (flag)
      cout << "Yes" << endl;
   else
      cout << "No" << endl;

}



Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>


#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define DOUT(obj,n) cout << fixed << setprecision(n) << obj << endl

#define PI 3.14159265359

using namespace std;
typedef long long unsigned int ll;

int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	ll len = a + b;
	cout << (n / len) * a + min(a, n % len);
	return 0;
}

Measured memory_bytes: 384
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 

	public static void main(String[] args) { //Write choose function for each k (0 <= k <= N-1)
		//Figure out why this even works to begin with (why no overcounting occurs)
		Scanner input = new Scanner(System.in);
		long N = input.nextLong();
		long M = input.nextLong();
		long K = input.nextLong();
		double START = System.nanoTime();
		long[][] fact = new long[(int) (N+1)][2]; //[Factorial][Inverse]
		fact[1][0]=1;
		fact[1][1]=1;
		long mod = 998244353;
		long baseCase = M;
		baseCase*=FastExp(M-1,N-1,mod);
		baseCase%=mod; //K=0 case
		long ans = baseCase;
		for (long i = 2; i <= N; i++) { //Pre-computing factorial and inverses
			fact[(int) i][0] = fact[(int) (i-1)][0]*i;
			fact[(int) i][0]%=mod;
			long inverse = FastExp(fact[(int) i][0],mod-2,mod);
			fact[(int) i][1] = inverse;
		}
		for (long i = 1; i <= K; i++) {
			if (K==N-1) {
				ans = FastExp(M,N,mod);
				break;
			}else {
				long curans = M; //M ways of making pairs same color
				long pairs = fact[(int) (N-1)][0];
				pairs*=fact[(int) i][1];
				pairs%=mod;
				pairs*=fact[(int)(N-i-1)][1]; //Choosing K pairs from N-1 adjacent pair slots
				pairs%=mod;
				curans*=pairs;
				curans%=mod; //Each pair has M possibilities
				//K pairs = K+1 slots used, therefore N-(K+1) = N-K-1 slots remain (1<=i<=K)
				long leftover = FastExp(M-1,N-i-1,mod);
				curans*=leftover;
				curans%=mod;
				ans+=curans;
				ans%=mod;
			}
		}
		System.out.println(ans);
		double END = System.nanoTime();
		double div = (double)(1e9);
		//System.out.println((END-START)/div);
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans = 1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			base*=base;
			base%=mod;
			ans%=mod;
			exp/=2;
		}
		return ans;
	}
}

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll INF = (1LL<<60);

int main(){

    ll a, b; cin >> a >> b;

    cout << 6-a-b << endl;

    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

int arr[] = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
             1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    cout << arr[N - 1] << endl;

    return 0;
}


Measured memory_bytes: 256
import numpy as np

MAX = 10**6+1
MOD = 10**9+7

fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX

def COMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD

def COM(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD


if __name__ == '__main__':
    x, y = map(int, input().split())
    if (x + y) % 3 != 0:
        res = 0
    else:
        n, m = map(int, np.linalg.solve([[1, 2], [2, 1]], [x, y]))
        if n < 0 and m < 0:
            res = 0
        else:
            COMinit()
            res = COM(n + m, n)
    print(res)


Measured memory_bytes: 134144
# Treasure Hunt
import math
x,y,pd = 0,0,-90
r,d = map(int, input().split(','))
while not (r == 0 and d == 0):
    x += r * math.cos(math.radians(-pd))
    y += r * math.sin(math.radians(-pd))
    pd += d
    r,d = map(int, input().split(','))
print(int(x))
print(int(y))


Measured memory_bytes: 7864
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}

int n,m;
vector<vector<int>> to;

signed main(){
	int n,m;
	cin>>n>>m;
	cout<<(n-1)*(m-1)<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[])
{
    
    int month, day, i;
    int monthdata[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    
    while (1) {
        scanf("%d %d", &month, &day);
        if (month == 0 || day == 0) {
            break;
        } else {
            
            for (i = 1; i < month; i++) {
                day += monthdata[i - 1];
            }
            
            switch (day % 7) {
                case 1:
                    printf("Thursday\n");
                    break;
                case 2:
                    printf("Friday\n");
                    break;
                case 3:
                    printf("Saturday\n");
                    break;
                case 4:
                    printf("Sunday\n");
                    break;
                case 5:
                    printf("Monday\n");
                    break;
                case 6:
                    printf("Tuesday\n");
                    break;
                default:
                    printf("Wednesday\n");
                    break;
            }
            
        }
    }
    
    return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string.h>
#include <cmath>

using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);++(i))

int h,w;

int c[10][10];

int sum[10];

int main()
{
	cin >> h >> w;
	rep(i,0,9) rep(j,0,9)
	{
		 cin >> c[i][j];
	}

	rep(i,0,h - 1) rep(i,0,w - 1)
	{
		int a;
		cin >> a;
		if(a != -1)
			sum[a]++;
	}

	rep(k,0,9) rep(i,0,9) rep(j,0,9)
		c[i][j] = min(c[i][j] , c[i][k] + c[k][j]);
	int result = 0;
	rep(i,0,9)
	{
		result += c[i][1] * sum[i];
	}
	cout << result << endl;
}

	


Measured memory_bytes: 256
MOD = 998244353
N, K = map(int, input().split())
LRs = []
sums = []
for _ in range(K):
    l, r = map(int, input().split())
    LRs.append([l, r])
    sums.append(1 if l <= 1 <= r else 0)

dp = [0] * (N * 2)
dp[1] = 1

for i in range(2, N+1):
    dp[i] = sum(sums) % MOD
    for k in range(K):
        l, r = LRs[k]
        sums[k] = (sums[k] + dp[i-l+1] - dp[i-r]) % MOD
print(dp[N])


Measured memory_bytes: 71696
def binary_search(l:list,a:int):
    #リストlからaの値のインデックスをサーチする。
    #二分探索を可能にするためにはリストlはソートされていなければならない。
    length = len(l)
    center = length//2
    low = 0
    high = length - 1
    while low <= high:
        if l[center] == a:
            return center
        elif l[center] < a:
            low = center + 1
        elif l[center] > a:
            high = center - 1

        center = (low + high) // 2
    return center


def main():
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    a_sums = [0] * (len(a) + 1)
    a_sums[0] = 0
    for i in range(len(a)):
        a_sums[i+1] = a_sums[i] + a[i]
    b_sums = [0] * (len(b)+1)
    b_sums[0] = 0
    for i in range(len(b)):
        b_sums[i+1] = b_sums[i] + b[i]
    #print(a_sums)
    #print(b_sums)
    mx = 0
    for i in range(len(a_sums)):
        if a_sums[i] > k:
            break
        b_take_ind = binary_search(b_sums,k-a_sums[i])
        if b_take_ind < 0:
            b_take = 0
        else:
            b_take = b_take_ind
        mx = max(mx,i + b_take)
    print(mx)


if __name__ == '__main__':
    main()


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

int main() {
    int N, M;
    cin>>N>>M;
    int k[M];
    int s[M][N];
    for(int i=0;i<M;++i){
        for(int j=0;j<N;++j){
            s[i][j] = -1;
        }
    }
    int p[M];
    for(int i=0;i<M;++i){
        cin>>k[i];
        for(int j=0;j<k[i];++j){
            cin>>s[i][j];
            s[i][j]--;
        }
    }
    for(int i=0;i<M;++i){
        cin>>p[i];
    }
    map<int, int> S;
    int ans = 0;
    bool tmp;
    int tmpnum;
    for(int bit=0;bit<(1<<N);++bit){
        tmp = true;
        for(int i=0;i<12;++i){
            S[i] = 0;
        }
        for(int i=0;i<N;++i){
            if(bit&(1<<i))S[i]++;
        }
        for(int i=0;i<M;++i){
            tmpnum = 0;
            for(int j=0;j<k[i];++j){
                if(S[s[i][j]])tmpnum++;
            }
            if(tmpnum%2!=p[i])tmp = false;
        }
        if(tmp)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

using ll = long long;

const int N = 3e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


bool DEBUG = 0;
#define debug(x) if (DEBUG) {cerr << #x << " = " << x << "\n";}
#define debug_vec(x) if (DEBUG) {cerr << #x << " = {"; for(auto a : x) cerr << a << ","; cerr << "}" << endl;}

#define int ll

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


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, a[N], cnt0[66], cnt1[66], ans;
main() {
    file("spainting");
    ios;
    cin >> n;
    fo(i, 1, n, 1) cin >> a[i];
    fo(i, 1, n, 1) {
        for (int j = 0; j < 62; ++j) {
            if ((a[i] >> j) & 1) {
                ans += ((1ll << j) % mod) * cnt0[j];
                ans %= mod;
                ++cnt1[j];
            } else {
                ans += ((1ll << j) % mod) * cnt1[j];
                ans %= mod;
                ++cnt0[j];
            }
        }
    }
    cout << ans;
    cerr << "\nTime elapsed: " << (clock() + 0.0) / CLOCKS_PER_SEC;
    return 0;
}
/**

*/


Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

namespace ConsoleAppAtCoderABC169
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = ReadLine().Split(' ').ToArray();
            var (a, b) = (long.Parse(ab[0]), double.Parse(ab[1]));

            var b100 = (long)((b + 0.0001) * 100);
            var ans = a * b100 / 100;

            WriteLine(ans);
        }
    }
}


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

long long n, k, ans, maxseg, l, r;
vector<long long>seg;
string s;

int main(){
	ans=0;
	maxseg=-1e9;
	cin >> n >> k >> s;
	long long tmp=1;
	for (int i=1;i<=n;i++){
		if (i==n || s[i]!=s[i-1]){
			seg.push_back(tmp);
			tmp=1;
		}
		else tmp++;
	}
//	for (long long i : seg) cout << i << " ";
//	cout << "\n";
	long long sez=seg.size();
	tmp=0;
	for (int i=0;i<sez;i++){
		tmp+=seg[i];
		if (i-k*2>0)tmp-=seg[i-k*2-1];
		if (tmp>maxseg){
			maxseg=tmp;
			l=i-k*2;
			r=i;
		}
	}
	ans+=maxseg-1;
	for (int i=0;i<sez;i++){
		if (i>=l && i<=r) continue;
		ans+=seg[i]-1;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
/* #pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/
typedef long long ll;
const ll MAXN = 1e6 + 5;
const ll MAXD = 1e3 + 5;
const ll MOD = 1e9 + 7;
const ll MODH = 1e9 + 9;
const ll p = 41;
const long double EPS = 1e-4;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll rand(ll a, ll b) {ll c = rng(); return a+((ll)abs(c))%(b-a+1);}

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


int l,r,d;
cin >> l >> r >> d;
cout << (r / d) - (l - 1) / d;

 
} 

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

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

  vector<int> A(N);
  bool flag = true;

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  for (int i = 0; i < N; i++) {
    if (A.at(i) % 2 == 0) {
      if (A.at(i) % 3 == 0 || A.at(i) % 5 == 0)
        continue;
      else
        flag = false;
      break;
    }
  }

  if (flag)
    cout << "APPROVED" << endl;
  else
    cout << "DENIED" << endl;
}

Measured memory_bytes: 256
import itertools

n,count=int(input()),0
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=[]

for i in itertools.permutations(range(1,n+1)):
  li = list(i)
  count += 1
  if li == a:
    ans.append(count)
  if li == b:
    ans.append(count)

print(abs(ans[1]-ans[0]))

Measured memory_bytes: 3064
A, B, C, D = map(int, input().split())


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    g = gcd(a, b)

    return a * (b // g)


def f(n):
    return n - n // C - n // D + n // lcm(C, D)


def main():
    print(f(B) - f(A - 1))
    return


main()


Measured memory_bytes: 3060
"""
必要十分条件
１）Sの中の同じ文字が、Tの別の文字に対応していない
２）Tの中の同じ文字が、Sの別の文字に対応していない
"""

s = input()
t = input()

dict_st = {}
dict_ts = {}

for x, y in zip(s, t):
    if x not in dict_st:
        dict_st[x] = y
    else:
        if dict_st[x] != y:
            print('No')
            break
    
    if y not in dict_ts:
        dict_ts[y] = x
    else:
        if dict_ts[y] != x:
            print('No')
            break
else:
    print('Yes')
    

Measured memory_bytes: 9400
<?php
fscanf(STDIN,"%d",$n);
$count['M']=0;
$count['A']=0;
$count['R']=0;
$count['C']=0;
$count['H']=0;
for ($i=0; $i < $n; $i++)
{
	fscanf(STDIN, "%s", $s[$i]);
	if($s[$i][0]=='M' || $s[$i][0]=='A' || $s[$i][0]=='R' || $s[$i][0]=='C' || $s[$i][0]=='H')
		$count[$s[$i][0]]++;
}

echo($count['M']*$count['A']*$count['R'] + $count['M']*$count['A']*$count['C'] + $count['M']*$count['A']*$count['H'] + $count['M']*$count['R']*$count['C'] + $count['M']*$count['R']*$count['H'] + $count['M']*$count['C']*$count['H'] + $count['A']*$count['R']*$count['C'] + $count['A']*$count['R']*$count['H'] + $count['A']*$count['C']*$count['H'] + $count['R']*$count['C']*$count['H']);


Measured memory_bytes: 14840
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> sum(n + 1, 0), v(n + 1, 0);
    rep(i, n)
    {
        sum[i + 1] = sum[i] + a[i];
        v[i + 1] = v[i] ^ a[i];
    }
    int ans = 0;
    rep(i, n)
    {
        int L = i + 1, R = n + 1;
        while (R - L > 1)
        {
            int mid = (L + R) / 2;
            int x = sum[mid] - sum[i];
            int y = v[mid] ^ v[i];
            if (x == y)
                L = mid;
            else
                R = mid;
        }
        //cout << L - i << endl;
        ans += (L - i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <queue>

typedef long long ll;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll x,y;
    cin >>x>>y;
    cout << x + y / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
def resolve():
	n, m = map(int, input().split())
	A = []
	B = []
	ans = False
	for _ in range(n):
		A.append(list(input()))
	for _ in range(m):
		B.append(list(input()))
	for i in range(n):
		for j in range(n):
			if i + m - 1 >= n or j + m - 1 >= n:
				continue
			tmp_ans = True
			for k in range(m):
				for l in range(m):
					if A[i+k][j+l] != B[k][l]:
						tmp_ans = False
						break
			if tmp_ans:
				ans = 'Yes'


	if ans:
		print('Yes')
	else:
		print('No')
resolve()

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

typedef struct Node{
  int value, priority;
  Node *left, *right;
} Node;

Node* Delete(Node *, int);
Node* _delete(Node *, int);

Node *NIL, *root;

Node* rightRotate(Node *t){
  Node *s = t->left;
  t->left = s->right;
  s->right = t;
  return s; // root of the subtree
}

Node* leftRotate(Node *t){
  Node *s = t->right;
  t->right = s->left;
  s->left = t;
  return s; // root of the subtree
}

Node* makenode(int key, int priority){
  Node *node = (Node *)malloc(sizeof(Node));
  node->value = key;
  node->priority = priority;
  node->left = node->right = NIL;

  return node;
}

Node* insert(Node *t, int key, int priority){    // 再帰的に探索
  Node *x;

  if(t == NIL) return x = makenode(key, priority); // 葉に到達したら新しい節点を生成して返す

  if(key == t->value) return t;                // 重複したkeyは無視

  if(key < t->value){                          // 左の子へ移動
      t->left = insert(t->left, key, priority); // 左の子へのポインタを更新
      if(t->priority < t->left->priority) t = rightRotate(t); // 左の子の方が優先度が高い場合右回転
  }else{                                       // 右の子へ移動
      t->right = insert(t->right, key, priority); // 右の子へのポインタを更新
      if(t->priority < t->right->priority) t = leftRotate(t); // 右の子の方が優先度が高い場合左回転
  }

  return t;
}

Node* find(Node *x, int k){
  if(x == NIL || x->value == k) return x;

  if(k < x->value) return find(x->left, k);
  else return find(x->right, k);
}

Node* Delete(Node *t, int key){
  if(t == NIL) return NIL;
  if(key < t->value) t->left = Delete(t->left, key); // 削除対象を検索
  else if(key > t->value) t->right = Delete(t->right, key);
  else return _delete(t, key);
  return t;
}

Node* _delete(Node *t, int key){ // 削除対象の節点の場合
  if(t->left == NIL && t->right == NIL) return NIL; // 葉の場合
  else if(t->left == NIL) t = leftRotate(t);   // 右の子のみを持つ場合左回転
  else if(t->right == NIL) t = rightRotate(t); // 左の子のみを持つ場合右回転
  else{                                        // 左の子と右の子を両方持つ場合
    if(t->left->priority > t->right->priority) t = rightRotate(t); // 優先度が高い方を持ち上げる
    else t = leftRotate(t);
  }
  return Delete(t, key);
}

void preParse(Node *node){
  if(node == NIL) return ;

  cout << " " << node->value;
  if(node->left != NIL) preParse(node->left);
  if(node->right != NIL) preParse(node->right);
}

void inParse(Node *node){
  if(node == NIL) return ;

  if(node->left != NIL) inParse(node->left);
  cout << " " << node->value;
  if(node->right != NIL) inParse(node->right);
}

int main(){

  int n, key, priority;
  string command;

  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> command;
    if(command == "insert"){
      cin >> key >> priority;
      root = insert(root, key, priority);
    }else if(command == "print"){
      inParse(root);
      cout << endl;
      preParse(root);
      cout << endl;
    }else if(command == "find"){
      cin >> key;
      if(find(root, key)) cout << "yes" << endl;
      else cout << "no" << endl;
    }else if(command == "delete"){
      cin >> key;
      root = Delete(root, key);
    }
  }

  return 0;
}



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

int main()
{
  int N;scanf("%d",&N);
  vector<int> B(N);B[N-1]=100000;
  for(int i=0;i<N-1;i++)scanf("%d ",&B[i]);
  int ans=B[0];
  for(int i=1;i<N;i++)
  {
    int Ai=min(B[i],B[i-1]);
    ans+=Ai;//cout<<"I"<<i<<"Ai"<<Ai;
  }
  printf("%d\n",ans);
}

Measured memory_bytes: 3732
#include <iostream>
#include <cstdio>
#include <queue>

using namespace std;

typedef long long ll;
ll n, mx = -4e18;
ll a[300005];
ll b[300005];
ll c[300005];
priority_queue<ll> pq2;
priority_queue<ll, vector<ll>, greater<ll> > pq1;

int main()
{
    scanf("%lld", &n);
    for(ll i = 0; i < n * 3; i++)
    {
        scanf("%lld", &a[i]);
    }
    for(ll i = 0; i < n; i++)
    {
        pq1.push(a[i]);
        b[n - 1] += a[i];
    }
    for(ll i = n; i < n * 3; i++)
    {
        b[i] = b[i - 1] + a[i];
        pq1.push(a[i]);
        b[i] -= pq1.top();
        pq1.pop();
    }
    for(ll i = 0; i < n; i++)
    {
        ll j = n * 3 - 1 - i;
        pq2.push(a[j]);
        c[n * 2] += a[j];
    }
    for(ll i = n; i < n * 3; i++)
    {
        ll j = n * 3 - 1 - i;
        c[j] = c[j + 1] + a[j];
        pq2.push(a[j]);
        c[j] -= pq2.top();
        pq2.pop();
    }
    for(ll i = n - 1; i < n * 2; i++)
    {
        mx = max(mx, b[i] - c[i + 1]);
    }
    printf("%lld", mx);
    return 0;
}


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

import numpy as np

n, k = map(int, input().split())
*v, = map(int, input().split())

v = np.array(v)

ans = 0
if n <= k:
    ans = v[v>0].sum()
else:
    for i in range(k+1):
        for j in range(k-i+1):
            if j == 0:
                take = v[0:i]
            else:
                take = np.append(v[0:i], v[-j:])
            take.sort()
            throw_num = k-i-j
            throw_num = min(throw_num, len(take[take<0]))
            su = take[throw_num:].sum()
            if su > ans:
                ans = su
print(ans)
        

Measured memory_bytes: 12508