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

typedef long long ll;
ll A, B, C, K;

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

    ll res = 0;
    if(K <= A){
        cout << K << endl;
    }
    else{
        res += A;
        K -= A;
        if(K <= B){
            cout << res << endl;
        }
        else{
            K -= B;
            res -= K;
            cout << res << endl;
        }
    }
    return 0;
}

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

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    string t;
    cin >> t;
    map<char, ll> mp;
    ll flag = 0;
    ll ans = 0;
    ll ans2 = 0;
    rep(i, t.size()){
        if(t[i] == 'P'){
            flag = 1;

            cout << 'P';
        }
        if(t[i] == 'D' || t[i] == '?'){
            if(flag == 1){
                ans++;
            }
            ans2++;
            flag = 0;
            cout << 'D';
        }

    }
    br;

    //cout << ans + ans2 << endl;


}

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

public class Main {

	static Scanner scanner;

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

        int n=gi();
        int[] d=new int[n];

        for (int i=0; i<n;i++) {
            d[i]=gi();
        }

        if(d[0]!=0) {
        	System.out.println(0);
        	return;
        }

        Arrays.parallelSort(d);

        int i=1;
        int now=1;
        long ans =1;
        long bc=1;
        while (i<d.length) {
            long cnt=0;
            while(i<d.length) {
                if(d[i]<now) {
                    System.out.println(0);
                    return;
            	} else if(d[i]>now) {
            		break;
            	} else {
            		cnt++;
            	}
                i++;
            }
            now++;
            long mod=modpow(bc, cnt, 998244353l);
            ans= (ans*mod) % 998244353l;
            bc=cnt;
        }

        System.out.println(ans);
	}

	// a^nをmodで割ったあまり
	public static long modpow(long a, long n, long mod) {
		long res=1;
		while(n>0) {
			if((n & 1) == 1) res=res*a%mod;
			a=a*a%mod;
			n=n>>1;
		}
		return res;
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 59644
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main(){
    VI a,b;
    int as=0,bs = 0;
    int N,K;
    cin >> N >> K;
    FOR(i,0,N){
        int n;
        cin >> n;
        if( n > 0 ){
            a.push_back(n);
            as++;
        }else if(n < 0){
            b.push_back(-1*n);
            bs++;
        }else{
            K--;
        }
    }
    if(b.size() == 0){ b.push_back(0);}
    if(a.size() == 0){ a.push_back(0);}
    int ans = -1;
    FOR(ofs,0,N-K+1){
        if( bs - ofs > K || ofs-bs > 0) continue;
        int bw = bs - ofs;
        int aw = K - bw;
        int t;
        if( a[aw-1] <= b[bs-bw] ){
            t = a[aw-1]*2 + b[bs-bw];
        }else{
            t = a[aw-1]   + b[bs-bw]*2;
        }
        if(ans < 0 || t < ans){
            ans = t;
        }        
    }

    cout << ans << endl;
    
    /* 
          FOR(j,0,W){
          FOR(i,0,H){
              if(minh <= i && maxh >= i
                 && minw <= j && maxw >= j )
                  cout << sv[i].at(j);
          }
          cout << endl;
      }    
     */
}

   






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

int main(){
    int w,h,tim;
    int p;
    cin >> w >> h >> tim;
    cin >> p;
    int hei[50][50]={{}};
    for(int i=0;i<p;i++){
        int x,y,t;
        cin >> x >> y >> t;
        hei[x][y]++;
    }
    int sum=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int a;
            cin >> a;
            //cout << hei[j][i] << " ";
            if(a)sum+=hei[j][i];
        }
      //  cout << endl;
   }
    cout << sum << endl;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int inf=409;
ll dp[inf][inf],n,a[inf],par[inf];

ll sum(ll l,ll r){

    return par[r]-par[l-1];
}

ll solve(ll l,ll r){

    if(l==r)
        return 0;

    if(r-l+1==2)
        return a[r]+a[l];

    ll &ret=dp[l][r];
    if(ret!=-1)
        return ret;
    ret=1e18+9;

    for(ll i=l;i<r;i++)
        ret=min(ret,solve(l,i)+solve(i+1,r)+sum(i+1,r)+sum(l,i));

    return ret;
}

int main(){

    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i],par[i]=par[i-1]+a[i];

    memset(dp,-1,sizeof(dp));
    cout<<solve(1,n)<<endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int main(){

  long long int N; cin >> N;
  long long l = N;
  vector<int> keta;
  while(true){
    keta.push_back(N % 10);
    N /= 10;
    if(N == 0)break;
  }


  reverse(keta.begin(),keta.end());


  long long int ans = 0;

  if(keta.size() == 1)ans = l;
  else{
    bool flag = true;
    for(int i = 1;i < keta.size();i++){
      if(keta[i] != 9)flag = false;
    }

    if(flag){
      for(int i = 0;i < keta.size();i++)ans += keta[i];
    }
    else{
      for(int i = 0;i < keta.size()-1;i++)ans += 9;
      ans += keta[0]-1;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const int N=101;
char a1[N],a2[N],a[N],b[N];
int cl[N],n;
ll ans=0,f[N][N];
ll upd(ll &x,ll y){x+=y;}
void calc(){
    int i,s1=0,s2=0,j;
    for(i=1;i<=n;i++){
        if(cl[i]==0) a1[++s1]=a[i];
        else a2[++s2]=a[i];
    }
    for(i=0;i<=s1;i++)for(j=0;j<=s2;j++) f[i][j]=0;
    f[0][0]=1;
    for(i=0;i<=s1;i++)
        for(j=0;j<=s2;j++){
            if(b[i+j+1]==a1[i+1]) upd(f[i+1][j],f[i][j]);
            if(b[i+j+1]==a2[j+1]) upd(f[i][j+1],f[i][j]);
        }
    upd(ans,f[s1][s2]);
}
void dfs(int x){
    if(x>n){calc();return;}
    cl[x]=0;dfs(x+1);
    cl[x]=1;dfs(x+1);
}
int main(){
    int i,k=0;
    scanf("%d",&n);
    scanf("%s",a+1);
    for(i=2*n;i>n;i--) b[++k]=a[i];
    dfs(1);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
n,q = map(int,input().split())
s = input()
inf = [0]*n
num = 0
for i in range(1,n):
    if s[i] == "C" and s[i-1] == "A":
        num += 1
    inf[i] += num
for i in range(q):
    a,b = map(int,input().split())
    print(inf[b-1] - inf[a-1])

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

typedef pair <int, int> pii;

const int MAX_N = 1e5 + 5;
int n, m;
int par[MAX_N];
int height[MAX_N];
int deep[MAX_N];
int cnt[MAX_N];
vector <int> child[MAX_N];
pii Arr[MAX_N];

int root(int v) {
	return (par[v] == v? v: root(par[v]));
}

void dfs(int v) {
	deep[v] = 1 + deep[par[v]];
	for (int i = 0; i < child[v].size(); i++)
		dfs(child[v][i]);
}

int DFS(int v) {
	int res = 0;
	for (int i = 0; i < child[v].size(); i++) {
		int o = DFS(child[v][i]);
		if (o == -1)
			return -1;
		res += o;
	}
	res += cnt[v];
	if (res & 1)
		return -1;

	return res;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		par[i] = i;
		height[i] = 1;
	}

	for (int i = 0; i < m; i++) {
		cin >> Arr[i].first >> Arr[i].second;
		Arr[i].first--;
		Arr[i].second--;
		if (root(Arr[i].first) != root(Arr[i].second)) {
			if (height[root(Arr[i].second)] < height[root(Arr[i].first)])
				swap(Arr[i].first, Arr[i].second);

			if (height[root(Arr[i].first)] == height[root(Arr[i].second)])
				height[root(Arr[i].second)]++;
			
			par[root(Arr[i].first)] = root(Arr[i].second);
		}
	}

	for (int i = 0; i < n; i++)
		if (par[i] != i)
			child[par[i]].push_back(i);

	for (int i = 0; i < n; i++)
		if (par[i] == i)
			dfs(i);

	for (int i = 0; i < m; i++) {
		if (deep[Arr[i].second] < deep[Arr[i].first])
			swap(Arr[i].first, Arr[i].second);
		cnt[Arr[i].second]++;
		cnt[Arr[i].first]--;
	}

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

	cout << "YES\n";
	return 0;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = (1e5)+1;

int n, m;
vector<ll> a, need;
priority_queue<pair<ll, ll> > q;
ll f[MAX];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	a.push_back(n);
	for(int i = 0; i < m; i++) {
		ll x; cin >> x;
		while(!a.empty() && a.back() >= x) a.pop_back();
		a.push_back(x);
	}
	need.resize(a.size());
	need.back() = 1;
	for(int i = a.size()-1; i >= 0; i--) {
		while(!q.empty() && q.top().first >= a[i]) {
			need[i] += (q.top().first / a[i]) * q.top().second;
			if(q.top().first % a[i]) q.emplace(q.top().first % a[i], q.top().second);
			q.pop();
		}
		if(i > 0) {
			if(a[i] % a[i-1]) q.emplace(a[i] % a[i-1], need[i]);
			need[i-1] += (a[i] / a[i-1]) * need[i];
		} else {
			f[a[0]] += need[i];
			while(!q.empty()) {
				assert(q.top().first <= a[0]);
				f[q.top().first] += q.top().second;
				q.pop();
			}
		}
	}
	for(int i = n-1; i >= 1; i--) f[i] += f[i+1];
	for(int i = 1; i <= n; i++) cout << f[i] << '\n';
}


Measured memory_bytes: 5744
#include<iostream>
#include<string>

using namespace std;

int main(void){

string s="",t="";


while(1){
	cin>>s;
	if(s.size()==0 || s.size()>10){
		cout<<"IDは1文字以上10文字未満です。"<<endl;
	}else{
		break;
	}
}


	cin>>t;
	t.pop_back();
	if(s==t){
		cout<<"Yes"<<endl;
	}else{
		 cout<<"No"<<endl;
	}

return 0;
}

Measured memory_bytes: 3612
import java.util.*;


public class Main {

    private static final int INF = Integer.MAX_VALUE;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double w = sc.nextDouble();
        double h = sc.nextDouble();
        double x = sc.nextDouble();
        double y = sc.nextDouble();

        if(x == w / 2 && y == h / 2){
            System.out.println((w * h) / 2 + " " + 1);
        }else{
            System.out.println((w * h)/ 2 + " " + 0);
        }
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define LOL cout<<'\n';
#define MOD 1000000007
#define sz(x) ((int)x.size())
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define deb(x) cout << "[" << #x << "=" << x << "]" << '\n';
#define deb2(x,y) cout << "[" << #x << "=" << x << "] [" << #y << "=" << y << "]" << '\n';
#define deb3(x,y,z) cout << "[" << #x << "=" << x << "] [" << #y << "=" << y << "] [" << #z << "=" << z << "]" << '\n';

void solve(){
	int n,m; cin>>n>>m;
	cout<<(n*(n-1))/2+(m*(m-1))/2;
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int _=1; //cin>>_;
  while(_--) solve();
  return 0;
}

Measured memory_bytes: 3656
import System.IO
import Control.Applicative ((<$>))

main = do
 s <- getLine
 putStrLn $ show $ cranke s 0

cranke :: [Char] -> Int -> Int
cranke [x] n = n
cranke (a:b:xs) n | a == b = cranke (b:xs) n
                  | otherwise = cranke (b:xs) (n+1)

Measured memory_bytes: 4988
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll Mod = 1000000007;
int main() {
  ll N,M;
  cin >> N >> M;
  vector<ll> A(N);
  vector<P> Card(M);
  for (int i = 0; i < N; i++ ){
    cin >> A[i];
  }
  ll sum = 0;
  for (int i = 0; i < M; i++) {
    cin >> Card[i].second >> Card[i].first;
    sum += Card[i].second;
  }
  sort(Card.begin(),Card.end());
  reverse(Card.begin(),Card.end());
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    A.push_back(Card[cnt].first);
    Card[cnt].second--;
    if (Card[cnt].second == 0) {
      cnt++;
    }
    if (i == sum - 1) {
      break;
    }
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += A[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>

#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#include <iomanip>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll mod = 1e9 + 7;


ll N, ans;


int main() {

	cin >> N;
	FOR(i, 0, N+1) {
		int cur = i;
		int cnt = 0;
		while (cur > 0) {
			cnt++;
			cur /= 10;
		}
		if (cnt % 2 == 1)ans++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>

using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)

int main(int argc, char *argv[]) {
    int a, b, result;
    cin >> a >> b;

    if (a * b % 2 != 0){
        cout << "Odd";
    }else
        cout << "Even";
    return 0;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
li=[input().split() for _ in range(H)]
a=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
for i in range(H):
  if "snuke" in li[i]:
    break
j=li[i].index("snuke")
print(a[j]+str(i+1))

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<=(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	string s, t;
	cin >> s >> t;
	char tmp;
	tmp = s[0];
	s[0] = s[2];
	s[2] = tmp;
	if (s == t) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}



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

int main()
{
    int n, k;
    cin >> n >> k;
    bool d[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
    for (int i = 0; i < k; i++) {
        int a;
        cin >> a;
        d[a] = 0;
    }

    int ans = n;
    while (1) {
        int i = ans;
        bool flag = 1;
        while (i != 0) {
            if (!d[i%10]) flag = 0;
            i /= 10;
        }
        if (flag) break;
        ans++;
    }

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

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <math.h>
// Custom Header <<<
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD  = int(1e9) + 7;
// >>>


signed main()
{
    i64 W, H, x, y;
    cin >> W >> H >> x >> y;

    long double w = W / 2.0;
    long double h = H / 2.0;

    long double ans = W * H / 2.0;

    int p = 0;
    if (fabs(w - x) < 1e-10 && fabs(h - y) < 1e-10) {
        p = 1;
    }

    printf("%.10LF %d\n", ans, p);

    return 0;
}

/* vim:set foldmethod=marker foldmarker=<<<,>>> : */


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cstdlib>

using namespace std;

class c_selection
{
private:
    int n;
    long x[100];
    
public:
    void f_selection();
    
};

void c_selection::f_selection()
{
    int i, j;
    int k;
    int min_x;
    int temp1;
    int temp2;
    int c;
    
    cin >> n;
    for ( i = 0; i < n; ++i){
        cin >> x[i];        
    }
    
    c = 0;
    temp2 = 0;
    
    for ( i = 0; i < n; ++i){
        min_x = i;
        temp2 = 0;
        for ( j = i; j < n; ++j){
            if (x[j] < x[min_x]){
                min_x = j;
                temp2 = 1;
            }
        }
        if (temp2 == 1){
            temp1 = x[min_x];
            x[min_x] = x[i];
            x[i] = temp1;
            c += 1;
            //cout << "i = "<< i << endl;
            //cout << "j = "<< j << endl;
            /*
            for ( k = 0; k < n; ++k){
                cout << x[k];
                if( k == n-1){
                    cout << endl;
                }else{
                    cout << " ";
                } 
            }
            */
        }
    }
    
    for ( i = 0; i < n; ++i){
        cout << x[i];
        if( i == n-1){
            cout << endl;
        }else{
            cout << " ";
        }        
    }
    cout << c << endl;
}

int main(){
    c_selection selection01;
    
    selection01.f_selection();
    
    return 0;
}

Measured memory_bytes: 3096
#include<stdio.h>
int main(void){
    int H,W,i,j,l;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0&&W==0){
            break;
        }
        for(i=1;i<=H;i++){

            for(j=1;j<=W;j++){
                if(i%2==0){
                    if(j%2==0){
                        printf("#");
                    }
                    else if(j==1||j%2==1){
                        printf(".");
                    }
                }
                if(i==1||i%2==1){
                    if(j%2==0){
                        printf(".");
                    }
                    if(j==1||j%2==1){
                        printf("#");
                    }
                }
            }
            printf("\n");
        }
        printf("\n");
    }


    return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 1000000007
#define h1 7897897897897897
#define h2 7897466719774591
#define b1 98762051
#define b2 98765431
#define inf 1000000000
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pii>
#define SET(a, b) memset(a, b, sizeof(a));
#define all(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
int n, m, k, t, T, x, y, sum, cnt, ans;
ll pref[100005], down[100005],dp[100005], up[100005];
vi edges[100005];
void dfs(int x, int p) {
  down[x] = 1;
  for (auto y: edges[x]) {
    if (y != p) {
      dfs(y, x);
      pref[y] = down[x];
      down[x] = down[x] * (down[y] + 1) % m;;
    }
  }
  int sz = edges[x].size();
  ll cur = 1;
  FORD(i, sz - 1, 0) {
    y = edges[x][i];
    if (y != p) {
      up[y] = pref[y] * cur % m;
      cur = cur * (down[y] + 1) % m;
    }
  }
}
void dfs2(int x, int p) {
  if (p == -1) dp[x] = down[x];
  for (auto y: edges[x]) {
    if (y != p) {
      up[y] = up[y] * (up[x] + 1) % m;
      dp[y] = down[y] * (up[y] + 1) % m;
      dfs2(y, x);
    }
  }
}
int main () {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  FOR(i, 1, n-1) {
    cin >> x >> y;
    edges[x].pb(y);
    edges[y].pb(x);
  }
  dfs(1, -1);
  FOR(i, 1, n) {
    cerr << down[i] << ' ' << up[i] <<  endl;
  }
  dfs2(1, -1);
  FOR(i, 1, n) {
    cout << dp[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 17776
#include<stdio.h>
int main(){
int n,a,b,ans1=111,ans2=0;
scanf("%d%d%d",&n,&a,&b);
ans1=a;
if(b<ans1)
ans1=b;
if(ans2<a+b-n)
ans2=a+b-n;
printf("%d %d\n",ans1,ans2);
return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define ll long long
#define umapii unordered_map <int,int>
#define umapll unordered_map<ll,ll>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define vs vector<string>
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define endl '\n'
#define all(v) (v).begin(),(v).end()
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define MP(a,b) make_pair(a,b)
#define debug(x)       cerr<< #x << " : " << x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[i].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";

/* ordered set: 
tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
member functions :
1. order_of_key(k) : number of elements strictly lesser than k
2. find_by_order(k) : k-th element in the set
*/
ll modexp(ll x, ll ex , ll md) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}

const int inf = 1e9 + 7;
int main(){
    IOS;
    string s , t;
    cin >> s >> t;
    if(t.substr(0 , (int) s.length()) == s) cout << "Yes\n";
    else cout << "No\n";
    #ifdef LOCAL
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";       
    #endif
    // g++ -DLOCAL -std=c++17 f.cpp
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll N,L,T;
    cin >> N >> L >> T;
    vector<ll> X(N),W(N);
    rep(i,N){
        cin >> X[i] >> W[i];
    }
    vector<ll> tmp;
    // まずはありの最終的な座標を出す
    rep(i,N){
        if(W[i]==1)tmp.push_back((X[i] + T) % L);
        else tmp.push_back((((X[i]-T)%L)+L)%L);
    }
    sort(ALL(tmp));
    // 次に原点から見て一番近い所のindexを探す
    ll cnt = 0;
    rep(i,N){
        // ありさんが原点を右から左に通過するときは cnt++;
        // 左から右に通過するときは cnt--;
        // 現在地がX[i] で T 秒間にどれだけ原点を通るかを出したい
        if(W[i]==1){
            cnt -= (T+X[i])/L;
        }else{
            cnt += (T+L-X[i]-1)/L;
        }
    }
    cnt = ((cnt%N)+N)%N;
    vector<ll> res(N);
    rep(i,N)res[(i+cnt)%N] = tmp[i];
    for(auto x:res)cout << x << endl;
}

Measured memory_bytes: 4468
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>

long long int Warshell_Floyd(std::vector<std::vector<long long int> > &G, std::vector<std::vector<long long int> > &reached, long long int V);

int main(){

  long long int H, W;
  scanf("%lld%lld", &H, &W);

  std::vector<std::string> field;
  std::string str_tmp;

  for(long long int i = 0; i < H; i++){
    std::cin >> str_tmp;
    field.push_back(str_tmp);
  }

  /*std::cerr << "field: " << std::endl;
  for(long long int i = 0; i < H; i++){
    std::cerr << field[i] << std::endl;
  }*/

  std::vector<std::vector<long long int> > G(H*W);
  std::vector<std::vector<long long int> > reached(H*W);

  for(long long int i = 0; i < H*W; i++){
    for(long long int j = 0; j < H*W; j++){
      G[i].push_back(0);
      reached[i].push_back(0);
    }
  }

  for(long long int i = 0; i < H; i++){
    for(long long int j = 0; j < W-1; j++){
      if(field[i][j] == '.' && field[i][j+1] == '.'){
        G[i*W+j][i*W+j+1] = 1;
        G[i*W+j+1][i*W+j] = 1;
        reached[i*W+j][i*W+j+1] = 1;
        reached[i*W+j+1][i*W+j] = 1;
      }
    }
  }

  for(long long int i = 0; i < H-1; i++){
    for(long long int j = 0; j < W; j++){
      if(field[i][j] == '.' && field[i+1][j] == '.'){
        G[i*W+j][(i+1)*W+j] = 1;
        G[(i+1)*W+j][i*W+j] = 1;
        reached[i*W+j][(i+1)*W+j] = 1;
        reached[(i+1)*W+j][i*W+j] = 1;
      }
    }
  }

  /*for(long long int i = 0; i < H*W; i++){
    for(long long int j = 0; j < H*W; j++){
      std::cerr << G[i][j] << " ";
    }std::cerr << std::endl;
  }*/

  Warshell_Floyd(G, reached, H*W);

  long long int ans = 0;
  for(long long int i = 0; i < H*W; i++){
    for(long long int j = i+1; j < H*W; j++){
      ans = std::max(ans, G[i][j]);
    }
  }

  std::cerr << "Answer: " << std::endl;
  std::cout << ans << std::endl;

  return 0;

  
  
}

long long int Warshell_Floyd(std::vector<std::vector<long long int> > &G, std::vector<std::vector<long long int> > &reached, long long int V){
  for(long long int k = 0; k < V; k++){
    for(long long int i = 0; i < V; i++){
      for(long long int j = 0; j < V; j++){
        if(reached[i][k] && reached[k][j]){
          if(reached[i][j]){
            G[i][j] = std::min(G[i][j], G[i][k] + G[k][j]);
          }
          else{
            G[i][j] = G[i][k] + G[k][j];
            reached[i][j] = 1;
          }
        }
      }
    }
  }
  
  return 0;
}



Measured memory_bytes: 3456
use proconio::input;
use proconio::marker::Usize1;

fn main() {
    input! {
        n: usize,
        k: usize,
        a: [Usize1; n],
    }

    let mut v: Vec<Vec<usize>> = vec![a];
    let mut i = 1usize;
    while i < k {
        let p = v.last().unwrap().clone();
        let mut next = vec![0; n];
        for j in 0..n {
            next[j] = p[p[j]];
        }
        v.push(next);
        i *= 2;
    }

    let mut k = k;
    let mut c = 0;
    let mut ans: Vec<usize> = (0..n).collect();
    while k > 0 {
        let p = ans.clone();
        if k & 1 > 0 {
            for i in 0..n {
                ans[i] = v[c][p[i]];
            }
        }
        c += 1;
        k /= 2;
    }

    println!("{}", ans[0] + 1);
}



Measured memory_bytes: 101608
import java.util.Scanner;

public class Main {
	public static Scanner sc;
	public static void main(String[] args){
		sc=new Scanner(System.in);
		String W=sc.next(),T;
		int ans=0;
		while(true){
			T=sc.next();
			if(T.equals("END_OF_TEXT"))break;
			if(T.equalsIgnoreCase(W))ans++;
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 26300
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<pair<int, int>>>;

int n;
vector<int> color(n, -1);

void dfs(Graph &G, int v, int cur = 0)
{
    color[v] = cur;

    rep(i, G[v].size())
    {
        if (color[G[v][i].first] == -1)
        {
            if (G[v][i].second % 2 == 0)
            {
                dfs(G, G[v][i].first, cur);
                continue;
            }
            dfs(G, G[v][i].first, 1 - cur);
        }
    }
}

int main()
{
    cin >> n;
    Graph G(n);
    rep(i, n - 1)
    {
        int u, v, w;
        cin >> u >> v >> w;
        G[u - 1].push_back({v - 1, w});
        G[v - 1].push_back({u - 1, w});
    }

    color.assign(n, -1);

    rep(i, n)
    {
        if (color[i] != -1)
            continue;
        dfs(G, i);
    }
    rep(i, n) cout << color[i] << endl;
    return 0;
}

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

typedef unsigned long long ullong;

ullong N;
ullong P;

ullong prim_fact(ullong n) {
    ullong ans = 1;
    for(ullong i = 2; (i * i) <= P; i++){
        ullong cnt = 0;
        ullong p = P;
        while((p % i) == 0){
            cnt++;
            p /= i;
        }
        
        if(cnt >= N) {
            ans = i;
        }
    }
    return ans;
}

int main(int argc, const char * argv[]) {
    
    cin >> N >> P;
    
    if (N == 1) {
        cout << P << endl;
    } else {
        ullong count = prim_fact(P);
        
        cout << count << endl;
    }
    
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////


int main(){fastio
    
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll ans=1;
    ll now=a[0];
    rep(i,1,n-1){
        if(now<=a[i]){
            ans++;
        }
        Max(now,a[i]);
    }
    cout<<ans<<endl;
    
    return 0;
}





Measured memory_bytes: 764
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

enum MOD = (10 ^^ 9) + 7;

void main()
{
    long A, B, C;
    scan(A, B, C);
    solve(A, B, C).writeln();
}

long solve(long A, long B, long C)
{
    if (C <= (A + B))
    {
        return B + C;
    }
    else if (C - 1 == A + B)
    {
        return B + C;
    }
    else
    {
        return (A + B) * 2 - A + 1;
    }
}


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

N,K=map(int,input().split())
A=[int(input()) for i in range(N)]

def seg_function(x,y): # Segment treeで扱うfunction
    return max(x,y)

seg_el=1<<((300000).bit_length()) # Segment treeの台の要素数
SEG=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化

def update(n,x,seg_el): # A[n]をxに更新
    i=n+seg_el
    SEG[i]=max(SEG[i],x)
    i>>=1 # 子ノードへ
    
    while i!=0:
        SEG[i]=seg_function(SEG[i*2],SEG[i*2+1])
        i>>=1
        
def getvalues(l,r): # 区間[l,r)に関するseg_functionを調べる
    L=l+seg_el
    R=r+seg_el
    ANS=0

    while L<R:
        if L & 1:
            ANS=seg_function(ANS , SEG[L])
            L+=1

        if R & 1:
            R-=1
            ANS=seg_function(ANS , SEG[R])
        L>>=1
        R>>=1

    return ANS

for a in A:
    MAX=getvalues(max(0,a-K),min(300001,a+K+1))
    update(a,MAX+1,seg_el)
print(SEG[1])


Measured memory_bytes: 129924
using System;

namespace ABC171A
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().ToCharArray()[0];
            if (char.IsLower(input))
            {
                Console.WriteLine("a");
            }
            else
            {
                Console.WriteLine("A");
            }
        }
    }
}


Measured memory_bytes: 17424
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define qwq(x) cerr<<"# "<<#x<<" = "<<x<<endl;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef double ld;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=(1<<16)+5;
namespace{
	const int mod=1e9+7;
	int fac[N],rev[N];
	int power(int x,int p){
		int res=1;
		for(;p;p>>=1,x=(ll)x*x%mod)
			if(p&1)res=(ll)res*x%mod;
		return res;
	}
	int C(int n,int m){
		return m<0||m>n?0:(ll)fac[n]*rev[m]%mod*rev[n-m]%mod;
	}
	void add(int &x,int y){
		x=(x+y>=mod?x+y-mod:x+y);
	}
	int mul(int x,int y){
		return (ll)x*y%mod;
	}
	void init(){
		const int n=1<<16;
		fac[0]=1;
		rep(i,1,n)fac[i]=(ll)fac[i-1]*i%mod;
		rev[n]=power(fac[n],mod-2);
		per(i,n,1)rev[i-1]=(ll)rev[i]*i%mod;
	}
}
int f[18][N],a[18];
int n,m,ans;

int main(){
	read(n),read(m),init();
	rep(i,1,m)read(a[i]);
	f[m+1][0]=1;
	per(i,m,1){
		memcpy(f[i],f[i+1],sizeof f[i]);
		REP(s,1<<n)if(f[i+1][s])
			rep(k,0,n-1)if(!(s>>k&1)){
				int coef=mod-mul(fac[1<<k],C((1<<n)-a[i]-s,(1<<k)-1));
				add(f[i][s|(1<<k)],mul(f[i+1][s],coef));
			}
	}
	REP(s,1<<n)add(ans,mul(fac[(1<<n)-s-1],f[1][s]));
	printf("%d\n",mul(1<<n,ans));
	return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define all(v) v.begin(),v.end()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, greater_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;

int main() {
	fast_io;
	int n;
	cin >> n;
	long double ans = pi * 2 * n ;
	cout << setprecision(10) << ans << '\n';
}


Measured memory_bytes: 3808
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <locale>
using namespace std;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int num = 0;
    for(int i=0;i < n-1;i++){
        if(s[i]=='A' && s[i+1]=='C'){
            num++;
        }
    }
    if(num >= 1){cout << "Yes" << endl;}
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int n,p[20],s[1<<20],s1[1<<10];

int main(){
	while(cin>>n){
		if(!n)return 0;
		int n2=n/2;
		fill(s1,s1+(1<<n2),0);
		int sum=0,dif=1e+9;
		for(int i=0;i<n;i++){cin>>p[i];sum+=p[i];}
		if(n<11){
			fill(s,s+(1<<n),0);
			for(int i=0;i<1<<n;i++){
				int sss=0;
				for(int j=0;j<n;j++)if((i/(1<<j))%2)sss+=p[j];
				dif=min(dif,abs(sss*2-sum));
			}
			cout<<dif<<endl;
		}
		else{
		for(int i=0;i<1<<n2;i++){
			for(int j=0;j<n2;j++)if(i>>j&1)s1[i]+=p[j];
		}
		sort(s1,s1+(1<<n2));
		int ans=1e+9;
		for(int i=0;i<1<<(n-n2);i++){
			int ss=0;
			
			for(int j=0;j<n-n2;j++)if(i>>j&1)ss+=p[j+n2];
			ans=min(ans,min(abs((*lower_bound(s1,s1+(1<<n2),(sum+1)/2-ss)+ss)*2-sum),abs((*(lower_bound(s1,s1+(1<<n2),(sum+1)/2-ss)-1)+ss)*2-sum)));
		}
		cout<<ans<<endl;
		}
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
 
#define int         long long
#define pb          push_back
#define mp          make_pair
#define scan(a, n)  for(int i = 0; i < n;i++)cin >> a[i];
#define print(a, n) for(int i = 0; i < n;i++)cout << a[i] <<' ';cout<<endl;
#define w(x)        int x; cin>>x; while(x--)
#define endl 		'\n'
#define Sort(v) 	sort(v.begin(), v.end())
// Tushar Goyal

const int INF = 1e9+5;
void solve() 
{
	int i, j, k, q ,n, m, ans = 0, cnt = 0, sum = 0,input;
	cin>>n;
	vector<int> h(n);
	scan(h,n);
	// print(h,n);
	vector<int> dp(n,INF);
	dp[0] = 0;
	for(int i = 0 ; i<n ; i++){
		for(int j=i+1;j<=i+2 and j<n;j++){
			if(j<n)dp[j] = min(dp[j],dp[i] + abs(h[j]-h[i]));
		}
	}

	cout<<dp[n-1]<<endl;

}
 
int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//    w(T)
    {
	    solve();
    }
    return 0;
}

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

using namespace std;

using int64 = long long;

int main()
{
  int A, B;
  string S;


  cin >> A >> B;
  cin >> S;

  if(S.find('-') == A && count(begin(S), end(S), '-') == 1) {
    puts("Yes");
  } else {
    puts("No");
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int n;
multiset<int> S, T;
vector<int> v;

int main() {
    cin >> n;
    REP(i,(1<<n)){
        int s;
        cin >> s;
        S.insert(s);
        v.push_back(s);
    }
    T.insert(*--S.end());
    S.erase(--S.end());
    S.insert(IINF);
    vector<int> tmp;
    REP(i,n){
        tmp.clear();
        for(auto itr = --T.end();;--itr){
            int x = *itr;
            auto y = S.lower_bound(x);
            if(y == S.begin()){
                cout << "No" << endl;
                return 0;
            }
            --y;
            tmp.push_back(*y);
            S.erase(y);
            //assert(x > *y);
            if(itr == T.begin()) break;
        }
        for(auto x : tmp) T.insert(x);
    }
    SORT(v);
    int k = 0;
    bool ok = true;
    for(auto x : T){
        //assert(v[k] == x);
        k++;
    }
    cout << (ok?"Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 14580
#include <iostream>
#include <string>

using namespace std;

typedef long long ll;

ll n, ans;
string s;
ll ls[5500][5500];

int main() {
  cin >> n >> s;
  
  for (int i = 0; i < n; i++) {
    ls[i][i] = n - i;
    ll j = 1, len = 0;
    while (i+j < n) {
      while (i+j+len < n and s[i+len] == s[i+j+len]) len++;
      ls[i][i+j] = len;
      ans = max(ans, min(j, len));
      if (len == 0) {
        j++;
        continue;
      }
      ll k = 1;
      while (k + ls[i][i+k] < len) {
        ls[i][i+j+k] = ls[i][i+k];
        ans = max(ans, min(j, ls[i][i+k]));
        k++;
      }
      j += k;
      len -= k;
    }
  }     
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 215296
#def main(S, b):
if __name__ == '__main__':
    n, m = map(int, input().split())

    a = list(map(int, input().split()))

    s = sum(a)
    cnt = 0
    for i in range(n):
        if (a[i] >= s / 4 / m):
            cnt += 1
    #print(cnt)
    if (cnt >= m):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
double num[11][11];
int main()
{
	int n,d;
	scanf("%d %d",&n,&d);
	int count=0;
	for(int i=0;i<n;i++)
	{
		
		for(int j=0;j<d;j++)
		{
			scanf("%lf",&num[i][j]);
		//	printf("%lf ",num[i][j]);
		}
	}
	
	
	for(int i=0;i<n;i++)
	{
		
		for(int j=i+1;j<n;j++)
		{
			double sum=0;
			if(j==i)
			continue;
			
			for(int k=0;k<d;k++)
			{
				sum+=pow(num[i][k]-num[j][k],2.0);
			}
			//printf("bijiao %d %d\n",i,j);
			//printf("sum=%lf\n",sum);
			double tmp=sqrt(sum);
			//printf("test",tmp);
			if(tmp-floor(tmp)==0.000) 
			count++;
		//	printf("tmp=%lf\n",tmp);
		}
		
		
		
		
	}
	printf("%d",count);
	
 } 

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
#define f0r(a, b) for (long long a = 0; a < (b); a++)
#define f1r(a, b, c) for (long long a = (b); a < (c); a++)
#define f0rd(a, b) for (long long a = (b); a >= 0; a--)
#define f1rd(a, b, c) for (long long a = (b); a >= (c); a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pb push_back
#define mp make_pair
#define f first
#define s second
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
 
void fio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); 
  cout.tie(0);
}
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 

 
const long double pi = 3.14159265358979323846;

string get(int x) {
  if (x == 3) return "bon";
  if (x == 0 || x == 1 || x == 6 || x == 8) return "pon";
  return "hon";
}

void solve() {
  ll n; cin >> n; cout << get(n % 10) << '\n';
}
 
int main() {
  fio();
  
  int T = 1;
  // cin >> T;
  while (T--) solve();
} 

Measured memory_bytes: 3644
use proconio::*;
use std::collections::BinaryHeap;

fn main() {
    input! {
        t: usize,
    };

    for _ in 0..t {
        input! {
            n: usize,
        };
        let mut l_cml = Vec::new();
        let mut r_cml = Vec::new();
        let mut ans = 0;

        for _ in 0..n {
            input! {
                k: usize,
                l: usize,
                r: usize,
            };

            if l < r {
                let t = r - l;
                ans += l;
                r_cml.push((n - k, t));
            } else {
                let t = l - r;
                ans += r;
                l_cml.push((k, t));
            }
        }
        fn f(cml: Vec<(usize, usize)>, n: usize) -> usize {
            let mut heap = BinaryHeap::new();
            let mut res = 0;
            let mut s = vec![vec![]; n + 1];
            for &c in &cml {
                s[c.0].push(c.1);
            }
            for i in s.iter().skip(1).rev() {
                for &j in i {
                    heap.push(j);
                }

                res += heap.pop().unwrap_or(0);
            }

            res
        }

        ans += f(l_cml, n);
        ans += f(r_cml, n);

        println!("{}", ans);
    }
}


Measured memory_bytes: 15912
#include<bits/stdc++.h>
#define _LIBCPP_DEBUG 0
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;
    
int main(void){
    int A,B; cin>>A>>B;
    cout<<max({A+B,A-B,A*B})<<endl;

    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define sqr(a) ((a) * (a))

using namespace std;

short mem[1 << 24];
int n, x[24], y[24], r[24], c[24];

bool jud(int b,int i){
	for(int j = 0;j < i;j++){
		if(((b >> j) & 1) == 0 && sqr(x[j] - x[i]) + sqr(y[j] - y[i]) < sqr(r[j] + r[i])){
			return false;
		}
	}
	return true;
}


short rec(int b){ // iは参照番地
	bool end = true;
	short res = 0;
	if(mem[b] != -1){
		return mem[b];
	}
	for(int i = 0;i < n;i++){
		if(((b >> i) & 1) == 0){ // iはとられていないものとられていないもの
			for(int j = 0;j < i;j++){
				if(((b >> j) & 1) == 0){ // jがとられていないもの
					if(jud(b,i) && jud(b,j) && c[i] == c[j]){
						res = max((int)rec(b | (1 << i) | (1 << j)) + 2,(int)res);
						end = false;
					}
				}
			}
		}
	}
	if(end){
		return 0;
	}
	return mem[b] = res;
}

int main(void){
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		fill(mem,mem + (1 << 24),-1);
		for(int i = 0;i < n;i++){
			cin >> x[i] >> y[i] >> r[i] >> c[i];
		}
		cout << rec(0) << endl;
	}
	return 0;
}

Measured memory_bytes: 33932
#include <stdio.h>
#include <string.h>

#define MAX 100000

typedef struct{
	char name[100];
	int t;
}Elements;

Elements Q[MAX];
int head=0;
int tail=0;
int n;

void enqueue(Elements x){
	Q[tail]=x;
	if(tail==n-1) tail=0;
	else tail++;
}

Elements dequeue(){
	Elements x;
	x=Q[head];
	if(head==n-1) head=0;
	else head++;
	return x;
}

int main(){
	int i,q,count=0,tim=0;
	Elements p;

	scanf("%d %d",&n,&q);
	for(i=0;i<n;i++){
		scanf("%s %d",Q[i].name,&Q[i].t);
	}

	while(count<n){
		p=dequeue();
		if(p.t<=q){
			tim+=p.t;
			printf("%s %d\n",p.name,tim);
			count++;
		}else{
			tim+=q;
			p.t-=q;
			enqueue(p);
		}
	}
	return 0;
}

Measured memory_bytes: 6740
S = input()
listS = list(S)
cnt = 0
if len(S) % 2 == 0 :
    for i in range(len(S)//2) :
        if S[i] != S[-(i+1)] :
            cnt += 1
else :
    for i in range((len(S))//2) :
        if S[i] != S[-(i+1)] :
            cnt += 1

print(cnt)

Measured memory_bytes: 9112
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
    int n;
    std::cin >> n;
    int d[n];
    for (int ii = 0; ii < n; ++ii)
    {
        std::cin >> d[ii];
    }
    std::sort(d, d+n);

    int prev = d[n-1];
    int counter = 1;
    for (int ii = n-2; ii >= 0; --ii)
    {
        if (prev > d[ii])
        {
            prev = d[ii];
            ++counter;
        }
    }

    std::cout << counter;
}


Measured memory_bytes: 256