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

using namespace std;
const int maxM = 1005;
char grid [1005][1005];
int dp [maxM][maxM] = { 0 };
int mod = 1e9 + 7;

int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> grid[i][j];
        }
    }
    dp[0][0] = 1;
    for (int i = 1; i < n; ++i) {

    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (grid[i][j] == '.') {
                if (i - 1 < 0 && j - 1 >= 0) {
                    dp[i][j] = dp[i][j - 1];
                } else if (j - 1 < 0 && i - 1 >= 0) {
                    dp[i][j] = dp[i - 1][j];
                } else if (i - 1 >= 0 && j - 1 >= 0) {
                    if (dp[i - 1][j] + dp[i][j - 1] >= mod) {
                        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - mod;
                    } else {
                        dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
                    }
                }
            } else {
                dp[i][j] = 0;
            }
           
        }
    }
    // for (int i = 0; i < n; ++i) {
    //     for (int j = 0; j < m; ++j) {
    //         cout << dp[i][j] << "\t";
    //     }
    //     cout << endl;
    // }
    cout << dp[n - 1][m - 1] << endl;
    return 0;
}

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

using ll = long long;
using ld  = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
// int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; i++ )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに


// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// -------- template end - //


// - library ------------- //


// --------- library end - //


int main(){

  ll N, H, W;
  cin >> N >> H >> W;

  cout << (N-H+1) * (N-W+1) << endl;


}

Measured memory_bytes: 3584
'use strict'

function main(input) {
  input = input.split('\n')[0].split(' ').map(n => Number(n));
  
  const n = input[0];
  const k = input[1];
  const ans = (n % k === 0) ? 0 : 1;
  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
typedef long long int lld;
typedef unsigned long long int llu;
#define INF (lld)(9223372036854775807)
#define IINF (int)(2147483647)

using namespace std;

int main(void) {
  int n, k;
  cin >> n >> k;
  vector<vector<int>> a;
  a.push_back(vector<int>(n + 1));
  for (int i = 0; i < n; i++) {
    cin >> a[0][i];
  }
  for (int i = 1; i <= k; i++) {
    int ms = 0;
    a.push_back(vector<int>(n + 1));
    for (int j = 0; j < n; j++) {
      a[i][max(0, j - a[i - 1][j])]++;

      a[i][min(n, j + a[i - 1][j] + 1)]--;
    }
    int c = 0;
    for (int j = 0; j < n; j++) {
      c += a[i][j];
      a[i][j] = c;
      if (c == n) {
        ms++;
      }
    }
    if (ms == n) {
      k = i;
      break;
    }
  }

  for (int i = 0; i < n; i++) {
    cout << a[k][i] << (i == n - 1 ? "\n" : " ");
  }
}

Measured memory_bytes: 36168
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }




long long N;
int main() {
  while (cin >> N) {
	long long ct = 1, ca = 1;
    for (int i = 0; i < N; ++i) {
	  long long t, a;
	  cin >> t >> a;
	  long long rt = (ct + t-1) / t;
	  long long ra = (ca + a-1) / a;
	  long long r = max(rt, ra);
	  chmax(r, 1LL);
	  ct = t*r;
	  ca = a*r;
	  //cout << t << ", " << a << " -> " << ct << ", " << ca << endl;
	}
	cout << ct + ca << endl;
  }
}


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

typedef long long llong;
int N = 0;
char chars[] = {
    'A', 'C', 'G', 'T'
};
llong MOD = 1000000000LL + 7LL;

vector<map<string, llong>> memo(100 + 1);
int dp[101][4][4][4];

int check(string str)
{
    if (str[3] == 'C' && str[2] == 'G' && str[1] == 'A') {
        return 0;
    }
    if (str[3] == 'G' && str[2] == 'C' && str[1] == 'A') {
        return 0;
    }
    if (str[3] == 'C' && str[2] == 'A' && str[1] == 'G') {
        return 0;
    }

    if (str[3] == 'C' && str[1] == 'G' && str[0] == 'A') {
        return 0;
    }
    if (str[3] == 'C' && str[2] == 'G' && str[0] == 'A') {
        return 0;
    }

    return 1;
}

llong make(int n, string str)
{
    if (memo[n].count(str) > 0) {
        return memo[n][str];
    } else if (n == N) {
        return 1LL;
    } else {
        llong ret = 0;
        for (int i = 0; i < 4; i++) {
            char c = chars[i];
            if (check(str + c)) {
                ret = (ret + make(n + 1, str.substr(1, 2) + c)) % MOD;
            }
        }
        memo[n][str] = ret;
        return ret;
    }
}

int main(int argc, const char * argv[]) {
    string str = "TTT";
    cin >> N;
    cout << make(0, str) << endl;
    return 0;
}


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

int main(){
  string s;
  cin >> s;
  int n=s.length();
  int ans=1000;//十分大きく初期化
  for (int i=0;i<=n-3;++i){
    int a=s[i]-'0';
    int b=s[i+1]-'0';
    int c=s[i+2]-'0';
    int x=100*a+10*b+c;
    ans = min(ans,abs(753-x));
  }
  cout << ans << endl;
  return 0;
}
    

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 Would
#define you
#define please

int main() {
	//おまじない
	cin.tie(0);
	ios::sync_with_stdio(false);

	string S;
	cin >> S;
	int K;
	cin >> K;

	vector<string> SA;

	rep(iii, 26) {
		string Skari = S;

		while (Skari.find('a' + iii) != string::npos) {
			
			string SSS = Skari.substr(Skari.find('a' + iii), 5);

			for (int ii = 1; ii <= SSS.length(); ii++) {
				int hantei = 0;
				string kari = SSS.substr(0, ii);
				for (string SS : SA) {
					if (SS == kari) {
						hantei = 1;
						break;
					}
				}
				if (hantei == 0) SA.push_back(kari);
			}
			
			Skari.erase(Skari.begin(), Skari.begin() + Skari.find('a' + iii));
			/*while (Skari[0] == 'a' + iii) Skari.erase(Skari.begin());*/
			Skari.erase(Skari.begin());
		}

		if (SA.size() >= 5) break;
	}


	//rep(i, S.length()) {
	//	for (int ii = i + 1; ii <= S.length(); ii++) {
	//		int hantei = 0;
	//		string kari = S.substr(i, ii - i);
	//		for (string SS : SA) {
	//			if (SS == kari) {
	//				hantei = 1;
	//				break;
	//			}
	//		}
	//		if (hantei == 0) SA.push_back(S.substr(i, ii - i));
	//	}
	//}





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

	cout << SA[K - 1] << "\n";

	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

vector<int> to[200005];
//int root[200005];
int depth[200005];

void dfs(int v, int p=-1) {
    if (p==-1) depth[v] = 0;
    else {
        depth[v] = depth[p]+1;
    }
    for(int e: to[v]) {
        if(e==p) continue;
        dfs(e, v);
    }
    
}

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if (a>b) swap(a, b);
        to[a].push_back(b);
        to[b].push_back(a);
    }
    dfs(0, -1);
    int odd = 0;
    int even = 0;
    rep(i, n) {
        if (depth[i]%2) odd++;
        else even++;
    }
    int mod3[3];
    rep(i, 3) {
        if (n%3==0) {
            mod3[0] = n/3;
            mod3[1] = n/3;
            mod3[2] = n/3;
        }
        else if (n%3==1) {
            mod3[0] = n/3;
            mod3[1] = n/3+1;
            mod3[2] = n/3+1;
        }
        else {
            mod3[0] = n/3;
            mod3[1] = n/3+1;
            mod3[2] = n/3+1;
        }
    }
    
    
    vector<int> ans(n);
    queue<int> res[3];
    rep(i, n) {
        int v = (i+1)%3;
        res[v].push(i+1);
    }
    if (even>odd) {
        rep(i, n) {
            depth[i]++;
        }
    }
    //cout << even << " " << odd << endl;
    if (min(odd, even)<=mod3[0]) {
        
        rep(i, n) {
            if (!(depth[i]%2)) {
                ans[i] = res[0].front();
                res[0].pop();
            }
            else {
                if (!res[1].empty()) {
                    ans[i] = res[1].front();
                    res[1].pop();
                }
                else if (!res[2].empty()) {
                    ans[i] = res[2].front();
                    res[2].pop();
                }
                else {
                    ans[i] = res[0].front();
                    res[0].pop();
                }
            }
            cout << ans[i] << " ";
        }
        cout << endl;
        
        return 0;
    }
    
    
    rep(i, n) {
        if(depth[i]%2) {
            if (!res[1].empty()) {
                ans[i] = res[1].front();
                res[1].pop();
            }
            else {
                ans[i] = res[0].front();
                res[0].pop();
            }
        }
        else {
            if (!res[2].empty()) {
                ans[i] = res[2].front();
                res[2].pop();
            }
            else {
                ans[i] = res[0].front();
                res[0].pop();
            }
        }
        cout << ans[i] << " ";
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 20224
package main

import "fmt"

const INF = 1000000000

var (
	N, A, B, C int
	L          []int
)

func dfs(cur, a, b, c int) int {
	if cur == N {
		if a != 0 && b != 0 && c != 0 {
			return abs(A-a) + abs(B-b) + abs(C-c) - 30
		}
		return INF
	}
	n1 := dfs(cur+1, a, b, c)
	n2 := dfs(cur+1, a+L[cur], b, c) + 10
	n3 := dfs(cur+1, a, b+L[cur], c) + 10
	n4 := dfs(cur+1, a, b, c+L[cur]) + 10
	return min(n1, n2, n3, n4)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(a ...int) int {
	ans := a[0]
	for _, v := range a {
		if v < ans {
			ans = v
		}
	}
	return ans
}

func main() {
	fmt.Scan(&N, &A, &B, &C)
	L = make([]int, N)
	for i := range L {
		fmt.Scan(&L[i])
	}

	fmt.Println(dfs(0, 0, 0, 0))
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i = 0;i < (n); ++i)
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int n,m,count=0;
    cin >> n >> m;
    int num;
    map<int, int> mp;
    for(int i=1;i<=4;i++){
        mp[i] = 0; 
    }
    rep(i,n){
        cin >> num;
        rep(j,num){
            int kind;
            cin >> kind;
            mp[kind]++;
        }
    }
    for(auto x:mp){
        if(x.second == n){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int sum = 0;
        for (int i = 0; i < n; i++) {
            if (sc.nextInt() >= k) {
                sum++;
            }
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 47972
#define ll     long long int
#define db     double
#include<bits/stdc++.h>
using namespace std ;
int main()
{   //ll q; cin>>q;while(q--)
    ll i,j,k,sum=0,ans,d,t=0;
     double r;
     double pi=3.14;
     cin>>r;
     cout<<fixed<<setprecision(20)<<2*pi*r<<endl;
   return 0;

}


Measured memory_bytes: 3780
#include<stdio.h>
int main(){
	int flag=1;
	int A[101];
	int n,i=0,j,tmp,cnt=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&A[i]);
	i=0;
	while(flag){
		flag=0;
		for(j=n-1;j>i;j--){
			if(A[j]<A[j-1]){
				cnt++;
				tmp=A[j];
				A[j]=A[j-1];
				A[j-1]=tmp;
				flag=1;
			}
		}
		i++;
	}
	for(i=0;i<n-1;i++)printf("%d ",A[i]);
	printf("%d\n",A[i]);
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 2052
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
A.sort()
d = {}
for i in range(N):
    a = A[i]
    if a not in d.keys():
        d[a] = 1
    else:
        d[a] += 1
if len(d.keys()) == 1:
    if list(d.keys())[0] == 0:
        print("Yes")
    else:
        print("No")
elif len(d.keys()) == 2:
    keys = list(sorted(list(d.keys())))
    if d[keys[0]] == N // 3:
        print("Yes")
    else:
        print("No")
elif len(d.keys()) == 3:
    keys = list(d.keys())
    if keys[0] ^ keys[1] ^ keys[2] == 0:
        if d[keys[0]] == d[keys[1]] == d[keys[2]]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    print("No")

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    string s;
    cin >> s;
    int n = (int)s.size();

    int res = n;
    for (int i=0; i<n-1; ++i) {
        if (s.at(i) != s.at(i+1)) {
            chmin(res, max(i+1, n-i-1));
        }
    }
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
const int mod=1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,x,n) for(int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first 
#define S second
#define PB push_back 
#define MP make_pair
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
using vl=vector<long long>;
using vp =vector<pair<int,int>>;

typedef pair<int,int> P;
string s;
int k; 
ll INF = 10000000000000000;

int main(){
    string S;
    cin >>S;
    if(S=="ABC") cout <<"ARC"<<endl;
    else cout <<"ABC"<<endl;
}

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

vector<int> s[5];
set<int> u;
char *code;

bool consume(char c){
    if(*code != c) return false;
    ++code;
    return true;
}

vector<int> expr();
vector<int> unary();

vector<int> expr(){
    vector<int> ret = unary(), lhs, rhs;
    while(true){
        if(consume('u')){
            lhs.clear();
            copy(ret.begin(), ret.end(), back_inserter(lhs));
            ret.clear();
            rhs = unary();
            set_union(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), back_inserter(ret));
        }else if(consume('i')){
            lhs.clear();
            copy(ret.begin(), ret.end(), back_inserter(lhs));
            ret.clear();
            rhs = unary();
            set_intersection(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), back_inserter(ret));
        }else if(consume('d')){
            lhs.clear();
            copy(ret.begin(), ret.end(), back_inserter(lhs));
            ret.clear();
            rhs = unary();
            set_difference(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), back_inserter(ret));
        }else if(consume('s')){
            lhs.clear();
            copy(ret.begin(), ret.end(), back_inserter(lhs));
            ret.clear();
            rhs = unary();
            set_symmetric_difference(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), back_inserter(ret));
        }else break;
    }

    return ret;
}

vector<int> unary(){
    vector<int> ret;
    if(consume('c')){
        auto lhs = unary();
        set_difference(u.begin(), u.end(), lhs.begin(), lhs.end(), back_inserter(ret));
        return ret;
    }
    if(consume('(')){
        ret = expr();
        assert(consume(')'));
        return ret;
    }
    if('A' <= *code && *code <= 'E'){
        return s[*(code++) - 'A'];
    }
    assert(false);
}

int main(){
    char name;
    int n;
    while(cin >> name >> n){
        for(int i=0;i<5;++i) s[i].clear();
        u.clear();
        while(true){
            if(name == 'R') break;
            s[name - 'A'].reserve(n);
            for(int i=0;i<n;++i){
                int x;
                cin >> x;
                s[name - 'A'].push_back(x);
                u.insert(x);
            }
            cin >> name >> n;
        }
        for(int i=0;i<5;++i) sort(s[i].begin(), s[i].end());
        string str;
        cin >> str;
        code = new char[str.size() + 1];
        for(size_t i=0;i<str.size();++i) code[i] = str[i];
        code[str.size()] = '\0';
        
        auto ans = expr();
        if(ans.size() == 0) cout << "NULL" << endl;
        else{
            for(size_t i=0;i<ans.size();++i) cout << ans[i] << " \n"[i==ans.size()-1];
        }
    }
    
    return 0;
}


Measured memory_bytes: 3060
n = int(input())

a = []
b = []
for i in range(n):
    aa, bb = map(int, input().split())
    a.append(aa)
    b.append(bb)


s = sorted(range(len(b)), key=lambda k: b[k])
fl = 0
time = 0
for si in s:
    time += a[si]
    if time > b[si]:
        fl = 1

if fl == 0:
    print('Yes')
else:
    print('No')

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

int main() {
	int n;cin>>n;
  	for(int i=0;i<=n/4;i++){
      for(int j=0;j<=n/7;j++){
      	if(i*4+j*7==n){cout<<"Yes"<<endl;return 0;}
      }
    }
  		cout<<"No"<<endl;
}

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

//long long
using ll = long long;

// pair<int, int>
using PII = pair<int, int>;

//最大値、mod
const int MOD = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;

//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

// a = max(a, b), a = min(a, b)
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; }

// 階乗(MODをとる)
ll pow_mod(ll num, ll pow, ll mod) {
    ll prod = 1;
    num %= mod;
    while (pow > 0) {
        if (pow & 1) prod = prod * num % mod;
        num = num * num % mod;
        pow >>= 1;
    }
    return prod;
}



// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う

// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

int main(){
    int N;
    cin >> N;
    int D[N];
    ll mo = 998244353;
    ll d[N] = {0};
    REP(i, N) {
        cin >> D[i];
        d[D[i]]++; 
    }
    ll ans = 1;
    bool flag = false;
    for(int i = N - 1; i >= 1; i--){
        if(d[i] != 0) flag = true;
        if(flag && d[i] == 0){
            print(0);
            return 0;
        }
    }
    if(d[0] != 1){
            print(0);
            return 0;
    }
    if(D[0] != 0){
            print(0);
            return 0;
    }
    for(int i = 1; i < N; i++){
        ans *= pow_mod(d[i - 1], d[i], mo);
        ans %= mo;
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
# define ll long long int
#define M 1000000007
#define ff first
#define ss second
#define pb push_back  
#define INF 1000000000000

									// nestedcode


 int main(){
   ios::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   ll n,i,mn,ans = 0;
   cin>>n;
   ll a[n+5];
   for(i=0;i<n;i++){
   	cin>>a[i];
   	if(i!=0){
   		mn = min(a[i],mn);
   	if(mn == a[i])	ans++;
	   }else	mn = a[i];
   	
   }
   cout<<ans+1;
   
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
//________
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define show(x) cerr << #x << ':' << (x) << endl
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef pair<int,int> Pii;
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline bool inside(int y, int x, int H, int W){return(y>=0 && x>=0 && y<H && x<W);}
inline int updiv(int a, int b){return((a+b-1) / b);}
const int INF = 1 << 29;
const int dx[] = {1, 0, -1, 0,  1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1,  -1, 1, 1, -1};
#define Size 1000011
#define NIL -1
//________

int N;
int pre[42], in[42];
int pos = 0;
vector<int> post;

int search(int a[], int n)
{
    int i = 0;
    while(a[i] != n)++i;
    return(i);
}
void reconst(int l, int r){
    if(l >= r)return;

    int root = pre[pos++];
    int m = search(in, root);

    reconst(l, m);
    reconst(m+1, r);

    post.pb(root);
}
void slv()
{
    pos = 0;
    reconst(0, N);
    cout << post[0];
    for(int i=1; i<N; ++i)cout << ' ' << post[i];
    outl("");
}
signed main()
{
    FAST();
    cin >> N;
    rep(i,N)cin >> pre[i];
    rep(i,N)cin >> in[i];

    slv();
}

Measured memory_bytes: 3180
from bisect import bisect_right

N=int(input())
A=list(map(int,input().split()))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))

bc=[0]*N
bcsum=[0]*N

for i in range(N):
    b=B[i]
    bc[i]=N-bisect_right(C,b)

bcsum[0]=sum(bc)

for i in range(1,N):
    bcsum[i]=bcsum[i-1]-bc[i-1]
ans=0
for a in A:
    p=bisect_right(B,a)
    if p<N:
        ans+=bcsum[p]

print(ans)

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 200001

ll gcd(ll a, ll b) {
    if(a < b) swap(a, b);
    if (b==0) return a;
    return gcd(b, a%b);
}

int main() {
    int n, a[MAXN], b[MAXN],  maxa, nexta;
    cin >> n;

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

    sort(b, b+n, std::greater<int>());
    maxa = b[0];
    nexta = b[1];

    if (maxa == nexta) {
        for(int i=0; i<n; i++) {
            cout << maxa << endl;
        }
    } else {

        for(int i=0; i<n; i++) {
            if (maxa == a[i]) cout << nexta << endl;
            else cout << maxa << endl;
        }
    }

}



Measured memory_bytes: 3200
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N = int(input())
As = list(mi())

ans = 0
prevcolor = 0 #左隣のスライムが何色だったか 色は1~Nなので0はダミー
nowsectionsize = 0
for a in As:
  if prevcolor != a: #もし色が違ったら
    ans += nowsectionsize//2 #左側までの区間size//2が魔法コストになる
    nowsectionsize = 1 #リセット（今の色が新しい区間になるので0でなく1）
  else: #色が同じなら
    nowsectionsize += 1 #区間が1増える
  prevcolor = a #どちらにしろ「前の色」は更新する

#ループを出た後、区間>=2なら最後のコストがかかる
ans += nowsectionsize //2

print(ans)





Measured memory_bytes: 38384
def main():
    a, b = map(int, input().split())
    tmp = []
    if a <= b:
        tmp.append(b-a)
    if -a <= b:
        tmp.append(b+a+1)
    if a <= -b:
        tmp.append(-b-a+1)
    if -a <= -b:
        tmp.append(-b+a+2)
    # print(tmp)
    print(min(tmp))
            

if __name__ == "__main__":
    main()

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

using namespace std;

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

signed main(){

	int N, A, B;
	cin >> N >> A >> B;
	cout << min(A, B) << " " << max(0LL, A + B - N) << endl;

	return 0;
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;

LL ans = 0;

void solve(){
	ans = 1000 - N%1000;
	if(N%1000==0) ans = 0;
}

int main(){
    cin >> N;

    solve();

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

Measured memory_bytes: 3184
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

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

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */

int n, m;
int l[100010];
int r[100010];
int a[100010];

int main() {
    cin >> n >> m;
    rep(i, m) cin >> l[i] >> r[i];
    rep(i, m) {
        a[l[i]]++;
        a[r[i] + 1]--;
    }
    reps(i, n){
        a[i] = a[i] + a[i-1];
    }
    int ans = 0;
    reps(i, n) if(a[i] == m)ans++;
    cout << ans << endl;

}



Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;




int main(void){
 
double wg;
string nm;

	while( cin >> wg){
		if(wg <= 48.0) nm = "light fly";
		else if(wg <= 51.0) nm = "fly";
		else if(wg <= 54.0) nm = "bantam";
		else if(wg <= 57.0) nm = "feather";
		else if(wg <= 60.0) nm = "light";
		else if(wg <= 64.0) nm = "light welter";
		else if(wg <= 69.0) nm = "welter";
		else if(wg <= 75.0) nm = "light middle";
		else if(wg <= 81.0) nm = "middle";
		else if(wg <= 91.0) nm = "light heavy";
		else  nm = "heavy";
	
		cout << nm << endl;
	}	
	
	return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 1e13
ll a[305][305], b[305][305]; 
int n, m, l, q;
int main(){
	cin >> n >> m >> l;
	int x, y, z;
	
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (i == j)
			{
				a[i][j] = 0;
				b[i][j] = 0;
			}
			else
			{
				a[i][j] = INF;
				b[i][j] = INF;
			}
			
	for (int i = 1; i <= m; i++)
	{
		cin >> x >> y >> z;
		if (z <= l && z < a[x][y])
			a[y][x] = z;
			a[x][y] = z;
	}
	
	for (int k = 1; k <= n; k++)
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				a[i][j] = min (a[i][j], a[i][k]+a[k][j]);
				
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (i != j && a[i][j] <= l)b[i][j] = 1;
				
	for (int k = 1; k <= n; k++)
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				b[i][j] = min (b[i][j], b[i][k]+b[k][j]);

	cin >> q;
	for (int i = 1; i <= q; i++){
		cin >> x >> y;
		if (x == y)cout << "0" << endl;
		else
		{
			if (b[x][y] >= INF)
				cout << "-1" << endl;
			else
				cout << b[x][y] - 1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 5084
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    if (N <= 3) {
        write(*max_element(all(A)));
        return 0;
    }

    vv<ll> dp = vvec(N, 3, -LINF);
    dp[0][0] = A[0];
    dp[1][1] = A[1];
    dp[2][0] = A[0] + A[2];
    dp[2][2] = A[2];
    dp[3][1] = A[3] + max(A[0], A[1]);
    rep(i, 4, N) {
        //if (i % 2 == 0) {
        //    dp[i][0] = max(dp[i][0], dp[i - 2][0] + A[i]);
        //    dp[i][1] = max(dp[i][1], dp[i - 2][1] + A[i]);
        //    dp[i][1] = max(dp[i][1], dp[i - 3][0] + A[i]);
        //    dp[i][2] = max(dp[i][2], dp[i - 2][2] + A[i]);
        //    dp[i][2] = max(dp[i][2], dp[i - 3][1] + A[i]);
        //    dp[i][2] = max(dp[i][2], dp[i - 4][0] + A[i]);
        //}
        //else {
        //    dp[i][1] = max(dp[i][0], dp[i - 2][1] + A[i]);
        //    dp[i][1] = max(dp[i][0], dp[i - 3][0] + A[i]);
        //}

        dp[i][0] = max(dp[i][0], dp[i - 2][0] + A[i]);
        dp[i][1] = max(dp[i][1], dp[i - 2][1] + A[i]);
        dp[i][1] = max(dp[i][1], dp[i - 3][0] + A[i]);
        dp[i][2] = max(dp[i][2], dp[i - 2][2] + A[i]);
        dp[i][2] = max(dp[i][2], dp[i - 3][1] + A[i]);
        dp[i][2] = max(dp[i][2], dp[i - 4][0] + A[i]);
    }

    ll ans;
    if (N % 2 == 0) {
        ans = max(dp[N - 2][0], dp[N - 1][1]);
    }
    else {
        ans = max({ dp[N - 3][0], dp[N - 2][1], dp[N - 1][2] });
    }
    write(ans);
}

Measured memory_bytes: 15868
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll INF = 5e15;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for (ll &e : A) cin >> e;
    ll X = 0;
    for (ll d = 60; d >= 0; d--) {
        ll cnt = 0;
        if (X + (1ll << d) > K) continue;
        for (ll e : A) cnt += !!((1ll << d) & e);
        if (cnt < N - cnt) {
            X += (1ll << d);
        }
    }
    ll ans = 0;
    for (ll &e : A) ans += X ^ e;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class MainClass
    {
        public static void Main(string[] args)
        {

            //問題158

            long n, a, b;
            string[] line = Console.ReadLine().Split(' ');
            n = long.Parse(line[0]);
            a = long.Parse(line[1]);
            b = long.Parse(line[2]);

            long x = n / (a + b);
            long y = n % (a + b);

            long ans = 0;
            ans += x * a;

            if (a >= y)
            {
                ans += y;
            }
            else
            {
                ans += a;
            }

            Console.WriteLine(ans);
        }

    }





    
}


Measured memory_bytes: 27296
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
using namespace std;

using ll = long long;
using boost::irange;

int main(){
    string N;

    cin >> N;
    
    switch(N[0]){
        case 'R':
            cout << "Sunny" << endl;
            break;
        case 'S':
            cout << "Cloudy" << endl;
            break;
        case 'C':
            cout << "Rainy" << endl;
            break;
    }

    return 0;
}

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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl
#define rep(n, i) for (int i = 0; i < n; i++)

using namespace std;
using i64 = long long;

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

    int prev1 = 0;
    int prev2 = -1;
    int preprev1 = -2;
    int preprev2 = -3;
    bool isok = false;
    for (int i = 0; i < n; i++)
    {
        int d1, d2;
        cin >> d1 >> d2;
        if (preprev1 == preprev2 && prev1 == prev2 && d1 == d2)
        {
            isok = true;
        }
        preprev1 = prev1;
        preprev2 = prev2;
        prev1 = d1;
        prev2 = d2;
    }

    if (isok)
    {
        cout << "Yes" << endl;
    }

    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S,a;
  cin >> S;
  vector<int> b(4);
  
  for(int i=0;i<4;i++){
    a = S[i];
    b.at(i) = stoi(a);
  }
    
  if (b.at(0)*10 + b.at(1) == 0 && b.at(2)*10 + b.at(3) == 0){
    cout << "NA" << endl;
  }
  else if (b.at(0)*10 + b.at(1) == 0) {
    if (b.at(2)*10 + b.at(3) <= 12) {
      cout << "YYMM" << endl;
    }
    else {
      cout << "NA" << endl;
    }  
  } 
  else if (b.at(2)*10 + b.at(3) == 0) {
    if (b.at(0)*10 + b.at(1) <= 12) {
      cout << "MMYY" << endl;
    }
    else {
      cout << "NA" << endl;
    }  
  }
  else if (b.at(0)*10 + b.at(1) <= 12 && b.at(2)*10 + b.at(3) <= 12){
    cout << "AMBIGUOUS" << endl;
  }
  else if (b.at(0)*10 + b.at(1) <= 12) {
      cout << "MMYY" << endl;
  }
  else if (b.at(2)*10 + b.at(3) <= 12) {
      cout << "YYMM" << endl;
  }
  else {
      cout << "NA" << endl;
  }  
}


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

using namespace std;

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

    sort(d.begin(), d.end());
    cout << d[d.size()/2] - d[d.size()/2-1] << endl;
    return 0;
}


Measured memory_bytes: 768
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  int N; cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  rep(i,N){
    cin >> a[i];
  }
  rep(i,N){
    cin >> b[i];
  }
  vector<int> v(N);
  rep(i,N){
    v[i]=i+1;
  }
  int cnta;
  int cntb;
  int cnt=0;
  do{
    cnt++;
    if(v==a){
      cnta=cnt;
    }
    if(v==b){
      cntb=cnt;
    }
  }while(next_permutation(all(v)));
  cout << abs(cntb-cnta) << endl;
}

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

#define ll              long long int
#define pb              push_back
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define fast_io         ios_base::sync_with_stdio(false); cin.tie(NULL);

double findAns(vector<double> &v, int i, int tail, vector<vector<double>> &dp){
	int n = v.size();
	int half = (n/2);


	// base case
	if(i == n){
		return 1;
	}

	if(dp[i][tail] != -1){
		return dp[i][tail];
	}

	double ans = 0;
	// take head
	ans = v[i] * findAns(v, i+1, tail, dp);

	// take tail
	if(tail < half){
		ans += ((1-v[i]) * findAns(v, i+1, tail+1, dp));
	}

	dp[i][tail] = ans;
	return ans;
}

int main(){
    fast_io;
    
    int n;
    cin >> n;

    vector<double> v(n);

    for(int i=0; i<n; i++){
    	cin >> v[i];
    }
    
    vector<vector<double>> dp(n, vector<double>(n, -1));
    double ans = findAns(v,0,0,dp);
    cout<<ps(ans, 15)<<"\n";
    
	return 0;
}


Measured memory_bytes: 70912
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
   

    ll n,k;
    cin >> n >> k;
    vector <ll> a, p(n);

    for(ll i=0;i<n;i++){
        ll tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    ll q = 0;
    for(ll i=0;i<n;i++){
        for(ll j=i+1;j<n;j++){
            if(a[i] > a[j]){
                q++;
                p[i]++;
            }else if(a[i] < a[j]){
                p[j]++;
            }
        }
    }
    ll ans = 0;
//    cout << q << endl;
    q %= mop;
    ans = k*q%mop;
    for(ll i=0;i<n;i++){
//        cout << p[i] << endl;
        ans += k*(k-1)/2 % mop * p[i] % mop;
        ans %= mop;
    }
    cout << ans%mop << endl;



}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
   class Program
    {
        static void Main(string[] args)
        {
            List<string> I = new List<string>();
            string[] I1;
            double[] A = new double[6];
            double[] X = new double[2];
            string s;

            for (int i = 0; true; i++)
            {
                s = Console.ReadLine();
                if (string.IsNullOrEmpty(s)) break;
                I.Add(s);
            }
            for (int i = 0;i<I.Count; i++)
            {
                I1 = I[i].Split();
                for (short j = 0; j < 6; j++) {
                    A[j] = double.Parse(I1[j]);
                }
                X = Solve(A);
                Console.WriteLine(string.Format("{0:F3} {1:F3}",X[0],X[1]));
            }
        }

        public static double[] Solve(params double[] A) {
            double[] A1 = new double[6];
            double[] A2 = new double[6];
            double X, Y;
            int j;
            for (int i = 0; i < 6; i++) {
                j = i < 3 ? 4 : 1;
                A1[i] = A[i] * A[j];
                j = i < 3 ? 3 : 0;
                A2[i] = A[i] * A[j];
            }

            X = (A1[2] - A1[5]) / (A1[0] - A1[3]);
            Y = (A2[2] - A2[5]) / (A2[1] - A2[4]);
            return new double[] {X,Y};
        }
    }

Measured memory_bytes: 9236
#include <iostream>
#include <vector>
#include <string>

#define ll long long
using namespace std;

int main()
{
  ll N, MOD = 998244353;
  cin >> N;
  ll maxs = N*300;
  vector<ll> a(N);
  vector<vector<ll>> dp(N+1, vector<ll>(maxs+1, 0));
  vector<vector<ll>> bicol(N+1, vector<ll>(maxs+1, 0));
  dp[0][0] = 1;
  bicol[0][0] = 1;
  for (ll i = 0; i < N; i++){
    cin >> a[i];
  }
  ll sum = 0;
  for (ll i = 0; i < N; i++){
    for (ll j = 0; j < maxs+1; j++){
      dp[i+1][j] += dp[i][j]*2;
      bicol[i+1][j] += bicol[i][j];
      if (j-a[i]>=0) {
        dp[i+1][j] += dp[i][j-a[i]];
        bicol[i+1][j] += bicol[i][j-a[i]];
      }
      dp[i+1][j] %= MOD;
      bicol[i+1][j] %= MOD;
    }
    sum += a[i];
  }

  ll ans = 1;
  for (ll i = 0; i < N; i++){
    ans *= 3;
    ans %= MOD;
  }

  for (ll i = sum/2+sum%2; i <= sum; i++){
    ans -= (dp[N][i]*3) % MOD;
    if(ans<0) ans+=MOD;
    ans %= MOD;
  }
  
  if(sum%2 == 0){
    ans += (bicol[N][sum/2] * 3) % MOD;
    ans %= MOD;
  }
  if(ans<0) ans += MOD;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 424512
#include <stdio.h>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <vector>
#include <map>
#include <ctime>
#include <cmath>
#include <string.h>
#define inf 0x7fffffff
using namespace std;
struct I
{
    int x,y;
};


int a,b,k,d,n,m,i,c,e,o[212026],l[232322],dx[20]={1,0,-1,0},dy[20]={0,1,0,-1},dz[20]={1,-1};

long long x,y,z;
//map <string,int> m;
int j[225060][3];



//deque<int> d;
struct P
{
    string r;
    int x,y,z;
    bool operator<(const P &a)const
    {
            if(x-y!=a.x-a.y)
            return x-y<a.x-a.y;
       return x<a.x;
    }
};
stack<int> s;
double u;
//P u[500000];
vector <int> v[411010];
queue<int> q,q1;
string r,r1;
//char r[3333];
map<int,int > p;
//A==65
//Z==90

//a==97
bool asd(P a,P b)
{
    if(a.z!=b.z) return a.z>b.z;
    if(a.y!=b.y) return a.y>b.y;
    return a.x>b.x;
}

int g(int t,int w)
{
    int k=0;
    if(t%10==w/100||t%10==(w/10%10)) k++;
    if(t/10%10==w/100||t/10%10==w%10) k++;
    if(t/100==w%10||t/100==(w/10%10)) k++;
    return k;
}

int f(int t,int w)
{
    if(t<w) swap(t,w);
    for(;w;)
    {
        int u=w;
        w=t%w;
        t=u;
    }
    return t;
}

int main()
{
    scanf("%d",&a);
    for(int t=1;t<=a;t++)
    {
        scanf("%d",&b);
        o[b]++;
        o[b+1]++;
        o[b+2]++;
    }
    for(int t=0;t<=100100;t++)
        k=max(k,o[t]);
    printf("%d",k);
}


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

const int INF=1<<20;

int main(){
    double top=-INF,btm=INF;
    double height;

    while(cin>>height){
        top=max(top,height);
        btm=min(btm,height);
    }

    cout<<setprecision(1)<<setiosflags(ios::fixed)<<top-btm<<endl;
    return 0;
}

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

int main(){
  string S;
  cin >> S;
  int ssize = S.size();
  set<int> a;
  for(int i = 0; i < ssize; i++){
    a.insert(S.at(i));
  }
  if(ssize == a.size()) cout << "yes" << endl;
  else cout << "no" << endl;
}

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

const int maxn = 4e3 + 5;

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

int A, B, n, stk[maxn], ans[maxn], top;
char s[15];
int query(int x, int y) {printf("? %d %d\n",x, y); fflush(stdout); scanf("%s", s); return s[0] == 'Y';}

int main()
{
	A = gi(); B = gi(); n = A + B;
	if (A <= B) return puts("Impossible"), 0;

	for (int i = 0; i < n; ++i)
		if (!top || query(stk[top], i)) stk[++top] = i;
		else --top;
	for (int i = 0; i < n; ++i)	ans[i] = query(stk[top], i);
	printf("! ");
	for (int i = 0; i < n; ++i) printf("%d", ans[i]);
	
	return 0;
}



Measured memory_bytes: 724
#include <bits/stdc++.h>
const int maxn = 100005;
int par[maxn];
int n,q;
void init()
{
	memset(par,0,sizeof(par));
}

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

int main()
{
	char op[2];
	int x;
	while(scanf("%d %d",&n,&q) != EOF && (n || q)){
		init();
		par[1] = 1;
		for(int i = 2;i <= n;i++){
			scanf("%d",&x);
			par[i] = x;
		}
		long long y = 0;
		while(q--){
			scanf("%s",op);
			if(op[0] == 'M'){
				scanf("%d",&x);
				par[x] = x;
			}else if(op[0] == 'Q'){
				scanf("%d",&x);
				y += find(x);
			}
		}
		printf("%lld\n",y);
	}
	return 0;
} 

Measured memory_bytes: 3580
#include <iostream>
using namespace std;
int main() {
    string s;
    cin >> s;
    int b = 0;
    long long sum = 0;
    for (int i=0; i<(int)(s.length()); i++) {
        if (s[i] == 'B') {
            b++;
        } else {
            sum += b;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3720
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  string S,T; cin>>S>>T;
  ll N=S.size(),M=T.size();
  ll ans=INF;
  rep(i,N-M+1){
    string s=S.substr(i,M);
    ll sans=0;
    rep(j,M) if(s[j]!=T[j]) sans++;
    chmin(ans,sans);
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3644