akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>

using namespace std;

#define int long long 

int n , m , mod;

const int N = 305;

int f[N][N][N];
 
void add(int &x , int y){
	x = (x + y >= mod ? x + y - mod : x + y);
}

main() {
	cin >> n >> m >> mod;
	f[0][1][0] = 1;
	for (int i = 0; i <= n; i++)
		for (int j = 1; j <= m; j++)
			for (int k = i; k >= 0; k--) {
				if (k) 
					add(f[i][j][k - 1] , f[i][j][k]);
				else 
					add(f[i][j + 1][i] , f[i][j][k]);
				add(f[i + 1][j][k] , (long long)(f[i][j][k] * (k + 1)) % mod);
	}
	cout << f[n][m][0];
	return 0;
}

Measured memory_bytes: 221440
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [ 0, 0 ]
i = 0
while i + 1 < n:
    if a[i] == a[i + 1]:
        b += [ a[i] ]
        i += 2
    else:
        i += 1
print(b[-2] * b[-1])


Measured memory_bytes: 14244
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	ll m, k;
	scanf("%ld %ld", &m, &k);
	if(k==0){
		ll ans[1<<(m+1)], val = 0;
		REP(i, 0, 1<<m) ans[(1<<m)+i] = ans[(1<<m)-i-1] = val++;
		REP(i, 0, 1<<(m+1)) printf("%ld ", ans[i]); puts("");
		return 0;
	}

	ll x = 0;
	REP(i, 0, 1<<m) if(i!=k) x ^= i;
	if(x!=k) puts("-1");
	else{
		ll ans[1<<(m+1)], val = 0;
		REP(i, 0, 1<<m){
			ans[(1<<m)+i+1] = ans[(1<<m)-i-1] = val;
			val++;
			if(val==k) val++;
		}
		ans[0] = ans[1<<m] = k;
		REP(i, 0, 1<<(m+1)) printf("%ld ", ans[i]); puts("");
	}

	return 0;
}



Measured memory_bytes: 5864
#include <iostream>

using namespace std;

int main() {
	int a, b; cin >> a >> b;
	int ans = 0;
	if (a > b) ans = 2 * a - 1;
	else if (a == b) ans = a * 2;
	else ans = 2 * b - 1;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
ll solve(vector<int> &wt,vector<int> &val,int W){
  int m = wt.size();
  vector<vector<ll>> dp(m+1,vector<ll>(W+1));
  for(int i=1; i<=m; i++){
    for(int j=1; j<=W; j++){
      if(wt[i-1] <= j){
        dp[i][j] = max(val[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);
      }else{
        dp[i][j] = dp[i-1][j];
      }
    }
  }
  return dp[m][W];
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n,W;
  cin>>n>>W;
  vector<int> wt(n);
  vector<int> val(n);
  for(int i=0; i<n; i++){
    cin>>wt[i]>>val[i];
  }
  cout<<solve(wt,val,W);
  return 0;
}


Measured memory_bytes: 80256
import math
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
l=[]
for i in range(n-1):
    for j in range(i+1,n):
        l.append(math.sqrt((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2))
print(sum(l)*2/n)

Measured memory_bytes: 3060
n=int(input())
a=[input() for i in range(n)]
b=set(a)
c=0
if len(a)!=len(b):print("No")
else:
  for x in range(n-1):
     if a[x][len(a[x])-1]!=a[x+1][0]:c+=1
  if c>0:print("No")
  else:print("Yes")

Measured memory_bytes: 3064
from fractions import gcd

T = int(input())
qs = [tuple(map(int,input().split())) for i in range(T)]

def solve(q):
    a,b,c,d = q
    if b > d: return False
    if a < b: return False
    a %= b
    if a > c: return False
    if b == d: return True
    g = gcd(b, d)
    return b-g <= c

for q in qs:
    print('Yes' if solve(q) else 'No')

Measured memory_bytes: 5084
import sys
input = sys.stdin.readline
def print_ans(n,dr):
    """Test Case
    >>> print_ans(6, [9, 1, 4, 4, 6, 7])
    2
    >>> print_ans(8, [9, 1, 14, 5, 5, 4, 4, 14])
    0

    >>> print_ans(14, [99592, 10342, 29105, 78532, 83018, 11639, 92015, 77204, 30914, 21912, 34519, 80835, 100000, 1])
    42685
    """
    ans_ar = sorted(dr)
    print(ans_ar[n//2] - ans_ar[n//2 - 1])

if __name__ == '__main__':
    n = int(input().rstrip())
    dr = list(map(int, input().rstrip().split()))
    print_ans(n,dr)




Measured memory_bytes: 14396
//TwentyFour
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define forinc(a,b,c) for(int a=b;a<=c;++a)
#define fordec(a,b,c) for(int a=b;a>=c;--a)
#define forv(a,b) for(auto &a:b)
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(),a.end()
#define reset(f,x) memset(f,x,sizeof(f))
#define bit(x,i) (x>>(i-1)&1ll)
#define onbit(x,i) (x|(1ll<<(i-1)))
#define offbit(x,i) (x&~(1ll<<(i-1)))
#define task ""

#define int long long

int n,a,b;
main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>n>>a>>b;
    if((a-b)%2){
        cout<<min(a-1,n-b)+1+(b-a)/2;
    }
    else cout<<(b-a)/2;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String s;
		String sd = "abcdefghijklmnopqrstuvwxyz";
		String sdnum = "0123456789";
		s = sc.next();
		int count[];
		int countnum[];
		count = new int[26];
		countnum = new int[10];

		for (int i = 0; i < s.length(); ++i) {
			if (s.charAt(i) >= '0' && s.charAt(i) <= '9') {
				++countnum[s.charAt(i) - '0'];
			}
			if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z') {
				++count[s.charAt(i) - 'a'];
			}
		}

		int ans = 0;
		for (int i = 26; i >= 3; --i) {
			for (int j = 0; j <= 26 - i; ++j) {
				int tmp = 10000;
				for (int k = j; k < j + i; ++k) {
					tmp = Math.min(tmp, count[k]);
				}
				ans += tmp * 3;
				for (int k = j; k < j + i; ++k) {
					count[k] -= tmp;
				}
			}
		}
		for (int i = 0; i < 26; ++i) {
			ans += count[i];
		}

		for (int i = 10; i >= 3; --i) {
			for (int j = 0; j <= 10 - i; ++j) {
				int tmp = 10000;
				for (int k = j; k < j + i; ++k) {
					tmp = Math.min(tmp, countnum[k]);
				}
				ans += tmp * 3;
				for (int k = j; k < j + i; ++k) {
					countnum[k] -= tmp;
				}
			}
		}
		for (int i = 0; i < 10; ++i) {
			ans += countnum[i];
		}

		System.out.println(ans);
		sc.close();
	}

}



Measured memory_bytes: 26320
#include<iostream>
using namespace std;
#define N 200

int main()
{
int a=0,b=0,n;

while( cin>>a>>b ){
	n=1;
 if(a>=0 && b>=0 && a<=1000000 && b<=1000000)
 	{
	 a = a+b;
	 while(a>=10)
	 	{
		 a = a/10;
		 n += 1;
	 	}
 	}
 	cout<<n<<endl;
 	
 	}


}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define reps(i, s, n) for (int i = (s); i < (n); ++i)
#define repse(i, s, n) for (int i = (s); i <= (n); ++i)
#define repsr(i, n, s) for (int i = (n); i >= (s); --i)
#define all(xs) (xs).begin(), (xs).end()
const int64_t inf = (int64_t)1e18;
const int64_t mod = (int64_t)1e9 + 7;

int64_t h[100];

int64_t solve(int left, int right) {
  if (left >= right) return 0;
  int mni = left;
  reps(i, left, right) if (h[i] < h[mni]) mni = i;
  int64_t mn = h[mni];
  if (mn == 0) return solve(left, mni) + solve(mni + 1, right);
  reps(i, left, right) h[i] -= mn;
  return solve(left, mni) + solve(mni + 1, right) + mn;
}

int main() {
  int N; cin >> N;
  rep(i, N) cin >> h[i];
  cout << solve(0, N) << endl;
  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 all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char>cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int main()	{
  int s,w;
  cin>>s>>w;
  if(s>w) cout<<"safe"<<endl;
  else cout<<"unsafe"<<endl;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  string s; cin >> s;
  int n = s.size();
  string ans;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'B') {
      if (ans.size() > 0) { ans = ans.substr(0, ans.size() - 1); }
    }
    else {
      ans.push_back(s[i]);
    }
  }
  printf("%s\n", ans.c_str());
  return 0;
}


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

int main(){
  char s[9];
  int ans=0, count=0;
  //string st; cin >> st;
  scanf("%s", s);
  for ( int i = 0; i < 10; i++ ){
    switch (s[i]) {
      case 'A':
      		count++;
      		break;
      case 'C':
      		count++;
      		break;
      case 'G':
      		count++;
      		break;
      case 'T':
      		count++;
      		break;
      default:
            ans = max(ans, count);
            count = 0;
      		break;
    }
  }
  ans = max(ans, count);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a_list = list(map(int, input().split()))
bc_list = [list(map(int, input().split())) for _ in range(m)]

a_list.sort()
bc_list.sort(key=lambda x: x[1], reverse=True)
counter = 0

for bc in bc_list:
    for b in range(bc[0]):
        a_list[counter] = max(a_list[counter], bc[1])
        counter += 1
        if counter >= n:
            break
    if counter >= n:
        break

print(sum(a_list))

Measured memory_bytes: 32968
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

int main()
{
    string s;
    cin >> s;

    stack<char> ans;
    for (auto c: s)
    {
        if (c == 'B')
        {
            if (!ans.empty())
            ans.pop();
        }
        else
            ans.push(c);
        // cout << "*" << ans.size() << c <<  (c == 'B') << endl;
    }

    string a = "";
    while (! ans.empty())
    {
        a = ans.top() + a;
        ans.pop();
    }
    // for (auto c: ans)
    //     cout << c ;
    cout <<  a << endl;
    return 0;
}

Measured memory_bytes: 256
import math

a,b,h,m=map(int,input().split())

x1=360*m/60
x2=30*h+30*m/60
theta=min(abs(x1-x2),360-abs(x1-x2))

ans=math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(theta)))
print(ans)

Measured memory_bytes: 9456
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;
 
Node treeMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
  }
  return x;
}
 
Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u;
  if(k < u->key){ 
    return treeSearch(u->left,k);
  }
  else { 
    return treeSearch(u->right,k);
  }
}
 
Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL) return treeMinimum(x->right);
  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}
 
Node treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL || z->right==NIL){ y=z;}//zが子を持たないか、子を1つ持つ場合は入力節点のz
  else {y= treeSuccessor(z);}//zが子を2つ持つ場合はzの次節点
  if(y->left!=NIL){//yの子xを決める
    x=y->left;//yに左の子があれば、xはyの左の子
  }
  else {
    x=y->right;//yに左の子がなければ、xはyの右の子
  }
  if(x!=NIL){ x->parent=y->parent;}//xの親を設定する
  if(y->parent==NIL){ root=x;}
  else if(y==y->parent->left){
    y->parent->left=x;
  }//yがその親の左の子ならば、pの左の子をxとする
  else{
    y->parent->right=x;
  }//yがその親の右の子ならば、pの右の子をxとする
  if(y!=z){//zの次節点が削除された場合
    z->key=y->key;//yのデータをzにコピーする
  }
    return y;
}
 
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  //printf("%d\n",x->key);
  while(x!=NIL){//親を設定
    y=x;
    if(z->key < x->key){ 
      x=x->left;
    }//左の子へ移動
    else x=x->right;//右の子へ移動
  }
  z->parent=y;
  if(y==NIL){ 
    root = z;
  }
  else if(z->key < y->key){
    y->left=z;
  }//zをyの左の子にする
  else y->right=z;//zをyの右の子にする
}
 
void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}
 
 
int main(){
  
  int n, i, x;
  char com[20];
  
  scanf("%d", &n);
  root=NIL;
  
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19364
#include<stdio.h>
#include<vector>
#include<utility>
#include<algorithm>
#include<iostream>
 
using namespace std;
signed main()
{
int a,b,c;
cin>>a>>b>>c;
if(a<=c&&c<=b)
cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}
 

Measured memory_bytes: 256
# include <bits/stdc++.h>
     
    # define x first
    # define y second
    # define mp make_pair
    // everything goes according to my plan
    # define pb push_back
    # define sz(a) (int)(a.size())
    # define vec vector
    // shimkenttin kyzdary, dzyn, dzyn, dzyn...
    # define y1    Y_U_NO_y1
    # define left  Y_U_NO_left
    # define right Y_U_NO_right
     
    # ifdef Local
    # define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
    # else
    # define debug(...) (__VA_ARGS__)
    # define cerr if(0)cout
    # endif
     
    using namespace std;
     
    typedef pair <int, int> pii;
    typedef long long ll;
    typedef long double ld;
     
    const int Mod = (int)1e9 + 7;
    const int MX = 1073741822;
    const ll MXLL = 4e18;
    const int Sz = 1110111;
    // a pinch of soul
    inline void Read_rap () {
      ios_base :: sync_with_stdio(0);
      cin.tie(0); cout.tie(0);
    }
    inline void randomizer3000 () {
      unsigned int seed;
      asm ("rdtsc" : "=A"(seed));
      srand (seed);
    }
    void files (string problem) {
      if (fopen ((problem + ".in").c_str(),"r")) {
        freopen ((problem + ".in").c_str(),"r",stdin);
        freopen ((problem + ".out").c_str(),"w",stdout);
      }
    }
    void localInput(const char in[] = "s") {
      if (fopen (in, "r")) {
        freopen (in, "r", stdin);
      }
      else
        cerr << "Warning: Input file not found" << endl;
    }
     
     
    int main()
    {
      # ifdef Local
        //localInput();
      # endif
      Read_rap();
      ll s, c;
      cin >> s >> c;
      ll ans = min (s, c/2);
      c -= ans * 2;
      ans += c/4;
     
      cout << ans;
     
      return 0;
    }
     
     
     
     
     
     
    // Coded by Z..

Measured memory_bytes: 256
n=int(input())
l1=[]
l2=[]
for i in range(n):
    sp=input().rstrip().split()
    l1.append(sp[0])
    l2.append(-int(sp[1]))
l=list(zip(l1,l2))

ans=sorted(l)

for i in range(len(ans)):
    print(l.index(ans[i])+1)





Measured memory_bytes: 3060
def is_prime(n):
    if n == 2 or n == 3: return True
    if n < 2 or n%2 == 0: return False
    if n < 9: return True
    if n%3 == 0: return False
    r = int(n**0.5)
    f = 5
    while f <= r:
        if n%f == 0: return False
        if n%(f+2) == 0: return False
        f +=6
    return True  

def divisors(n):
    lower_divs , upper_divs = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divs.append(i)
            if i != n // i:
                upper_divs.append(n//i)
        i += 1
    return lower_divs + upper_divs[::-1]

def resolve():
    A, B = list(map(int, input().split()))
    divs = divisors(A)
    i = 1
    cnt = 0
    while i < len(divs):
        if B%divs[i]==0 and is_prime(divs[i]):
            cnt += 1
        i += 1
    print(cnt+1)
    

if '__main__' == __name__:
    resolve()


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

const ll MOD = 1e9+7;

int main()
{
	int n;
	string s;
	string t[]={"Sunny","Cloudy","Rainy","Sunny"};
	string ans;
	cin>>s;
	if(s=="Sunny")
		ans=t[1];
	if(s=="Cloudy")
		ans=t[2];
	if(s=="Rainy")
		ans=t[3];
	
	cout<<ans<<endl;
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9

using namespace std;

int main(){
  int n, w;
  while(cin >> n >> w and n + w){
    vector<int> data(n);
    REP(i, n){
      cin >> data[i];
    }
    sort(ALL(data));
    int maxim = data[n-1];
    int bars = ((maxim+1) / w);
    if((maxim+1) % w) bars++;
    int count[bars] = {0};
    int tmp = 0;
    int maxsize = 0;
    REP(i, n){
      if(data[i] < w * (tmp + 1)) count[tmp]++;
      else { tmp++; i--; }
      maxsize = max(maxsize, count[tmp]);
    }
    double res = 0.01;
    REP(i, bars) res += (double)(bars-i-1) * count[i] / ((bars-1) * maxsize);
    cout << setprecision(15) << res << endl;
  }
  return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// stringの数字をint型にしてアスキーコードになったら -48する
// 切り上げ　ceil(a)


int main() {
    ll h, n;
    cin >> h >> n;
    vector<ll> a(n);
    vector<ll> b(n);

    rep(i,n){
        cin >> a.at(i) >> b.at(i);
    } 

    vector<ll> dp(h+1, INF);
    dp.at(0) = 0;
    rep(i,n){
        rep(j,h+1){
            ll tmp;
            if(j + a.at(i) > h){
                tmp = h;
            }else{
                tmp = j + a.at(i);
            }
            chmin(dp[tmp], dp[j] + b.at(i));
        }
    }

    cout << dp[h] << endl;
    

}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }

int main() {
    int n, m; cin >> n >> m;
    string s, t; cin >> s >> t;
    int g = gcd(n, m);
    for (int i = 0; i < g; i++) {
        if (s[n / g * i] != t[m / g * i]) return !(cout << -1 << endl);
    }
    cout << 1LL * n / g * m << endl;
    return 0;
}


Measured memory_bytes: 512
def make_divs(n):
    divisors = {}
    d = 2
    while n > 1:
        if n % d == 0:
           divisors[d] = 0
        while n % d == 0:
            divisors[d] += 1
            n //= d
        d += 1
    return divisors

n = int(input())
nn = 1
for i in range(1,n+1):
    nn *= i
if n < 10:
    print(0)
    exit()
div = make_divs(nn)
cnt = 0
t,f = 0,0
a,b = 0,0
u,s = 0,0
aa = 0
for v in div.values():
    if v >= 74:
        aa += 1
    if v >= 4:
        f += 1
    if 4 > v >= 2:
        t += 1
    if v >= 24:
        a += 1
    if 24 > v >= 2:
        b += 1
    if v >= 14:
        u += 1
    if 14 > v >= 4:
        s += 1

tmp = (f)*(f-1)*(f-2)//2 if f > 2 else 0
tmp2 = (f)*(f-1)*t//2 if f > 1 else 0
tmp3 = a*(a-1) if a > 1 else 0
tmp4 = u*(u-1) if u > 1 else 0
print(tmp + tmp2 + a*b + u*s + tmp3 + tmp4 + aa)
# print(f,t,a,b,u,s,aa)
# print(div)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<long long,int> P;

int main(){
	char s[100001];
	scanf("%s",s);

	int ans = 0;
	for(int i=1;i<strlen(s);i++){
		if(s[i-1]!=s[i]) ans++;
	}

	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 384
N=int(input())
CSF=[]
for i in range(N-1):
    CSF.append(list(map(int,input().split())))
C=[]  #運行時間
S=[]  #スタート
F=[]  #周期
for i in range(N-1):
    C.append(CSF[i][0])
    S.append(CSF[i][1])
    F.append(CSF[i][2])

A=[0]*N

for i in range(N-1):
    A[i]=0
    for j in range(i,N-1):
        if A[i]<S[j]:
            A[i]=S[j]
        elif A[i]%F[j]!=0:
            A[i]=A[i]+F[j]-A[i]%F[j]
        A[i]+=C[j]

for i in A:
    print(i)

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    char a[7],ans[26],b[26],x=0,y=0;
    scanf("%s",a);
    x=strlen(a);
    scanf("%s",ans);
    y=strlen(ans);  

    for(int j=0;j<y;j++)
      b[j]=ans[j];

    for(int k=x-1;k>=0;k--){
      if(a[k]=='C'){//??????
	b[y-1]=ans[0];
	for(int j=1;j<y;j++) b[j-1]=ans[j];
      }
      else if(a[k]=='J'){//??????
	b[0]=ans[y-1];
	for(int j=0;j<y-1;j++) b[j+1]=ans[j];
      }
      else if(a[k]=='E'){//swap
	if(y%2==0)
	  for(int j=0;j<y/2;j++) 
	    swap(b[j],b[j+(y/2)]);
	else
	  for(int j=0;j<y/2;j++) 
	    swap(b[j],b[j+(y/2)+1]);



      }
      else if(a[k]=='A'){//????????????
	int o=y;
	while(1){
	  if(o==0)break;
	  for(int j=0;j<y;j++){
	    b[j]=ans[o-1];
	    o--;
	  }
	}
      }
      else if(a[k]=='M'){//+1
	for(int j=0;j<y;j++) 
	  if(ans[j]>='0'&&ans[j]<='8') b[j]=ans[j]+1;
	  else if(ans[j]=='9') b[j]=ans[j]-9;
      }
      else if(a[k]=='P')//-1
	for(int j=0;j<y;j++) 
	  if(ans[j]>='1'&&ans[j]<='9') b[j]=ans[j]-1;
	  else if(ans[j]=='0') b[j]=ans[j]+9;

      for(int j=0;j<y;j++)
	ans[j]=b[j];
    }
    for(int j=0;j<y;j++)
      cout<<ans[j];
    cout<<endl;

  }
  return 0;
}

Measured memory_bytes: 1176
N,A,B = map(int, input().split())
ans = 0

def kakuwa(a): #各桁の和
    k = 0
    for i in range(0,len(str(a))):
        k = k + int(str(a)[i])
    return(k)

for j in range(N+1):
    if kakuwa(j) >= A and kakuwa(j) <= B:
        ans = ans + j

print(ans)

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

#define int long long int
#define double long double
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i=a; i<b; ++i)
#define dbg(x) { cerr<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int inf = INT_MAX;
const double eps = 0.0000001;
const double PI = acos(-1.0);
const int MOD = 1e9+7;
const int N  = 1e5+5;

int s[N],h[N];

signed main(){
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif  
    IOS;

    s[1] = 0;
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; ++i)
    {
        cin >> h[i];
    }
    s[2] = abs(h[2]-h[1]);
    for (int i = 2; i<=k; i++) {
        s[i+1] = abs(h[i+1]-h[1]);
    }
    for (int i = k+1; i <= n; i++) {
        s[i] = inf;
        for (int j = 1; j <= k; ++j) {
            s[i]=min(s[i],s[i-j]+abs(h[i]-h[i-j]));
        }
    }
    cout << s[n];
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll x, y, z;

int main() {
	cin >> x >> y >> z;
	cout << z << " " << x << " " << y << endl;
	return 0;
}

Measured memory_bytes: 256
#include "iostream"
using namespace std;
int main() {
	int N, K;
	char S[10];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	cin >> K;
	K = K - 1;
	for (int i = 0; i < N; i++) {
		if (S[i] != S[K]) {
			S[i] = '*';
		}
	}
	for (int i = 0; i < N; i++) {
		cout << S[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 100000000

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        a = a^b;
        b = a^b;
        a = a^b;
    }
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }
    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

 //118
 
void solve(void){
    int n,m;
    cin >> n >> m;
    int k;
    int num[m+1];
    rep(i,0,m+1) num[i] = 0;
    rep(i,0,n){
        cin >> k;
        rep(j,0,k){
            int a;
            cin >> a;
            num[a]++;
        }
    }
    int ans = 0;
    rep(i,0,m+1){
        if(num[i] == n) ans++;
    }
    cout << ans << endl;
}



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


Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <vector>

using namespace std;

#define int long long
#define dotimes(i, n) for (int i = 0, i##max__ = (n); i < i##max__; i++)

int rint() {
  int x;
  scanf("%lld", &x);
  return x;
}
void wint(int x) {
  printf("%lld\n", x);
}

template <typename T>
bool maxs(T& a, T const& b) {
  return a < b ? a = b, true : false;
}

template <typename T>
bool mins(T& a, T const& b) {
  return a > b ? a = b, true : false;
}

constexpr int modulus = 1e9 + 7;

int egcd_rec(int a, int b, int& x, int &y) {
  int q = b / a, r = b % a;
  if (r == 0) {
    x = 1 - q;
    y = 1;
    return a;
  }
  int d = egcd_rec(r, a, x, y);
  int z = x;
  x = y - x * q;
  y = z;
  return d;
}

inline int egcd(int a, int b, int& x, int& y) {
  if (abs(a) > abs(b))
    swap(a, b);
  int d = egcd_rec(a, b, x, y);
  if (d < 0) {
    d = -d;
    x = -x;
    y = -y;
  }
  return d;
}

class modint {
  int x;
public:
  modint(int x) : x(((x % ::modulus) + ::modulus) % ::modulus) {}
  int value() const {
    return x;
  }
  modint inv() const {
    int a, b;
    egcd(x, ::modulus, a, b);
    return modint(a);
  }
#define modint_operator_impl(op, impl) \
  modint operator op(modint const &y) { \
    return impl; \
  } \
  modint operator op(int const &y) { \
    return *this op modint(y); \
  } \
  modint& operator op##=(modint const& y) { \
    *this = *this op y; \
    return *this; \
  }
#define modint_operator(op) modint_operator_impl(op, modint(x op y.value()))
  modint_operator(+)
  modint_operator(-)
  modint_operator(*)
  modint_operator_impl(/, *this * y.inv())
#undef modint_operator
#undef modint_operator_impl
};

modint modpow(int a, int n) {
  modint r(1), b(a);
  for (; n; n >>= 1) {
    if (n & 1)
      r *= b;
    b *= b;
  }
  return r;
}

signed main() {
  const int N = rint();
  vector<vector<int>> edges(N);
  dotimes(i, N-1) {
    int A = rint() - 1;
    int B = rint() - 1;
    edges[A].emplace_back(B);
    edges[B].emplace_back(A);
  }
  modint s(0);
  function<int(int, int)> dfs;
  dfs = [&](int a, int p) {
    int c = 1;
    for (int b : edges[a]) {
      if (b == p)
        continue;
      int d = dfs(b, a);
      s += modpow(2, d-1) + modpow(2, N-d-1) - 1;
      c += d;
    }
    return c;
  };
  dfs(0, -1);
  modint r(((modpow(2, N-1) - 1) * N - s * 2) / modpow(2, N));
  wint(r.value());
  return 0;
}


Measured memory_bytes: 29556
# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-


def main():
    S = input()

    first = int(S[:2])
    second = int(S[2:])

    if 0 < first <= 12 and 0 < second <= 12:
        print('AMBIGUOUS')
    elif 0 < first <= 12:
        print('MMYY')
    elif 0 < second <= 12:
        print('YYMM')
    else:
        print('NA')


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

ll modnum = 1000000007;


long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}



int main() {
    ll n,x,y; cin >> n >> x >> y;
    Graph G(n);

    rep(i, n-1) {
        G[i].push_back(i+1);
        G[i+1].push_back(i);

    }
    G[x-1].push_back(y-1);
    G[y-1].push_back(x-1);

//    rep(i, n) {
//        cout << G[i].size() << endl;
//    }

    vector<ll> ans(n,0);
    rep(i, n) {
        // BFS のためのデータ構造
        vector<int> dist(n, -1); // 全頂点を「未訪問」に初期化
        queue<int> que;

        // 初期条件 (頂点 0 を初期ノードとする)
        dist[i] = 0;
        que.push(i); // 0 を橙色頂点にする

        // BFS 開始 (キューが空になるまで探索を行う)
        while (!que.empty()) {
            int v = que.front(); // キューから先頭頂点を取り出す
            que.pop();

            // v から辿れる頂点をすべて調べる
            for (int nv : G[v]) {
                if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

                // 新たな白色頂点 nv について距離情報を更新してキューに追加する
                dist[nv] = dist[v] + 1;
                que.push(nv);
            }
        }
//        rep(j, n) {
//            cout << dist[j] << endl;
//        }
        FOR(j, i+1, n) {
            ans[dist[j]]++;
        }
    }


    rep(i,n-1) {
        cout << ans[i+1] <<  endl;
    }

    return 0;
}


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

#define fi first
#define se second
const int N = 2010;
int n;
pair <ll, int> a[N];
ll dp[N][N]; // dp[i][j] - prof cu primele i nr , j fiind plasate la stanga

int main(){
    long long ans = 0;
    cin >> n;
    for (int i=1; i<=n; i++) cin >> a[i].fi, a[i].se = i;
    sort(a+1, a+1+n, greater<pair<int,int>>());
    for (int i=1; i<=n; i++){
        for (int j=1; j<i; j++){
            dp[i][j] = max(dp[i-1][j] + a[i].fi * abs(n - (i-j) + 1 - a[i].se), dp[i-1][j-1] + a[i].fi * abs(a[i].se - j));
        }
        dp[i][i] = dp[i-1][i-1] + a[i].fi * abs(a[i].se - i);
        dp[i][0] = dp[i-1][0] + a[i].fi * abs(n - i + 1 - a[i].se);
    }
    for (int i=0; i<=n; i++) ans = max(ans, dp[n][i]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 26280
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,z=0,zz=0;
	cin>>n>>m;
	int h[n+5],a[m+5],b[m+5],f[n+5];
	memset(f,0,sizeof(f));
//	for(int i=0;i<n;i++)
//	{
//		cout<<f[i]<<" ";
//	}
//	cout<<endl;
	
	for(int i=1;i<=n;i++)
	{
		cin>>h[i];
	}
	for(int i=1;i<=m;i++)
	{
		cin>>a[i]>>b[i];
		if(f[a[i]]==0)
		f[a[i]]=1;
		if(f[b[i]]==0)
		f[b[i]]=1;
		if(h[a[i]]<=h[b[i]])
		f[a[i]]=2;
		if(h[b[i]]<=h[a[i]])
		f[b[i]]=2;
	}
	for(int i=1;i<=n;i++)
	{
	//	cout<<f[i]<<" ";
		if(f[i]!=2)
		z++;
	}
	cout<<endl;
	cout<<z;
}

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

bool can_pay(int x, vector<int> ds) {
    for ( ; x > 0; x /= 10) {
        int digit = x % 10;
        if (find(begin(ds), end(ds), digit) != end(ds)) {
            return false;
        }
    }
    return true;
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> ds(k);
    for (auto &d : ds) {
        cin >> d;
    }

    for (int i = n; i < 1000000; i++) {
        if (can_pay(i, ds)) {
            cout << i << endl;
            break;
        }
    }
}


Measured memory_bytes: 256
use std::io;


fn main() {
    let (a, b) = {
        let i = read::<usize>();
        (i[0], i[1])
    };
    if (a * b) % 2 == 0 { println!("Even"); }
    else { println!("Odd"); }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char> > maze(h,vector<char>(w));
  vector<vector<int> > ans(h,vector<int>(w,MOD));
  rep(i,h)rep(j,w) cin >> maze[i][j];
  ans[0][0] = 1;
  vector<pair<int,int> > dd;
  dd.push_back(make_pair(1,0));
  dd.push_back(make_pair(-1,0));
  dd.push_back(make_pair(0,-1));
  dd.push_back(make_pair(0,1));
  queue<pair<int,int> > q;
  q.push(make_pair(0,0));
  while(!q.empty()){
    pair<int,int> p = q.front();
    q.pop();
    int x = p.second;
    int y = p.first;
    for(d:dd){
      int x_ = x + d.second;
      int y_ = y + d.first;
      if(0<=x_&&x_<w&&0<=y_&&y_<h)
        if(maze[y_][x_] == '.' && ans[y_][x_] == MOD){
          q.push(make_pair(y_,x_));
          ans[y_][x_] = ans[y][x] + 1;
        }
    }
  }
  if (ans[h-1][w-1] == MOD){
    cout << -1 << endl;
    return 0;
  }
  int white = 0;
  rep(i,h)rep(j,w)if(maze[i][j] == '.') white++;
  cout << white - ans[h-1][w-1]<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;

int n, q, ds[100005], rnk[100005], sz[100005];
long long m;

int numsets;

int find(int x) {
    return (ds[x] == x) ? x : ds[x] = find(ds[x]);
}

void merge(int x, int y) {
    x = find(x), y = find(y);
    if (x != y) {
        --numsets;
        if (rnk[x] < rnk[y]) swap(x, y);
        ds[y] = x;
        sz[x] += sz[y];
        if (rnk[x] == rnk[y]) ++rnk[x];
    }
}

void init() {
    numsets = n;
    for (int i = 0; i < n; ++i) ds[i] = i, sz[i] = 1;
}

int main() {
    scanf("%d%lld%d", &n, &m, &q);
    init();
    vector<ii> e;
    for (int i = 0; i < q; ++i) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        if (c == 0) {
            // merge a and b
            merge(a, b);
        } else {
            e.push_back({a, b});
        }
    }
    for (auto E : e) {
        int a = find(E.first), b = find(E.second);
        if (a == b) {
            // printf("No on bad edge\n");
            puts("No");
            return 0;
        }
    }

    // printf("numsets = %d\n", numsets);

    if (m == n - 1) {
        if (e.empty()) {
            puts("Yes");
        } else {
            puts("No");
        }
        return 0;
    }

    if (m <= 1LL * n + 1LL * numsets * (numsets - 3) / 2)
        puts("Yes");
    else {
        // printf("No because m is too big (max is %lld)\n", 1LL * n + 1LL * numsets * (numsets - 3) / 2);
        puts("No");
    }
}

Measured memory_bytes: 2168
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

#define ll long long
#define rep(cnt,a,n) for(ll cnt=a;cnt<n+a;cnt++) //aから始めてn回ループ
#define vector2(type,name,a,b) vector<vector<type>> name(a, vector<type>(b))

int main()
{
    ll a;
    ll b;
    ll n;
    
    cin >> a;
    cin >> b;
    cin >> n;



    ll first = 0;
    ll last = n;
    ll max = 0;

    vector<ll> f(11);

    while (last - first > 100) {
        ll fmax;
        ll haba = (last - first) / 10;
        if (haba <= 0) {
            haba = 1;
        }
        for (ll cnt = 0; cnt < 11; cnt++) {
            f[cnt] = a * (cnt * haba + first) / b - (cnt * haba + first) / b * a;
            
        }
        vector<ll> g = f;
        sort(g.begin(), g.end());
        for (ll cnt = 0; cnt < 11; cnt++) {
            if (f[cnt] == g[10]) {
                fmax = cnt;
            }
        }

        if (fmax == 0) {
            last = haba + first;
        }
        else if (fmax == 10) {
            first = haba * 9 + first;
        }
        else {
            last = haba * (fmax + 1) + first;
            first = haba * (fmax - 1) + first;

        }
        
    }
    for (ll cnt = first; cnt <= last; cnt++) {
        ll hoge = a * cnt / b - cnt / b * a;
        if (max < hoge) {
            max = hoge;
        }
    }
    
    cout << max << endl;

    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;

int main()
{
    long long n, k, r, s, p, ans;
    ans = 0;
    string t;
    cin >> n >> k >> r >> s >> p >> t;
    vector<char> hand(n);
    vector<char> rsp(3);
    rsp = {'r', 's', 'p'};
    for (int i = 0; i < k; i++)
    {
        char h;
        for (int j = 0; j < 3; j++)
        {
            if (t.at(i) == rsp.at(j))
            {
                h = rsp.at((j + 2) % 3);
                if (h == 'r')
                {
                    ans += r;
                }
                else if (h == 's')
                {
                    ans += s;
                }
                else
                {
                    ans += p;
                }
            }
        }
        hand.at(i) = h;
    }
    for (int i = k; i < n; i++)
    {
        char h, l;
        for (int j = 0; j < 3; j++)
        {
            if (t.at(i) == rsp.at(j))
            {
                h = rsp.at((j + 2) % 3);
                l = 'x';
            }
        }
        if (h == hand.at(i - k))
        {
            hand.at(i) = l;
        }
        else
        {
            hand.at(i) = h;
            if (h == 'r')
            {
                ans += r;
            }
            else if (h == 's')
            {
                ans += s;
            }
            else
            {
                ans += p;
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

vector<vector<int>> hozo;

int N,M,Q;

void dfs(vector<int> A, int last){
    int sz = A.size();
    if(sz == N){
        hozo.push_back(A);
        return;
    }

    for(int i = last; i <= M; i++){
        vector<int> tmp;
        tmp = A;
        tmp.push_back(i);
        dfs(tmp, i);
    }
}


//signed main(int argc, char const *argv[])
int main()
{
    cin >> N >> M >> Q;
    vector<int> a(Q),b(Q),c(Q),d(Q);
    for(int i = 0; i < Q; i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }

    vector<int> empty;
    dfs(empty, 1);

    long long ans = 0;

    for(vector<int> A : hozo){
        long long score = 0;
        for(int i = 0; i < Q; i++){
            if((A[b[i]] - A[a[i]]) == c[i]){
                score += d[i];
            }
        }

        ans = max(ans,score);
    }

    cout << ans << endl;



}

Measured memory_bytes: 9760
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a, b, c = map(int, readline().split())
    k = int(readline())
    cnt = 0

    while a >= b:
        b *= 2
        cnt += 1

    while b >= c:
        c *= 2
        cnt += 1

    if cnt <= k:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61740
/*

Coded by peyha X

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int NMAX=3*1e3+2,FIRST=1,SECOND=2;
const ll AUCUN=-1e15;
int n,a[NMAX];
ll dp[NMAX][NMAX][3];

int autre(int x){
	return (x)%2+1;
}

ll state(int player,int debut,int fin){
	
	int signe=1;
	if(player==SECOND) signe=-1;
	
	if(dp[debut][fin][player]!=AUCUN){
		return dp[debut][fin][player];
	}
	if(debut==fin){
		dp[debut][fin][player]=signe*a[debut];
		return dp[debut][fin][player];
	}
	
	ll premier=signe*a[debut]+state(autre(player),debut+1,fin),deux=signe*a[fin]+state(autre(player),debut,fin-1);
	//cout << player << ' ' << debut << ' ' << fin << ' ' << premier << ' ' << deux << endl;
	if((player==FIRST && premier>deux) ||(player==SECOND && deux>premier)){
		 dp[debut][fin][player]=premier;
	}
	else{
		dp[debut][fin][player]=deux;
	}
	return dp[debut][fin][player];
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n;
	
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			for(int id=0;id<=2;id++){
				dp[i][j][id]=AUCUN;
			}
		}
	}
	
	
	cout << state(FIRST,1,n) << '\n';
	
	
	
}


Measured memory_bytes: 211712
fun main (args:Array<String>){
    val list = readLine()!!.split(" ").map(String::toInt)
    if(list[0] == list[1]) {
        if(list[0] == list[2]) {
            print("No")
        }
        else{
            print("Yes")
        }
    }
    else if(list[0] == list[2]) {
        print("Yes")
    }
    else if(list[1] == list[2]){
        print("Yes")
    }
    else{
        print("No")
    }
}

Measured memory_bytes: 36440
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=61
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef pair<int,int> pairii;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)

int main() {
  ll a,b,ab,x,y=0;
  ll ans=0;
  cin>>a>>b>>ab>>x>>y;
  if(a+b<=ab*2){
    ans=x*a+y*b;cerr<<1;
  }
  else{
    ans=2*ab*min(x,y);
    if(x<=y){
      
      ans+=(y-x)*b;cerr<<ans;
    }
    else
    {
      ans+=(x-y)*a;cerr<<22;
    }
    
  }cerr<<y;
  ans=min(ans,max(y,x)*ab*2);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

void fprint() { std::cout << '\n'; }
template <class H, class... T> void fprint(H &&head, T &&... args) {
    std::cout << std::fixed << std::setprecision(10) << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    fprint(std::forward<T>(args)...);
}

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

    int N;
    scan(N);
    double ans = (double)(N - N / 2) / N;
    fprint(ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;

#define MAX 200003
#define MOD 1000000007

int main(){
  int N,A,B;
  cin>>N>>A>>B;
  vector<ll> v(N);
  for(int i=0;i<N;i++){
    cin>>v.at(i);
  }
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  ll sum=0;
  for(int i=0;i<A;i++){
    sum+=v.at(i);
  }
  ll V=v.at(A-1);
  ll count1=0;
  ll count2=0;
  for(int i=0;i<N;i++){
    if(v.at(i)==V){
      count1++;
      if(i<A){
        count2++;
      }
    }
  }
  ll ans=0;
  ll com=1;
  for(int i=0;i<count2;i++){
    com*=(count1-i);
    com/=(i+1);
  }
  ans+=com;
  if(v.at(0)==V){
    for(ll i=count2;i<min<ll>(B-A+count2,count1);i++){
      com*=(count1-i);
      com/=(i+1);
      ans+=com;
    }
  }
  printf("%lf\n",(double)sum/(double)A);
  cout<<ans<<endl;
}


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

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
// #define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...) 42
#define dump(x) 42
#define debug(x) 42
#endif

typedef long long ll;

const ll MOD = 1e9 + 7;

void solve(int N, int K) {
    double answer = 0;
    unordered_map<int, int> counts;
    REP(n,1,N+1) {
        if (K <= n) {
            answer += 1.0;
            continue;
        }
        int count = ceil(log((double)K/n) / log(2.0));
        counts[count]++;
    }

    for (const auto count : counts) {
        answer += count.second * pow(1.0 / 2, count.first);
    }

    answer /= (double)N;

    cout << setprecision(12) << answer << '\n';

    return;
}

signed main() {
    int N, K;
    cin >> N >> K;
    
    solve(N, K);
    
    return 0;
}



Measured memory_bytes: 512