akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int a,b;
    cin >> a >> b;
    cout << (b-a)*(b-a+1)/2 - b << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
    int N,M;
    cin>>N>>M;
    vector<vector<int> > connect(N);
    rep(i,M){
        int A,B;
        cin>>A>>B;
        connect[A-1].push_back(B-1);
        connect[B-1].push_back(A-1);
    }
    cout<<"Yes"<<endl;
    vector<int> used(N,1);
    vector<int> ans(N,-1);
    queue<int> que;
    que.push(0);
    used[0]=0;
    while(!que.empty()){
        int v=que.front();
        que.pop();
        for(int i:connect[v]){
            if (used[i]==1){
                used[i]=0;
                ans[i]=v;
                que.push(i);
            }
        }
    }
    rep(i,N-1) cout<<ans[i+1]+1<<endl;
    return 0;
}

Measured memory_bytes: 10616
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================
//using系

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;
using ui = unsigned int;
using qul = queue<ll>;
using pql = priority_queue<ll>;
using kaage = priority_queue<int, vector<int>, greater<int>>;

// ========================================================================
//define系

//#define int long long;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i <= n; i++)

// ========================================================================


ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a)
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a)
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll mch(ll n) {
	if (n == 1) return 1;
	else return n * mch(n - 1);
}
//1から整数nまでの階乗を出す(INFで割っていない)
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double m = sqrt(a);
	for (int i = 3; i <= m; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}
//素数判定
ll modpow(ll a, ll n, ll mod) {
	ll hi = 1;
	while (n > 0) {
		if (n & 1) hi = hi * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return hi;
}
//いろいろやります（ただの前座）
ll mg(ll a, ll mod) {
	return modpow(a, mod - 2, mod);
}
//割り算の10^9+7等対策で逆元を出します 




// ========================================================================


/*signed*/int main() {
	ll n, h; cin >> h >> n;
	vl a(n);
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		ans += a[i];
	}
	if (ans >= h) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 4052
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long

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

    int n,m; cin >> n >> m;
    vector<string> a(n),b(m);
    for(int i = 0;i < n;i ++) cin >> a.at(i);
    for(int i = 0;i < m;i ++) cin >> b.at(i);

    for(int i = 0;i < n-m+1;i ++){
        for(int j = 0;j < n-m+1;j ++){
            int hantei = 1;
            for(int k = 0;k < m;k ++){
                for(int l = 0;l < m;l ++){
                    if(b.at(k).at(l) != a.at(i+k).at(j+l)) hantei = 0;
                }
            }
            if(hantei == 1){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
}

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

int main() {
    string s;
    cin >> s;
    if(s == "Sunny") cout << "Cloudy" << endl;
    else if(s == "Cloudy") cout << "Rainy" << endl;
    else if(s == "Rainy") cout << "Sunny" << endl;

    return 0;
}

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, m;
  cin >> n >> m;

  vector<int> K(m);
  vector<vector<int> > S(m, vector<int>(10));
  rep(i, m) {
    int k;
    cin >> k;
    K[i] = k;
    rep(j, k) {
      int s;
      cin >> s;
      s--;
      S[i][j] = s;
    }
  }

  vector<int> P(m);
  for (int i = 0; i < m; i++) cin >> P[i];

  int ans = 0;
  // スイッチの付け方をビット全探索
  for (int bits = 0; bits < (1 << n); bits++) {
    bool ok = true;

    // 電球を全探索
    for (int i = 0; i < m; i++) {
      int tmp_sum = 0;
      for(int j = 0; j < K[i]; j++) {
        // int mask = 1 << S[i][j];
        int mask = bits >> S[i][j];
        // if (bits & mask) {  // i番目のbitが立っていれば加算する
        if (mask & 1) {
          tmp_sum++;
        }
      }
      if (tmp_sum % 2 != P[i]) ok = false;
    }
    if (ok) ans++;
  }

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


Measured memory_bytes: 3564
import itertools
H,W,K=map(int,input().split())
 
C=[]
 
for i in range(H):
  C.append(input())
 
ans=0
for i in range(H+1):
  for j in range(W+1):
    for n in itertools.combinations(list(range(H)),i):
      for m in itertools.combinations(list(range(W)),j):
        count = 0
        for a in n:
          for b in m:
            if(C[a][b]=="#"):
                count+=1
        if(count == K):
          ans += 1
print(ans)

Measured memory_bytes: 9216
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class A_166_AC
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            string s = Console.ReadLine();

            if (s == "ABC")
            {
                Console.WriteLine("ARC");
            }
            else
            {
                Console.WriteLine("ABC");
            }

            Console.Out.Flush();
        }
    }
}


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

void print_vector(vector<int> &vec, int N)
{
    for (int i = 0; i < N; i++)
    {
        if (i != N - 1)
        {
            printf("%d ", vec[i]);
        }
        else
        {
            printf("%d\n", vec[i]);
        }
    }
}

void insertion_sort(vector<int> &vec, int N)
{
    for (int i = 1; i < N; i++)
    {
        //中間配列を出力
        print_vector(vec, N);

        //sort
        int j = i - 1; //ソート済み部分裂の最後尾アドレス
        int m;         //swap用変数
        while (j >= 0 && vec[j]> vec[j + 1])
            {
                m = vec[j + 1];
                vec[j + 1] = vec[j];
                vec[j] = m;
                j--;
            }
    }
    //最終配列を出力
    print_vector(vec, N);
}

int main()
{
    //vectorのサイズnと要素の入力
    int n;
    scanf("%d", &n);
    vector<int> A(n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &A[i]);
    }

    insertion_sort(A, n);
}


Measured memory_bytes: 3208
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]

H,W=mint()
s=[input() for _ in range(H)]
dp=[[0]*W for _ in range(H)]
dp[0][0]=int(s[0][0]=='#')
for i in range(H):
    for j in range(W):
        if i==j==0:
            continue
        tmp = INF
        if i>0:
            tmp = min(tmp,dp[i-1][j]+int(s[i-1][j]=='.' and s[i][j]=='#'))
        if j>0:
            tmp = min(tmp,dp[i][j-1]+int(s[i][j-1]=='.' and s[i][j]=='#'))
        dp[i][j] = tmp
print(dp[H-1][W-1])

Measured memory_bytes: 74996
using System;
class Program
{
	static void Main(string[] args)
	{
		// スペース区切りの整数の入力
		string[] input = Console.ReadLine().Split(' ');
		int b = int.Parse(input[0]);
		int c = int.Parse(input[1]);
		if (b * c % 2 == 0)
        {
            //出力
            Console.WriteLine("No");
        }
		else
        {
            //出力
            Console.WriteLine("Yes");
        }
	}
}

Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <fstream>
#include <queue>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <sstream>
#include <math.h>

#define For(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  For(i,0,n)

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define SORT(c) sort((c).begin(),(c).end())
#define vi(m,a) vector<int> m(a)
#define vti(m,a,i) vector<vector<int>> m(a,vector<int>(i))
#define ALL(it,a) for(auto it = a.begin(); it!=a.end(); it++)
#define Fe(it,a) for(auto &it : a)
#define all(a) begin(a),end(a)

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define WARU 1000000007;

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
void printhoge(set<int> v) {
	ALL(it, v) {
		cout << *it << " ";
	}
	cout << endl;

}

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	rep(i, n)
		cin >> v[i];

	double ave = 0;
	rep(i, n) {
		ave += v[i];
	}
	ave /= n;
	int piv = 0;
	double saisyou = INT32_MAX;
	rep(i, n) {
		if (abs(ave - v[i]) < saisyou) {
			saisyou = abs(ave - v[i]);
			piv = i;
		}
	}
	cout << piv << endl;

}



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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

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

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <fstream>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LL long long
#define LI long int
#define LLI long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int main(){
    long int n; cin>>n;
    long int sum[200002]={};
    FOR(i,0,n){
        long int k; cin>>k;
        sum[i+1]=sum[i]+k;
    }
    sort(sum,sum+n+1);
    long long int b[200002]={};
    int t=0;
    long int now=sum[0];
    b[0]=1;
    FOR(i,1,n+1){
        if(sum[i]==now){
            b[t]++;
        }else{
            t++;
            b[t]++;
        }
        now=sum[i];
    }
    long long int ans=0;
    FOR(i,0,t+2){
        ans+=(b[i]-1)*b[i]/2;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3328
def kaijou(num):
  ac = 1
  for i in range(num):
    ac = ((i + 1) * ac) % (10 ** 9 + 7)
  return ac
[n,m] = list(map(int,input().split()))
x = abs(n - m)
ans = 0
if (x >= 2):
  ans = 0
elif (x == 1):
  ans = (kaijou(m) * kaijou(n)) % (10 ** 9 + 7)
elif (x == 0):
  ans = (kaijou(m) * kaijou(n) * 2) % (10 ** 9 + 7)
print(ans)


Measured memory_bytes: 3064
N = int(input())
F = []
for i in range(N):
    F_temp = list(map(int, input().split()))
    F.append(F_temp)
P = []
for i in range(N):
    P_temp = list(map(int, input().split()))
    P.append(P_temp)

ans = -1000000000

for i in range(1,1024):
    F0 = [0]*10
    i_temp = i
    for j in range(10):
        F0[j] = i_temp%2
        i_temp = int(i_temp/2)
    
    c = [0]*N
    for j in range(10):
        if F0[j] == 1:
            for k in range(N):
                c[k] += F[k][j]
    
    ans_temp = 0
    for j in range(N):
        ans_temp += P[j][c[j]]
    ans = max(ans, ans_temp)

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
int main() {
long long W,H,x,y;
  cin >> W >> H >> x >> y;
  long long a = W * H;
  
  cout << a / 2;
  if(a % 2 == 1)cout << ".5";
  if(x * 2 == W&&y * 2 == H){
   cout << " " << 1; 
  }else{
   cout <<" " << 0; 
  }
}

Measured memory_bytes: 3544
#include<bits/stdc++.h>
#define N 200009
#define ll long long
using namespace std;
int n;
string s;
int main()
{
    cin>>n>>s;
    if(n%2)
    {
        cout<<"No";
        return 0;
    }
    for(int i=0;i<s.size()/2;i++)
    {
        if(s[i]==s[i+s.size()/2])continue;
        else
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans;
    char t[21][21];//w,h
    ll dx[4]={-1,1,0,0};
    ll dy[4]={0,0,-1,1};
    ll dbg_cnt=0;
    while(true){
        ans=0;
        ll w,h,px,py;
        cin >>w>>h;
        if(w==0&&h==0)break;
        for(int y=0;y<h;y++){
            for(int x=0;x<w;x++){
                cin >>t[x][y];
                if(t[x][y]=='@'){
                    px=x,py=y;
                    t[x][y]='.';
                }
            }
        }

        queue< pair<ll,ll> > kouho;//x,y
        kouho.push(make_pair(px,py));
        t[px][py]='#';
        dbg{
            cout <<"kokomadeiketa "<<dbg_cnt<<endl;
            dbg_cnt++;
            if(dbg_cnt>5)break;
        }
        ans++;
        while(!kouho.empty()){
            pair<ll,ll> now=kouho.front();//x,y
            kouho.pop();
            if(t[now.first][now.second]=='.'){
                t[now.first][now.second]='#';
                ans++;
            }
            for(int i=0;i<4;i++){
                ll qx=now.first+dx[i],qy=now.second+dy[i];
                if(ISRANGE(qx,0,w) && ISRANGE(qy,0,h)){
                    if(t[qx][qy]=='.'){
                        kouho.push(make_pair(qx,qy));
                    }
                }
            }
            dbg{
                for(int y=0;y<h;y++){
                    for(int x=0;x<w;x++){
                        cout << t[x][y];
                    }
                    cout <<endl;
                }
            }
        }

        cout <<ans<<endl;
    }

    return 0;

}


Measured memory_bytes: 9432
/* *****fireice**** */

#include<bits/stdc++.h>

#define ll long long int
#define vi vector<int>
#define vc vector<char>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define pb emplace_back
#define el '\n'
#define N 1000000007
#define re return
#define PI 3.14159265
#define take(a,n) for(int i=0;i<n;i++) cin>>a[i]
#define out(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";
#define all(a) (a).begin(),(a).end()
#define forup(i,n) for(int (i)=0;i<(n);(i)++)
#define ford(i,n) for(int (i)=(n)-1;i>=0;(i)--)
using namespace std;

int gcdExtended(int a, int b, int *x, int *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    int x1, y1; // To store results of recursive call
    int gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll modInverse(int a, int m)
{
    int x, y;
    int g = gcdExtended(a, m, &x, &y);
        // m is added to handle negative x
    ll res = ((ll)x%m + (ll)m) % m;

    return res;
}

void fastscan(int &number)
{
    bool negative = false;
    register int c;
    number = 0;
    c = getchar();
    if (c=='-')
    {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
    if (negative)
        number *= -1;
}

ll poww(ll a,ll b)
{
  ll ans=1;
  for(int i=1;i<=b;i++)
  {
    ans*=a;
  }
  return ans;
}

inline ll max(ll a, ll b)
{
  if(a>b) re a;
  else re b;
}

inline ll min(ll a, ll b)
{
  if(a>b) re b;
  else re a;
}

ll ncr(int n,int r)
{
  ll ans=1;
  r=min(r,n-r);
  forup(i,r)
  {
    ans=(ans*(n-i)/(i+1))%N;
  }
  re ans;
}


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

  int t=1;
  //fastscan(t);
  while(t--)
  {
    int n,m,k;
    cin>>n;
    int b[n-1];
    forup(i,n-1)
    cin>>b[i];
    int ans=0;
    ans=b[n-2]+b[0];
    for(int i=n-2;i>=1;i--)
    {
      ans+=min(b[i],b[i-1]);
    }

    cout<<ans;

  }


  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
const int MAX=1010;
const int MOD=1e9+7;
char P[MAX][MAX];
int n,m;
int dp[MAX][MAX];
int add(int x,int y){
	return (x+y)%MOD;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>P[i];
	}
	dp[1][1]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(i==1&&j==1) continue;
			if(P[i-1][j-1]=='#') continue;
			dp[i][j]=add(dp[i-1][j],dp[i][j-1]);
		}
	}
	cout<<dp[n][m]<<"\n";
	return 0;
}

Measured memory_bytes: 5248
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long,long>
#define INF 1000000000000000000
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 MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
class Union_Find {
private:
	vector<int> par;
	vector<int> rank;
public:
	Union_Find(int n) {
		rep(i, n) {
			par.push_back(i);
			rank.push_back(0);
		}
	}
	int find(int x) {
		if (par.at(x) == x) return x;
		else return par.at(x) = find(par.at(x));
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank.at(x) < rank.at(y)) {
			par.at(x) = y;
		}
		else {
			par.at(y) = x;
			if (rank.at(x) == rank.at(y)) rank.at(x)++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int tmp = n;
	int k = 1;
	while (true) {
		if (n >= 10) k++;
		else break;
		n /= 10;
	}
	if (k == 1) cout << tmp << endl;
	else if (k == 2) cout << 9 << endl;
	else if (k == 3)cout << 9 + tmp - 100 + 1 << endl;
	else if(k==4)cout << 909 << endl;
	else if (k == 5)cout << 909 + tmp - 10000 + 1 << endl;
	else cout << 90909 << endl;
	return 0;
}

Measured memory_bytes: 256
let i_inp_list : unit -> int list = fun () ->
  let inp_split = Str.split (Str.regexp " ") (input_line stdin) in
  List.map (fun x -> int_of_string x) (inp_split)

let i_inp_array : 'a array -> int -> unit = fun a n ->
  let rec loop i = 
    if i = n then ()
    else
      (a.(i) <- (Scanf.scanf " %d" (fun x -> x));
       loop (i + 1))
  in loop 0

let () =
  let n = Scanf.sscanf (input_line stdin) "%d" (fun a -> a) in
  let a = i_inp_list () in
  let b = Array.make n 0 in
  let c = Array.make (n-1) 0 in
  i_inp_array b n;
  i_inp_array c (n-1);
  let rec loop = function
  	[] -> 0
  | [x] -> b.(x-1)
  | (x::y::xs) -> if(x + 1 = y) 
						  then b.(x-1) + c.(x-1) + loop (y::xs)
  						else b.(x-1) + loop (y::xs)
  in 
  let ans = loop a in
  print_int ans;
  print_newline ()
  

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define p(x) cout << x << endl;
#define all(v) (v).begin(), (v).end()

#define MOD 1000000007
#define PI acos(-1)

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

    string s;
    cin >> s;

    int len = s.size();

    if(len == 0 || len == 1) {
        cout << 0 << endl;
        return 0;
    }

    int cnt0 = 0;
    int cnt1 = 0;

    for(int i = 0; i < len; i++){
        if(s[i] == '0'){
            cnt0++;
        }else{
            cnt1++;
        }
    }

    int num = abs(cnt0 - cnt1);

    cout << len - num << endl;

}

Measured memory_bytes: 512
#include <stdio.h>


int main(void)
{
	int a, b;
	int temp;
	int count = 0;

	scanf("%d %d", &a, &b);

	for (int i = 1; i <= 3; i++){
		temp = a*b*i;
		if ((temp % 2) == 1){
			count++;
		}
	}

	if (count != 0){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}

	return 0;
}



Measured memory_bytes: 128
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.cpp                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: monoue <marvin@student.42.fr>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/22 12:30:15 by monoue            #+#    #+#             */
/*   Updated: 2020/05/01 05:52:19 by monoue           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>

/* #include <boost/multi_array.hpp> */
/* #include <boost/optional.hpp> */
/* #include <boost/range/irange.hpp> */
/* #include <boost/range/algorithm.hpp> */
/* #include <boost/range/adaptors.hpp> */
/* #include <boost/multiprecision/cpp_int.hpp> */
/* #include <boost/algorithm/string/classification.hpp> // is_any_of */
/* #include <boost/algorithm/string/split.hpp> */
/* #include <boost/algorithm/string/join.hpp> */
/* #include <boost/algorithm/string/replace.hpp> */
/* #include <boost/math/tools/minima.hpp> */
/* namespace adaptor = boost::adaptors; */
/* using boost::math::tools::brent_find_minima; */
/* using boost::irange; */
/* using boost::algorithm::join; */
/* using boost::algorithm::split; */
/* using boost::algorithm::replace_all; */
/* using boost::multiprecision::cpp_int; */

#define MOD 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

using namespace std;
using ll = long long;
using P = pair<int, int>;

// TOP
void	Main()
{
	int	n;
	cin >> n;

	vector<vector<double>>	dp(n + 1, vector<double>(n + 1));
	dp.at(0).at(0) = 1;
	rep(i, n)
	{
		double	p;
		cin >> p;

		rep(head, n)
		{
			dp.at(i + 1).at(head) += dp.at(i).at(head) * (1 - p);
			dp.at(i + 1).at(head + 1) += dp.at(i).at(head) * p;
		}
	}
	double	ans;
	ans = 0;
	rep2(i, (n + 1) / 2, n + 1)
		ans += dp.at(n).at(i);
	cout << ans << endl;
}
// END

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


Measured memory_bytes: 70784
#include "stdio.h"

int main(void)
{
    int a,b,c,i;
    int N;
    scanf("%d",&N);

    a=N%10;
    N=N/10;
    b=N%10;
    N=N/10;
    c=N;

    if(a==7 || b==7 || c==7)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    
}

Measured memory_bytes: 1668
#include<bits/stdc++.h>
using namespace std;
int a[2010];
double s[2010];
int i,j,k,n,m,t,h;
int main(){
    cin>>n>>t>>h;
    for(i=1;i<=n;i++)scanf("%d",&a[i]);
    for(i=1;i<=n;i++)s[i]=(double)a[i]*0.006;
    for(i=1;i<=n;i++)s[i]=fabs(h-(t-s[i]));
    int sum=1;
    double num=s[1];
    for(i=2;i<=n;i++){
        if(s[i]<num){
            num=s[i];
            sum=i;
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
odds = input()
evens = input()

result = ""
while (not(len(odds) == 0 and len(evens) == 0)):
   if (len(odds) != 0):
      result += odds[0]
      odds = odds[1:]
   if (len(evens) != 0):
      result += evens[0]
      evens = evens[1:]

print(result)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
	int H, W;
	int L[2001][2001] = {{0}}, R[2001][2001] = {{0}}, U[2001][2001] = {{0}}, D[2001][2001] = {{0}};
	string S[2001];

	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> S[i];
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '.') {
				if (j == 0) {
					L[i][j] = 1;
				} else {
					L[i][j] = L[i][j - 1] + 1;
				}
				if (i == 0) {
					U[i][j] = 1;
				} else {
					U[i][j] = U[i - 1][j] + 1;
				}
			} else {
				L[i][j] = 0;
				U[i][j] = 0;
			}
		}
	}
	for (int i = H - 1; i >= 0; i--) {
		for (int j = W - 1; j >= 0; j--) {
			if (S[i][j] == '.') {
				if (j == W - 1) {
					R[i][j] = 1;
				} else {
					R[i][j] = R[i][j + 1] + 1;
				}
				if (i == H - 1) {
					D[i][j] = 1;
				} else {
					D[i][j] = D[i + 1][j] + 1;
				}
			} else {
				R[i][j] = 0;
				D[i][j] = 0;
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3);
		}
	}

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

Measured memory_bytes: 66944
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }

        static void SolveA(string[] args)
        {
            int n = ReadAndParseInt();
            bool[] isprime = eratos(55555);
            List<int> prime = new List<int>();
            for(int i=2;i<isprime.Length;++i)
            {
                if (i > 55555) { break; }
                if(isprime[i]) { prime.Add(i); }
            }

            var ans = new List<int>();
            for(int i=0;i<prime.Count;++i)
            {
                if( prime[i] % 5 == 1)
                {
                    ans.Add(prime[i]);
                    if(ans.Count == n) { break; }
                }
            }

            //if (isprime[ans.Sum()]){
            //    Console.WriteLine("wa");
            //}

            string sz = "";
            for(int i=0;i<ans.Count;++i)
            {
                if( i != 0) { sz += " "; }
                sz += ans[i];
            }
            Console.WriteLine(sz);
        }

        static bool[] eratos(int n)
        {
            bool[] isprime = new bool[n+1];
            for(int i = 0; i < isprime.Length; ++i) { isprime[i] = true; }

            isprime[0] = isprime[1] = false;

            int end =(int) Math.Ceiling( Math.Sqrt(n));
            for(int i=2;i<=end;++i)
            {
                if(isprime[i])
                {
                    int j = i + i;
                    while(j <= n)
                    {
                        isprime[j] = false;
                        j = j + i;
                    }
                }
            }
            return isprime;
        }
    }
}


Measured memory_bytes: 11216
#include <bits/stdc++.h>                 // [PRIMES]               1777 ~2^10.80
using namespace std;                     //                       10333 ~2^13.33
using ll = long long;                    // seq 1 128 | factor   100333 ~2^16.61
using ld = long double;                  //   | grep -v ' .* '  1300111 ~2^20.31
using vl = vector<ll>;                   //                    10300777 ~2^23.30
using vvl = vector<vl>;                  //                   100400999 ~2^26.58
using pll = pair<ll,ll>;                 //                  1300400999 ~2^30.28
using vpll = vector<pll>;                //                 10200500333 ~2^33.25
using vb = vector<bool>;                 //                100200400777 ~2^36.54
using vs = vector<string>;               //               1200300700111 ~2^40.13
const ll oo = 0x3f3f3f3f3f3f3f3fLL;      //              10200300500777 ~2^43.21
const ld eps = 1e-9;                     //             100200300400777 ~2^46.51
#define sz(c) ll((c).size())             //            1200300400600999 ~2^50.09
#define all(c) begin(c),end(c)           //           10200300400600111 ~2^53.18
#define mp make_pair                     //          100200300400600333 ~2^56.48
#define mt make_tuple                    //         1200300400500800999 ~2^60.06
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

ll calc_longest_path(const vvl &adj, vl &dp, ll node) {
	if (dp[node]) {
		return dp[node];
	}

	ll best = 0;
	for (auto next : adj[node]) {
		best = max(best, calc_longest_path(adj, dp, next) + 1);
	}

	dp[node] = best;

	return best;
}

int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);

	ll n, m;
	cin >> n >> m;
	vvl adj(n+1, vl());

	FOR(i,0,m) {
		ll x, y; cin >> x >> y;
		adj[x].pb(y);
	}

	vl dp(n+1, 0);
	FOR(i,1,n+1) {
		calc_longest_path(adj, dp, i);
	}

	cout << *max_element(all(dp)) << "\n";

	return 0;
}


Measured memory_bytes: 9216
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
int n,m,i,j;
int cn,cs,cw,ce;
string st;
int main()
{
	cin>>st;
	for(i=0;i<st.length();i++){
		if(st[i]=='N')cn=1;
		if(st[i]=='S')cs=1;
		if(st[i]=='W')cw=1;
		if(st[i]=='E')ce=1;
	}
	if(cn&&!cs){
		puts("No");
		return 0;
	}
	if(cs&&!cn){
		puts("No");
		return 0;
	}
	if(cw&&!ce){
		puts("No");
		return 0;
	}
	if(ce&&!cw){
		puts("No");
		return 0;
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(raw_input())

def digit_sum(num):
    ret = 0
    while num > 0:
        ret = ret + num % 10
        num = num // 10
    return ret

ans = digit_sum(n)
buff = n
d = 10
while n > 0:
    n = n // 10
    buff = (buff // d) * d - 1
    d = d * 10
    if buff < 0 : break
    ans = max([ans,digit_sum(buff)])

print ans


Measured memory_bytes: 2568
input = input().split()
# inputList = list(input[0])

a = int(input[0])
b = int(input[1])
c = int(input[2])

# inputList.sort()

list = [a+b, b+c ,c+a]

ans = min(list)
print(ans)



# flg = 1
# for i in range(0, len(inputList)-1):
#     if inputList[i] == inputList[i + 1]:
#         flg = 0
#         break
#
# if flg == 0:
#     print("Bad")
# else:
#     print("Good")


Measured memory_bytes: 38256
from functools import reduce
N = int(input())
a = list(map(int, input().split()))

def gcd_impl(n,m):
    for _ in range(10):
        t = n - m
        q = m > t
        if q:
            n = m
        else:
            n = t
        if q:
            m = t
        else:
            m = m
        if m == 0:
            return n
    return gcd_impl(m, n%m)

def gcd(n,m):
    if n > m:
        return gcd_impl(n,m)
    else:
        return gcd_impl(m,n)

def lcm(a,b):
    return (a*b)//gcd(a,b)

def lcm_list(lst):
    return reduce(lcm, lst)

M = lcm_list(a) - 1

res = 0
for i in a:
    res += M%i
print(res)

Measured memory_bytes: 3812
n, p = map(int, input().split())

def prime_factor(n):
    ass = []
    for i in range(2,int(n**0.5)+1):
        while n % i==0:
            ass.append(i)
            n = n//i
    if n != 1:
        ass.append(n)
    return ass

if p == 1:
    print(1)
    exit()
if n == 1:
    print(p)
    exit()

prime = prime_factor(p)
dprime = {}
for i in set(prime):
    dprime[i] = 0
for i in prime:
    dprime[i] += 1
key = []
for k, v in sorted(dprime.items(), key=lambda x:-x[0]):
    if v >= n:
        for i in range(int(v//n)):
            key.append(k)
res = 1
for i in key:
    res *= i
print(res)

Measured memory_bytes: 3064
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

int main(){

  int N;
  cin >> N;

  set<int> amt;
  amt.insert(1);
  int v1 = 6, v2 = 9;
  while(v1 <= N){
    amt.insert(v1);
    v1 *= 6;
  }
  while(v2 <= N){
    amt.insert(v2);
    v2 *= 9;
  }

  int dp[N+1];
  fill(dp, dp+N+1, INF);
  dp[0] = 0;
  for(int i=1; i<N+1;++i){
    for(auto x: amt){
      if(i-x>=0 && dp[i-x] != INF) dp[i] = min(dp[i], dp[i-x]+1);
    }
    // cout << i << " " << dp[i] << endl;
  }
  cout << dp[N] << endl;

}

Measured memory_bytes: 640
package main

import (
    "bufio"
    "fmt"
	"os"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var S string
	fmt.Scan(&S)
	slice_S := strings.Split(S, "")
	if (slice_S[2] == slice_S[3]) && (slice_S[4] == slice_S[5]){
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()
#define var(t, ...) t __VA_ARGS__;in,__VA_ARGS__;

void Calc();
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
template<class A>int comp(A a, A b) { return a < b ? 1 : b < a ? -1 : 0; }
struct Scanner {
  template<class A = string>A Next() { A a; Next(a); return a; }
  template<class A, class B>void Next(pair<A, B>& a) { cin >> a.first >> a.second; }
  template<class A>void Next(A& a) { cin >> a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) (*this), i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;
/*---------------------------------------------------------------------*/


void Calc() {

  var(int, n, t);

  const int INF = 1e9 - 1;

  int ans = INF;

  rep(i, n) {
    var(int, a, b);
    if (b > t)continue;
    amin(ans, a);
  }

  if (ans == INF) {
    cout << ("TLE") << endl;
    return;
  }
  cout << (ans) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

template<unsigned P> struct ModInt {
  using M = ModInt;
  unsigned v;
  constexpr ModInt() : v(0) {}
  constexpr ModInt(auto x) : v(x >= 0 ? x % P : (P - -x % P) % P) {}
  constexpr ModInt(unsigned v, int) : v(v) {}
  static constexpr unsigned p() { return P; }
  M operator+() const { return *this; }
  M operator-() const { return {v ? P - v : 0, 0}; }
  explicit operator bool() const noexcept { return v; }
  bool operator!() const noexcept { return !(bool)*this; }
  M operator*(M r) const { return M(*this) *= r; }
  M operator/(M r) const { return M(*this) /= r; }
  M operator+(M r) const { return M(*this) += r; }
  M operator-(M r) const { return M(*this) -= r; }
  bool operator==(M r) const { return v == r.v; }
  bool operator!=(M r) const { return !(*this == r); }
  M& operator*=(M r) { v = (uint64_t)v * r.v % P; return *this; }
  M& operator/=(M r) { return *this *= r.inv(); }
  M& operator+=(M r) { if ((v += r.v) >= P) v -= P; return *this; }
  M& operator-=(M r) { if ((v += P - r.v) >= P) v -= P; return *this; }
  M inv() const {
    int a = v, b = P, x = 1, u = 0;
    while (b) {
      int q = a / b;
      swap(a -= q * b, b);
      swap(x -= q * u, u);
    }
    assert(a == 1);
    return x;
  }
  M pow(auto n) const {
    if (n < 0) return pow(-n).inv();
    M res = 1;
    for (M a = *this; n; a *= a, n >>= 1) if (n & 1) res *= a;
    return res;
  }
  friend M operator*(auto l, M r) { return M(l) *= r; }
  friend M operator/(auto l, M r) { return M(l) /= r; }
  friend M operator+(auto l, M r) { return M(l) += r; }
  friend M operator-(auto l, M r) { return M(l) -= r; }
  friend ostream& operator<<(ostream& os, M r) { return os << r.v; }
  friend istream& operator>>(istream& is, M& r) { lint x; is >> x; r = x; return is; }
  friend bool operator==(auto l, M r) { return M(l) == r; }
  friend bool operator!=(auto l, M r) { return !(l == r); }
};
using Mint = ModInt<(unsigned)1e9 + 7>;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, k; cin >> n >> k;
  V<> a(n); for (auto&& e : a) cin >> e;
  Mint res = 0;
  for (int j = 0; j < n; ++j) for (int i = 0; i < j; ++i) {
    res += a[i] > a[j];
  }
  res *= k;
  Mint curr;
  for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
    curr += a[i] > a[j];
  }
  res += curr * k * (k - 1) / 2;
  cout << res << '\n';
}

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

namespace AtCoder
{
    class Program
    {
        private const int K = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static int Fac(int n)
        {
            long fac = 1;
            for (int i = 2; i <= n; ++i)
            {
                fac *= i;
                fac %= K;
            }
            return (int)fac;
        }
        static int Solve(int N, int M)
        {
            if (Math.Abs(N - M) > 1) { return 0; }
            long p = Math.BigMul(Fac(N), Fac(M));
            return (N != M) ? (int)(p * 1 % K)
                            : (int)(p * 2 % K);
        }
        static void Main(string[] args)
        {
            int[] values = ReadInts();
            Console.WriteLine(Solve(values[0], values[1]));
        }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>
#include<string.h>
int main()
{
    char s[10];
    scanf("%s",s);
    if(s[2]==s[3] && s[4]==s[5])
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9

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

    ans = INF
    for i in range(n):
        count = 0
        num = A[i]
        while num%2 == 0:
            count += 1
            num = num // 2
        ans = min(ans, count)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 63008
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<queue>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

typedef long long ll;
const ll INF = 1e17;
const int BIG = 998244353;

ll rui(ll a, ll b) {
	if (a == 0) { return 0; }
	if (b == 0) { return 1; }
	return rui(a, b - 1)*a%BIG;
}





int main() {

	ll N;
	cin >> N;

	int c[200000];

	ll D[200000] = {};//距離がiのものの個数

	int max = 0;

	
	

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

		D[c[i]]++;
		if (c[i] > max) { max = c[i]; }

	}

	int ans = 1;

	for (int i = 0; i <= max - 1; i++) {

		ans = ans * rui(D[i], D[i + 1]) % BIG;
	}

	if (D[0] != 1 || c[1]!=0) { ans = 0; }

	cout << ans;


	system("PAUSE");

}


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

using namespace std;
typedef long long ll;
int main(){
  int N; cin >> N;
   vector<ll> A(N); vector<ll> B(N);
  for(int i = 0; i < N; i++){
    cin >> A[i];}
  for(int j = 0; j < N; j++){
    cin >> B[j];}
  ll res1 = 0; ll res2 = 0;
  for(int i = 0; i < N; i++){
    res1 += max( 0LL, A[i] - B[i]);
    res2 += max( 0LL, (B[i] - A[i])/2);}
  


if( res2 >= res1){ cout << "Yes" << endl;} else{ cout << "No" << endl;}
return 0;}
    

Measured memory_bytes: 384
(r,c)=gets.split().map(&:to_i)
result=[]
sum=nil
while line=gets
  result<<line.split().map(&:to_i)
  s=0
  result.last.each {|x|s+=x}
  result.last<<s
  if sum
    result.last.each_with_index {|x,i| sum[i]+=x}
  else
    sum=result[0].clone
  end
end
result.each {|x| puts x.join(" ")}
puts sum.join(" ")

Measured memory_bytes: 6136
n,m=map(int,input().split())
s=input()
a=[]
x=n
while x>0:
  f=1
  for i in range(min(m,x),0,-1):
    if int(s[x-i]):
      continue
    else:
      a.append(i)
      x-=i
      f=0
      break
  if f:
    x=0
    a=[-1]
a=a[::-1]
print(*a)

Measured memory_bytes: 6372
#include<algorithm>
#include<cstdio>
#define mxn 1000010
#define pii pair<int,int>
#define fr first
#define sc second
#define mp make_pair
#define LL long long
using namespace std;
const int mod=1e9+7;
int n,m,K,N,sl,fh,ans,a[mxn];
LL s[mxn];
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
int main()
{
	n=rd();m=rd();K=rd();ans=N=rd();K=max(1,K-N+1);
	for(int i=1;i<=n;++i) a[i]=rd();
	sort(a+1,a+n+1,[&](const int &x,const int &y){return x>y;});
	for(int i=1;i<=n;++i) s[i]=s[i-1]+a[i];
	for(int i=N+1;i<=n;++i)
		if(i+K-1<=n) ans+=a[i]+m>=a[N];
		else if(a[i]+m>=a[N]) ans+=1ll*(i-N)*(a[i]+m)-s[i-1]+s[N-1]>=1ll*m*(K-(n-i+1));
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4992
package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	n := r()
	kmp := func(text, s []int) (pos []int) {
		f := make([]int, n)
		c := 0
		for i := 1; i < n; i++ {
			b := s[i]
			for c > 0 && s[c] != b {
				c = f[c-1]
			}
			if s[c] == b {
				c++
			}
			f[i] = c
		}
		c = 0
		for i, b := range text {
			for c > 0 && s[c] != b {
				c = f[c-1]
			}
			if s[c] == b {
				c++
			}
			if c == n && i-n+1 < n {
				pos = append(pos, i-n+1)
				c = f[c-1]
			}
		}
		return
	}

	a := make([]int, n)
	for i := range a {
		a[i] = r()
	}
	c := make([]int, n)
	for i, v := range a {
		c[i] = v ^ a[(i+1)%n]
	}
	c = append(c, c...)
	b := make([]int, n)
	for i := range b {
		b[i] = r()
	}
	d := make([]int, n)
	for i, v := range b {
		d[i] = v ^ b[(i+1)%n]
	}
	for _, p := range kmp(c, d) {
		Fprintln(out, p, a[p]^b[0])
	}
}

func main() { run(os.Stdin, os.Stdout) }


Measured memory_bytes: 24064