akhauriyash/Code-Regression huggingface dataset:
from collections import deque


class Bt(object):
    def __init__(self):
        self.used = [False] * 10  # 0-9????????°???????????¨?????????????????????????????°
        self.answers = []  # ?????¶???????????????????????????
        self.Q = deque()  # ????????§???????????¢??????????????°???????¨???¶??¨

    def solve(self, num, remain):
        # ????´¢??????????°??????§?????????????????????????????§????????????????????§????????°??????????????????????????????
        try:
            min_choice = max(self.Q) + 1
        except ValueError:
            min_choice = 0

        if min_choice <= remain < 10 and self.used[remain] == False and num == 1:
            #self.Q.append(remain)
            #print('{0}'.format(self.Q))
            #ans = [*self.Q]
            #ans.sort()
            #if not ans in self.answers:
            #    self.answers.append(ans)
            #self.Q.pop()
            self.answers.append(1)
            return
        elif num < 0:
            return

        for i in range(min_choice, 10):
            if self.used[i] == False and (remain - i) >= 0:
                self.used[i] = True
                self.Q.append(i)
                self.solve(num - 1, remain - i)
                self.used[i] = False
                self.Q.pop()


if __name__ == '__main__':
    while True:
        # ??????????????\???
        n, s = [int(x) for x in input().split(' ')]
        if n == 0 and s == 0:
            break

        if 0 <= s <= 45:
            # ????????????
            a = Bt()
            a.solve(n, s)

            # ???????????¨???
            print(len(a.answers))
        else:
            print(0)

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

using namespace std;

int main() {
	int N;
	bool jikan[100][10];
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> jikan[i][j];
		}
	}
	int nedan[100][11];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= 10; j++)cin >> nedan[i][j];
	}
	int ans = -1145141919, ct = 0;
	for (int i = 1; i < (1 << 10); i++) {
		int tmp = 0;
		for (int j = 0; j < N; j++) {
			int c = 0;
			for (int k = 0; k < 10; k++) {
				if ((i >> k) & 1 && jikan[j][k])c++;
			}
			tmp += nedan[j][c];
		}
		ans = max(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<string>

using namespace std;
#define ll long long

int main(){
    ll N;
    ll a, b, sum = 0;
    cin >> N;
    vector<ll> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
        A[i] = 2*A[i];
        if(i%2 ==0){
            sum += A[i];
        }else{
            sum -= A[i];
        }
    }
    for(int i = 0; i < N; i++){
        cout << sum / 2 << " ";
        sum = -sum + 2*A[i]; 
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
int n, m;
vector< vector< int > > edg;
vector< int > d;
int main(void){
    cin >> n >> m;
    edg.assign(n+1, vector<int>());
    for(int i=0;i<m;i++){
        int a, b;
        cin >> a >> b;
        edg[a].push_back(b);
        edg[b].push_back(a);
    }
    d.assign(n+1, -1);
    d[1] = 0;
    queue<int> q;
    q.push(1);
    while(!q.empty()){
        int v = q.front();
        q.pop();
        for(int w: edg[v]) if(d[w] == -1){d[w] = v; q.push(w);}
    }
    puts("Yes");
    for(int i=2;i<=n;i++) cout << d[i] << endl;
}


Measured memory_bytes: 9752
#include <vector>
#include <climits>
#include <algorithm>
#include <iostream>
using namespace std;

template <typename T> class Segment_Tree {
private:
    int n;
    std::vector<T> SegTree;

public:
    Segment_Tree(int n_) {
	n = 1;
	while( n < n_ )  n *= 2;
	SegTree = std::vector<T>(2*n-1, INT_MAX);
	for(int i=0; i<2*n-1; i++) SegTree[i] = INT_MAX;
    }
    
    void update(int k, T a) {
	k += n - 1; // ??????index
	SegTree[k] = a;
	while( k > 0 ) { // ????????§?????????????????´??°
	    k = (k-1) / 2;
	    SegTree[k] = min(SegTree[k*2+1], SegTree[k*2+2]); // ?????????????°????
	}
    }

    T range_query(int a, int b) { // [a,b)?????????????§£
	return query(a,b,0,0,n);
    }

    // [a,b)???????°????????±?????????¢??°
    // k:?????????index???l,r:????????????????????????????????????[l,r)
    // ?????£?????????????????? query(a,b,0,0,n) ????????¶
    T query(int a, int b, int k, int l, int r) {
	if( r <= a or  b <= l ) return INT_MAX;    // ?????????????????§??????
	if( a <= l and r <= b ) return SegTree[k]; // [a,b)???[l,r)????????¨???????????????????????´???

	T vl = query(a,b,k*2+1,l,(l+r)/2);
	T vr = query(a,b,k*2+2,(l+r)/2,r);
	return min(vl,vr);
    }

    void dump() {
	cout << "Tree : ";
	for( int i=0; i<n; i++ )
	    cout << SegTree[i] << " ";
	cout << endl;
    }
};



int main() {

    int n,q;
    cin >> n >> q;
    Segment_Tree<long long > seg(n);

    for( int i=0; i<q; i++ ) {
	long long c,x,y; cin >> c >> x >> y;
	if(c == 0)
	    seg.update((int)x,y);
	else
	    cout << seg.range_query((int)x,(int)y+1) << endl;
    }
}

Measured memory_bytes: 7064
#include <queue>
#include <cstdio>
#include <algorithm>
using namespace std;
void reader(int *x) {
	int k = getchar_unlocked(); *x = k - '0';
	while (1) {
		k = getchar_unlocked();
		if (k < '0' || k > '9') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}
struct state {
	int sx, sy, cost;
};
bool operator<(const state& s1, const state& s2) {
	return s1.cost < s2.cost;
}
int R, H[2], W[2], sx[2], sy[2], a[2][509][509], cnt[2], b[2][250009]; bool vis[509][509];
int dir[] = { 0, 1, 0, -1 };
int main() {
	while (scanf("%d", &R), R) {
		for (int i = 0; i < 2; i++) {
			scanf("%d%d%d%d", &W[i], &H[i], &sy[i], &sx[i]); sy[i]--, sx[i]--;
			for (int j = 0; j < H[i]; j++) {
				for (int k = 0; k < W[i]; k++) {
					reader(&a[i][j][k]);
					vis[j][k] = false;
				}
			}
			priority_queue<state> que; que.push(state{ sx[i], sy[i], -1 });
			vis[sx[i]][sy[i]] = true; cnt[i] = 1;
			while (!que.empty()) {
				state u = que.top(); que.pop();
				b[i][cnt[i]++] = a[i][u.sx][u.sy];
				for (int j = 0; j < 4; j++) {
					int tx = u.sx + dir[j], ty = u.sy + dir[j ^ 1];
					if (0 <= tx && tx < H[i] && 0 <= ty && ty < W[i] && !vis[tx][ty]) {
						a[i][tx][ty] = max(a[i][tx][ty], a[i][u.sx][u.sy]);
						vis[tx][ty] = true;
						que.push(state{ tx, ty, -a[i][tx][ty] });
					}
				}
			}
		}
		int ret = 2000000009;
		for (int i = 0; i <= H[0] * W[0]; i++) {
			int z = max(R - i, 0);
			if (z > H[1] * W[1]) continue;
			ret = min(ret, b[0][i] + b[1][z]);
		}
		printf("%d\n", ret);
	}
	return 0;
}

Measured memory_bytes: 7188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PAIR;
const int N = 1e3+5;
const int INF = 0x3f3f3f3f;

int main(){
	int x,y,z;
	cin >> x >> y >> z;
	swap(x,y);
	swap(x,z);
	printf("%d %d %d\n",x,y,z);
    return 0;
}


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

struct Scanner<'a> {
    cin : StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin : StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main(){
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    loop {
        let r0: i32 = sc.read();
        let w0: i32 = sc.read();
        let c: i32 = sc.read();
        let r: i32 = sc.read();
        if r0 == 0 { break; };
        println!("{}", if w0 * c <= r0 { 0 } else { (w0 * c - r0 - 1) / r + 1});
    }
}



Measured memory_bytes: 5028
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

#define rep(i,n) for(int i=0; i < n; i++)
using ll =  long long;
using namespace std;
#define pi 3.14159265358979

int main()
{
	ll ans, n, a, b;							// 入力nの条件が10^18より long longにした
	cin >> n >> a >> b;							// 入力を受け取る

	ans = (n / (a + b)) * a;					// 割り切れた数 × 青ボールの数(a) は入っている
	if (n % (a + b) > a) ans += a;				//余りの中の青ボールを足す
	else				 ans += n % (a + b);

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rlcfpoj(x) scanf("%I64d",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define plcfpoj(x) printf("%I64d",x)
#define lfd() printf("\n")
#define sp() printf(" ")
#define inrep(x) int x;scanf("%d",&x);while(x--)
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
int cnt[100100];
vector<int> ga[100100];
vector<int> vt;
int wtsd;
int n,u,v;
void dfs(int u,int p){
	cnt[u]=1;
	vt.push_back(u);
	if(u==n){
		wtsd=vt[(vt.size()+1)/2];
	}
	for(int i=0;i<ga[u].size();i++){
		int v=ga[u][i];
		if(v!=p){
			dfs(v,u);
			cnt[u]+=cnt[v];
		}
	}
	vt.pop_back();
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<n;i++){
		cin>>u>>v;
		ga[u].push_back(v);
		ga[v].push_back(u);
	}
	dfs(1,0);
	int snuke=cnt[wtsd];
	int fennec=n-snuke;
	if(fennec>snuke)
		cout<<"Fennec"<<endl;
	else
		cout<<"Snuke"<<endl;
	return 0;
}


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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        string s = sc.Next();
        string t = "CODEFESTIVAL2016";

        long answer = 0;

        for (int i = 0; i < 16; i++)
        {
            if (s[i] != t[i])
            {
                answer++;
            }
        }

        Console.WriteLine(answer);

    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 25860
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define llu unsigned long long int
#define sa(a,n,t) for(int ii=0;ii<n;ii++) scanf("%"#t"",&(a)[ii])
#define rep(i,n) for(int i=0;i<n;i++) 
#define reps(i,a,n) for(int i=a;i<n;i++) 
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rreps(i,a,n) for(int i=n-1;i>=a;i--)
#define validl(i,a,b) ((i>=a)&&(i<=b))?1:0
#define validmat(x,y,a,b,c,d) (validl(x,a,b) && validl(y,a,b))?1:0
#define validmn(x,y,m,n) validmat(x,y,0,m,0,n)
#define valid(i,n) validl(i,0,n)
#define v(t) vector<t>
#define vv(t) vector<vector<t> >
#define mk make_pair
#define pb push_back
#define pa(a,n,t)  for(int i=0;i<n;i++) printf("%"#t"",a[i])
#define p2 pair<int,int>
#define p3 pair<p2,int>
#define fi first
#define se second
#define sd(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld",a)
#define pd(a) printf("%d",a)
#define sf(a) scanf("%lf",&a)
#define pf(a) printf("%lf",a)
#define nline printf("\n")
#define ss(a) scanf("%s",a)
#define ps(a) printf("%s",a)
#define sc(a) scanf("%c",&a)
#define pc(a) printf("%c",&a)
#define mf(m,f) m.find(f)!=m.end()
#define pp3(m) cout<<m.fi.fi<<" "<<m.fi.se<<" "<<m.se<<" "
#define pp2(m) cout<<m.fi<<" "<<m.se<<" "
#define debug 0
/*v(int) adj[200001];
void dfs(int i,int p){
    rep(j,adj[i].size()){
        if(p!=adj[i][j])
            dfs(adj[i][j],i);
    }
}*/
int main()
{
    int n;
    int arr[200001]={0};
    int a,b;
    int sum=0;
  cin>>n;
  rep(i,n) cin>>arr[i],sum^=arr[i];
  rep(i,n) cout<<(sum^arr[i])<<" ";
  cout<<endl;
}


Measured memory_bytes: 4376
#1問目
N = int(input())
A = list(map(int, input().split()))
color = [0,0,0,0,0,0,0,0]
overColor = 0
Min = 0
Max = 0

for i in range(N):
    if 1 <= A[i] <= 399:
        color[0] += 1
    elif 400 <= A[i] <= 799:
        color[1] += 1
    elif 800 <= A[i] <= 1199:
        color[2] += 1
    elif 1200 <= A[i] <= 1599:
        color[3] += 1
    elif 1600 <= A[i] <= 1999:
        color[4] += 1
    elif 2000 <= A[i] <= 2399:
        color[5] += 1
    elif 2400 <= A[i] <= 2799:
        color[6] += 1
    elif 2800 <= A[i] <= 3199:
        color[7] += 1
    else:
        overColor += 1

count = 0
for i in range(8):
    if(color[i] > 0):
        count+=1

if(overColor == 0):
    print(str(count) + " " + str(count))
else:
    if(count == 0):
        print("1 " + str(overColor))
    else:
        print(str(count) + " " + str(count + overColor))

Measured memory_bytes: 3064
s = input().strip().replace('BC', 'D')
n = len(s)

count = 0
a_count = 0
for i in range(n):
  if s[i] == 'A':
    a_count += 1
  elif a_count > 0 and s[i] == 'D':
    count += a_count
  else:
    a_count = 0

print(count)

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back

using namespace std;

// #define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline void chmax(T& a,T const& b){a=max(a,b);}
template<class T> inline void chmin(T& a,T const& b){a=min(a,b);}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<29;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<59; 

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H,W; cin >> H >> W ;
  vvi d(10,vi(10));
  rep(i,10) rep(j,10) cin >> d[i][j] ;
  rep(k,10) rep(i,10) rep(j,10) d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
  vi cnt(10);
  rep(i,H*W){
    int a; cin >> a ;
    if(a==-1) continue;
    cnt[a]++;
  }
  int ans = 0;
  rep(i,10) ans += cnt[i] * d[i][1];
  cout << ans << endl;
  return 0;
}

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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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


int main(void){
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<string> vec(n);
  REP(i, n) cin >> vec[i];
  sort(vec.begin(), vec.end());
  vec.erase( unique(vec.begin(), vec.end()), vec.end() );
  int ans = vec.size();
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 9596
#include<iostream>

using namespace std;

// consider the inversion of the operation.
// let the final standing be 0, ..., N-1
// then for N rounds, it will be 1, ..., N
// for r rounds, it will be N-r+1, ..., N(index r-1), -r, ..., -r

const int N = 50;
long long a[N];

int main() {
    long long K;
    cin>>K;
    if (K == 0) {
        //cout<<1<<endl; // N \ge 2 must hold
        //cout<<0<<endl;
        //return 0;
    } 
        cout<<N<<endl;
        for (int i = 0; i < N; ++i)
            a[i] = i;
        long long q = K / N;
        int r = K % N;
        for (int i = 0; i < r; ++i) {
            a[i] += N - r + 1;            
        }
        for (int i = r; i < N; ++i) {
            a[i] -= r;
        }
        for (int i = 0; i < N; ++i) {
            cout<<a[i]+q<<" ";            
        }
        cout<<endl;
   
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<ll(n); i++)

int main(){
    ll A, B, C, K;
    cin >> A >> B >> C >> K;

    ll ans = 0;
    int i;
    if(K <= A){ans += K;}
    else if(K <= (A + B)){ans += A;}
    else{ans += A; ans += (A + B - K);}

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3172
n = int(input())
ame = [[int(i) for i in input().split()] for i in range(2)]
road1 = [0]
road2 = [0]

for i in range(n):
    road1.append(ame[0][i] + road1[i]) # 累積和の表を作った
for i in range(n):
    road2.append(ame[1][i] + road2[i])
ans = 0
if n == 1:
    print(road1[1] + road2[1])
    exit()
else:
    for i in range(1, n):
        tmp = road1[i] - road1[0] + road2[n] - road2[i - 1]
        if tmp > ans:
            ans = tmp
print(ans)

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

int main()
{
  string S;
  cin>>S;
  int count=0,flag=0;
  for(int i=0;i<S.length();i++)
  {
    if(S[i]==S[i+1]&&(i==2||i==4))
    {
      count++;
      flag++;
    }
  }
  if(count==2&&flag==2)
       cout<<"Yes"<<endl;
  else
       cout<<"No"<<endl;
}

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

using namespace std;
int main(){
	int a,b,c,d;
	cin>>a;
	cin>>b;
	cin>>c;
	cin>>d;
	cout<<min(a,b)+min(c,d);
	return 0;	
}

Measured memory_bytes: 256
#include<map>
#include<queue>
#include<cmath>
#include<bitset>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=400;
int n,cnt[10],x;
double f[maxn][maxn][maxn];
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		cnt[x]++;
	}
	for(int i=0;i<=n;i++)
		for(int j=0;j<=n;j++)
			for(int k=0;k<=n;k++){
				if(i+j+k>n||!(i+j+k)) continue;
				double d=i+j+k;
				if(k) f[i][j][k]=f[i][j][k-1]*k/d;
				if(j) f[i][j][k]+=f[i][j-1][k+1]*j/d;
				if(i) f[i][j][k]+=f[i-1][j+1][k]*i/d;
				f[i][j][k]+=n/d;
			}
	printf("%.11lf\n",f[cnt[3]][cnt[2]][cnt[1]]);
	return 0;
}


Measured memory_bytes: 376704
import java.io.*
import java.util.*
import kotlin.math.*

fun main(){
	val f = BufferedReader(InputStreamReader(System.`in`))


	val n = f.readLine().toInt()

	if(n%2 == 0){
		println(-1)
	} else {
		var i = (7+n)%n
		var answer = 1
		var found = false
		for(k in 1 until 1000005){
			if(i%n == 0){
				println(k)
				found = true
				break
			}

			i = (i*10+7+n)%n
		}

		if(!found) println(-1)
	}


}


Measured memory_bytes: 34168
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,x,ans;
	cin>>a>>b>>c>>x;
	for(int i=0;i<=a;i++)
	{
		for(int j=0;j<=b;j++)
		{
			for(int k=0;k<=c;k++)
				if(i*500+j*100+k*50==x)	ans++;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
int main() {
  int a, b;
  cin >> a >> b;
  if(a > b){
    rep(i, a) cout << b;
  }else {
    rep(i, b) cout << a;
  }
  return 0;
}

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

def main():
    N = int(input())
    H = list(map(int, input().split()))
    
    n = 0
    maxN = 0

    for i in range(1, N):
        if H[i-1] >= H[i]:
            n += 1
            maxN = max(maxN, n)
        else:
            n = 0

    print(maxN)






if __name__ == '__main__':
    main()


Measured memory_bytes: 14252
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;

public class Main{
	public static void main(String[] args)
	{
		Scanner sc =new Scanner(System.in);
		int n=sc.nextInt();
		int l=sc.nextInt();
		String str[]=new String[n];

		for(int i=0;i<n;i++)
		{
			//文字列読み取り
			str[i]=sc.next();
		}

		Arrays.sort(str);
		for (int i=0;i<n;i++) {
			System.out.print(str[i]);
		}
		System.out.println();
	}
} 

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <cstring>
#include <algorithm>
#include <set>
#include <climits>
#include <numeric>

//usings
using namespace std;

//type def
typedef long long int64;
typedef pair<int, int> ii;

//consts
const int mod = 1e9 + 7;

//methods
template<typename T>
bool chmax(T& source, const T& compare_to) {
    if(source < compare_to) {
        source = compare_to;
        return true;
    }
    return false;
}

int modpow(int64 base, int n) {
    int64 ret = 1;
    while(n) {
        if(n & 1) ret = ret * base % mod;
        base = base * base % mod;
        n >>= 1;
    }
    return ret;
}

class Solution {
private:
    
public:
    int64 solve(int n, int k) {
        vector<int64> dp(k + 1);
        for(int i = k; i; --i) {
            auto& cur = dp[i];
            cur = modpow(k / i, n);
            //cout << "i: " << i << ", k/i: " << k / i << ", val: " << cur << endl;
            for(int j = 2; i * j <= k; ++j) {
                cur = (cur + mod - dp[i * j]) % mod;
            }
        }
        int64 ret = 0;
	    for(int i = 1; i <= k; ++i) {
            ret = (ret + i * dp[i]) % mod;
        }
        return ret;
    }
};

int main() {
    
    int n, k;
    cin >> n >> k;
    
    Solution sol;
    auto ret = sol.solve(n, k);
    cout << ret << endl;
}

Measured memory_bytes: 3948
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void solve() {
	ll n, d;
	cin >> n >> d;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ll x, y;
		cin >> x >> y;
		if (x * x + y * y <= d * d)
			ans++;
	}
	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << endl;
	}
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <valarray>
#include <iterator>
#include <stack>
#include <set>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <list>
#include <map>

#define def(type,vec) vector<type> vec
#define last(arr) arr.size()-a
#define loop(i,n) for(ll i=0 ; i<n ; ++i)
#define all(v) ((v).begin()),((v).end())
#define pb push_back
#define ll long long
#define iteloop(type,data,name,it) for(type<data>::iterator it=name.begin() ;it!=name.end() ; ++it)

using namespace std;

int main(){
    int n,k;
    string str;
    cin>>n>>k;
    multiset<string> mulst;
    loop(i,n){
        cin>>str;
        mulst.insert(str);
    }
    iteloop(multiset,string,mulst,it){
        cout<<*it;
    }
}



Measured memory_bytes: 256
main :: IO ()
main = do
    [a, b] <- map read . words <$> getLine :: IO [Int]
    print $ solve a b

solve :: Int -> Int -> Int
solve a b =  length
            $ filter isP [a..b]
  where
    isP n = let s = show n in
                go (length s `div` 2) s (reverse s)
    go 0 _ _ = True
    go n (c1:s1) (c2:s2)
        | c1 == c2 = go (n-1) s1 s2
        | otherwise = False


Measured memory_bytes: 1020
a,b,c = map(int,input().split())
k=int(input())

count=0
while True:
    if a>=b:
        b*=2
        count+=1
    else:
        break
while True:
    if b>=c:
        c*=2
        count+=1
    else:
        break
if count<=k:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61664
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define files(name) name!=""?freopen(name".in","r",stdin),freopen(name".out","w",stdout):0
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define elif else if
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
 
using namespace std;
#define int long long
 
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;
 
const int arr=2e5+10;
const int ar=2e3+10;
const ld pi=acos(-1);
const ld eps=1e-10;
const ll md=1e9+7;
const ll inf=1e18+10;
 
///---program start---///

int n,k;
int a[arr];
vi reb[arr];

int dfs(int now,int& ans)
{
    int res=0;
    for (auto wh:reb[now]){
        int cur_res=dfs(wh,ans);
        if (cur_res==k-1&&now!=1){
            cur_res=-1;
            ans++;
        }
        res=max(res,cur_res+1);
    }
    return res;
}

main()
{
    #ifdef Barik
        files("barik");
        freopen("debug.txt","w",stderr);
    #endif
    
    cin>>n>>k;
    for (int i=1;i<=n;i++){
        cin>>a[i];
    }
    int ans=0;
    ans+=(a[1]!=1);
    for (int i=2;i<=n;i++){
        reb[a[i]].pb(i);
    }
    
    dfs(1,ans);
    cout<<ans<<"\n";
}




Measured memory_bytes: 14208
#include <iostream>

int main(){
    int R,G,B,N;
    std::cin>>R>>G>>B>>N;
    int ans=0;
    for(int i=0;i<=N;++i){
        for(int j=0;j<=N;++j){
            if( (N-i*R-G*j)>=0 && (N-i*R-G*j)%B==0) ans+=1;
        }

    }
    std::cout<<ans<<std::endl;


}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    a = LIR(3)
    n = I()
    b = IR(n)
    f = defaultdict(lambda : 0)
    for i in b:
        f[i] = 1
    for i in range(3):
        m = 0
        for j in range(3):
            m += f[a[i][j]]
        if m == 3:
            print("Yes")
            return
        m = 0
        for j in range(3):
            m += f[a[j][i]]
        if m == 3:
            print("Yes")
            return
    m = 0
    for j in range(3):
        m += f[a[j][j]]
    if m == 3:
        print("Yes")
        return
    m = 0
    for j in range(3):
        m += f[a[-1-j][j]]
    if m == 3:
        print("Yes")
        return
    print("No")
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<ctime>
#include<set>
#include<queue>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);++(i))
#define fd1(i,n) for ((i)=(n);(i)>=1;--(i))
#define fz0g(i,n) for ((i)=0;(i)<=(n);++(i))
#define fd0g(i,n) for ((i)=(n);(i)>=0;--(i))
#define fz0k(i,n) for ((i)=0;(i)<(n);++(i))
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;--(i))
#define fz(i,x,y) for ((i)=(x);(i)<=(y);++(i))
#define fd(i,y,x) for ((i)=(y);(i)>=(x);--(i))
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
using namespace std;
const int mod=998244353;
int n,m,i,j,a[300005],dep[300005],pre[300005],dp[300005][3][3],f[3][3],mx,mxd,rt;
vector<int> bi[300005],seq;
void dfs1(int x,int fa)
{
	if(dep[x]>mx){
		mx=dep[x];
		mxd=x;
	}
	ff(bi[x],it){
		if(*it==fa) continue;
		dep[*it]=dep[x]+1;
		pre[*it]=x;
		dfs1(*it,x);
	}
}
void dfs2(int x,int fa)
{
	if(dep[x]==seq.size()/2) dp[x][1][1]=1; else dp[x][0][0]=1;
	ff(bi[x],it){
		if(*it==fa) continue;
		dep[*it]=dep[x]+1;
		dfs2(*it,x);
		memset(f,0,sizeof(f));
		int a,b,c,d,i;
		fz0k(a,3)fz0k(b,3){
			fz0k(c,3)fz0k(d,3){
				fz0k(i,3){
					int na=min(2,a+c*(i==1));
					int nb=min(2,b+d*(i==2));
					f[na][nb]=(f[na][nb]+1ll*dp[x][a][b]*dp[*it][c][d])%mod;
				}
			}
		}
		memcpy(dp[x],f,sizeof(f));
	}
}
int main()
{
	scanf("%d",&n);
	fz1(i,n-1){
		int x,y;
		scanf("%d%d",&x,&y);
		bi[x].push_back(y);
		bi[y].push_back(x);
	}
	mx=mxd=-1;
	dfs1(1,0);
	dep[mxd]=0;
	mx=-1;
	dfs1(rt=mxd,0);
	int x=mxd;
	while(x!=rt){
		seq.push_back(x);
		x=pre[x];
	}
	seq.push_back(x);
/*	ff(seq,it){
		cerr<<*it<<' ';
	}cerr<<endl;*/
	if(seq.size()&1){
		int x=seq[seq.size()/2];
		dep[x]=0;
		dfs2(x,0);
		printf("%lld\n",1ll*dp[x][1][1]*(mod+1)/2%mod);
	}
	else{
		int x=seq[seq.size()/2-1],y=seq[seq.size()/2];
		dep[x]=dep[y]=1;
		dfs2(x,y);dfs2(y,x);
		printf("%lld\n",(0ll+dp[x][1][0]+dp[x][1][1]+dp[x][1][2])*(0ll+dp[y][1][0]+dp[y][1][1]+dp[y][1][2])%mod);
	} 
	return 0;
}

Measured memory_bytes: 31740
#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);
    int x[20][20], y[20][20];
    rep(i, n)
    {
        cin >> a[i];
        rep(j, a[i])
        {
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }
    int ans = 0;
    rep(I, 1 << n)
    {
        vector<int> b(n);
        rep(i, n)
        {
            if (I & (1 << i))
                b[i] = 1;
            else
                b[i] = 0;
        }
        bool f = true;
        rep(i, n)
        {
            if (b[i] == 0)
                continue;
            rep(j, a[i])
            {
                int who = x[i][j];
                if (y[i][j] == 1)
                {
                    if (b[who] == 0)
                        f = false;
                }
                else
                {
                    if (b[who] == 1)
                        f = false;
                }
            }
        }
        if (f)
        {
            int sum = 0;
            rep(i, n) sum += b[i];
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#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);}
int d[2005][2005];
int ans[2005];
void solve(){
	int n,x,y;
	cin>>n>>x>>y;
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)d[i][j]=abs(i-j);
		d[x][y]=d[y][x]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			d[i][j]=min(d[i][j],d[i][x]+1+d[y][j]);
		}
	}
	for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)ans[d[i][j]]++;
	for(int i=1;i<n;i++)cout<<ans[i]<<"\n";
}
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: 16000
n = int(input())
a = list(map(int, input().split()))

Range = []
x = a[0]
y = a[0]
end = 0
for i in range(n):
    start = i
    while x == y:
        end = end + 1
        if end >= n:
            end = end - 1
            break
        x = x + a[end]
        y = y ^ a[end]
    else:
        x = x - a[end]
        y = y ^ a[end]
        end = end - 1
    Range.append([start, end])
    x = x - a[i]
    y = y ^ a[i]
    if start == end and end < n - 1:
        end = end + 1
        x = x + a[i + 1]
        y = y ^ a[i + 1]

ans = 0
for i in range(len(Range)):
    ans = ans + Range[i][1] - Range[i][0] + 1
print(ans)

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


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

typedef long long ll;
typedef vector < ll > vl;
typedef vector < int > vi;
typedef vector < bool > vb;
typedef vector < vl > vvl;
typedef vector < vi > vvi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef vector < pll > vpll;
typedef vector < pii > vpii;
typedef vector < vpll > vvpll;
typedef vector < vpii > vvpii;

#define pb push_back
#define pf push_front
#define all(c) (c).begin(), (c).end()
#define ff first
#define ss second
#define mp(x,y) make_pair((x), (y))
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL)

const int maxn = 1e6+1;

void solve(){
    
    int n; cin >> n;
    vi a(n);
    for(int& u : a)
        cin >> u;
    map<int, int> m;
    for(int u : a){
        m[u]++;
    }
    set< int > s;
    for(auto u : m){
        if(u.ss == 1){
            s.insert(u.ff);
        }
    }
    for(auto u : m){
        int val = u.ff;
        for(int i = 2 * val; i < maxn; i += val){
            if(s.find(i) != s.end())
                s.erase(i);
        }
    }
    cout << (int)s.size() << '\n';
}


int main(){
	boost;
	int t = 1;
// 	cin >> t;
	
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 22700
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> &P){
os << P.first;
os << " ";
os << P.second;
os << "\n";
return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
//fixed<<setprecision(10)<<ans<<endl;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q;
    cin >> N;
    string a,b;
    unordered_set<string> S;
    REP(i,N){
        cin >> a >> b;
        if(a=="insert"){
            S.insert(b);
        }else{
            if(S.find(b)!=S.end()){
                cout << "yes" << endl;
            }else{
                cout << "no" << endl;
            }
        }
    }
}


Measured memory_bytes: 29624
<?php
  
  fscanf(STDIN, "%d", $n);
  $nArray = str_split($n);
  $num = count($nArray) - 1;
  if($nArray[$num] == 2 || $nArray[$num] == 4 ||$nArray[$num] == 5 ||$nArray[$num] == 7 ||$nArray[$num] == 9){
      echo 'hon';
  }elseif($nArray[$num] == 0 ||$nArray[$num] == 1 ||$nArray[$num] == 6 ||$nArray[$num] == 8){
  	  echo 'pon';
  }else{
    echo 'bon';
  }

Measured memory_bytes: 16076
n, m = map(int, input().split())
cards = [0]*(n+1)
for _ in range(m):
    l, r = map(int, input().split())
    cards[l] += 1
    if r == n:
        continue
    cards[r+1] -= 1

for i in range(n):
    cards[i+1] += cards[i]
print(cards.count(m))

Measured memory_bytes: 6900
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){

    int n;
    int debt = 100000;
    while(cin >> n){
        for(int i=0;i<n;i++){
            debt += debt * 0.05;
            if(debt%1000 != 0){
                debt = debt - debt%1000 + 1000;
            }
        }
        cout << debt << endl;
    }
    return 0;
}

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

int main(){
	map<int, int> m;
	map<int, int> r;
	int a[6], n, x, y;
	int d[6][6]={{0,3,5,2,4,0},{4,0,1,6,0,3},{2,6,0,0,1,5},
		{5,1,0,0,6,2},{3,0,6,1,0,4},{0,4,2,5,3,0}};
	for(int i = 0;i < 6;i++){cin >> a[i];m[a[i]] = i;r[i] = a[i];}
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> x >> y;
		//int f = m[x];
		//int t = m[y];
		int tmp = d[m[x]][m[y]];
		cout << r[tmp-1] << endl;
	}
	
	return 0;
}

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

int main() {
    vector <char> alpha = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p',
                            'q','r','s','t','u','v','w','x','y','z'};
    string S;
    cin >> S;
    sort(S.begin(), S.end());
    S.erase(std::unique(S.begin(), S.end()), S.end());
    bool found;
    for (int i=0; i<alpha.size(); i++) {
        found = false;
        for(int j=0; j<S.size(); j++) {
            if (alpha.at(i)==S.at(j)) {
                found = true;
                break;
            }
        }
        if (!found) {
            cout << alpha.at(i) << "\n";
            return 0;
        }
    }
    cout << "None\n";
}

Measured memory_bytes: 512
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
        PrintWriter pw=new PrintWriter(System.out);
        String str[]=br.readLine().split(" ");
        int n=Integer.parseInt(str[0]);
        int m=Integer.parseInt(str[1]);
        pw.println((n*(n-1)+m*(m-1))/2);
        pw.flush();
        pw.close();
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >>a>>b;
  int ans=0;
  for(int i=0;i<2;i++){
    if(a<b){
      ans+=b--;
    }else{
      ans+=a--;
    }
  }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int push( int Stack[], int *ptop, int x ){

  Stack[*ptop] = x;
  *ptop += 1;
  
  return 0;
  
}
int pop( int Stack[], int *ptop ){

  *ptop -= 1;
  return Stack[*ptop];

}
int main(){

  char S[8];
  int len,i,x,y,z,Stack[101],top;
  top = 0;

  
  while( scanf("%s", S ) != EOF ){

    if ( S[0] == '@' ) {
      break;
    }

    if ( S[0] == '+' ){
      y = pop( Stack, &top );
      z = pop( Stack, &top );
      x = y + z;
      push( Stack, &top, x );
    } else if ( S[0] == '-' ){
      y = pop( Stack, &top );
      z = pop( Stack, &top );
      x = z - y;
      push( Stack, &top, x );
    } else if ( S[0] == '*' ){
      y = pop( Stack, &top );
      z = pop( Stack, &top );
      x = y * z;
      push( Stack, &top, x );
    } else {
      
      len = strlen(S);
      x = 0;
      
      for ( i = 0 ; i < len ; i++ ){
	x = 10 * x + ( S[i] - '0' );
      }

      push ( Stack, &top, x );
      
    }

  }
  
  printf("%d\n", Stack[0] );
  
  return 0;
    
    
}

Measured memory_bytes: 540
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,x;
  cin>>a>>b>>x;
   if (x<0.5*a*a*b)
   {
    cout<<setprecision(10)<<180/M_PI*atan(0.5*(double)a*b*b/(double)x);
    return 0;
  } 
  else 
   {
    cout<<setprecision(10)<<180/M_PI*atan(2.0*(double)(a*a*b-x)/((double)a*a*a));
    return 0;
   }
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
long long n,m,f[100010],w[100200],v[100200];
int main ()
{
	cin>>n>>m;
	for(long long i=1;i<=n;i++)
	{
		cin>>v[i]>>w[i];
	}
	for(long long i=1;i<=n;i++)
	{
		for(long long j=m;j>=v[i];j--)
		{
			f[j]=max(f[j],f[j-v[i]]+w[i]);
		}
	}	
	long long ans=0;

	cout<<f[m];
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5+5;
const ll mod = 998244353;

int n;
ll a,b,k,x,y,fac[N],rev[N];

ll qpow(ll a,ll b){
	ll r=1;
	while(b){
		if(b&1)r=r*a%mod;
		b>>=1;a=a*a%mod;
	}
	return r;
}

void init(){
	int i;
	for(fac[0]=i=1;i<N;++i)fac[i]=fac[i-1]*i%mod;
	for(rev[N-1]=qpow(fac[N-1],mod-2),i=N-2;~i;--i)rev[i]=rev[i+1]*(i+1)%mod;
}

ll C(int n,int m){
	return n<m?0:fac[n]*rev[m]%mod*rev[n-m]%mod;
}

int main(){
	init();
	cin>>n>>a>>b>>k;
	ll ans=0; 
	for(ll i=0;i<=n;++i)
	if(k>=a*i&&(k-a*i)%b==0&&(k-a*i)/b<=n){
		ll j=(k-a*i)/b;
		(ans+=C(n,i)*C(n,j)%mod)%=mod;
	}
	cout<<ans<<endl;
}

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

const ll MOD = 1e9+7;

const int MAX=100010;

vector<ll> fac(MAX), finv(MAX), inv(MAX);

void cmbInit() {
    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;
    }
}

int main() {
    int n;
    cin >> n;
    vector<ll> x(n);
    ll xin,oxin;
    for (int i=0;i<n;i++) {
        cin >> xin;
        if (i>0) x[i]=xin-oxin;
        oxin = xin;
    }
    vector<ll> p(n), sump(n);
    cmbInit();
    for (int i=1;i<n;i++) {
        p[i]=(fac[n-1]*inv[i])%MOD;
        if (i==1) sump[i]=p[i];
        else sump[i]=(p[i]+sump[i-1])%MOD;
    }
    
    ll ans=0;
    for (int i=1;i<n;i++) {
        ans+=(x[i]*sump[i])%MOD;
        ans=ans%MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if self.v is None:
            self.v = n
        else:
            self.v = self.f(self.v, n) 


def main():
    N = int(input())
    S = read_list()

    res = V(max, 0)
    for c in range(1, N):
        r = 0
        t1 = 0
        while True:
            t1 += c
            if t1 > N - 1 - c:
                break
            
            if (N - 1) % c == 0 and 2 * t1 >= N - 1:
                break

            r += S[t1] + S[N - 1 - t1]
            res.ud(r)

    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14988
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

	int n;
	cin >> n;

	vector<ll> h(n);
	ll hi = 0;
	int id = -1;
	for (int i = 0; i < n; i++)
	{
		cin >> h.at(i);
		if (hi < h.at(i))
		{
			hi = h.at(i);
			id = i;
		}
	}

	bool res = true;
	for (int i = 1; i < n; i++)
	{
		if ((h.at(i - 1) - 1 > h.at(i)) || (i - id > 1 && hi - 1 > h.at(i)))
		{
			res = false;
			break;

		}
	}

	cout << (res ? "Yes" : "No") << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
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(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<vector<ll>> dp(52,vector<ll> (52,0));
    dp[0][0] = 1;
    for(int i=1; i<52; i++){
        for(int j=0; j<=i; j++){
            dp[i][j] += dp[i-1][j];
            if(j) dp[i][j] += dp[i-1][j-1];
        }
    }
    int N,A,B;
    cin >> N >> A >> B;
    vector<ll> v(N);
    for(int i=0; i<N; i++) cin >> v[i];
    sort(v.begin(),v.end(),greater<ll>());
    ll sum = 0;
    for(int i=0; i<A; i++){
        sum += v[i];
    }
    double ave = (double)(sum)/A;
    ll res = 0;
    int num = 0;
    for(int i=0; i<N; i++) if(v[i] == v[A-1]) num++;
    if(v[0] == v[A-1]){
        for(int j=A; j<=B; j++){
            res += dp[num][j];
        }
    }else{
        int a = 0;
        for(int i=0; i<A; i++){
            if(v[i] == v[A-1]) a++;
        }
        res = dp[num][a];
    }
    cout << fixed << setprecision(10) << ave << enld;
    cout << res << enld;
    return 0;
}

Measured memory_bytes: 256