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

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

const int N = 2e3 + 11;
const int M = 1e6 + 11;
const int MOD = 1e9 + 7;

int n, x, y;
int cnt[N];
int dis(int a, int b){
    if(a <= x){
        if(b <= x) return b - a;
        else if(b > x  && b < y) return x - a + min(b - x, 1 + y - b); 
        else return  x - a + b - y  + 1;
    }else if(a > x && a < y){
        if(b > x && b < y)  return min(b - a,  1 + a - x + y - b);
        else return b - y + min(y - a, a - x + 1);
    }else 
        return b - a;
}

int main(int argc, char **args){
    cin >> n >> x >> y ;
    if(x > y) swap(x, y);
    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
            
            cnt[dis(i, j)]++;
            //cout << "i,j :" << i <<" " << j << " "<< dis(i, j) << " \n";
        }
    }

    for(int i = 1; i <= n - 1; i++){
        cout << cnt[i]<<"\n";
     }
return 0;
}

Measured memory_bytes: 256
//Odds of Oddness
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();

    double s=n/2;
    double m=n-Math.floor(s);
    double ans=m/n;

    System.out.println(ans);

  }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define eps 1e-9
#define maxp 101010
#define mod 1000000007
#define pi 3.141592653589793238
#define sin(s) scanf("%lld",&s);
#define sout(s) printf("%lld\n",s);
#define in(s) cin>>s
#define in2(a,b) cin>>a>>b
#define in3(a,b,c) cin>>a>>b>>c
#define vll vector<ll>
#define out(s) cout<<s
#define outs(s,a) cout<<s<<a
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gear_change ios_base::sync_with_stdio(false),cin.tie(0)
#define nfl(i,n) for(i=0;i<n;i++)
#define sfl(i,s,e) for(i=s;i<e;i++)
#define ufl(i,n) for(i=n-1;i>=0;i--)
void solve(){
	ll a,b,c;
	in3(a,b,c);
	swap(a,b);
	swap(a,c);
	cout<<a<<" "<<b<<" "<<c<<"\n";
}	
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	clock_t t1=clock();
	gear_change;
	ll test=1;
	// in(test);
	while(test--){
		solve();
	}
	clock_t t2=clock();
	cerr<<"Time elapsed:- "<<(double)(t2-t1)/CLOCKS_PER_SEC<<'\n';
}	

Measured memory_bytes: 3744
#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <math.h>
using namespace std;

vector< long long > divisor(long long n) {
  vector< long long > ret;
  for(long long i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main(){
    long long N;
    cin >> N;
    vector<long long> a_list(N);
    vector<long long> n_list(1000000);
    for(long long i=0;i<N;i++){
        long long a;
        cin >> a;
        a_list[i]=a;
        n_list[a-1]++;
    }
    long long cnt =0;
    for (long long i =0;i<N;i++){
        vector<long long> y_list=divisor(a_list[i]);
        int flag=0;
        for(long long j=0;j<y_list.size()-1;j++){
            if(n_list[y_list[j]-1]>=1){
                flag=1;
                continue;
            }
        }
        if (n_list[a_list[i]-1]>=2){
            flag=1;
        }
        if (flag==0){
            cnt++;
        }

    }
	
    cout << cnt;

}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

void solve() {
	ll x,ans = 0LL, res = 0LL;
	cin >> x;
	if (x <= 6) {
		cout << 1 << endl;
		return;
	}
	else if (x <= 11) {
		cout << 2 << endl;
		return;
	}
	ans = (x / 11LL) * 2LL;
	res = x % 11LL;
	if (res != 0) {
		if (1 <= res && res <= 6)ans++;
		else if (7 <= res && res <= 10) ans += 2LL;
	}
	cout << ans << endl;
}

int main() {
	solve();
	return 0;
}



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


int main()
{
    long long a, b, c, d, n;
    cin>>n>>a>>b>>c>>d;
    n--;
    for(int i=0; i<=n; i++)
    {
        if((c*(n-i)-d*i)<=(b-a) && (b-a)<=(d*(n-i)-c*i))
        {
            return 0*printf("YES\n");
        }
    }   
    printf("NO\n");
}



Measured memory_bytes: 256
n = int(input())
A = [int(i) for i in input().split()]

B = set()
crown = 0
for i in range(n):
    x = A[i] // 400
    if x < 8:
        B.add(x)
    else:
        crown += 1
        
print(1 if len(B) == 0 else len(B), len(B) + crown)

Measured memory_bytes: 3060
//もふとんさんの写経コード。入力とかは別にスペース叩かなくてもええんやな〜って感じ(つめつめコードの方がコーディング早そう）
#include <bits/stdc++.h>

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int main()
{
	ll n,a,b;
	cin >> n>>a>>b;
	ll cnt = a+b;
	ll k = n/cnt;

	//a+bを1セットとしてみたとき,kセット並べることが出来て、残り並べられる個数がn%cnt;
	if(n%cnt <= a){
		cout << a*k + n%cnt <<endl;
	} else {
		cout << a*(k+1) << endl;
	}
}


Measured memory_bytes: 256
/* Manish Pant - insider_pants, hello_my_friend */
    
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define endl "\n"
#define pb push_back

typedef long long ll;
typedef long double ldob;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T> ostream& operator << (ostream &os, const multiset<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.F << ' ' << v.S; return os; }
template <class T, class S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << '(' << i.F << " => " << i.S << ')' << ' '; return os; } 

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int N = 2e5 + 5;
int n;
vector<int> v;

void solve()
{
    map<ll, ll> m;
    ll ans = 0;
    for(int i = 0; i < n; i++)
    {
        int mx = max(i, n - i - 1);
        if(v[i] >= mx) continue;

        ans += m[i - v[i]];
        m[i + v[i]]++;
    }
    cout << ans << endl;
}

int main()
{
    fast();
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        int a; cin >> a;
        v.pb(a);
    }
    solve();
}

Measured memory_bytes: 17036
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e18;
template<class T> void print(const T& t){ cout << t << endl; }
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 gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  bool res = true;
  if(a!=1&&b!=1&&c!=1&&d!=1){
    res = false;
  }
  if(a!=4&&b!=4&&c!=4&&d!=4){
    res = false;
  }
  if(a!=7&&b!=7&&c!=7&&d!=7){
    res = false;
  }
  if(a!=9&&b!=9&&c!=9&&d!=9){
    res = false;
  }
  if(res){
    print("YES");
  }
  else{
    print("NO");
  }
}

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

template<typename T>
istream& operator >> (istream& istr, vector<T>& v){
    for(T& x: v) istr >> x;
    return istr;
}

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

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

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    // ostr << p.first << p.second;
    ostr << p.first << ", " << p.second;
    return ostr;
}

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

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& vp){
    if(!vp.empty()){
        ostr << vp.front();
        for(auto itr = ++vp.begin(); itr != vp.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<double> vd;
// vll v(n); v[i]=x;
typedef vector<vll> vvll;
typedef vector<vc> vvc;
typedef vector<vd> vvd;
// vvll v(m,vll(n)); v[i][j]=x;
typedef pair<ll,ll> pll;
typedef pair<double,double> pd;
typedef vector<pll> vpll;
typedef vector<pd> vpd;
// vpll v(n); v[i]={x,y}; v[i].first/second;
// v.front() : v[0]
// v.back()  : v[v.size()-1]

#define PI 3.1415926535897932
#define EPS 1e-12
#define INF (ll)1e+12
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<=(b); i++)
#define FORR(i,a,b) for(ll i=(b); i>=(a); i--)
#define fix(x) cout << fixed << setprecision(x)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()

template<typename T> T sum(vector<T>& v){return accumulate(all(v), (T)0);}
template<typename T> inline void sort(vector<T>& v){sort(all(v));}
template<typename T> inline void rsort(vector<T>& v){sort(all(v), greater<T>());}
template<typename T> inline void chmin(T& a, T b){if(a>b) a=b;}
template<typename T> inline void chmax(T& a, T b){if(a<b) a=b;}

int main(){
    ll n, W, ans=0;
    cin >> n >> W;
    vll v(n), w(n);
    REP(i,n) cin >> w[i] >> v[i];
    const ll V = sum(v);
    vvll dp(n+1, vll(V+1, INF));
    dp[0][0]=0;

    REP(i,n){
        FOR(j,0,V){
            // ll m = max(0LL, j-v[i]);
            chmin(dp[i+1][j], dp[i][j]);
            if(j-v[i]>=0) chmin(dp[i+1][j], dp[i][j-v[i]]+w[i]);
        }
    }
    FOR(j,0,V) if(dp[n][j]<=W) ans = j;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 80256
import sys, math

input = sys.stdin.readline

N, M = map(int, input().split())
path = [set() for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    path[a-1].add(b-1)
    path[b-1].add(a-1)

cost = [[math.inf, -1]]*N
cost[0] = [0, 0]
pre = [0]

for d in range(N):
    next = []
    for i in pre:
        for j in path[i]:
            if cost[j][0] != math.inf:
                continue
            cost[j] = [d, i]
            next.append(j)
    pre = next
    if len(next)==0:
        break

if max(cost)[0] == math.inf:
    print('No')
    sys.exit()

print('Yes')
for d, pre_idx in cost[1:]:
    print(pre_idx+1)


Measured memory_bytes: 126832
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m
    
    def add(self, a, b):
        return (a + b ) % self.m

    def sub(self, a, b):
        return (a - b) % self.m
    
    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, self.pow(b, self.m-2))

    def pow(self, x, y):
        if y == 0: 
            return 1
        elif y == 1: 
            return x % self.m
        elif y % 2 == 0: 
            return self.pow(x, y//2)**2 % self.m
        else: 
            return self.pow(x, y//2)**2 * x % self.m



@mt
def slv(N, S):
    CC = defaultdict(lambda: 1)
    for c in S:
        CC[c] += 1
    
    m = Mod(10**9+7)
    return reduce(m.mul, CC.values()) - 1


def main():
    N = read_int()
    S = read_str()
    print(slv(N, S))


if __name__ == '__main__':
    main()


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

int main() {
	string a;
	cin >> a ;
	for(int i=0; i<5;i++)cout << a[i];
	cout << " ";
	for(int i=6; i<13;i++)cout << a[i];
	cout << " ";
	for(int i=14; i<19;i++)cout << a[i];
}

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

int main(){
    int A[3][3],N,d=0;
    for (int i=0;i<3;i++){
        for (int j=0;j<3;j++){
            cin >> A[i][j];
        }
    }
    cin >> N;
    long long int B[N];
    for(int i = 0;i<N;i++){
        cin >> B[i];
    }
    int C[3][3];
    for (int i=0;i<3;i++){
        for (int j=0;j<3;j++){
            C[i][j] = 0;
        }
    }
    for (int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<N;k++){
                if(A[i][j] == B[k]){
                    C[i][j] = 1;
                } 
            }
        }
    }
    for(int i=0;i<3;i++){
        if(C[i][0]+C[i][1]+C[i][2] == 3){
            cout << "Yes";
            d++;
            break;
        }
    }
    for(int j=0;j<3;j++){
        if (d > 0) break;
        if(C[0][j]+C[1][j]+C[2][j] == 3){
            cout << "Yes";
            d++;
            break;
        }
    }
    if(d == 0){
        if(C[0][0]+C[1][1]+C[2][2] == 3){
        cout << "Yes";
        d++;
    }
    }
    if(d == 0){
        if(C[0][2]+C[1][1]+C[2][0] == 3){
        cout << "Yes";
        d++;
    }
    }
    if(d==0) cout << "No";
}


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

int main(){
  int W,H,N; cin >> W >> H >> N;
  vector<pair<int,int>> MY(N);
  for(int i=0;i<N;i++){
    int a,b,c;
    cin >> a >> b >> c;
    if(c==1 || c==2){
      MY.at(i).first=a;
    }
    else MY.at(i).first=b;
    MY.at(i).second=c;
  }
  int one=0;
  int two=W;
  int three=0;
  int four=H;
  for(int i=0;i<N;i++){
    if(MY.at(i).second==1){
      one=max(one,MY.at(i).first);
    }
    if(MY.at(i).second==2){
      two=min(two,MY.at(i).first);
    }
    if(MY.at(i).second==3){
      three=max(three,MY.at(i).first);
    }
    if(MY.at(i).second==4){
      four=min(four,MY.at(i).first);
    }
  }
  if(one>=two || three>=four){
    cout << 0 << endl;
  }
  else cout << (two-one)*(four-three) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

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

const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int INF_INT = 1e9;

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;
}

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int N;
    cin >> N;
    int cnt = 0;
    bool flag = false;
    for(int i = 0; i < N; i++){
        int a,b;
        cin >> a >> b;
        if(a == b) cnt++;
        else cnt = 0;
        if(cnt >= 3) flag = true;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3632
import itertools

n,k = map(int, input().split())
if k > (n-1) * (n-2) // 2:
  print(-1)
  exit()
m = n * (n-1) // 2 - k
print(m)
for i in range(1,n):
  print(i,n)
add = (n-1) * (n-2) // 2 - k
for i in itertools.combinations(range(1,n),2):
  if not add:
    break
  print(*i)
  add -= 1

Measured memory_bytes: 3616
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    s: Chars,
    t: Chars,
    }
    let n = s.len();
    let mut ans = "Yes";
    for i in 0..n {
        if s[i] != t[i] {
            ans = "No";
            break;
        }
    }
    println!("{}", ans);
}


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

#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(long long i=0;i<(n);i++)

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

  string St = S;
  int ans = 0;
  if(St[0] == '1') {
    ans++;
    St[0] = '0';
  }
  for(int i = 1; i < St.size(); i++) {
    if(St[i-1] == '0' && St[i] == '0') {
      St[i] = '1';
      ans++;
    } else if(St[i-1] == '1' && St[i] == '1') {
      St[i] = '0';
      ans++;
    }
  }

  int anst = 0;
  St = S;
  if(St[0] == '0') {
    anst++;
    St[0] = '1';
  }
  for(int i = 1; i < St.size(); i++) {
    if(St[i-1] == '0' && St[i] == '0') {
      St[i] = '1';
      anst++;
    } else if(St[i-1] == '1' && St[i] == '1') {
      St[i] = '0';
      anst++;
    }
  }
  ans = min(ans, anst);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std ;
#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )
#define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
#define drep( i, s, t ) for( register int i = (t); i >= (s); -- i )
#define re register
#define pb push_back
#define int long long
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 50 + 5 ; 
const int M = 2e5 + 5 ; 
int n, m, D, c[N], Sum, top, w[N], num[N], f[M] ; 
vector<int> Go[N] ; 
struct node { int w, c, f ; double p ; } a[N] ;
struct A { int w, c ; } b[M] ;
void Dfs( int x, int fa ) {
	w[x] = 1 ; 
	for(int v : Go[x]) if(v ^ fa) Dfs(v, x), w[x] += w[v], c[x] += c[v], c[x] = min( c[x], m + 1 ) ; 
}
bool cmp(node x, node y) { return x.p < y.p ; }
signed main()
{
	n = gi(), m = gi(), D = gi() ; 
	c[1] = gi() ; int p ; 
	rep( i, 2, n ) c[i] = gi(), p = gi(), Go[p].pb(i) ; 
	Dfs(1, 1) ; num[1] = n ; 
	a[1].w = w[1], a[1].c = c[1], a[1].f = m ; 
	a[1].p = (1.0 * c[1]) / (1.0 * w[1]) ; 
	rep( i, 2, n ) 
		a[i].w = w[i], a[i].c = c[i], a[i].f = ( 0 > D - n ) ? 0 : D - n,
		a[i].p = (1.0 * c[i]) / (1.0 * w[i]) ; 
	rep( i, 2, n ) num[i] = min( D, n ) ; 
	rep( i, 1, n ) {
		A u ; u.w = w[i], u.c = c[i] ; int mi = num[i] ; 
		for( re int j = 1; j <= mi; j = j * 2 ) 
			b[++ top] = u, u.w *= 2, u.c *= 2, mi -= j ; 
		u.w = w[i] * mi, u.c = c[i] * mi, b[++ top] = u ; 
	}
	rep( i, 1, top ) Sum += b[i].w ; 
	memset( f, 63, sizeof(f) ), f[0] = 0 ; 
	rep( i, 1, top ) drep( j, b[i].w, Sum ) f[j] = min( f[j], f[j - b[i].w] + b[i].c ) ; 
	int Ans = 0 ; 
	sort( a + 1, a + n + 1, cmp ) ; 
	rep( j, 0, Sum ) {
		int u = f[j], s = j ; if( u > m ) continue ; 
		rep( i, 1, n ) {
			int v = u + a[i].c * a[i].f ; 
			if( v > m ) {
				v = m - u, v /= a[i].c, s += a[i].w * v, Ans = max( Ans, s ) ; break ;
			} s += a[i].f * a[i].w, u = v ; 
		}
	}
	cout << (long long)Ans << endl ; 
	return 0 ;
}

Measured memory_bytes: 5216
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int h,w,x,y;
  cin >> w >> h >> x >> y;
  cout << (double)w*h/2 << endl;
  if (x*2==w&&y*2==h) cout << 1 << endl;
  else cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

struct edge{
    int to, idx;
};

int par[60];
int idx[60];
int N, M, root = 1;
ll ans = 1;
vector<edge> G[60];
vector<int> ms[21];
vector<int> path(int u, int v){
    vector<int> us, vs;
    while(par[u] != 0){
        us.emplace_back(idx[u]);
        u = par[u];
    }

    while(par[v] != 0){
        vs.emplace_back(idx[v]);
        v = par[v];
    }
    reverse(us.begin(), us.end());
    reverse(vs.begin(), vs.end());
    int sz = min(us.size(), vs.size());
    int id = 0;
    for(; id < sz; id++){
        if(us[id] != vs[id]) break;
    }
    vector<int> res;
    for(int i = id; i < us.size(); i++) res.emplace_back(us[i]);
    for(int i = id; i < vs.size(); i++) res.emplace_back(vs[i]);
    return res;
}

void dfs(int v, int p, int id){
    par[v] = p;
    idx[v] = id;
    for(auto u : G[v]){
        if(u.to == p) continue;
        dfs(u.to, v, u.idx);
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    for(int i = 1; i < N; i++){
        ans *= 2;
        int a, b;
        cin >> a >> b;
        G[a].emplace_back(edge{b, i});
        G[b].emplace_back(edge{a, i});
    }
    dfs(root, 0, -1);

    cin >> M;
    for(int i = 0; i < M; i++){
        int u, v;
        cin >> u >> v;
        ms[i] = path(u, v);
    }
    for(int i = 1; i < (1 << M); i++){
        bool used[50] = {};
        int co = 1;
        int cnt = 0;
        for(int k = 0; k < M; k++){
            if((i >> k) & 1){
                co *= -1;
                for(auto u : ms[k]) used[u] = true;
            }
        }
        for(int k = 1; k < N; k++) cnt += !used[k];
        ll num = 1LL << cnt;
        ans += num * co;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np

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

angle_m = (360.0 * (H + M / 60.0))%  360
angle_h = 30.0 * (H + M / 60.0)

angle = abs(angle_m - angle_h)

x2 = A ** 2 + B ** 2 - 2.0 * A * B * np.cos(angle * np.pi / 180.0)

x = np.sqrt(x2)

print(x)

Measured memory_bytes: 27200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

int main(){
    string s;
    cin >> s;
    string t;
    int n = s.size();
    t = s;
    reverse(t.begin(),t.end());
    int a = 0,b = 0;
    for(int i = 0; min(i+a,i+b) < n; i++){
        if(s[i+a] != t[i+b]){
            if(s[i+a] == 'x') b--;
            else if(t[i+b] == 'x') a--;
            else {
                cout << -1 << endl;
                return 0;
            }
        } 
        //cout << a << " " << b << endl;
    }
    int ans = -(a+b);
    ans /= 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define N 2000500
using namespace std;
int n,m,fa[N],vis[N],D[N],C[N];
int gf(int x) {return fa[x]==x?x:fa[x]=gf(fa[x]);}
inline int rd() {int r;scanf("%d",&r);return r;}
int main() {
	n = rd(), m = rd();

	for (int i=1;i<=1000;i++) fa[i] = i;
	for (int _=1;_<=n;_++)  {
		int x, y,a,b,c,d;
		a = rd(), b = rd(), c = rd(), d = rd();
		x=!c?a:-c; x+=500;
		y=!d?-b:d; y+=500;
		fa[ gf(x) ] = gf(y);
		D[x]++, D[y]--, vis[x] = 1;
	}

	int flag = 1;
	for (int i=1;i<500;i++) D[i]>0 ? flag=0 :0;
	for (int i=501;i<=1000;i++) D[i]<0 ? flag=0 :0;
	for (int i=1;i<=1000;i++) vis[gf(i)] |= vis[i];
	for (int i=1;i<=1000;i++) if (D[i]) C[gf(i)] = 1;
	for (int i=1;i<=1000;i++) if (fa[i]==i && !C[i] && vis[i]) flag = 0;
	puts(flag?"YES":"NO");
	return 0;
}

Measured memory_bytes: 6528
import java.util.Scanner;

public class Main {

    private void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L = sc.nextInt();

        int min = 0;
        int prevTaste = 0;
        int sum = 0;
        for (int i = 0; i < N; i++) {
            int taste = L + (i + 1) - 1;
            sum += taste;

            // 初回
            if (i == 0) {
                min = L;
            }
            // 2回目以降
            else {
                if (Math.abs(taste) < Math.abs(prevTaste)) {
                    min = taste;
                }
            }

            prevTaste = taste;
        }
        System.out.print(sum - min);

    }
    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
}


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

int main()
{

	int n;
	cin >> n;
	vector<int> a(n);
	for (int i=0;i<n;++i)
	{
		cin >> a[i];
	}

	int q;
	cin >> q;
	vector<int> m(q);
	map<int,string> mm;
	for (int i=0;i<q;++i)
	{
		cin >> m[i];
		mm[m[i]]="no";
	}

	int maxmask=(1<<n);
	for (int i=0;i<maxmask;++i)
	{
		int total=0;
		for (int j=0;j<n;++j)
		{
			if ((i&(1<<j))!=0)
			{
				total+=a[j];
			}
		}
		if (mm.count(total)>0)
		{
			mm[total]="yes";
		}
	}

	for (int i=0;i<q;++i)
	{
		cout << mm[m[i]] << endl;
	}
}







Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

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

	int n, m;
	scanf("%d%d", &n, &m);
	vi d;
	long long total = 0;
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		total += a;
		while (a > 0) {
			d.push_back(a - a/2);
			a /= 2;
		}
	}

	sort(d.rbegin(), d.rend());
	m = min(m, (int)d.size());
	for (int i = 0; i < m; i++) total -= d[i];
	printf("%lld\n", total);
}


Measured memory_bytes: 18536
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

int h, w;
string mas[10];
bool isvisited[10][10] = {false};

void dfs(int x, int y){
  if(isvisited[y][x]){
    return;
  }
  if(mas[y][x] != '#'){
    return;
  }
  isvisited[y][x] = true;
  dfs(x + 1, y);
  if(mas[y][x + 1] != '#'){
      dfs(x, y + 1);
  }
  return;
}

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

    cin >> h >> w;
    rep(i, h){
      cin >> mas[i];
    }
    dfs(0, 0);
    rep(i, h){
      rep(j, w){
	if(!isvisited[i][j] && mas[i][j] == '#'){
	  cout << "Impossible\n";
	  return 0;
	}
      }
    }
    cout << "Possible\n";
    return 0;
}


Measured memory_bytes: 256
/*  ex2_3
    supercomputerjoi    */

#include <stdio.h>

int main(void){

    int oneside;
    int whiteplace;

    // input N
    scanf("%d", &oneside);

    // input A
    scanf("%d", &whiteplace);

    // calculate and output
    printf("%d\n", oneside * oneside - whiteplace);
    return 0;
}

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

int main(){
    int N;
    int t;
    cin>>N;
    //社員番号　0~N-1
    //mapに入るのは　0~N-1 だが　0 は空値
    map<int,int>a;//buka,zyousi
    vector<int>buka(N);//社員番号0~N-1の人のbukaの人数
    for(int i=0;i<N;i++){
        if (i==0){
            buka.at(0)=0;
            continue;
        }
        cin>>a[i];
        buka.at(i)=0;
    }
    for(int i=1;i<N;i++){
        t=a[i]-1;//t=zyosi
        buka.at(t)++;
    }
    for(int i=0;i<N;i++){
        cout<<buka.at(i)<<endl;
    }
}

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

const int64_t mod = 1000000007;

int64_t fact[2000013];

int64_t add_mod (int64_t a, int64_t b) {
	return (a + b) % mod;
}

int64_t sub_mod (int64_t a, int64_t b) {
	return (a + mod - b) % mod;
}

int64_t mul_mod (int64_t a, int64_t b) {
	return (a * b) % mod;
}

int64_t pow_mod (int64_t a, int64_t b) {
	int64_t res = 1, t = a;
	while (b) {
		if (b & 1)
			res = mul_mod(res, t);
		t = mul_mod(t, t);
		b >>= 1;
	}
	return res;
}

int64_t div_mod (int64_t a, int64_t b) {
	return mul_mod(a, pow_mod(b, mod - 2));
}

int64_t ncr_mod (int64_t n, int64_t k) {
	return div_mod(fact[n], mul_mod(fact[n - k], fact[k]));
}

void precalc () {
	fact[0] = 1;
	for (int64_t i = 1; i < 2000013; ++i)
		fact[i] = mul_mod(fact[i - 1], i);
}

signed main () {
	precalc();
	
	int x, y;
	cin >> x >> y;
	int64_t ans = 0;
	for (int n = 0; n <= x; ++n) {
		if (!((x - n) & 1)) {
			int m = ((x - n) >> 1);
			if (y == 2 * n + m) 
				ans = add_mod(ans, ncr_mod(n + m, n));
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 15872
def solve(n):
  cnt = 0
  for i in range(1,n+1):
    if n%i == 0: cnt += 1
  if cnt == 8: return True
  else: return False

n = int(input())
ans = 0
for i in range(1, n+1, 2):
  if solve(i): ans += 1
print(ans)

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

#define pb push_back
#define mp make_pair
#define inside sl<=l&&r<=sr
#define outside r<sl||sr<l
#define INF 1000000009
using namespace std;
typedef long long ll;

double dp[3000][3000];
double arr[3000];
int n;

int main(){
	//freopen("stl.gir", "r", stdin);
	
	
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> arr[i];
	}
	
	for (int j = 1; j <= n; j++) dp[0][j] = 0;
	dp[0][0] = 1;
	
	for (int i = 1; i <= n; i++){
		for (int j = 0; j <= n; j++){
			dp[i][j] += dp[i-1][j]*(1.00 - arr[i-1]);
			dp[i][j] += dp[i-1][j-1]*(arr[i-1]);
		}
	}
	
	
	double ans = 0;
	for (int i = 0; i <= n; i++){
		if (i > (n-i)) ans += dp[n][i];
	}
	
	cout << setprecision(15) << ans << endl;
	
}

Measured memory_bytes: 70528
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3
ll n, m;

int main() {
	while (cin >> n >> m&&n + m) {
		ll cnt[100] = {};
		REP(i, n) {
			ll d, p;
			cin >> d >> p;
			cnt[p] += d;
		}
		ll ans = 0;
		for (int i = 100 - 1; i >= 0; i--) {
			if (m - cnt[i] >= 0)m -= cnt[i];
			else {
				ans += i*(cnt[i] - m);
				m = 0;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int main(){
    cin>>n;
    int k;
    cin>>k;
    int a[n];
    for(int i = 0;i < n; i++){
        cin>>a[i];
    }
    int cnt=0;
    for(int i = 0;i < n; i++){
        if(a[i]>=k) cnt++;
    }
    cout<< cnt <<endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
  cerr << ' ' << head;
  debug_cerr(tail...);
}
void chmax(lint &a, lint b) { if (a < b) a = b; }
void chmin(lint &a, lint b) { if (a > b) a = b; }
struct IoSetup{
    IoSetup(){
      ios::sync_with_stdio(false);
      cin.tie(nullptr);
      cout << fixed << setprecision(20);
      cerr << fixed << setprecision(20);
    }
} iosetup;

int main() {
  int x; cin >> x;
  vector<bool> dp(x + 1000);
  vector<int> dif = {100, 101, 102, 103, 104, 105};
  int i = -1;
  dp[0] = true;
  while (i < x) {
    i++;
    if (dp[i] == false) continue;
    for (int j = 0; j < 6; ++j) {
      dp[i + dif[j]] = true;
    }
  }
  cout <<  (int)dp[x] << '\n';
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
#define P pair<ll,ll>
#define fs first
#define sc second

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

int main(){
	int a,p; cin >> a >> p;
	p += a * 3;
	cout << p/2 << endl;
}

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s; cin >> s;
	int N = int(s.size());
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int j;
		for (j = i; j < N; j++) {
			if (s[j] != 'A' && s[j] != 'C' && s[j] != 'G' && s[j] != 'T') {
				break;
			}
		}
		ans = max(ans, j - i);
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main(){
    int K,S;
    scanf("%d%d",&K,&S);
    
    int ans;
    for(int x=0;x<=K;x++){
        for(int y=0;y<=K;y++){
            int z = S-x-y;
            if(0 <= z && z <= K){
                ans += 1;
            }
        }
    }
    printf("%d",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef string str;
typedef vector<str> vst;typedef vector<ll> vll;
ll mod = 1000000007, INF = 10000000000000000;
// ll gcd(ll a, ll b){if (b==0){return a;}return gcd(b, a%b);}
// for (ll i = 0; i < n; i++) {
// sort(.begin(),.end());
int main(){
  ll n;
  cin >> n;
  vll a(n), b(2*n, -1);
  for (ll i = 0; i < n; i++) cin >> a[i];
  for (ll i = 0; i < n; i++) {
    if (i % 2 == 0) {
      b[n + i/2] = a[i];
    }
    else {
      b[n - i/2 - 1] = a[i];
    }
  }
  
  if (n % 2 == 0) {
    for (ll i = 0; i < 2*n; i++) {
      if (b[i] < 0) continue;
      cout << b[i];
      if (i < 2*n-1) cout << ' ';
    }
  }
  else {
    for (ll i = 0; i < 2*n; i++) {
      if (b[2*n - i - 1] < 0) continue;
      cout << b[2*n - i - 1];
      if (i < 2*n-1) cout << ' ';
    }
  }
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

void solve(int n, int a, int b, int c, int x)
{
    VI y(n);
    rep(i, n) cin >> y[i];
    int ans = 0;
    rep(i, n)
    {
        while (y[i] != x)
        {
            x = (a * x + b) % c;
            ans++;
            if (ans > 10000)
            {
                cout << -1 << endl;
                return;
            }
        }
        if (i != n - 1)
        {
            x = (a * x + b) % c;
            ans++;
        }
    }

    cout << ans << endl;
}

int main()
{
    int n, a, b, c, x;
    while (cin >> n >> a >> b >> c >> x, n)
    {
        solve(n, a, b, c, x);
    }

    return 0;
}


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

int main(){
    int K,S;
    cin >> K >> S;
    int c=0;
    for(int i=0;i<=K;i++){
        for(int j=0;j<=K;j++){
            int z=S-i-j;
            if(z>=0&&z<=K)c++;
        }
    }
    cout << c <<endl;   
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

typedef struct directed_edge {
  int32_t vertex;
  int32_t next;
} graph_edge;

typedef struct directedGraph {
  graph_edge *edge;
  int32_t *start;
  int32_t pointer;
  int32_t vertex_num;
  int32_t edge_max_size;
} graph;

graph* new_graph (const int vertex_num) {
  graph *g = (graph *) calloc (1, sizeof (graph));
  g->edge = (graph_edge *) calloc (1, sizeof (graph_edge));
  g->start = (int32_t *) calloc (vertex_num, sizeof (int32_t));
  g->pointer = 0;
  g->vertex_num = vertex_num;
  g->edge_max_size = 1;
  for (int32_t i = 0; i < vertex_num; ++i) {
    g->start[i] = -1;
  }
  return g;
}

void add_edge (graph *g, int32_t from, int32_t to) {
  if (g->pointer == g->edge_max_size) {
    g->edge_max_size *= 2;
    g->edge = (graph_edge *) realloc (g->edge, sizeof (graph_edge) * g->edge_max_size);
  }
  g->edge[g->pointer] = (graph_edge) {to, g->start[from]};
  g->start[from] = g->pointer++;
}

void BFS_graph (graph *g, int32_t src, i32 *q, i32 *parent) {
  uint8_t *used = (uint8_t *) calloc (g->vertex_num, sizeof (uint8_t));
  int32_t front = 0;
  int32_t last = 0;
  used[src] = 1;
  q[last++] = src;
  while (front < last) {
    const int32_t v = q[front++];
    for (int32_t p = g->start[v]; p != -1; p = g->edge[p].next) {
      const int32_t u = g->edge[p].vertex;
      if (!used[u]) {
        used[u] = 1;
        q[last++] = u;
        parent[u] = v;
      }
    }
  }
  free(used);
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  graph *g = new_graph (n);
  for (i32 i = 1; i < n; ++i) {
    i32 x, y;
    scanf ("%" SCNi32 "%" SCNi32, &x, &y);
    x--;
    y--;
    add_edge (g, x, y);
    add_edge (g, y, x);
  }
  i32 *q = ALLOC (2 * n, i32);
  i32 *parent = q + n;
  BFS_graph (g, 0, q, parent);
  i32 *dp = ALLOC (2 * n, i32);
  const i32 mod = 1000000007;
  for (i32 i = n - 1; i >= 0; --i) {
    i32 v = q[i];
    dp[v] = dp[v + n] = 1;
    for (i32 p = g->start[v]; p != -1; p = g->edge[p].next) {
      i32 u = g->edge[p].vertex;
      if (u == parent[v]) continue;
      dp[v] = (i64) dp[v] * (dp[u] + dp[u + n]) % mod;
      dp[v + n] = (i64) dp[v + n] * dp[u] % mod;
    }
  }
  i32 ans = (dp[0] + dp[n]) % mod;
  printf ("%" PRIi32 "\n", ans);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 3840
from math import sqrt
N = int(input()) # 2 <= N <= 10^12
# (1,1) (x,y) = x*y
a = N-1
for x in range(2, int(sqrt(N))+1):
  q, r = divmod(N, x)
  if r == 0:
    a = min(x-1 + q - 1, a)
print(a)
    
    
  
  

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
    int a, b, c, x, y;
    ll price = 0;
    cin >> a >> b >> c >> x >> y;
    ll which = (a + b) * min(x, y);
    if (which > c * 2 * min(x, y)) {
        price = c * 2 * min(x, y);
        if (x > y)price += a * (x - y);
        else if (y > x)price += b * (y - x);
        if (price > (c * 2 * max(x, y)))cout << c * 2 * max(x, y) << endl;
        else cout << price << endl;
    }
    else {
        cout << a * x + b * y << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int n,a[1001],i;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(i=n-1;i>=0;i--){
if(i<n-1||i<0) printf(" ");
printf("%d",a[i]);
}
printf("\n");
return 0;
}


Measured memory_bytes: 2052
#include <iostream>
using namespace std; 
int main()
{
double a,b,c,d,e,f;
while(cin>>a>>b>>c>>d>>e>>f)
{
printf("%.3f %.3f\n", (c*e-b*f)/(a*e-b*d)+0.0001, (c*d-a*f)/(b*d-a*e)+0.0001);
}
return 0;
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ACC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mod 1000000007
#define MAXN 10000001
//string alpha="abcdefghijklmnopqrstuvwxyz";
//int dx[]={1,-1,0,0};
//int dy[]={0,0,1,-1};
//int dx8[]={1,-1,0,0,1,1,-1,-1};
//int dy8[]={0,0,1,-1,1,-1,1,-1};
int spf[MAXN];
void sieve()
{
	int i,j;
	for(i=0;i<MAXN;i++)
	spf[i]=i;
	for(i=4;i<MAXN;i+=2)
	spf[i]=2;
	for(i=3;i*i<MAXN;i++)
	{
		if(spf[i]==i)
		{
			for(j=i*i;j<MAXN;j+=i)
			{
				if(spf[j]==j)spf[j]=i;
			}
		}
	}
}
int nofac(int n)
{
    if(n==1)return 1;
    int ans = 1;
    int y = spf[n];
    int ctr = 1;
    int j = n / y;
    while (j != 1) {
        if (spf[j] == y)
            ctr += 1;
        else {
            y = spf[j];
            ans = ans * (ctr + 1);
            ctr = 1;
        }
        j = j / spf[j];
    }
    ans = ans *(ctr + 1);
    return ans;
}
/*
bool isvowel(char c)
{
    switch(c)
    {
        case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':return true;
        default : return false;
    }
}*/
/*bool isValid(int x,int y,int n,int m)
{
    if(x<0||x>n-1||y<0||y>m-1)return false;
    return true;
}*/
/*
bool comp(pair<int,int> x,pair<int,int> y)
{
    if(y.second==x.second)
        return y.first<x.first;
    return y.second<x.second;
}*/

int32_t main()
{
    ACC
    int T;
    T=1;
    sieve();
    //cin>>T;
    while(T--)
    {
        int i,n;
        cin>>n;
        int ans=0;
        for(i=1;i<=n-1;i++)
        {
            ans+=nofac(n-i);
        }
        cout<<ans<<"\n";
    }

    return 0;
}


Measured memory_bytes: 81772
n = int(input())
front = n // 100
back = n - front * 100
s=1
t=1
if 1 <= front <= 12 :
    s=2
if 1 <= back <= 12 :
    t=3
u = s*t
if u == 1:
    print('NA')
elif u == 2:
    print('MMYY')
elif u == 3:
    print('YYMM')
else:
    print('AMBIGUOUS')

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

int main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    ll cnt[N]{};
    // i < j
    for (int i = 1; i <= N; i++) {
        for (int j = i + 1; j <= N; j++) {
            int i_j = j - i;
            int i_X_Y_j = abs(X - i) + 1 + abs(Y - j);
            cnt[min(i_j, i_X_Y_j)]++;
        }
    }
    for (int i = 1; i < N; i++) {
        cout << cnt[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
n, a, b, c, d = map(int, input().split())
if a > b:
    a, b = b, a

for k in range(n):
    if a + k * c - (n - k - 1) * d <= b <= a + k * d - (n - k - 1) * c:
        print("YES")
        exit()

print("NO")

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


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
 
    int x,y;
    cin>>x>>y;
    int dx[4]={0,-1,0,1};
    int dy[4]={1,0,-1,0};
    int r=1,l=0,u=0,d=0;
    int f1=1,f2=1,f;
    int red=1,yellow=2,blue=3;
    if(x==0 && y==0){
        cout << red << endl;
        return 0;
    }
    if(x==1 && y==0){
        cout << yellow << endl;
        return 0;
    }
    int cnt = 0;
    int now = 2;
    while(true){
        f = f1+f2;
        f1 = f2;
        f2 = f;
        r += max(0,dx[cnt])*f;
        l += min(0,dx[cnt])*f;
        u += max(0,dy[cnt])*f;
        d += min(0,dy[cnt])*f;
        if(l<=x && r>=x && u>=y && d<=y){
            cout << now%3 + 1 << endl;
            return 0;
        }
        cnt = (cnt+1)%4;
        now++;
    }

}


Measured memory_bytes: 3160
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

#define NMAX 500010

struct QUARR{
    int l;
    int r;
    int index;
    int type;
    int ans;
    bool operator<(QUARR q) const{
        if(type==1){
            if(q.r==r) return q.l>l;
            return q.r>r;
        }
        else{
            return q.index>index;
        }
    }
};

int ft_bit[NMAX];
void ft_add(int a,int w,int N){
    for(int x=a;x<=N;x+=x&-x){
        ft_bit[x]+=w;
    }
}

int ft_sum(int a){
    int ret=0;
    for(int x=a;x>0;x-=x&-x){
        ret+=ft_bit[x];
    }
    return ret;
}

signed main(){
    //ios::sync_with_stdio(false);
    cin.tie(nullptr);
    QUARR qu[NMAX];
    int last[NMAX];
    int c[NMAX];
    int N,Q;

    cin>>N>>Q;
    for(int i=1;i<=N;i++){
        cin>>c[i];
        last[i]=-1;
    }

    for(int i=1;i<=Q;i++){
        int l,r;
        cin>>l>>r;
        qu[i].l=l;
        qu[i].r=r;
        qu[i].index=i;
        qu[i].type=1;
        qu[i].ans=0;
    }

    sort(qu+1,qu+Q+1);

    for(int i=1;i<=qu[1].r;i++){
        if(last[c[i]]==-1){
            ft_add(i,1,N);
            last[c[i]]=i;
        }
        else{
            ft_add(last[c[i]],-1,N);
            ft_add(i,1,N);
            last[c[i]]=i;
        }
    }

    qu[1].ans=ft_sum(qu[1].r)-ft_sum(qu[1].l-1);
    qu[1].type=2;
    for(int i=2;i<=Q;i++){
        for(int j=qu[i-1].r+1;j<=qu[i].r;j++){
            if(last[c[j]]==-1){
                ft_add(j,1,N);
                last[c[j]]=j;
            }
            else{
                ft_add(last[c[j]],-1,N);
                ft_add(j,1,N);
                last[c[j]]=j;
            }
        }
        qu[i].ans=ft_sum(qu[i].r)-ft_sum(qu[i].l-1);
        qu[i].type=2;
    }

    sort(qu+1,qu+Q+1);

    for(int i=1;i<=Q;i++){
        cout<<qu[i].ans<<"\n";
    }
}


Measured memory_bytes: 35080
// https://atcoder.jp/contests/dp/tasks/dp_b

#include<bits/stdc++.h>
using namespace std;

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> v(n,0);
    for(int i=0;i<n;i++) cin>>v[i];
    vector<int> cost(n,INT_MAX);
    cost[0] = 0;
    for(int i=1;i<n;i++){
        for(int j=i-1; j>=i-k && j>=0; j--)
        cost[i] = min(cost[i], cost[j] + abs(v[i] - v[j]));
    }
    cout<<cost[n-1]<<"\n";
    return 0;
}

Measured memory_bytes: 1024