akhauriyash/Code-Regression huggingface dataset:
import itertools

n, m = map(int, input().split())
li = [list(map(int, input().split())) for i in range(m)]
iter_list = itertools.permutations(range(1, n + 1), n)


def checker(tup):
    if tup[0] != 1:
        return False
    for i in range(len(tup)-1):
        path = [tup[i], tup[i + 1]]
        re_path = [tup[i+1], tup[i]]
        if not (path in li or re_path in li):
            return False
    return True


res = 0
for i in iter_list:
    if checker(i):
        res += 1

print(res)


Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
using namespace std;
const int N=200005;
const int C=27;

int len,k;
char s[N];
unsigned long long now,lst;

int main() {
	scanf("%s",s+1);
	len=strlen(s+1);
	for(int i=1;i<=len;i++) {
		now=now*C+s[i]-'a'+1;
		if(lst!=now)
			lst=now,now=0,k++;
	}
	printf("%d\n",k);
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
int h1,h2,s1,s2;
  cin>>h1;
  cin>>s1;
  cin>>h2;
  cin>>s2;
  int flag=1;
  while(h1>0 && h2>0){
    if(flag){
      h2=h2-s1;
      flag=0;
    }
    else{
      h1=h1-s2;
      flag=1;
    }
  }
  if(h1<=0)
    cout<<"No";
  else
    cout<<"Yes";

}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define N 1000500
using namespace std;

int a[N],b[N],n,m,cnt,t;

inline int rd() {
    int x=0,f=1;char ch=getchar();
    while (ch>'9'||ch<'0') {if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    return x*f;
}

int main() {
    n = rd(), m = rd();
    for (int _=1;_<=m;_++) a[_] = rd();
    sort(a+1,a+m+1, greater<int>() );

    if (m==1) {

        if (n==1) {printf("1\n1\n1\n"); return 0;}

        printf("%d\n",a[1]);
        printf("2\n");
        printf("%d %d\n",a[1]-1,1);
        return 0;
    }

    for (int _=1;_<=m;_++) (a[_]&1) ? ++cnt : 0;
    if (cnt > 2) return puts("Impossible"), 0;
    for (int _=2;_<=m-1;_++)
        if (a[_]&1) (a[1]&1) ? swap(a[_],a[m]) : swap(a[_],a[1]);
    for (int _=1;_<=m;_++) printf("%d%c",a[_],_==m?'\n':' ');
    (a[1]==1) ? (t=2) : (t=1);
    printf("%d\n",m-t+1);
    memcpy(b,a,sizeof(a));
    b[1]--, b[m]++;
    for (int _=t;_<=m;_++) printf("%d%c",b[_],_==m?'\n':' ');
    return 0;
}

Measured memory_bytes: 4352
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double[] p = new double[n], q = new double[n];
        for(int i = 0; i < n; i++){
            p[i] = sc.nextDouble();
            q[i] = 1 - p[i];
        }
        double[][] dp = new double[n][n + 1];
        dp[0][0] = q[0];
        dp[0][1] = p[0];
        for(int i = 1; i < n; i++){
            dp[i][0] = dp[i-1][0] * q[i];
            dp[i][i+1] = dp[i-1][i] * p[i];
            for(int j = 1; j <= i; j++){
                dp[i][j] = dp[i-1][j] * q[i] + dp[i-1][j-1] * p[i];
            }
        }
        double ans = 0;
        for(int i = n / 2 + 1; i <= n; i++){
            ans += dp[n-1][i];
        }
        System.out.println(ans);
    }
}

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

#define pb push_back
#define ff first
#define ss second

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

int a, b, c, d, e, k, mx, mn;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> a >> b >> c >> d >> e >> k;
	mx = max(max(max(a, b), max(c, d)), e), mn = min(min(min(a, b), min(c, d)), e);
	if (mx - mn > k)
		cout << ":(";
	else
		cout << "Yay!";
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<functional>
#include<algorithm>

using namespace std;

int main(){
    int N;
    cin >> N;

    int a[N];
    int max = 0;
    int count = 1;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        if(a[i] > max){
            max = a[i];
        }
    }

    sort(a, a + N, greater<int>());

    for(int i = 1; i < N; i++){
        if(max > a[i]){
            max = a[i];
            count++;
        }
    }

    cout << count << endl;
}

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


int main() {
  int N, P;
  cin >> N >> P;
  string S;
  cin >> S;

  ll ans = 0;
  if (10 % P == 0) {
    rep(r, N) {
      if ((S[r] - '0') % P == 0) ans += r + 1;
    }
  } else {
    vector<int> d(N + 1);
    int ten = 1;
    for (int i = N - 1; i >= 0; i--) {
      int a = (S[i] - '0') * ten % P;
      d[i] = (d[i + 1] + a) % P;
      ten *= 10;
      ten %= P;
    }
    vector<int> cnt(P);
    for (int i = N; i >= 0; i--) {
      ans += cnt[d[i]];
      cnt[d[i]]++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
char capitalize(char c) { return static_cast<char>(std::toupper(static_cast<unsigned char>(c))); }
// template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
// template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

// #define int long long
#define YES "Yes"
#define NO  "No"

using namespace std;

signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  bool flag = false;
  // flag = true;

  int n, k, x, y; cin >> n >> k >> x >> y;

  num = min(n, k) * x + max(n - k, 0) * y;

  cout << num << endl;
  // cout << (flag ? YES : NO) << endl;
  
  return 0;
}


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

int main()
{
    ios::sync_with_stdio(0);
    register int n,l,r,ans=0;
    cin>>n;
    while(n--)
    {
        cin>>l>>r;
        ans+=r-l+1;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
        int n;
        long long z, w;
        scanf("%d%lld%lld", &n, &z, &w);
        vector<long long> a(n);
        for (int i = 0; i < n; i ++) scanf("%lld", &a[i]);
        if (n == 1) printf("%lld\n", abs(a[0] - w));
        else printf("%lld\n", max(abs(a[n - 1] - w), abs(a[n - 1] - a[n - 2])));
        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
signed main(){
    int a,b,c;  cin>>a>>b>>c;
    if(a==b)cout<<c<<endl;
    if(a==c)cout<<b<<endl;
    if(c==b)cout<<a<<endl;
}


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


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

int main(){
    int h,w;
    cin >> h >> w;
    int map[52][52] = {0};
    string str;
    int vx[8] = {-1, 0, 1,-1, 1,-1,0,1};
    int vy[8] = {-1,-1,-1 ,0 ,0, 1,1,1};
    rep(i,h){
        cin >> str;
        rep(j,w){
            if(str[j] == '.'){
                map[i+1][j+1] = 0;
            }else{
                map[i+1][j+1] = -1;//地雷
            }
        }
    }


    rep(i,h){
        rep(j,w){
            if(map[i+1][j+1] == -1){
                rep(k,8){
                    if(map[i+1+vy[k]][j+1+vx[k]] != -1){
                        map[i+1+vy[k]][j+1+vx[k]]++;
                    }
                }
            }
        }
    }

    reps(i,1,h+1){
        reps(j,1,w+1){
            if(map[i][j] == -1){
                cout << "#";
            }else{
                cout << map[i][j];
            }
        }
            cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
const int INF = (int)1e9;
#ifdef WIN32
#include "dbg.h"  // https://github.com/sharkdp/dbg-macro
#else
#define dbg(...)
#endif

map<ll, int> m;
void dfs(ll i) {
	m[i] = 1; 
	if (i > 3234566667ll) return;
	int ld = i % 10;
	if(ld+1<=9) dfs(i * 10 + ld + 1);
	dfs(i * 10 + ld);
	if(ld-1>=0)dfs(i * 10 + ld - 1);
}
int main()
{
	for (int i = 1; i < 10; i++) dfs(i);
	int k; cin >> k;
	int ix = 1;
	for (auto a : m) {
		if (ix++ == k) cout << a.first << endl;
	}
	return 0;
}

Measured memory_bytes: 18432
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define repp(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second



int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll m,n,i,f=0,j,ans=0,k,x,r,l,t;
    cin >> n ;
   ll a[n],b[n];
    rep(i,n) cin >> a[i] >> b[i] ;
    sort(a,a+n);
    sort(b,b+n);
    if(n%2==1)
    {
          cout << b[n/2]-a[n/2]+1;
    }
    else
    {
          cout << ((b[n/2]+b[n/2-1])-(a[n/2]+a[n/2-1]))+1 ;
          
    }
    
    return 0;
}

Measured memory_bytes: 6784
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>

using namespace std;

int main() {
    vector<int> cost(3);
    for (int i = 0; i < 3; i++) {
        cin >> cost[i];
    }
    int a = 100000, b = 100000;
    for (int i = 0; i < 3; i++) {
        if (cost[i] < a) {
            b = a;
            a = cost[i];
        } else if (cost[i] < b) {
            b = cost[i];
        }
    }
    cout << a + b << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
void insertionSort(int a[],int n)
{
    int i,v,j,k;
    for(i=1; i<=n-1; i++)
    {
        v=a[i];
        j=i-1;
        while(j>=0&&a[j]>v)
        {
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=v;
        for(k=0; k<=n-1; k++)
        {
            if(k!=n-1)
                printf("%d ",a[k]);
            else
                printf("%d\n",a[k]);
        }
    }
}
int main()
{
    int n,a[105],i;
    scanf("%d",&n);
    for(i=0; i<=n-1; i++)
        scanf("%d",&a[i]);
    for(i=0; i<=n-1; i++)
    {
        if(i!=n-1)
            printf("%d ",a[i]);
        else
            printf("%d\n",a[i]);


    }
    insertionSort(a,n);
    return 0;
}



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

// C: Peak
int main() {
    int N, M;
    cin >> N >> M;

    int H[100010];
    int m[N];
    for (int i=1; i <= N; i++) {
        cin >> H[i];
        m[i] = 0;
    }

    for (int j=1;j <= M; ++j) {
        int a, b;
        cin >> a >> b;
        m[a] = max(m[a], H[b]);
        m[b] = max(m[b], H[a]);
    }
    int ans = 0;
    for (int i=1; i<=N; ++i) {
        // cout << H[i] << " - " << m[i] << endl;
        ans += H[i] > m[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3932
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,w;
    cin>>h>>w;
    int c[10][10];
    for(int i=0;i<10;i++)for(int j=0;j<10;j++)cin>>c[i][j];
    for(int k=0;k<10;k++)for(int i=0;i<10;i++)for(int j=0;j<10;j++)c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
    int a[h][w];
    int x=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];
            if(a[i][j]!=1 && a[i][j]!=-1)x+=c[a[i][j]][1];
        }
    }
    cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 384
//---------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//                                                        NEVER  GIVE  UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first 
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define LINF 98765432123456789
#define testcases() ll t; cin>>t; while(t--)
#define debug cout<<"Hello\n";
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define debug4(w,x,y,z) cout<<#w<<" "<<w<<" "<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
//------------------------------------------------------------------------------------------------------------------------------

int main()
{
	
	#ifndef ONLINE_JUDGE
	freopen("C:/Users/DELL/Desktop/input.txt", "r", stdin);
	#endif

	fast;
	ll n,x,m;
	cin>>n>>x>>m;
	map<ll,ll> mp;
	ll val = x;
	mp[val] = 1;
	ll loop_val = 0;
	vector<ll> loopv;
	ll ans = 0;
	while(n)
	{
		val = (val*val) % m;
		if(mp[val] == 1)
		{
			loopv.pb(val);
			loop_val = (loop_val + val);
		}
		else if(mp[val] == 2)
			break;
		++mp[val];
	}
	for(auto it: mp)
	{
		if(it.se == 1)
		{
			ans += it.fi;
			n--;
		}
		if(!n)
			break;
	}
	ans += (n/sz(loopv)) * loop_val;
	ll rem = n - (n/sz(loopv))*sz(loopv);
	for(int i=0;i<rem;i++)
		ans = ans + loopv[i];
	cout<<ans;
	return 0;
}


Measured memory_bytes: 6936
//@author rohit_0801

 
#include <bits/stdc++.h>
#define ll int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define debug 0
 
using namespace std;
const ll MOD = 1000000007;
const ll MODD = MOD-1;
 
ll ar[900780],has[1234567];

vector<ll> vec,pec;

map<ll,ll> mark;

 
 
int main() {
	//srand(time(0));
	ll a,b,n,m,flag=0,r,t,u,v,w,x,y,z,k,res=0,d,maxm=-999999999,i,j,ct,h,ans=0,s,l,e,f,p,minm=999999999,c,type,q,len,siz,g;
 	
 	map<ll,ll>::iterator it,jt;
 	
 	string str="",ptr="";
 	char ch;
 	
 	cin>>a>>b;
 	
 	cout<<(a-b+1);
 	
 	
		
	return 0;
}  

Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>


using std::cout;
using std::cin;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


ll gcd(ll a, ll b) {
    while (b != 0) {
        auto tmp = a;
        a = b;
        b = tmp % a;
    }
    return a;
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

int isPrime(int a) {
    for (int i = 2; i * i <= a; ++i) {
        if (a % i == 0) {
            return 0;
        }
    }
    return 1;
}





void oneCase () {
    int a, b, c;
    cin >> a >> b >> c;
    for (int i = 2; i < b; ++i) {
        if (abs(i * a - c) % b == 0) {
            cout << "YES" << "\n";
            return;
        }
    }
    cout << "NO" << "\n";

}





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

    return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/agc026/tasks/agc026_a

import itertools
import collections
import bisect

def main():
    N = int(input())
    A = list(map(int, input().split()))

    count = 0
    prev = -1
    for i in range(N):
        if prev == A[i]:
            count += 1
            A[i] = -1

        prev = A[i]
    print(count)


if __name__ == '__main__':
    main()



Measured memory_bytes: 3316
#include <stdio.h>

int main(void){
  int n;
  scanf("%d", &n);
  
  int w[n+1];
  int i;
  w[0]=0;
  for(i=1; i<n+1; i++){
    scanf("%d",&w[i]);
    w[i]+=w[i-1];
  }
  
  int b, a;
  int min=100000;
  for(i=1; i<n; i++){
    b=w[i];
    a=w[n]-w[i];
    if(b <= a){
      if(a-b <= min){
        min=a-b;
      }
    }else{
      if(b-a <= min){
      min=b-a;
      }
    }
  }
  
  printf("%d\n", min);
  
  return 0;
}

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

int main(){
  int n;
  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);
  
  int ans = 0;
  for (int i=0 ; i<n ; i++)
    ans += b.at(a.at(i)-1);
  for (int i=0 ; i<n-1 ; i++){
    if (a.at(i+1) == a.at(i) + 1)
      ans += c.at(a.at(i)-1);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3640
use std::cmp::Ordering;
use std::io::Read;
use std::collections::{BTreeMap, BinaryHeap};

#[derive(PartialEq, Eq, Debug, Copy, Clone, Default, Hash)]
pub struct Reverse<T>(pub T);

impl<T: PartialOrd> PartialOrd for Reverse<T> {
    #[inline]
    fn partial_cmp(&self, other: &Reverse<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }

    #[inline]
    fn lt(&self, other: &Self) -> bool {
        other.0 < self.0
    }
    #[inline]
    fn le(&self, other: &Self) -> bool {
        other.0 <= self.0
    }
    #[inline]
    fn gt(&self, other: &Self) -> bool {
        other.0 > self.0
    }
    #[inline]
    fn ge(&self, other: &Self) -> bool {
        other.0 >= self.0
    }
}

impl<T: Ord> Ord for Reverse<T> {
    #[inline]
    fn cmp(&self, other: &Reverse<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

fn solve(nv: usize, _ne: usize, e: &[(usize, usize, i32)]) -> i32 {
    let mut g = vec![BTreeMap::new(); nv];
    for &(s, t, w) in e.iter() {
        g[s].insert(t, w);
        g[t].insert(s, w);
    }
    let v = 0;
    let mut vis = vec![false; nv];
    vis[v] = true;
    let mut h = g[v].iter().map(|(&t, &w)| Reverse((w, v, t))).collect::<BinaryHeap<_>>();
    let mut e = Vec::new();
    while let Some(Reverse((w, s, t))) = h.pop() {
        if vis[s] && !vis[t] {
            e.push((s, t, w));
            vis[t] = true;
            for (&u, &w) in g[t].iter() {
                if !vis[u] {
                    h.push(Reverse((w, t, u)));
                }
            }
        }
    }
    e.iter().map(|&(_, _, w)| w).sum::<i32>()
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let nv: usize = iter.next().unwrap().parse().unwrap();
    let ne: usize = iter.next().unwrap().parse().unwrap();
    let e = (0..ne)
        .map(|_| {
            let s: usize = iter.next().unwrap().parse().unwrap();
            let t: usize = iter.next().unwrap().parse().unwrap();
            let w: i32 = iter.next().unwrap().parse().unwrap();
            (s, t, w)
        })
        .collect::<Vec<_>>();
    let w = solve(nv, ne, &e);
    println!("{}", w);
}



Measured memory_bytes: 23456
import java.util.*;

class Main{

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

		String n = sc.next();
		String ans = "";

		for(int i = 0; i < 3; i++){
			String a = n.substring(i,i+1);

			if(a.equals("1")){
				ans += '9';
			}else{ 
				ans += '1';
			}
		}
		System.out.println(ans);

	}
}

Measured memory_bytes: 23892
#include <stdio.h>

int main()
{
  int i, n, x;

  scanf("%d", &n);
  for( i = 1 ; i <= n ; i++ )
  {
    x = i;
    if( x % 3 == 0 )
    {
      printf(" %d", x);
      continue;
    }

    while( x != 0 )
    {
      if( x % 10 == 3 )
      {
        printf(" %d", i);
        break;
      }
      else
        x /= 10;
    }
  }
  printf("\n");
}



Measured memory_bytes: 2104
/*
* Note: This template uses some c++11 functions , so you have to compile it with c++11 flag.
*       Example:-   $ g++ -std=c++11 c++Template.cpp
*
* Author : Akshay Pratap Singh
* Handle: code_crack_01
*
*/
 
/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
// #include <unordered_map>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <climits>

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for(int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for(int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
typedef long long int ll;
typedef unsigned long long int  ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

using namespace std;

int main () {

    int N; cin >> N;
    vector<vector<ll> > a(N, vector<ll>(N, INF));
    vector<vector<ll> > b(N, vector<ll>(N, INF));

    REP(i, N){
        REP(j, N) { 
            cin >> a[i][j];
            b[i][j] = a[i][j];
        }
    }

    REP(i, N){
        REP(j, N){
            REP(k, N){
                b[i][j] = min(b[i][j], b[i][k] + b[k][j]);
            }
        }
    }

    REP(i, N){
        REP(j, N){
            // cout << i << " " << j << " " << a[i][j] << " " << b[i][j] << endl;
            // /*
			if (b[i][j] != a[i][j]) {
				cout << -1 << endl;
				return 0;
			}
            // */
            // cout << b[i][j] << " ";
        }
        // cout << endl;
    }

    ll res = 0;
    REP(i, N){
        REP(j, i){

            if (i == j) continue;

            bool isfound = false;
            REP(k, N){

                if (i == k || k == j) continue; 

                if (b[i][k] + b[k][j] == b[i][j]) {
                    // cout << b[i][k] << " " << b[k][j] << " " << b[i][j] << endl;
                    isfound = true;
                }
            }
            if (!isfound) res += b[i][j];
        }
    }

    cout << res << endl;
	return 0;
}


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

#define REP(i,n) for(int i = 0;i < n;i++)
#define REPR(i,n) for(int i = n-1;i >= 0;i--)
#define FOR(i,m,n) for(int i = m;i < n;i++)
#define PRINT(s) cout<<s
#define PRINTS(s) cout<<s<<' '
#define PRINTL(s) cout<<s<<endl
#define INF 2e9
#define ALL(v) v.begin(),v.end()
#define ll long long

using namespace std;



int gcd(int max,int min){
    
    if(max<min){
        int tmp=max;
        max=min;
        min=tmp;
    }

    if(max%min==0)return min;
    else return gcd(min,max%min);

}

int main(void){

    int n,m;
    cin>>n>>m;

    int road[n]={0};

    REP(i,m){
        int a,b;
        cin>>a>>b;
        road[a-1]++;
        road[b-1]++;
    }

    REP(i,n)PRINTL(road[i]);

    return 0;
}

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

int main()
{
    char c;

    cin >> c;

    if(c >= 97)cout << "a" << "\n";else cout << "A" << "\n";
    
}

Measured memory_bytes: 3560
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    int K = (N+1)/2;
    cout << fixed << setprecision(10) << double(K)/double(N) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

//大して速くもないコードをIOだけでがんばらせる

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 20;
char dn[dm], *di = dn, dt;
inline void putint(ll X) {
	if (!X) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[20];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--) *di++ = (*(C + i));
	*di++ = '\n';
}

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


	int N = getint();
	int A[100000];
	rep(i, N) *(A + i) = getint();

	int k = 0;
	vector<int> V, V2;
	V.pb(0);
	rep(i, N) {
		if (A[i] > k) {
			V.pb(A[i]);
			V2.pb(i);
			k = A[i];
		}
	}
	ll B[100001] = {};
	int C[100001] = {};
	rep(i, N) {
		int k2 = lower_bound(V.begin(), V.end(), A[i]) - V.begin();
		B[k2] += A[i] - V[k2 - 1];
		C[k2]++;
	}

	int mae = V.back();
	ll l = C[(int)V.size()];
	ll kotae[100001] = {};
	for (int k = (int)V.size() - 2; k >= 0; k--) {
		kotae[V2[k]] = B[k + 1] + l * (mae - V[k]);
		mae = V[k];
		l += C[k + 1];
	}

	rep(i, N) putint(kotae[i]);

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

Measured memory_bytes: 5364
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<int> v(n);
	vector<int> sorted_v(n);
	for(int i = 0; i < n; i++){
		cin >> v[i];
		sorted_v[i] = v[i];
	}

	sort(sorted_v.begin(), sorted_v.end());
	
	int cnt = 0;
	for(int i = 0; i < n; i++){
		if(v[i] != sorted_v[i])cnt++;
	}
	string ans = (cnt == 2 || cnt == 0)? "YES" : "NO";
	cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	vi bit(n);
	int x, y, z;
	cin >> x;
	rep(i, x){ int m; cin >> m; bit[m - 1] |= 1; }
	cin >> y;
	rep(i, y){ int m; cin >> m; bit[m - 1] |= 2; }
	cin >> z;
	rep(i, z){ int m; cin >> m; bit[m - 1] |= 4; }
	
	int ans = 0;
	rep(i, n) if(bit[i] == 4 || bit[i] == 6 || bit[i] == 7) ans++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3216
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	//adjMatrix[u][v] = 1 if there is an edge from u to v, otherwise 0
	private int[][] adjMatrix;
	//adjWeight[u][v] -- the weight of the edge from u to v if there is one
	private int[][] adjWeight;
	//if a node is settled (e.g., processed in the Dijkstra's algorithm)
	private Boolean[] ifSettled;
	public Graph() { totalVertex = 0; }
	public int getTotalVertex() { return totalVertex; }
	//load graph from standard input
	public void loadAdjMatrix() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjMatrix = new int[totalVertex][totalVertex];
		adjWeight = new int[totalVertex][totalVertex];
		ifSettled = new Boolean[totalVertex];
		int u,v;
		for(int i = 0; i < totalVertex; i ++) {
			for(int j = 0; j < totalVertex; j ++) {
				adjWeight[i][j] = in.nextInt();
				if (adjWeight[i][j] != -1) {
					adjMatrix[i][j] = 1;
				}
			}
			ifSettled[i] = false;
		}
		in.close();
	}
	//return weight of the edge from u to v if there is one
	public int getWeight(int u, int v) {
		return adjWeight[u][v];
	}
	//return neighbors of u as a LinkedList
	public LinkedList<Integer> getNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if(adjMatrix[u][v] == 1) tmp.add(v);
		}
		return tmp;
	}
	//return unsettled neighbors of u as a LinkedList
	public LinkedList<Integer> getUnsettledNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if((adjMatrix[u][v] == 1) && (ifSettled[v] == false)) tmp.add(v);
		}
		return tmp;
	}
	//return the unsettled node that has the smallest dist
	public int getUnsettledNearest(int[] dist) {
		int md = Integer.MAX_VALUE;
		int mv = -1;
		int v;
		for(v = 0; v < totalVertex; v ++) {
			if((ifSettled[v] == false) && (dist[v] < md)) {
				md = dist[v];
				mv = v;
			}
		}
		return mv;
	}
	//implement the following	
	public int[] Dijkstra(int s) {
		int[] distance = new int[totalVertex];
		for(int i = 0; i < totalVertex; i++) {
			distance[i] = Integer.MAX_VALUE;
		}
		distance[s] = 0;
		int curr = findMinVertex(distance);
		while (curr != -1 && distance[curr] != Integer.MAX_VALUE) {
			ifSettled[curr] = true;
			LinkedList<Integer> neighbors = getUnsettledNeighbors(curr);
			for(Integer n: neighbors) {
				distance[n] = Math.min(distance[n], getWeight(curr,n));
			}
			
			curr = findMinVertex(distance);
		}
		return distance;
	}
	
	public int findMinVertex(int[] distance) {
		int v = Integer.MAX_VALUE;
		int index = -1;
		for(int i = 0; i < totalVertex; i++) {
			if(distance[i] < v && ifSettled[i] == false) {
				v = distance[i];
				index = i;
			}
		}
		return index;
	}
	
}

public class Main {
	public static void main(String[] argv) {
		Graph g = new Graph();
		g.loadAdjMatrix();
		int[] dist = g.Dijkstra(0);
		int cost = 0;
		for(int i = 0; i < g.getTotalVertex(); i ++) {
			cost += dist[i];
		}
		System.out.println(cost);
	}
}


Measured memory_bytes: 41364
class Dice:
    def __init__(self, f):
        self.f = f

    def roll(self, s):
        for f in s:
            n = self.f[:]
            if f == 'E':
                t = n[0]
                n[0] = n[3]
                n[3] = n[5]
                n[5] = n[2]
                n[2] = t
            elif f == 'W':
                t = n[0]
                n[0] = n[2]
                n[2] = n[5]
                n[5] = n[3]
                n[3] = t
            elif f == 'N':
                t = n[0]
                n[0] = n[1]
                n[1] = n[5]
                n[5] = n[4]
                n[4] = t
            else:
                t = n[0]
                n[0] = n[4]
                n[4] = n[5]
                n[5] = n[1]
                n[1] = t
            self.f = n

    def top(self):
        return self.f[0]

d = Dice(list(map(int, input().split())))
r = input()
d.roll(r)
print(d.top())

Measured memory_bytes: 7748
#include <iostream>
using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    int d[20] = {0};
    for (int i=0; i<m; ++i) {
        cin >> d[i];
    }
 
    int dp[50001];
    fill_n(dp, 50001, n);
    dp[0] = 0;
    for (int i=1; i<=n; ++i) {
        for (int j=0; j<20; ++j) {
            if (i - d[j] >= 0) {
                dp[i] = min(dp[i], dp[i - d[j]] + 1);
            }
        }
    }
    cout << dp[n] << "\n";
 
    return 0;
}

Measured memory_bytes: 3288
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  char a,b;
  cin >> a >> b;
  int x,y;
  if(a >= 'A' && a <= 'F') {
    x = 10 + (a-'A');
  } else {
    x = a-'0';
  }
  if(b >= 'A' && b <= 'F') {
    y = 10 + (b-'A');
  } else {
    y = b-'0';
  }
  if(x<y) {
    cout << "<" << endl;
  } else if(x==y) {
    cout << "=" << endl;
  } else {
    cout << ">" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <string>
#include <cstring>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

ll ans;

void solve(ll S, ll H, ll W)
{
    ans = min(ans, max(S, ((H + 1) / 2) * W) - min(S, (H / 2) * W));
    ans = min(ans, max(S, H * ((W + 1) / 2)) - min(S, H * (W / 2)));
}

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

    ll H, W;
    cin >> H >> W;
    ans = H * W;

    solve((H / 3) * W, H - H / 3, W);
    solve(((H + 2) / 3) * W, H - (H + 2) / 3, W);
    solve(H * (W / 3), H, W - W / 3);
    solve(H * ((W + 2) / 3), H, W - (W + 2) / 3);

    cout << ans << endl;

    return 0;
}

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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX / 2;
const ll MOD = 1e9 + 7;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H, W;
    cin >> H >> W;
    ll h, w;
    cin >> h >> w;
    cout << (H - h) * (W - w) << endl;
    return 0;
}


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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

signed main() {
  int A,B;
  cin>>A>>B;
  cout<<lcm(A,B)<<endl;
}


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

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int[] ABC = { in.nextInt(), in.nextInt(), in.nextInt() };
		Arrays.sort(ABC);
		int ans = 0;
		if ((ABC[0] % 2 == 0 && ABC[1] % 2 == 0) || (ABC[0] % 2 != 0 && ABC[1] % 2 != 0)) {
			int max = Math.max(ABC[0], ABC[1]);
			int min = Math.min(ABC[0], ABC[1]);
			ans += ABC[2] - max;
			ans += (ABC[2] - (ans + min)) / 2;
		} else {
			int even = ABC[0] % 2 == 0 ? ABC[0] : ABC[1];
			int odd = ABC[0] % 2 == 0 ? ABC[1] : ABC[0];
			if (ABC[2] % 2 == 0) {
				ans += (ABC[2] - even) / 2;
				ans += (ABC[2] + 1 - odd) / 2;
				ans++;
			} else {
				ans += (ABC[2] - odd) / 2;
				ans += (ABC[2] + 1 - even) / 2;
				ans++;
			}
		}
		System.out.println(ans);
		in.close();
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
const int MAXN=200010,P=1e9+7;
int n, x, y, eg, hd[MAXN], vr[2*MAXN], nx[2*MAXN], sz[MAXN], f[MAXN], tp=1;
void add_edge (int x,int y){
    vr[++eg]=y, nx[eg]=hd[x], hd[x]=eg;
}
int qpow (int a,int b){
	int res=1;
	while (b){
		if (b&1) res=(1ll*res*a)%P;
		a=(1ll*a*a)%P,b>>=1;
	}
	return res;
}
void dfs1 (int x,int fa){
	sz[x]=1;
	for (register int i=hd[x]; i; i=nx[i]){
		if (vr[i]==fa) continue;
		dfs1 (vr[i],x);
		sz[x]+=sz[vr[i]];
	}
	f[1]=(1ll*f[1]*sz[x])%P;
}
void dfs2 (int x,int fa){
	for (register int i=hd[x]; i; i=nx[i]){
		if (vr[i]==fa) continue;
		f[vr[i]]=(1ll*f[x]*((1ll*(n-sz[vr[i]])*qpow(sz[vr[i]],P-2))%P))%P;
		dfs2 (vr[i],x);
	}
}
int main (){
	ios::sync_with_stdio(false);
	cin >> n;
	f[1]=1;
	for (register int i=1; i<n; i++){
		cin >> x >> y;
		add_edge(x,y), add_edge(y,x);
	}
	dfs1(1,0), dfs2(1,0);
	for (register int i=1; i<=n; i++) tp=(1ll*tp*i)%P;
	for (register int i=1; i<=n; i++) cout << (1ll*tp*qpow(f[i],P-2))%P << endl;
	return 0;
}

Measured memory_bytes: 7808
#include<bits/stdc++.h>
using namespace std;
const int N=305,mo=998244353;
int n,K,i,j,k,l,f[N][N][N],a[N],ps[N],m,ans;
char c[N];
int main(){
	scanf("%s%d",c+1,&K);n=strlen(c+1);
	m=1;for(i=1;i<=n;++i)if(c[i]=='0')++m;else ++a[m];
	f[0][0][0]=1;
	for(i=1;i<=m;++i){
		for(j=0;j<=n;++j)for(k=0;k<=n;++k)
			f[i][j][k]=(f[i-1][j][k]+(j && k?f[i][j-1][k-1]:0))%mo;
		for(j=0;j<=n;++j){
			for(k=n;k>=0;--k)ps[k]=(f[i-1][j][k]+ps[k+1])%mo;
			for(k=0;k<=n;++k)f[i][j][k]=(f[i][j][k]+1ll*mo+ps[k+1]-ps[min(n+1,k+a[i]+1)])%mo;
		}
	}
	for(j=0;j<=min(K,n);++j)ans=(ans+f[m][j][0])%mo;
	printf("%d\n",ans);
}

Measured memory_bytes: 112112
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
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;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;



int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	int i,j,n,ans=0;
	cin>>n;
	int a[n];
	rep(i,n)cin>>a[i];
	for(i=0;i<n;i++){
		bool ch=true;
		for(j=i-1;j>=0;j--){
			if(a[j]>a[i])ch=false;
		}
		if(ch)ans++;
	}
	fin(ans);
	
	
	
	
	
	
	
//////////////////////////////////////////////////////
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
int main() {
  int n;
  cin >> n;
  cout << (1000 - n % 1000) % 1000 << endl;
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1, q = 0;
    // cin >> t;
    while (t--) {
        long long a, b, n;
        cin >> a >> b >> n;
        long long x = min(b - 1, n);
        cout << ((a * x) / b) << endl;
    }
    return 0;
}

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int R, C, M;
char room[55][55];
int cost[3][55][55];
int rs[1001], cs[1001];

int d[55][55];
int pv[55][55];

int dr[] = {0, 1, 0, -1};
int dc[] = {1, 0, -1, 0};

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> R >> C >> M;
  rep(i, R) rep(j, C) cin >> room[i][j];
  rep(i, 3) rep(j, R) rep(k, C) cin >> cost[i][j][k];
  rep(i, M) cin >> rs[i] >> cs[i];

  vector< tuple<int, int, int> > vec;
  vec.emplace_back(rs[0], cs[0], 0);
  int st = 0;
  rep(i, M-1) {
    memset(d, -1, sizeof(d));
    memset(pv, -1, sizeof(pv));
    d[rs[i]][cs[i]] = st;
    pv[rs[i]][cs[i]] = 4;
    queue< pair<int, int> > que;
    que.emplace(rs[i], cs[i]);
    while(!que.empty()) {
      int r, c;
      tie(r, c) = que.front(); que.pop();
      if(r == rs[i+1] && c == cs[i+1]) {
	st = d[r][c];
	break;
      }
      rep(j, 4) {
	int nr = r + dr[j], nc = c + dc[j];
	if(nr < 0 || R <= nr || nc < 0 || C <= nc) continue;
	if(room[nr][nc] == '#' || d[nr][nc] != -1) continue;
	d[nr][nc] = d[r][c] + 1;
	pv[nr][nc] = j;
	que.emplace(nr, nc);
      }
    }
    vector< tuple<int, int, int> > tmp;
    int r = rs[i+1], c = cs[i+1];
    while(r != rs[i] || c != cs[i]) {
      tmp.emplace_back(r, c, d[r][c]);
      int nr = r - dr[pv[r][c]], nc = c - dc[pv[r][c]];
      r = nr, c = nc;
    }
    reverse(all(tmp));
    rep(j, tmp.size()) vec.emplace_back(tmp[j]);
  }

  int ans = 0;
  int used[R][C];
  memset(used, -1, sizeof(used));
  for(auto v : vec) {
    int r, c, e;
    tie(r, c, e) = v;
    //cout << r << " " << c << " " << e << endl;
    if(~used[r][c]) {
      ans += min((e - used[r][c]) * cost[0][r][c], cost[2][r][c] + cost[1][r][c]);
    } else {
      ans += cost[1][r][c] + cost[2][r][c];
    }
    used[r][c] = e;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 52192
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  int x = stoi(to_string(a) + to_string(b));
  for(int i = 1; i < 400; i++){
    if(i*i==x){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int a,b,c,x,y;
int main(){
    cin>>a>>b>>c>>x>>y;
    a=min(a,c*2); b=min(b,c*2); c=min(a+b,c*2);
    int ab=min(x,y);
    cout<<ab*c+a*(x-ab)+b*(y-ab);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<'YES'<<endl;}else{cout<<'NO'<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

vi vec[200001];
int x[200001]={};
int dp[200001];
int main() {
	int r=0;
	string s,t;
	cin>>s>>t;
	if(s[0]==t[0])r++;
	if(s[1]==t[1])r++;
	if(s[2]==t[2])r++;
	cout<<r<<endl;
	return 0;
}


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

int main(){
    int c[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> c[i][j];
        }
    }
    int ci[3] = {};
    int cj[3] = {};
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            ci[i] += c[i][j];
        }
    }
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cj[i] += c[j][i];
        }
    }

    if((((ci[0] % 3) == (ci[1] % 3)) && ((ci[1] % 3) == (ci[2] % 3))) && (((cj[0] % 3) == (cj[1] % 3)) && ((cj[1] % 3) == (cj[2] % 3)))){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

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

map<int,long long> mp;
map<int,long long>::iterator it;
int main(){
	int n;
	long long k;
	int a,b;
	
	cin >> n >> k;
	while(n--){
		cin >> a >> b;
		mp[a]+=b;
	}
	for(it = mp.begin();it!=mp.end();it++){
		k-=it->second;
		if(k<=0){
			cout << it->first;
			return 0;
		}
	}
}

Measured memory_bytes: 4224
n = int(input())
w = list(map(int, input().split()))


ans = 999999
for i in range(n):
  s1 = 0
  s2 = 0
  for j in range(0,i):
    s1 += w[j]
  for k in range(i,n):
    s2 += w[k]
  ans = min(ans, abs(s1-s2))
print(ans)

Measured memory_bytes: 38640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod=1000000007;
#define PI 3.1415926535
#define pb  push_back
#define FOR(i,n) for(int i=0;i<(n);i++)
#define FORA(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define count_1(n)  __builtin_popcountll(n)
#define parity(n)   __builtin_parityll(n)   //Even parity 0 as output
void show    (int a[], int arraysize) { for (int i = 0; i < arraysize; ++i)  {cout << a[i] << " ";}	cout<<endl;}
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
void sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
int main()
{FAST
int n;
cin>>n;
int a[n-1],b[200002]={0};
FOR(i,n-1)
{
	cin>>a[i];
	b[a[i]]++;
}
FORA(i,1,n)
{
	cout<<b[i]<<"\n";

}
return  0;
}




Measured memory_bytes: 5212