akhauriyash/Code-Regression huggingface dataset:
M,D = map(int,input().split())
ans = 0
for m in range(1,M+1):
    for d in range(1,D+1):
        if d >= 10:
            if int(str(d)[0]) >= 2 and int(str(d)[1]) >= 2:
                if int(str(d)[0]) * int(str(d)[1]) == m:
                    ans += 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    vector<int> rui_L(n + 1, 0), rui_R(n + 1, 0);
    for (int i = 0; i < n; i++)
    {
        s[i] == 'L' ? rui_L[i + 1] = rui_L[i] + 1 : rui_L[i + 1] = 0;
    }
    for (int i = n - 1; i >= 0; i--)
    {
        s[i] == 'R' ? rui_R[i] = rui_R[i + 1] + 1 : rui_R[i] = 0;
    }
    vector<int> ans(n, 0);
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'R')
        {
            rui_R[i] % 2 == 0 ? ans[i + rui_R[i]]++ : ans[rui_R[i] + i - 1]++;
        }
        else
        {
            rui_L[i + 1] % 2 == 0 ? ans[i - rui_L[i + 1]]++ : ans[i - rui_L[i + 1] + 1]++;
        }
    }
    for (auto a : ans)
    {
        cout << a << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1872
L=[]
A=0
B=0

try:
    while True:
        M=str(input())
        L.append(M)
        
except EOFError:
    pass

N=len(L)
L.remove(L[N-1])
N=len(L)

for i in range(N):
    P=list(L[i])

    P.remove(P[0])
    if i==N-1 or i//3==0:
        A=P.count('A')
        B=P.count('B')
        if A>B:
            A+=1
        else:
            B+=1
        print(A,B)
    
    else:
        A=P.count('A')
        B=P.count('B')
        Q=list(L[i+1])
        if Q[0]=='A':
            A+=1
        else:
            B+=1
        print(A,B)
    
    i+=1



Measured memory_bytes: 5560
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	ll a, b, v, u, t;
	cin >> a >> v >> b >> u >> t;
	if (abs(a - b) <= (v - u) * t)
		cout << "YES\n";
	else
		cout << "NO\n";

	return 0;
}


Measured memory_bytes: 3132
import math
N = int(input())
x = [0]*N
y = [0]*N
for i in range(N):
    x[i],y[i] = map(int,input().split())
at=[]
for i in range(N):
    for j in range(N):
        ea = math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)
        at.append(ea)
da = 0
for ag in at:
    da += ag
avg = da * math.factorial(N - 1) / math.factorial(N)
print(avg)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

long long int a[1000000];

int main(){
	
	int N;
	
	cin >> N;
	
	long long int sum = 0;
	
	for(int i = 0; i < N; i++){
		cin >> a[i];
		sum += a[i];
	}
	
	long long int ans = abs(a[0] - (sum - a[0]));
	
	long long int count = 0;
	
	for(int i = 0; i < N - 1; i++){
		count += a[i];
		ans = min(ans, abs(count - (sum - count)));
	}
	
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <list>
#include <cmath>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define mp make_pair
#define pb push_back
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, ans = LINF;
	cin >> n;
	for (ll i = 1; i*i <= n; i++) {
		if (n % i != 0) continue;
		ll j = n / i;
		ans = min(ans, i+j-2);
	}

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


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 100005

void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}
int GCD(int a,int b){int c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
int LCM(int a,int b){return a*b/GCD(a,b);}
int POW(int a,int n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return (int)ans;}
int icmp(const void* a,const void* b){return *(int*)a-*(int*)b;}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL fac[NUM],finv[NUM],inv[NUM];
void comi(){int i;fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fac[i]=fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
int com(int n,int k){if(n<k||n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}


int main(){
  int N,i,ans=0;
  scanf("%d",&N);
  char S[N];
  scanf("%s",S);
  if(N%2==1)ans=1;
  FOR(i,0,N/2)if(S[i]!=S[i+N/2])ans=1;
  if(ans==0)printf("Yes");
  else printf("No");

  //printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] m = new int[10];
		
		for(int i=0; i<10; i++) {
			m[i]=sc.nextInt();
		}
		Arrays.sort(m);
		
		for(int i=9; i>=7; i--) {
			System.out.println(m[i]);
		}
	}
}


Measured memory_bytes: 26228
fun Int.isPrime(): Boolean {
    var i = 2
    while (i * i <= this) {
        if (this % i == 0) return false
        ++i
    }
    return true
}
fun main(args: Array<String>) {
    val n = readLine()!!.trim().toInt()
    println((1 .. 5555).map{i -> i * 10 + 1}.filter(Int::isPrime).take(n).joinToString(" "))
}

Measured memory_bytes: 33508
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define MAXN 200005
using namespace std;
using namespace __gnu_pbds;  

ll n;
ll arr[MAXN];
map<ll,ll> m;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	ll cnt=0;
	for(ll i=0;i<n;i++) 
	{
		cin>>arr[i];
		ll a=m[arr[i]];
		m[arr[i]]++;
		ll b=m[arr[i]];
		cnt-=((a*(a-1))/2);
		cnt+=((b*(b-1))/2);
	}
	for(ll i=0;i<n;i++)
	{
		ll cnt1=cnt;
		ll a=m[arr[i]];
		ll b=m[arr[i]]-1;
		cnt1-=((a*(a-1))/2);
		cnt1+=((b*(b-1))/2);
		cout<<cnt1<<endl;
	}
}

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

int main(){
    int n;
    string s1,s2;
    int a=0,b=0;
    cin>>n;
    
    for (int i=0;i<n;i++){
        cin>>s1>>s2;
        if (s1>s2) a+=3;
        else if (s1<s2) b+=3;
        else{
            a++,b++;
        }
    }
    cout<<a<<" "<<b<<endl;
    
    return 0;
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int N = 100009, M = 1000000055;
int n;
pair<int, int> a[N];

pair<int, int> f[N], b[N];
int ans = 0;

pair<int, int> comb(pair<int, int> p1, pair<int, int> p2) {
    pair<int, int> ret;
    ret.first = max(p1.first, p2.first);
    ret.second = min(p1.second, p2.second);
    return ret;
}

int diff(pair<int, int> p) {
    return max(0LL, p.second - p.first + 1);
}

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

    sort(a, a+n);

    f[0] = {0, M};
    for(int i = 0; i < n; ++i) {
        f[i+1] = comb(f[i], a[i]);
    }
    b[n] = {0, M};
    for(int i = n-1; i >= 0; --i) {
        b[i] = comb(b[i+1], a[i]);
    }

    //try putting just one in one group and the rest in the other
    for(int i = 0; i < n; ++i) {
        int cand = diff(a[i]) + diff(comb(f[i], b[i+1]));
        ans = max(ans, cand);
    }

    //other cases
    for(int i = 1; i < n; ++i) {
        int cand = diff(f[i]) + diff(b[i]);
        ans = max(ans, cand);
    }

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


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const long long INF = 1LL << 60;
const ll C = 1000000000+7;

int main() {
    int N;
    cin >> N;
    vector<int> V(N);
    for(int i=0; i<N; i++) cin >> V[i];

    ll count = 0;
    for(int i=0; i<N; i++) {
        int num = V[i];
        while(num % 2 == 0) {
            count++;
            num /= 2;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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; }
const int INF = 1e18;

signed main(){
    int t1, t2, a, b, c, d; cin >> t1 >> t2 >> a >> b >> c >> d;
    a -= c; b -= d;
    a *= t1;
    b *= t2;
    if(a + b == 0){
        cout << "infinity" << endl;
        return 0;
    }
    if((a == 0 or b == 0) or (a > 0 and b > 0) or (a < 0 and b < 0) ){
        cout << 0 << endl;
		return 0;
    }
    a = abs(a),b = abs(b);
    if(a > b){
        cout << 0 << endl;
        return 0;
    }
    cout << a/(b-a)*2 + (a%(b-a) !=0 ? 1: 0) <<endl;
}

Measured memory_bytes: 256
def calc(a, memo, i, c, n)
    if i + c >= n
        0
    elsif memo[c][i].nil?
        memo[c][i] = calc(a, memo, i + 2, c, n) + a[i]
        if c != 0 
            x = calc(a, memo, i + 1, c - 1, n)
            memo[c][i] = x if memo[c][i] < x
        end
        memo[c][i]
    else
        memo[c][i]
    end
end

n = gets.to_i
a = gets.split.map(&:to_i)
memo = Array.new(3) {Array.new(n)}

puts n.even? ? calc(a, memo, 0, 1, n) : calc(a, memo, 0, 2, n)

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

ll integer(string s,ll i,ll j){
    ll ans=0;
    for(ll k=i;k<=j;k++){
        ans=ans*10+s[k]-'0';
    }
    return ans;
}

ll power(ll a,ll b){
    if(b==0){
        return 1;
    }
    ll s=power(a,b/2);
    s*=s;
    if(b&1) return s*a;
    return s;
}

ll solve(string s,ll i){
    // Base Case
    if(i<0) return 0;
    if(i==0){
        return s[i]-'0';
    }

    ll ans=0;
    for(ll j=i-1;j>=-1;j--){
        if(j==-1){
            ans+=integer(s,j+1,i);
        }
        else
            ans+=solve(s,j)+integer(s,j+1,i)*power(2,j);
    }
    return ans;
}

int main() {

    string s;
    cin>>s;
    cout<<solve(s,s.length()-1)<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
using datas=pair<ll,ll>;
using tdata=pair<datas,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll modncrlistp[200000],modncrlistm[200000];

ll modncrs(ll n,ll r){
  ll i,j;
  if(modncrlistp[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistp[i])break;
    }
    if(i<0){
      modncrlistp[0]=1;
      rep1(i,n+1){
        modncrlistp[i]=(modncrlistp[i-1]*i)%mod;
      }
    }else{
      For(j,i+1,n+1){
        modncrlistp[j]=(modncrlistp[j-1]*j)%mod;
      }
    }
  }
  if(modncrlistm[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistm[i])break;
    }
    if(i<0){
      modncrlistm[0]=1;
      rep1(i,n+1){
        modncrlistm[i]=(modncrlistm[i-1]*modinv(i))%mod;
      }
    }else{
      For(j,i+1,n+1)modncrlistm[j]=(modncrlistm[j-1]*modinv(j))%mod;
    }
  }
  return (((modncrlistp[n]*modncrlistm[r])%mod)*modncrlistm[n-r])%mod;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}

int main(){
  ll i,j,N,M,K=0;
  cin>>N;
  set<ll> se;
  rep(i,N){
    cin>>M;
    se.insert(M);
  }
  cin>>N;
  rep(i,N){
    cin>>M;
    auto p=se.insert(M);
    if(!p.second)K++;
  }
  cout<<K<<endl;
  return 0;
}


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

using namespace std;

//typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)


signed main(){

	int N, H, W;
	cin >> N >> H >> W;
	cout << (N - W + 1)*(N - H + 1) << endl;

	return 0;
}


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


int main(){
	
	int N , L;
	
	cin >> N >> L;
	
	vector<string> v;
	
	string s;
	
	for(int i =0 ; i < N ; i ++){
		cin >> s ;
		v.push_back(s);
	}
	
	sort(v.begin(),v.end());
	
	
	string ans;
	
	for(int i = 0 ; i< N ; i++){
		ans+=v[i];
	}
	
	cout << ans << endl;
	
	return 0;
}


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


using namespace std;

int main() {
    string a, b;
    cin >> a;
    cin >> b;
    if(a.length() >= 1 && a.length() <= 10) {
        if(b.length() == a.length()+1 && a.compare(b.substr(0, b.length()-1)) ==0 ) {
            cout << "Yes";
        }
        else {
            cout << "No";
        }
    }
    else {
        cout << "No";
    }
    cout << "\n";
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
typedef long long ll;

ll mod = (ll)pow(10,9)+7;

ll mpow2(ll a){
  if(a == 0) return 1;
  return (2*mpow2(a-1))%mod;
}

int main(){
  int n;
  cin >> n;
  int zero = 0;
  map<pair<ll,ll>,pair<int,int>> mp;
  rep(i,n){
    ll a,b;
    cin >> a >> b;
    if(a==0 && b==0){
      zero ++;
      continue;
    }
    ll g = gcd(a,b);
    a /= g;
    b /= g;
    bool rev = 0;
    if(b < 0){
      a = -a;
      b = -b;
    }
    if(a <= 0){
      ll tmp = a;
      a = b;
      b = -tmp;
      rev = 1;
    }
    if(rev == 0) mp[{a,b}].first++;
    if(rev == 1) mp[{a,b}].second++;
  }
  ll ans = 1;
  for(auto p : mp){
    ll s = p.second.first;
    ll t = p.second.second;
    ll tmp = mpow2(s)+mpow2(t)-1+mod;
    tmp %= mod;
    ans *= tmp;
    ans %= mod;
  }
  cout << (ans+zero-1+mod)%mod << endl;
}

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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int N;
vector<int> f, a, t, x, y;
int pow2(int x) { return x * x; }
void solve(int team) {
    int ans_d = 0, ans_t = 1e8;
    rep(i, N) if (i) {
        if (a[i - 1] == a[i]) continue;
        if (t[i - 1] != t[i]) continue;
        if (t[i - 1] != team) continue;
        int d = pow2(x[i - 1] - x[i]) + pow2(y[i - 1] - y[i]);
        int diff = f[i] - f[i - 1];
        if (ans_d < d) {
            ans_d = d;
            ans_t = diff;
        } else if (ans_d == d && ans_t > diff) {
            ans_d = d;
            ans_t = diff;
        }
    }
    if (ans_t == 1e8) {
        cout << "-1 -1" << endl;
    } else {
        printf("%.20f %.20f\n", sqrt(ans_d), ans_t / 60.0);
    }
}
int main() {
    cin >> N;
    f.resize(N);
    a.resize(N);
    t.resize(N);
    x.resize(N);
    y.resize(N);
    rep(i, N) cin >> f[i] >> a[i] >> t[i] >> x[i] >> y[i];
    solve(0);
    solve(1);

    return 0;
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template <class T>
void print(T& x){printf("%d\n", x);}

int operate(string c, int x, int y){
    if (c=="+")
    {
        return x+y;
    }else if(c=="-"){
        return x-y;
    }else if(c=="*"){
        return x*y;
    }
}
 
int main()
{
    stack<int> stk;

    char c[10];
    int ic;
    string s;
    int x, y;

    while(cin >> c){
        s = c;
        if(!(s == "+" || s == "-" || s=="*")){
            ic = atoi(c);
            stk.push(ic);
        }else{
            y = stk.top();
            stk.pop();
            x = stk.top();
            stk.pop();
            stk.push(operate(s, x, y));
        }
    }

    print(stk.top());
    return 0;
}


Measured memory_bytes: 3284
#include<iostream>
using namespace std;
#define ll long long
ll dp[2000];
ll n;
ll mod=1e9+7;
ll solve(ll i) {
    if(i<3)return 0;
    if(dp[i]!=0)return dp[i];
    for(ll j=3; j<=i-3; j++)
        dp[i]=(dp[i]+solve(j))%mod;
    dp[i]=(dp[i]+1)%mod;
    return dp[i];
}
int main()
{
    cin>>n;
    cout<<solve(n)<<endl;
    return 0;
}

Measured memory_bytes: 3680
import math

n = int(input())
dic = {}

ans = 0
for i in range(1,n+1):
  for j in range(1,n+1):
    tmp1 = math.gcd(i,j)
    for k in range(1,n+1):      
      tmp = math.gcd(tmp1,k)
      
      ans += tmp
      
print(ans)
      

Measured memory_bytes: 9176
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
using namespace std;
//emplace_back next_permutation tie get

typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define SE second
#define FI first
#define OUT(a) cout<<(a)<<endl;

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

    int n;
    LL a=0,t=0,rt,ra;
    cin >> n;
    REP(i,n){
        cin >> rt >> ra;
        LL r=max(max(((t+a-1)/(rt+ra)+1),((t-1)/rt+1)),((a-1)/ra+1));
        t=rt*r;
        a=ra*r;
    }

    cout << a+t <<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define rep(i,a,n) for (int i=a ; i<n ; i++)
#define per(i,a,n) for (int i=n-1 ; i>=a ; i--)
#define LLINF (llong)1e18+5
#define INF 1e9+5

using namespace std;
using llong = long long;
using VI = vector<int>;
using VLL = vector<long long>;
using PII = pair<int, int>;

int n, m;
vector<vector<int>> f(100002);

VI dp; // dp[i] = i번째 node에서 시작하는 제일 긴 path

int dfs(int a)
{
	if (f[a].size() == 0) return dp[a] = 0;
	if (dp[a] != -1) return dp[a];
	int maxx = -1;
	for (int i : f[a])
	{
		maxx = max(dfs(i), maxx);
	}
	return dp[a] = maxx + 1;
}

int main()
{
	IOS;
	cin >> n >> m;
	rep(i, 0, m)
	{
		int x, y;
		cin >> x >> y;
		f[x].emplace_back(y);
	}
	int mmax = 0;
	dp.resize(n + 1);
	fill(all(dp), -1);
	rep(i, 1, n + 1)
	{
		mmax = max(dfs(i), mmax);
	}
	cout << mmax;
	return 0;
}


Measured memory_bytes: 10988
N = input()
V = list(map(int,input().split())) #Value
Y = list(map(int,input().split())) #Cost (yen)
goukei = 0
for v, y in zip(V,Y): #zip関数でシーケンスの最小の値をとって、無くなるまでfor文で繰り返す.
    if(y-v >= 0):
        goukei +=0
    else:
        goukei += v-y
print(goukei)        
 

Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<map>

using namespace std;

#define rep(i,N) for(int i=0;i<N;i++) //0から


typedef long long ll;




ll binary_search(vector<ll> a, ll n, ll key){
    ll right = n, left = -1;
    ll md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}

vector<ll> prime;
void Prime(ll n){ //線形篩,素数列挙
    vector<ll> p(n,0);
    p[0]=1;
    p[1]=1;
    for(ll i=2;i<n;i++){
        if(p[i]==0){
            prime.push_back(i);
            p[i]=i;
        }
        ll k=prime.size();
        for(ll j=0;j<k && i*prime[j]<n && prime[j]<=p[i];j++){
            p[i*prime[j]]=prime[j];
        }
    }
}

#define MOD ((ll)1e+9 + 7)




//cout<<fixed<<setprecision(10);
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(m);
    rep(i,m){
        cin>>a[i];
        if(i!=0){
        }
    }


    vector<ll> cnt(n+1,0);
    cnt[0]=1;
    int c=0;
    rep(i,n+1){
        cnt[i]%=MOD;
        if(c<m && a[c]==i){
            c++;
            continue;
        }
        if(i+1<=n){
            cnt[i+1]+=cnt[i];
        }
        if(i+2<=n){
            cnt[i+2]+=cnt[i];
        }
    }

    cout<<cnt[n]<<endl;


    return 0;
}



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

int main() {
  int X;
  cin >> X;
  
  int Y=X/100;

  if(X%100<=Y*5){
  	cout << 1 << endl;
  }else{
  	cout << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 3536
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  int n;
  cin >> n;
  VI a(n);
  VI freq(123456);
  REP(i, 0, n) {
    cin >> a[i];
    freq[a[i] + 1] += 1;
  }
  int ma = 0;
  REP(i, 1, 123455) {
    int tot = freq[i - 1] + freq[i] + freq[i + 1];
    ma = max(ma, tot);
  }
  cout << ma << endl;
}


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

int main() {
    int a, b, k, cnt = 0;

    cin >> a >> b >> k;

    for (int i = min(a, b); i > 0; i--)  {
        if(a % i == 0 && b % i == 0) cnt++;
        if(cnt == k) {
            cout << i << endl;
            return 0;
        }
    }
}

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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;
typedef priority_queue< int, vector< int >, greater< int > >  minHeap;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define sz(v) v.size()
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define sqr(x) x*x
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ten(n) (int)1e##n
#define tenll(n) (lli)1e##n
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}


inline int addmod(int x ,int y){return (x%mod + y%mod)%mod;}
inline int submod(int x ,int y){return (x%mod - y%mod + mod)%mod;}
inline int mulmod(int x ,int y){return (x%mod *1LL* y%mod)%mod;}
inline int nextSubMask(int i , int mask) {return (i-1)&mask;} /// returns next smallest submask

void we_r_done(){cout<<"NO"; exit(0);}

void debug(bool ok , string mssg)
{
    if(ok)return;
    cout<<mssg;
    exit(0);
}

int main()
{
    ///freopen("output.txt","w",stdout);
    ///freopen("input.txt","r",stdin);

    ///FastIO;

    lli a,b,c,d;
    cin>>a>>b>>c>>d;//w,h,x,y

    double x,y ;
  	int ok = 0;
  	if(a%2 == 0 && b%2 == 0 && a/2 == c && b/2 == d) ok = 1;
  	x = a*b;
  	cout<<x/2.0<<" "<<ok;

    return 0;

}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///using bs = bitset<MX>; // how many distinct number can be form?


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

using namespace std;

typedef long long ll;

int main() {
    int a, b;
    cin >> a >> b;
    cout << max(max(a + b, a - b), a * b) << endl;
    return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
h=list(map(int,input().split()))

cost=[-1 for _ in range(N)]


for i in range(N):
    if i==0:
        cost[i]=0
    else:
        siten=max(i-K,0)
        min_cost=10**12
        for j in range(siten,i):
            m=cost[j]+abs(h[j]-h[i])
            min_cost=min(m,min_cost)
        cost[i]=min_cost

print(int(cost[N-1]))

Measured memory_bytes: 56544
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	void run() {
		Scanner sc=new Scanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		char[] cs=sc.next().toCharArray();
		boolean ans=false;
		for (char c:cs) ans|=c=='7';
		pw.println(ans?"Yes":"No");
		pw.close();
	} 
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
	
    public static void main(String[] args) {
    	new Main().run();
    }
}


Measured memory_bytes: 35764
#include<cmath>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

const double PI = acos(-1);

int sx, sy, tx, ty;
int N;
int X[200111], Y[200111];
int lis[200111];

void MAIN() {
    scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
    scanf("%d", &N);
    REP (i, N) scanf("%d%d", X+i, Y+i);

    if (sx > tx) {
	swap(sx, tx);
	swap(sy, ty);
    }
    if (sy > ty) {
	sy = -sy;
	ty = -ty;
	REP (i, N) Y[i] = -Y[i];
    }
    tx -= sx;
    ty -= sy;
    REP (i, N) {
	X[i] -= sx;
	Y[i] -= sy;
    }
    sx = sy = 0;

    if (ty < tx) {
	swap(tx, ty);
	REP (i, N) swap(X[i], Y[i]);
    }

    double ans = (tx + ty) * 100.0;
    vector<pair<int, int> > v;
    REP (i, N) if (sy <= Y[i] && Y[i] <= ty && sx <= X[i] && X[i] <= tx) {
	v.emplace_back(X[i], Y[i]);
    }

    sort(v.begin(), v.end());

    memset(lis, 0x3f, sizeof lis);
    EACH (e, v) {
	*lower_bound(lis, lis+N, e->second) = e->second;
    }
    int len = lower_bound(lis, lis+N, lis[N]) - lis;

    if ((int)v.size() == len && tx + 1 == len) {
	ans += (len-1.0) * (5*PI - 20) + (10*PI - 20); 
    } else {
	ans += len * (5*PI - 20);
    }

    printf("%.20f\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 4336
// ---------- begin ModInt ----------
const MOD: u32 = 998_244_353;

#[derive(Clone, Copy)]
struct ModInt(u32);

impl std::ops::Add for ModInt {
    type Output = ModInt;
    fn add(self, rhs: ModInt) -> Self::Output {
        let mut d = self.0 + rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModInt(d)
    }
}

impl std::ops::AddAssign for ModInt {
    fn add_assign(&mut self, rhs: ModInt) {
        *self = *self + rhs;
    }
}

impl std::ops::Sub for ModInt {
    type Output = ModInt;
    fn sub(self, rhs: ModInt) -> Self::Output {
        let mut d = self.0 + MOD - rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModInt(d)
    }
}

impl std::ops::SubAssign for ModInt {
    fn sub_assign(&mut self, rhs: ModInt) {
        *self = *self - rhs;
    }
}

impl std::ops::Mul for ModInt {
    type Output = ModInt;
    fn mul(self, rhs: ModInt) -> Self::Output {
        ModInt((self.0 as u64 * rhs.0 as u64 % MOD as u64) as u32)
    }
}

impl std::ops::MulAssign for ModInt {
    fn mul_assign(&mut self, rhs: ModInt) {
        *self = *self * rhs;
    }
}

impl std::ops::Neg for ModInt {
    type Output = ModInt;
    fn neg(self) -> Self::Output {
        ModInt(if self.0 == 0 {0} else {MOD - self.0})
    }
}

impl std::fmt::Display for ModInt {
    fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl std::str::FromStr for ModInt {
    type Err = std::num::ParseIntError;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let val = s.parse::<u32>()?;
        Ok(ModInt::new(val))
    }
}

#[allow(dead_code)]
impl ModInt {
    pub fn new(n: u32) -> ModInt {
        ModInt(n % MOD)
    }
    pub fn zero() -> ModInt {
        ModInt(0)
    }
    pub fn one() -> ModInt {
        ModInt(1)
    }
    pub fn pow(self, mut n: u32) -> ModInt {
        let mut t = ModInt::one();
        let mut s = self;
        while n > 0 {
            if n & 1 == 1 {
                t *= s;
            }
            s *= s;
            n >>= 1;
        }
        t
    }
    pub fn inv(self) -> ModInt {
        assert!(self.0 > 0);
        self.pow(MOD - 2)
    }
}
// ---------- end ModInt ----------

use std::io::Read;

fn trans(dp: &mut [ModInt], a: usize) {
    for i in (a..dp.len()).rev() {
        dp[i] = dp[i] + dp[i - a];
    }
}

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let _n: usize = it.next().unwrap().parse().unwrap();
    let w: usize = it.next().unwrap().parse().unwrap();
    let a: Vec<usize> = it.map(|s| s.parse().unwrap()).collect();
    let mut ans = ModInt::zero();
    let mut dp = vec![ModInt::zero(); w + 1];
    for a in a.iter() {
        dp[0] += ModInt::one();
        trans(&mut dp, *a);
        ans += dp[w];
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 4352
a = input()
b = input()

ans = "EQUAL"
if len(a)>len(b):
    ans = "GREATER"
elif len(a)<len(b):
    ans = "LESS"
else:
    for i in range(len(a)):
        if int(a[i])>int(b[i]):
            ans = "GREATER"
            break
        elif int(a[i])<int(b[i]):
            ans = "LESS"
            break
print(ans)

Measured memory_bytes: 38384
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, readline().split()))
    s = str(readline().rstrip().decode('utf-8'))
    if s[-1] == "1":
        print(-1)
    else:
        now = n
        ans = []
        while True:
            b = False
            for j in range(now - m, now):
                if 0 <= j < n:
                    if s[j] != "1":
                        b = True
                        ans.append(now - j)
                        now = j
                        if j == 0:
                            ans.reverse()
                            print(*ans)
                            exit()
                        break
            if not b:
                print(-1)
                exit()


if __name__ == '__main__':
    solve()


Measured memory_bytes: 49648
// Why I am so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

int a[3005], b[3005];

string best[3005];

string dp[3005];

int pref[6005];

int id[6005];

char s[6005];

int n;

string calc(int l, int r) {
    static string ret;
    ret.clear();

    int cl = id[l];
    int cr = id[r + 1] - 1;

    if (s[l] == 'a') {
        int p = -1;
        
        for (int i = cl; i <= cr; ++i) {
            if (a[i] > p) {
                p = b[i];
                ret += "ab";
            }
        }
    }
    else {
        string cur;

        for (int i = cl; i <= cr; ++i) {
            cur.clear();    

            for (int j = b[i]; j <= r; ++j) {
                if (id[j] >= i && id[j] <= cr) {
                    cur += s[j];
                }
            }

            ret = max(ret, cur);
        }
    }

    return ret;
}

void solve() {                   
    scanf("%d", &n);
    scanf("%s", s + 1);
    id[n * 2 + 1] = n + 1;

    for (int i = 1, szA = 0, szB = 0; i <= n * 2; ++i) {
        pref[i] = pref[i - 1];

        if (s[i] == 'a') {
            a[++szA] = i;
            id[i] = szA;
            ++pref[i];
        }    
        else {
            b[++szB] = i;
            id[i] = szB;
            --pref[i];
        }
    }

    vector<pair<int, int>> vv;

    for (int l = 1, r; l <= (n << 1); l = r) {
        int bal = 0;
        r = l + 1;
                  
        s[l] == 'a' ? ++bal : --bal;

        while (r <= (n << 1) && bal != 0) {
            s[r] == 'a' ? ++bal : --bal;
            ++r;
        }

        vv.pb(mp(l, r - 1));
    }

    for (int i = 0; i < vv.size(); ++i) {
        best[i] = calc(vv[i].fi, vv[i].se);
    }

    for (int i = (int)vv.size() - 1; i >= 0; --i) {
        dp[i] = max(dp[i + 1], best[i] + dp[i + 1]);
    }

    cout << dp[0] << '\n';
}

int main() {    
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 10752
#include <stdio.h>

int main(void){
    long a,b,k;
    scanf("%ld %ld %ld", &a,&b,&k);

    long tmp=a;
    a -= k;

    if(a<0){
        a=0;
        b -= k-tmp;
        if(b<0){
            b=0;
        }
    }
    printf("%ld %ld\n", a,b);
    return 0;
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<cctype>
#include<iomanip>
#include<cassert>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

	int n;
	double p1_d = 0.0;
	double p2_d = 0.0;
	double p3_d = 0.0;
	double p4_d = 0.0;
	cin >> n;
	vector<double> x(n);
	vector<double> y(n);

	//xに代入
	rep(i, n){
		cin >> x[i];
	}

	//yに代入
	rep(i, n){
		cin >> y[i];
	}

	//p=1
	rep(i, n){
		p1_d += abs(x[i] - y[i]);
	}

	//p=2
	rep(i, n){
		p2_d += (x[i] - y[i]) * (x[i] - y[i]);
	}
	p2_d = sqrt(p2_d);

	//p=3
	rep(i, n){
		p3_d += abs((x[i] - y[i]) * (x[i] - y[i]) * (x[i] - y[i]));
	}
	p3_d = pow(p3_d, 1.0 / 3.0);

	//p=4
	rep(i, n){
		if (abs(x[i] - y[i]) > p4_d){
			p4_d = abs(x[i] - y[i]);
		}
	}

	//出力
	cout << fixed;
	cout << setprecision(6) << p1_d << '\n' << p2_d << '\n' << p3_d << '\n' << p4_d << '\n';

	return 0;
}


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

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

	int h, w; cin >> h >> w;
	
	for (int j = 0; j < h; j++){
		
		for (int i = 0; i < w; i++){
			string s; cin >> s;
			if (s == "snuke"){
				
				cout << char('A' + i)<<j+1 << endl;
				return 0;
			}
		}
	}
	return 0;
}



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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

const int MAX_N = 100005;

int N;
int K;

class Node {
public:
    Node() {
        l = -INF, r = -INF, p = -INF, m = 0;
    }
    vector<int> next;
    int l, r, p, m;
}nodeList[MAX_N];

using II = pair<int, int>;

bool dfs(int pos, int L, int R, int M, int pre = -1) 
{
    cerr << pos << " " << M << " " << L << " " << R << endl;
    II ret; ret.first = L; ret.second = R;

    int nextM = (M+1)%2;
    int m = (1 << M);
    Node& node = nodeList[pos];

    if(node.p != -INF) {
        m &= (1 << node.m);
        if(m == 0) {
            return false;
        }
        ret.first = node.p; ret.second = node.p;
    }

    // cerr << pos << " " << m << endl;
    
    int tmpM = m;

    for(int next : node.next) {
        if(next == pre) {
            continue;
        }
        if(!dfs(next, L-1, R+1, nextM, pos)){
            return false;
        }
        const Node& nextNode = nodeList[next];
        int mm = nextNode.m;
        if(mm == 1) {
            mm = 2;
        } else {
            mm = 1;
        }
        tmpM &= mm;
        ret.first = max(ret.first, nextNode.l-1);
        ret.second = min(ret.second, nextNode.r+1);
    }

    cerr << "ret: " << pos << " " << tmpM << " " << ret.first << " " << ret.second << endl;

    if(tmpM == 0 || ret.second - ret.first < 0) {
        return false;
    }

    node.l = ret.first;
    node.r = ret.second;
    node.m = m;

    return true;
}

void reg(int pos, int kp, int pre = -1) {
    Node& node = nodeList[pos];

    if(node.l <= kp+1 && kp+1 <= node.r && node.m == (1 << ((kp+1)%2))) {
        node.p = kp+1;
    } else {
        node.p = kp-1;
    }

    for(int next : node.next) {
        if(next == pre) {
            continue;
        }
        reg(next, node.p, pos);
    }

}

signed main()
{
    cin >> N;
    for(int i = 0; i < N-1; i++) {
        int a, b; cin >> a >> b; a--; b--;
        nodeList[a].next.push_back(b);
        nodeList[b].next.push_back(a);
    }
    cin >> K;
    int v, p;
    for(int i = 0; i < K; i++) {
        cin >> v >> p; v--; p += 1000000;
        nodeList[v].p = p;
        nodeList[v].m = p%2;
    }

    if(!dfs(v, p, p, p%2)) {
        cout << "No" << endl;
        return 0;
    } else {
        for(int nextNode : nodeList[v].next) {
            reg(nextNode, nodeList[v].p, v);
        }
    }

    cout << "Yes" << endl;
    for(int i = 0; i < N; i++) {
        cout << nodeList[i].p - 1000000 << endl;
    }

    return 0;
}

Measured memory_bytes: 20480
n=int(input())
a=list(map(int,input().split()))
b=sum(a)
ans=[0]*n
for i in range(n//2):
    ans[(i+1)*2]=ans[i*2]-(2*(a[i*2]-a[i*2+1]))
ans[1]=ans[-1]-(2*(a[-1]-a[0]))
for i in range(1,n//2):
    ans[i*2+1]=ans[(i-1)*2+1]-(2*(a[(i-1)*2+1]-a[i*2]))
c=(b-sum(ans))//n
ans2=[0]*n
for i in range(n):
    ans2[i]=c+ans[i]
print(*ans2)


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

#define MAX_N 20

long long a, b, k;
long long c[MAX_N + 1], d[MAX_N + 1], e[MAX_N + 1], bor[MAX_N + 1];
long long p[MAX_N];
long long maxn = 0;

int main() {
	cin >> a >> b >> k;
	p[0] = 1;
	for (int i = 1; i < MAX_N - 1; i++) {
		p[i] = p[i - 1] * 10;
	}
	for (int i = 0; i < MAX_N - 1; i++) {
		c[i] = (a / p[i]) % 10;
		d[i] = (b / p[i]) % 10;
	}
	for (int i = 0; i < (1 << MAX_N); i++) {
		int q[MAX_N];
		int sum = 0;
		for (int j = 0; j < MAX_N; j++) {
			q[j] = (i / (1 << j)) % 2;
			sum += q[j];
		}
		if (sum <= k) {
			for (int j = 0; j < MAX_N; j++) {
				if (q[j] == 1) {
					if (c[j] >= d[j]) {
						e[j] = c[j] - d[j];
					}
					else {
						e[j] = c[j] + 10 - d[j];
						bor[j + 1] = 1;
					}
				}
				else {
					if (c[j] - bor[j] >= d[j]) {
						e[j] = c[j] - bor[j] - d[j];
					}
					else {
						e[j] = c[j] - bor[j] +10 - d[j];
						bor[j + 1] = 1;
					}
				}
			}
			long long res = 0;
			for (int j = 0; j < MAX_N - 1; j++) {
				res += e[j] * p[j];
			}
			maxn = max(maxn, res);
		}
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<climits>
using namespace std;
int main()
{
    int n,s=0,mi=INT_MAX,i,j,c=0;
    cin>>n;
    int m[n];
    for(i=0;i<n;i++)
    {
        cin>>m[i];
    }
    for(i=0;i<n-1;i++)
    {
        if(m[i]==m[i+1])
        {
            c++;
        }
    }
    if(c==n-1)
    {
        cout<<"0"<<endl;

    }
    else{
    for(j=-105;j<=105;j++)
    {
        s=0;
        for(i=0;i<n;i++)
        {
            s=s+(m[i]-j)*(m[i]-j);
        }
        mi=min(mi,s);
    }

    cout<<mi<<endl;
    }
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
using namespace std;


int main() {
	long long n, a, b, c;
	long long x[100000];
	long long ans = 0;
	cin >> n >> a >> b;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	for (int i = 0; i < n - 1; i++) {
		c = x[i + 1] - x[i];
		if (b > c*a) {
			ans += c*a;
		}
		else {
			ans += b;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        String s = std.next();
        String[] texts = s.split("/");
        String monthS = texts[1];
        String dayS = texts[2];
        int month = Integer.parseInt(monthS);
        int day = Integer.parseInt(dayS);
        if (month <= 4 && day <= 30) {
            System.out.println("Heisei");
        } else {
            System.out.println("TBD");
        }
    }
}


Measured memory_bytes: 21716
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <bitset>
#include <sstream>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef unsigned long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void calc(int val, int div){
    if(div==0){
        cout << 0 << endl;
        return;
    }
    int res=val%div, count=1;
    while(res){
        int tmp=__builtin_popcount(res);
        res%=tmp;
        count++;
    }
    cout << count << endl;
}

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

    int first=0;
    vector<int> x(n);
    rep(i,n){
        x[i] = s[i] - '0';
        if(x[i]) first++;
    }
    
    int pos=0,neg=0;
    vector<int> pmod(n), nmod(n);
    pmod[0] = 1; nmod[0]=1;
    rep(i,n){
        pos= (pos*2+x[i])%(first+1);
        if(first>1) neg= (neg*2+x[i])%(first-1);
    }
    rep(i,n-1){
        pmod[i+1] = (pmod[i]*2)%(first+1);
        if(first>1) nmod[i+1] = (nmod[i]*2)%(first-1);
    }

    rep(i,n){
        if(x[i]){
            calc(neg-nmod[n-1-i]+first-1, first-1);
        }
        else{
            calc(pos+pmod[n-1-i], first+1);
        }
    }
    return 0;
}


Measured memory_bytes: 5992
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#define LL long long 
using namespace std;
int a[110];
int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	int ans = 0;
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; i++)
		for(int j = i + 1; j <= n; j++)
			for(int k = j + 1; k <= n; k++)
				if(a[i] != a[j] && a[j] != a[k]&& a[i] + a[j] > a[k])
					ans ++;
	printf("%d",ans); 
	return 0;
 } 

Measured memory_bytes: 3828
fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map {it.toInt()}
    val a = readLine()!!.split(" ").map{it.toLong()}.sorted()

    var l = -1
    var u = a.size

    while (u - l > 1) {
        val c = (l + u) / 2

        fun judge(c: Int): Boolean {
            if (a[c] >= K) return true

            val dp = BooleanArray(K) { false }
            dp[0] = true

            for (i in a.indices) {
                if (i == c) continue
                if (a[i] >= K) continue

                for (k in K - 1 downTo a[i].toInt()) {
                    dp[k] = dp[k] || dp[k - a[i].toInt()]
                }
            }

            for (i in K - a[c].toInt() until K) {
                if (dp[i]) return true
            }

            return false
        }

        if (judge(c)) {
            u = c
        } else {
            l = c
        }
    }

    println(u)
}


Measured memory_bytes: 41996
n=int(input())
a=n//100
b=n%100
if((a>12 or a==0) and b<13 and b>0):
  print("YYMM")
elif(a<13 and (b>12 or b==0) and a>0):
  print("MMYY")
elif(a<13 and b<13 and b>0 and a>0):
  print("AMBIGUOUS")
else:
  print("NA")

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

int main() {
  int n;
  int ans = 0;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n-1);
  for(int i=0;i<n;i++){
    cin >> a.at(i);}
  for(int i=0;i<n;i++){
    cin >> b.at(i);}
  for(int i=0;i<n-1;i++){
    cin >> c.at(i);}
  
  for(int k=0;k<n;k++){
    ans += b.at(k);}
  for(int j=0;j<n-1;j++){
    if(a.at(j+1)-a.at(j)==1){
      ans += c.at(a.at(j)-1);}
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256