akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
  fast;
  int n,mx=INT_MIN,i;
  cin>>n;
  map<string,int> st;
  string s;
  for (i=0;i<n;i++)
  {
    cin>>s;
    st[s]++;
    mx=max(mx,st[s]);
  }
  vector<string> ans;
  for (auto e: st)
  {
    if (e.ss==mx)
      ans.pb(e.ff);
  }
  sort(ans.begin(),ans.end());
  for (auto e: ans)
    cout<<e<<endl;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int n;

void dfs(string s = "a") {
    if (n == s.size()) {
        cout << s << endl;
        return;
    }
    vector<int> a(10);
    rep (i, s.size()) a[s[i] - 'a']++;
    int maxi = 0;
    rep (i, n) if (a[i]) maxi = min(n - 1, i + 1);
    rep (i, maxi + 1) dfs(s + char('a' + i));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    cin >> n;
    dfs();
    
    return 0;
}



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

using namespace std;

using int64 = long long;

int main() {
  int N;
  cin >> N;
  vector< int > g[100000];
  int deg[100000] = {};
  for(int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    g[x].push_back(y);
    g[y].push_back(x);
    deg[x]++;
    deg[y]++;
  }
  queue< int > que;
  for(int i = 0; i < N; i++) {
    if(deg[i] == 1) {
      que.emplace(i);
    }
  }
  while(que.size()) {
    int idx = que.front();
    que.pop();
    for(auto &to : g[idx]) {
      if(--deg[to] == 1) {
        que.emplace(to);
      }
    }
  }
  int Q;
  cin >> Q;

  while(Q--) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    if(deg[a] >= 2 && deg[b] >= 2) cout << 2 << endl;
    else cout << 1 << endl;
  }

}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

inline ll get_number(ll i, ll skip){
	if(i < skip)
		return i;
	else
		return i + 1;
}

const ll inf = 1LL << 60;
ll mul(ll a, ll b){
	if(b == 0) return 0;
	if(a >= inf / b) return inf;
	return a * b;
}

ll calc(ll sum,ll a, ll b){
	//cerr << sum << " " << a << " " << b << endl;
	if(a >= b) return 0;
	--b;
	ll ret = 0LL;
	chmax(ret, mul(a,sum - a));
	chmax(ret, mul(b,sum - b));
	ll mid = sum / 2;

	for(ll i = mid - 5; i <= mid + 5; ++i){
		if(i < a or b < i) continue;
		chmax(ret, mul(i, sum - i));
	}

	return ret;
}


bool check(ll n,ll a,ll b){
	ll cmax = 0LL;

	{
		const ll sum = get_number(1,a) + get_number(n,b);
		chmax(cmax,calc(sum, 1, a));
	}

	{
		const ll sum = get_number(a, a) + get_number(n + 1 - a, b);
		chmax(cmax,calc(sum, a + 1, n - b + 2));
	}
	
	{
		const ll sum = get_number(n,a) + get_number(1,b);
		chmax(cmax,calc(sum, max(a + 1, n - b + 2)  , n + 2));
	}

	//cerr << n << " " << cmax << endl;
	return (cmax < a * b) ;
}


int main(void){
	int q;
	cin >> q;
	rep(loop,q){
		ll a,b;
		cin >> a >> b;	

		ll lb = 0LL, ub = 1LL << 40;

		while(ub - lb > 1){
			const ll mid = (lb + ub) / 2;
			if(max(check(mid,a,b),check(mid,b,a)))
				lb = mid;
			else
				ub =  mid;
		}

		cout << lb << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    BufferedReader rd;

    Main() throws IOException {
        rd = new BufferedReader(new InputStreamReader(System.in));
        compute();
    }

    private void compute() throws IOException {
        out(Integer.highestOneBit(pint()));
    }

    private int pint() throws IOException {
        return pint(rd.readLine());
    }

    private int pint(String s) {
        return Integer.parseInt(s);
    }

    private static void out(Object x) {
        System.out.println(x);
    }

    public static void main(String[] args) throws IOException {
        new Main();
    }
}


Measured memory_bytes: 21460
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define INF 0x3f3f3f3f
const int maxn=1e5+10;
struct node{
int x,y;
}a[maxn];
bool cmp(node a,node b)
{

    if(a.x==b.x){
        return a.y<b.y;
    }
    return a.x<b.x;
}
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d %d",&a[i].x,&a[i].y);
    }
    sort(a+1,a+1+m,cmp);
    int L,R;int ans=0;
    L=a[1].x,R=a[1].y;
    ans++;
    for(int i=2;i<=m;i++){
        if(a[i].x<R){
            L=a[i].x;
            if(a[i].y<R) R=a[i].y;
            continue;
        }
        else {
            ans++;
            L=a[i].x;
            R=a[i].y;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1024
while input = gets
  *l, v1, v2 = input.split(",").map(&:to_i)
  len = l.inject(:+).to_f
  pos = len/(v1+v2) * v1
  sum = 0
  i = 0
  while pos > sum
    sum += l[i]
    i += 1
  end
  puts i
end

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A[] = new long[3];
		for (int i=0;i<3;i++) {
			A[i] = sc.nextLong();
			if (A[i]%2==0) {
				System.out.println(0);
				return ;
			}
		}
		Arrays.parallelSort(A);
		System.out.println(A[0]*A[1]);
	}
}

Measured memory_bytes: 35820
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,x,t;
	long long ans= 0;
	cin>>n>>x>>t;
	if(n == 0){
		cout<<"0";
	}else if(n<=x){
		cout<<t;
	} else {
		ans = (n / x) * t + (n % x > 1 ? t : 0);
		cout<<ans;
	}
	cout<<endl;
	return 0;
}

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

int main(){
	int a, b;
	while(true){
		cin >> a >> b;
		if(a==0&&b==0){
			break;
		}
		if(a<b){
			cout << a << " " << b << "\n";
		}
		else{
			cout << b << " " << a << "\n";
		}
	}
}


Measured memory_bytes: 3004
/*#include<iostream>
#include<bitset>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    bitset<32>c(a);
    bitset<32>d(b);
    cout<<(c&d)<<endl;
    cout<<(c|d)<<endl;
    cout<<(c^d)<<endl;
    return 0;
}*/

#include <bits/stdc++.h>
#define int long long
using namespace std;
main(){
  int x,y;
  cin>>x>>y;
  bitset<32>a(y),b(x);
  //cout<<b<<endl;
  //cout<<(~b)<<endl;
  //cout<<(b<<1)<<endl;
  //cout<<(b>>1)<<endl;
  cout<<(a&b)<<endl;
  cout<<(a|b)<<endl;
  cout<<(a^b)<<endl;
}



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

using namespace std;

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

const double pi = 3.14159265358979323846;

// #define fio() cin.tie(0); ios::sync_with_stdio(false);
// template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
// template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define TG0 get< 0 >
#define TG1 get< 1 >
#define TG2 get< 2 >
#define F first
#define S second
#define VL vector< ll >

// to_string(123)
// atoi("123"); atoi(s.c_str());
// "abc".size()
// s.find('+') == string::npos
// 1e18

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

  ll N;
  cin >> N;

  cout << N / 2 + N % 2 << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int[] a = new int[n];
			int b = 0;
			int[] c = new int[n];

			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
			}
			for (int i = 0; i < n; i++) {
				b += sc.nextInt();
			}
			for (int i = 0; i < n - 1; i++) {
				c[i] = sc.nextInt();
			}

			int result = 0;
			int before = -50;
			for(int num : a) {
				if(num - before == 1) {
					result += c[before - 1];
				}
				before = num;
			}

			System.out.println(result + b);
		}
	}
}


Measured memory_bytes: 21588
S = str(input())

a = []
b = []
for i in S:
    if i == "N" or i == "S":
        a.append(i)
    else:
        b.append(i)

if len(set(a)) == 1 or len(set(b)) == 1:
    print("No")

else:
    print("Yes")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout(val) cout << std::fixed << std::setprecision(20) << val;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };

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

  int a,b,c,d; cin >> a >> b >> c >> d;
  bool nowtaka = 0;
  while(true) {
    if(a <= 0) {
      cout << "No" << endl;
      return 0;
    } else if(c <= 0) {
      cout << "Yes" << endl;
      return 0;
    }

    if(nowtaka) {
      a -= d;
    } else {
      c -= b;
    }
    nowtaka = !nowtaka;
  }
}


Measured memory_bytes: 3652
#include <iostream>
using namespace std;
typedef long long LL;
LL n, s;

LL f(LL b, LL n) {
    if (n < b) return n;
    return f(b, n/b) + n%b;
}

LL solve(LL L, LL R) {
    LL s1 = f(L, n);
    if (s1 == s) return L;
    if (L == R) return -1;
    LL s2 = f(L+1, n);
    LL d = s1 - s2;
    if (s <= s1 && (s1 - s) % d == 0 && (s1 - s) / d <= R - L)
        return L + (s1 - s) / d; 
    return -1;
}

int main() {
    cin >> n >> s;
    if (n == s) {
        return !printf("%lld\n", n+1);
    } 
    if (n == 1) {

        if (s == 1) {
            printf("2\n");
        } else {
            printf("-1\n");
        }
        return 0;
    }

    LL nex;
    for (LL i = 2; i <= n; i = nex + 1) {
        nex = n / (n / i);
        LL ans = solve(i, nex);
        if (ans != -1) {
            return !printf("%lld\n", ans);
        }
    }
    printf("-1\n");
}





Measured memory_bytes: 256
from collections import deque


def main():
    X, Y, A, B, C = map(int, input().split(' '))
    a_list = list(map(int, input().split(' ')))
    b_list = list(map(int, input().split(' ')))
    c_list = list(map(int, input().split(' ')))
    a_deq = deque(sorted(a_list, reverse=True)[:X])
    b_deq = deque(sorted(b_list, reverse=True)[:Y])
    c_deq = deque(sorted(c_list, reverse=True))
    result = sum(a_deq) + sum(b_deq)
    while len(c_deq) > 0:
        try:
            if a_deq[-1] < b_deq[-1]:
                min_ab = a_deq.pop()
            else:
                min_ab = b_deq.pop()
        except IndexError:
            if len(a_deq) > 0:
                min_ab = a_deq.pop()
            elif len(b_deq) > 0:
                min_ab = b_deq.pop()
            else:
                break

        if min_ab >= c_deq[0]:
            break
        result += c_deq.popleft() - min_ab

    print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 23616
#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;
#define INF (1e9)
#define LINF (1LL << 60)
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,k,n) for(int i=(k);(i)<(n);(i)++)
#define REP(i,n) for(int i = 0;(i)<(n);(i)++)
#define REPR(i,n) for(int i = n; i >= 0; i--)
#define F first
#define S second
#define MOD 1000000007

int get_digit(LL n) {
	int digit = 0;
	while (n > 0) {
		digit++;
		n /= 10;
	}
	return digit;
}

int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> c(m);	//c[i] F:県 S:県下で何番目
	vector<vector<pair<int, int>>> p(n);	//F:年 S:市の順番
	REP(i, m) {
		int tmp1, tmp2;
		cin >> tmp1 >> tmp2;
		c[i].F = tmp1;
		p[tmp1 - 1].push_back(make_pair(tmp2, i));
	}
	REP(i, n) {
		sort(ALL(p[i]));
		REP(j, p[i].size()) c[p[i][j].S].S = j + 1;
	}
	REP(i, m) {
		REP(j, 6 - get_digit(c[i].F)) cout << 0;
		cout << c[i].F;
		REP(j, 6 - get_digit(c[i].S)) cout << 0;
		cout << c[i].S << endl;
	}
}


Measured memory_bytes: 7808
from heapq import heappop, heappush

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

list.sort(A, reverse = True)
list.sort(B, reverse = True)
list.sort(C, reverse = True)

hq = []
heappush(hq, (-(A[0] + B[0] + C[0]), 0, 0, 0))
for _ in range(K):
    ans, i, j, k = heappop(hq)
    print(-ans)
 
    if i+1 < X:
        t = (-(A[i+1] + B[j] + C[k]), i+1, j, k)
        if t not in hq:
            heappush(hq, t)
 
    if j+1 < Y:
        t = (-(A[i] + B[j+1] + C[k]), i, j+1, k)
        if t not in hq:
            heappush(hq, t)
    
    if k+1 < Z:
        t = (-(A[i] + B[j] + C[k+1]), i, j, k+1)
        if t not in hq:
            heappush(hq, t)

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int a,b;cin>>a>>b;
  cout<<(a+b-1)/b<<endl;
 

  return 0;
}

Measured memory_bytes: 256
// [[ABC134C] Exception Handling] https://www.luogu.com.cn/problem/AT4843
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
using namespace std;
long long a[30], b[30];
int main() {
  string s, k;
  cin >> s >> k;

  for (int i = 0; i < s.length(); i++) {
    a[s[i]-'a']++;
    b[k[i]-'a']++;
  }

  sort(a, a+26);
  sort(b, b+26);

  for (int i = 0; i < 26; i++) {
    if (a[i] != b[i]) {
      cout << "No\n";
      return 0;
    }
  }
  
  cout << "Yes\n";
  return 0;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b

signed main(){
	ll n,a,b; cin>>n>>a>>b;
	if(n==1 && a!=b)cout<<0<<endl;
	else if(a>b)cout<<0<<endl;
	else cout<<(n-2)*(b-a)+1<<endl;
	
	return 0;
}

Measured memory_bytes: 3576
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(998244353)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

bool cmp(pii a,pii b){
	return a.S<b.S;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b; cin>>a>>b;
	int ans=0;
	For(i,1,a){
		For(j,20,b){
			if(j%10>=2 && (j%10)*(j/10)==i) ans++;
		}
	}
	cout<<ans<<"\n";
	return 0;
}





























Measured memory_bytes: 256
# instead of AVLTree
class BITbisect():
    def __init__(self, max):
        self.max = max
        self.data = [0]*(self.max+1)
    
    # 0からiまでの区間和
    # 立っているビットを下から処理
    def query_sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    # i番目の要素にxを足す
    # 覆ってる区間すべてに足す
    def add(self, i, x):
        while i <= self.max:
            self.data[i] += x
            i += i & -i

    def insert(self, x):
        self.add(x, 1)

    def delete(self, x):
        self.add(x, -1)

    def count(self, x):
        return self.query_sum(x) - self.query_sum(x-1)
    
    def length(self):
        return self.query_sum(self.max)
    
    # 下からc番目(0-indexed)の数
    # O(log(N))
    def search(self, c):
        c += 1
        s = 0
        ind = 0
        l = self.max.bit_length()
        for i in reversed(range(l)):
            if ind + (1<<i) <= self.max:
                if s + self.data[ind+(1<<i)] < c:
                    s += self.data[ind+(1<<i)]
                    ind += (1<<i)
        if ind == self.max:
            return False
        return ind + 1
    
    def bisect_right(self, x):
        return self.query_sum(x)

    def bisect_left(self, x):
        if x == 1:
            return 0
        return self.query_sum(x-1)

    # listみたいに表示
    def display(self):
        print('inside BIT:', end=' ')
        for x in range(1, self.max+1):
            if self.count(x):
                c = self.count(x)
                for _ in range(c):
                    print(x, end=' ')
        print()

import sys
input = sys.stdin.readline

base = 10**9

N, M = map(int, input().split())
Pairs = [[] for _ in range(M+1)]
for _ in range(N):
    a, b = map(int, input().split())
    Pairs[b-a+1].append(a*base+b)

ansbit = BITbisect(M+1)
usingbit = BITbisect(M+1)

for length, inPairs in enumerate(Pairs):
    if length==0: continue

    ansbit.add(1, len(inPairs))
    ansbit.add(length+1, -len(inPairs))

    rem = M//length
    c = 0
    for r in range(1, rem+1):
        c += usingbit.query_sum(r*length)
    ansbit.add(length, c)
    ansbit.add(length+1, -c)

    for p in inPairs:
        l = p//base
        r = p%base
        usingbit.add(l, 1)
        usingbit.add(r+1, -1)
    
for n in range(1, M+1):
    print(ansbit.query_sum(n))

Measured memory_bytes: 75952
// https://atcoder.jp/contests/abc096/tasks/abc096_c

#include "algorithm"
#include "iostream"
#include "set"
#include "vector"
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
using namespace std;
typedef long long ll;

template <class T>
inline bool chmax(T& a, T b);
template <class T>
inline bool chmin(T& a, T b);

void solve() {
  ll H, W;
  cin >> H >> W;

  string G[H];
  rep(i, 0, H) cin >> G[i];

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

  auto yes = "Yes";
  auto no = "No";

  rep(i, 0, H) {
    rep(j, 0, W) {
      if (G[i][j] == '.') {
        continue;
      }

      auto ok = false;

      rep(k, 0, 4) {
        if (G[i + dy[k]][j + dx[k]] == '#') {
          ok = true;
        }
      }

      if (!ok) {
        cout << no << endl;
        return;
      }
    }
  }

  cout << yes << endl;
}

#ifndef TEST
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
#endif

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


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

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
const ll MOD = 1e9+7;
const vi dx = {1, 0, -1, 0, 1, -1, -1, 1};
const vi dy = {0, 1, 0, -1, 1, 1, -1, -1};


int main() {
    string S; cin>>S;

    string ans = "";
    rep(i, S.size()){
        ans.push_back('x');
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns, FlexibleContexts #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import qualified Data.Array as A
import qualified Data.Array.Unboxed as AU
import Control.Monad.ST
import Data.Array.ST
import Data.Char

import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
readInt = fst . fromJust . B.readInt
readInts = map readInt . B.words <$> B.getLine :: IO [Int]
readIntegers = map (fst . fromJust . B.readInteger) . B.words <$> B.getLine :: IO [Integer]
read2dInts = map (map (fst . fromJust . B.readInt) . B.words) . B.lines <$> B.getContents
readVInts = map (fst . fromJust . B.readInt) . B.lines <$> B.getContents
readVTuple = map ((\(a:b:_) -> (readInt a, readInt b)) . B.words) . B.lines <$> B.getContents :: IO [(Int, Int)] 

main :: IO ()
main = do
  (n:q:_) <- map read . words <$> getLine :: IO [Int]
  buff <- readVTuple :: IO [(Int, Int)]
  let (abs, pxs) = splitAt (n-1) buff
  putStrLn . unwords . map show $ solve' n q abs pxs

    
solve' n q abs pxs = AU.elems dfs
  where
    tree :: A.Array Int [Int]
    tree = runSTArray $ do
      t <- newArray (1, n) [] :: ST s (STArray s Int [Int])
      forM_ abs $ \(a, b) -> do
        aprev <- readArray t a
        writeArray t a $ b:aprev
        bprev <- readArray t b
        writeArray t b $ a:bprev
      return t

    countMap = runSTUArray $ do
      mp <- newArray (1, n) 0 :: ST s (STUArray s Int Int)
      forM_ pxs $ \(p, x) -> do
        prev <- readArray mp p
        writeArray mp p $ prev + x
      return mp

    dfs :: AU.UArray Int Int 
    dfs = runSTUArray $ do
      c <- newArray (1, n) 0 :: ST s (STUArray s Int Int)
      let 
        loop current parent point = do
          let p = point + countMap AU.! current
          writeArray c current p
          forM_ (tree A.! current) $ \next -> 
            if next == parent then return () else loop next current p

      loop 1 0 0
      return c


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

using ll = long long;

#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define len(x) int((x).size())

ll ceil(ll a, ll b)
{
	if(a%b==0LL) return ll(a/b);
	return 1LL+ll(a/b);
}

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

	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	int h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;

	int mins=(h2-h1)*60+(m2-m1);

	cout << max(0,mins-k) << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;
typedef map<string,ll> mapstl;
#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define inf 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll a,b;
	cin>>a>>b;
	cout<<max((a+b),max((a-b),(a*b)))<<endl; 
	return 0;
}

Measured memory_bytes: 3552
import java.util.Scanner;

/**
 * https://abc050.contest.atcoder.jp/tasks/arc066_b
 */
public class Main {

	static final int MOD = 1000000007;
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		sc.close();
		
		long bit = (long)(Math.log10(N)/Math.log10(2) + 1.0);
		long[][] dp = new long[(int)bit+1][3];
		dp[0][0] = 1;
		for (int i = 1; i <= bit; i++) {
			if(((long)1<<(bit-i)&N)>0){
				dp[i][0] = dp[i-1][0];
				dp[i][1] = (dp[i-1][0] + dp[i-1][1]) % MOD;
				dp[i][2] = (2*dp[i-1][1] + 3*dp[i-1][2]) % MOD;
			} else {
				dp[i][0] = (dp[i-1][0] + dp[i-1][1]) % MOD;
				dp[i][1] = dp[i-1][1];
				dp[i][2] = (dp[i-1][1] + 3*dp[i-1][2]) % MOD;
		    }
		}
	 
		long ans = (dp[(int)bit][0] + dp[(int)bit][1] + dp[(int)bit][2]) % MOD;
		System.out.println(ans);

	}

}

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

string s, t, u;

int main(){
  cin >> s >> t >> u;
  int a = 'A' - 'a';
  char S, T, U;
  S = s[0] + a;
  T = t[0] + a;
  U = u[0] + a;
  cout << S << T << U << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;

template<typename T>void chmax(T &a,T b){a=max(a,b);}
template<typename T>void chmin(T &a,T b){a=min(a,b);}
using namespace std;

void solve(){
	int h,w,n;
	cin>>h>>w>>n;
	vector<int>a;
	int cnt=h*w;
	rep(i,n){
		int x;
		cin>>x;
		rep(j,x)a.pb(i+1);
	}
	vector<vector<int>>ans(h,vector<int>(w));
	rep(i,h){
		if(i%2){
			for(int j=w-1;j>=0;--j){
				ans[i][j]=a[h*w-cnt];
				--cnt;
			}
		}
		else {
			rep(j,w){
				ans[i][j]=a[h*w-cnt];
				--cnt;
			}
		}
	}
	rep(i,h){
		rep(j,w){
			if(j)cout<<" ";
			cout<<ans[i][j];
		}
		cout<<"\n";
	}
}

signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	solve();
	return 0;
}


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

int main(void) {
	char S[27];
	int A,i,len,j;
	scanf("%s",S);
	len=strlen(S);
	for(j=1;j<=len;j++){
		for(i=1;i<=len;i++){
			if(S[i-1]==S[j-1]){
				A++;
			}
	}
	}
	if(A==len){
		printf("yes");
	}
	else{
		printf("no");
	}
	return 0;
}


Measured memory_bytes: 128
N = int(input())
def next_str(num):
    #一番下の桁を大きくする
    dic = {"3":"5","5":"7","7":"3"}
    ketaagari = True
    ret_str = ""
    for char in reversed(str(num)):
        if ketaagari:
            ret_str = str(dic[char]) + ret_str
            if char in ("3","5"):
                ketaagari = False
        else:
            ret_str = str(char) + ret_str
    if ketaagari:
        ret_str = "3" + ret_str
            
    return ret_str
now = 3
cnt = 0
while int(next_str(now))<=N:
    if(set(next_str(now)) == {"3","5","7"}):
        cnt+=1
        # print(next_str(now),"yes!")
    now = next_str(now)
print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define mino "A"
#define ll long long
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define matrix vector<vector<ll>>
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define Down(i,a,b) for(int i = a; i >= b; i--)
#define FOR_(i,a,b) for(int i = a; i < b; i++)
#define turbo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oo 1e9

const int N = 505;

using namespace std;

typedef pair<int,int> pii;


int L;

struct ii
{
    int u, v, w;
};
vector <ii> kq;

void nhap()
{
    cin >> L;
}

void xuli()
{
    int t = 1, n = 1;
    while(t * 2 <= L)
    {
        kq.pb({n,n+1,0});
        kq.pb({n,n+1,t});
        t *= 2;
        n++;
    }

    L -= t;
    Down(i,n-2,0)
    {
        if(L & (1 << i))
        {
            kq.pb({i+1,n,t});
            t += int(1 << i);
        }
    }
    cout << n << ' ' << kq.size() << '\n';
    FOR(i,0,kq.size()-1)
    {
        cout << kq[i].u << ' ' << kq[i].v << ' ' << kq[i].w << endl;
    }
}

int main()
{
    //freopen(mino".inp","r",stdin);
    //freopen(mino".out","w",stdout);
    nhap();
    xuli();
}


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

map<string,int> table;

int main()
{
    string word,frequent,longest;
    size_t N=0;
    while(cin>>word)
    {
        table[word]++;
        if(table[word]>N)
        {
            N=table[word];
            frequent=word;
        }
        if(word.size()>longest.size())
          longest=word;
    }
    cout << frequent << " " << longest <<endl;
}


Measured memory_bytes: 3004
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

ll dp[1010][20010];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    tlglglg t[N];
    REP(i, 0, N) {
        ll w, s, v;
        cin >> w >> s >> v;
        t[i] = tlglglg(w, s, v);
    }
    sort(t, t + N, [] (tlglglg x, tlglglg y) -> bool {
            return get<0>(x) + get<1>(x) < get<0>(y) + get<1>(y);
        });
    REP(i, 0, 1010) {
        fill(dp[i], dp[i] + 20010, -1);
    }
    dp[0][0] = 0;
    REP(i, 0, N) {
        tlglglg now = t[i];
        ll w = get<0>(now);
        ll s = get<1>(now);
        ll v = get<2>(now);
        REP(j, 0, 20010) {
            if (dp[i][j] != -1) {
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
                if (j <= s && j + w < 20010) {
                    dp[i + 1][j + w] = max(dp[i + 1][j + w], dp[i][j] + v);
                }
            }
        }
    }
    ll ans = 0;
    REP(i, 0, 20010) {
        ans = max(ans, dp[N][i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 158208
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

vector<pii> norm(vector<pii> vp){
    int y = vp[0].first, x = vp[0].second;
    
    for(auto &e:vp)e.first-=y, e.second-=x;
    
    return vp;
}

vector<pii> f(vector<pii> vp){
    vp = norm(vp);
    for(auto &e:vp){
        int nx = e.first;
        int ny = -e.second;
        e = pii(ny,nx);
    }
    
    return vp;
}

int main(){
    int n;
    while(cin>>n&&n){
        vector<pii> base;
        int m;
        cin>>m;
        rep(i,m){
            int x,y;
            cin>>x>>y;
            base.pb(pii(y,x));
        }
        base = norm(base);
        
        vector<vector<pii>> vs;
        rep(i,n){
            cin>>m;
            vector<pii> tmp;
            rep(j,m){
                int x,y;
                cin>>x>>y;
                tmp.pb(pii(y,x));
            }
            vs.pb(norm(tmp));
            vs.pb(norm(f(tmp)));
            vs.pb(norm(f(f(tmp))));
            vs.pb(norm(f(f(f(tmp)))));

            reverse(all(tmp));
            vs.pb(norm(tmp));
            vs.pb(norm(f(tmp)));
            vs.pb(norm(f(f(tmp))));
            vs.pb(norm(f(f(f(tmp)))));
}
        
        set<int> st;
        rep(i,vs.size()){
            if(base==vs[i]){
                st.insert(1+i/8);
            }
        }
        for(auto e:st)cout<<e<<endl;
        cout<<"+++++"<<endl;
    }
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define INF 1000000000

typedef long double Real;
#define EPS 1e-11
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

int main(){
  int y,m,d;
  while(~scanf("%d%d%d",&y,&m,&d)){
    if(y<1868 || (y==1868 && (m<9 || (m==9 && d<8)))){
      cout<<"pre-meiji"<<endl;
    }else if(y<1912 || (y==1912 && (m<7 || (m==7 && d<30)))){
      printf("meiji %d %d %d\n",y-1867,m,d);
    }else if(y<1926 || (y==1926 && (m<12 || (m==12 && d<25)))){
      printf("taisho %d %d %d\n",y-1911,m,d);
    }else if(y<1989 || (y==1989 && m==1 && d<8)){
      printf("showa %d %d %d\n",y-1925,m,d);
    }else{
      printf("heisei %d %d %d\n",y-1988,m,d);
    }
  }
  return 0;
}

Measured memory_bytes: 1228
import java.util.*;

public class Main {

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

        if(a == 22){
            System.out.println("Christmas Eve Eve Eve");
        } else if (a == 23){
            System.out.println("Christmas Eve Eve");
        } else if (a == 24){
            System.out.println("Christmas Eve");
        } else {
            System.out.println("Christmas");
        }
    }
}

Measured memory_bytes: 21460
#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, r;
    cin >> n >> r;
    
    int ans=r;
    if(n<10) ans+=100*(10-n);

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

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x


using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL<<40;
const double PI = atan(1)*4;
const long long MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}


int main() {
    int n;cin>>n;
    vector<ll> l(n+2);
    repsg(i,1,n+1){
        cin>>l[i];
    }
    vector<ll> r(n+2);
    repsg(i,1,n+1){
        cin>>r[i];
    }
    r[0] = r[1];
    l[n+1] = l[n];

    ll w = 1;
    
    ll ex,mx;
    
    for(auto i = 1;i<=n;i++){
        ex = -1;
        mx=INFL;
        
        if(l[i]>l[i-1]){ /// l更新
            ex=l[i];
        }else{
            mx=l[i];
        }
        
        if(r[i]>r[i+1]){ //// r更新
            if(ex!=-1 && ex!= r[i]){
                w=0;
            }
            ex=r[i];
        }else{
            mx = min(mx,r[i]);
        }
        
        if(ex!=-1){  /// l, rの一方からの情報で山の高さが確定し、それともう一方が矛盾している時は0
            if(ex>mx) w=0;
        }else{
            w*=mx;
            w%=MOD;
        }
    }
    
    cout<<w<<endl;
    return 0;
}




Measured memory_bytes: 1792
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
#include <map>

typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define out(s) cout << s << endl



int main(){
    int k,n;cin >> n >> k;
    
    int c=1;
    for(int i=1;i<=n-1;i++){
        c=c*(k-1);
    }
    cout << k*c << endl;
    return 0;
}


Measured memory_bytes: 256
S = [int(_) for _ in input()]

ptA = [_ % 2  for _ in range(len(S))]
ptB = [abs(_ - 1)  for _ in ptA]
cntA = 0
cntB = 0

for s, a, b in zip(S, ptA, ptB) :
    if s != a:
        cntA += 1

    if s != b:
        cntB += 1

ans = min(cntA, cntB)
print(ans)

Measured memory_bytes: 5532
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) {cin >> a[i]; a[i]--;}
    vector<int> b(n);
    rep(i, n) {
        int num = a[i];
        b[num] = i;
    }

    debug(b);
    int cur = -1;
    int cnt = -1;
    int max = 0;
    rep(i, n-1) {
        if (cur==-1) {
            cur = b[i];
            cnt = 1;
        }
        if (cur<b[i+1]) {
            cnt++;
            cur = b[i+1];
        }
        else cur = -1;
        chmax(max, cnt);
    }
    int ans = 0;
    if (n>1) ans = n-max;
    cout << ans << endl;
}

Measured memory_bytes: 1792
// https://atcoder.jp/contests/jsc2019-qual/tasks/jsc2019_qual_b

package main

import "fmt"
import "bufio"
import "os"
import "strconv"

var _sw = bufio.NewScanner(os.Stdin)

func main() {
	N := nextInt()
	K := nextInt()
	A := make([]int, N)

	for i := range A {
		A[i] = nextInt()
	}

	w := 0
	h := 0
	for i := range A {
		for j := range A {
			if A[i] > A[j] {
				w++
				if i < j {
					h++
				}
			}
		}
	}

	D := 1000000000 + 7
	ans := (K*h + ((K-1)*K/2%D)*w) % D
	fmt.Println(ans)
}

func init() {
	_sw.Split(bufio.ScanWords)
}

func nextInt() int {
	if _sw.Scan() == false {
		panic(_sw.Err())
	}
	i, e := strconv.Atoi(_sw.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	if _sw.Scan() == false {
		panic(_sw.Err())
	}
	return _sw.Text()
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x > y {
		return y
	}
	return x
}


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

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

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

	int x;
	cin >> x;

	int res = x / 500 * 1000;
	x %= 500;
	res += x / 5 * 5;

	cout << res;

	return 0;
}

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

int main() {
    string ans;
    string S;
    cin >> S;
    if(S == "Sunny")
        ans = "Cloudy";
    if(S == "Cloudy")
        ans = "Rainy";
    if(S == "Rainy")
        ans = "Sunny";

    cout << ans << endl;
}

Measured memory_bytes: 3420
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
char s[N];
int n,ans;
int main()
{
	scanf("%s",s+1);
	n=ans=strlen(s+1);
	for(int i=1;i<n;i++)
		if(s[i]!=s[i+1])
			ans=min(ans,max(i,n-i));
	printf("%d\n",ans);
	return 0;
}

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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

int w,h,x;
/*←↓↑→ */
void moveto(int r,int x,int y,vector<vector<int>>&map,vector<vector<bool>>&kabe);

int main() {
    while(true){
        cin>> w>>h;
        if(w==0&&h==0)break;
        vector<vector<int>> map(w,vector<int>(h,INT_MAX));
        vector<vector<bool>> kabe(w,vector<bool>(2*h,true));
        rep(i,2*h-1){
            int cnt=(i%2) ? w : w-1;
            rep(k,cnt){
                cin>>x;
                if(x==0)kabe[k][i]=false;
            }
        }
        map[0][0]=1;
        moveto(1,0,0,map,kabe);
        moveto(3,0,0,map,kabe);
        cout<<((map[w-1][h-1]==INT_MAX) ? 0 : map[w-1][h-1])<<endl;
    }
    return (0);
}
int check[4][4]={{-1,0,-1,0},{0,1,0,1},{0,-1,0,-1},{1,0,0,0}};
void moveto(int r,int x,int y,vector<vector<int>> &map,vector<vector<bool>> &kabe){
    if(check[r][0]==-1&&x==0)return ;
    if(check[r][1]==-1&&y==0)return ;
    if(!kabe[x+check[r][2]][2*y+check[r][3]] && map[x][y]+1<map[x+check[r][0]][y+check[r][1]]){
        map[x+check[r][0]][y+check[r][1]]=map[x][y]+1;
        moveto(0,x+check[r][0],y+check[r][1],map,kabe);
        moveto(1,x+check[r][0],y+check[r][1],map,kabe);
        moveto(2,x+check[r][0],y+check[r][1],map,kabe);
        moveto(3,x+check[r][0],y+check[r][1],map,kabe);
    }



    return ;
}




Measured memory_bytes: 3112
def solve():
    r1, c1, r2, c2 = map(int, input().split())
    
    p = 10 ** 9 + 7
    N = r2 + c2 + 2
    fact = [1, 1]
    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % p)
    
    def comb(n, r):
        a = fact[n]
        b = pow(fact[r], p - 2, p)
        c = pow(fact[n-r], p - 2, p)
        return a * b * c % p
    
    def f(i, j):
        return comb(i + j, i)
    
    def g(i, j):
        return f(i + 1, j + 1) - 1
    
    ans = g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)
    
    print(ans % p)

solve()

Measured memory_bytes: 82220
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int solve(int x,int y);
int dx[2]={1,0};
int dy[2]={0,1};
int way[20][20];
int a,b,n;
int main(void){
  int tx,ty;
  while(1){
    scanf("%d %d",&a,&b);
    if(a==0 && b==0) break;
    scanf("%d",&n);
    memset(way,0,sizeof(way));
    for(int i=0;i<n;i++){
      scanf("%d %d",&tx,&ty);
      way[tx][ty]=1;
    }
    printf("%d\n",solve(1,1));
  }
}

int solve(int x,int y){
  int res=0;
  if(x==a && y==b) return 1;
  if(way[x][y])return 0;
  for(int i=0;i<2;i++){
    int nx=x+dx[i];
    int ny=y+dy[i];
    if(nx<=a && ny<=b) res+=solve(nx,ny);
  }
  return res;
}

Measured memory_bytes: 876
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  vector<pair<string,int>>v;
  int n;
  cin>>n;
    int total_time=0;
  for(int i=0;i<n;i++){
      string play_list;
      int time;
      cin>>play_list>>time;
      v.push_back(make_pair(play_list,time));
      total_time+=time;
  }
  string s=v[0].first;
  string target;
  cin>>target;
  if(s==target)
  cout<<total_time - v[0].second<<endl;
  else{
    int res=0;
     int i;
    for(i=0;i<v.size();i++){
        if(v[i].first!=target){
        res+=v[i].second;
       }
        else
     break; 
    }
     cout<<total_time-res-v[i].second<<endl;
  }
}

Measured memory_bytes: 256
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque

def run():
    A,B = map(int, sysread().split())
    K = math.gcd(A,B)
    factorials = []
    L = int(max(A,B)**0.5)
    for i in range(2, L+1):
        done = False
        limit = int(i ** 0.5)
        for j in factorials:
            if j > limit:break
            if not i % j:
                done = True
                break
        if not done:
            factorials.append(i)

    factors = [1]
    for f in factorials:
        if f > K:break
        if not K % f:
            factors.append(f)
            while not K % f:
                K = K // f

    if K != 1:
        factors.append(K)
    print(len(factors))


    #print(factorials)
if __name__ == "__main__":
    run()

Measured memory_bytes: 12652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int h,w,k;
ll dp[1000][110];
int s[] = {1,1,2,3,5,8,13,21};

int main(int argc, char const *argv[])
{
	cin>>h>>w>>k;
	if(w == 1)
		{
			printf("1\n");
			return 0;
		}
	dp[0][0] = 1;
	rep(i,0,h)
		rep(j,0,w)
		{
			dp[i][j] %= mod;
			if(j == 0)
			{
				dp[i+1][j+1] += dp[i][j] * s[max(0,w - j - 2)];
				dp[i+1][j] += dp[i][j] * s[w - j - 1];
			}
			else if(j != 0)
			{
				dp[i+1][j+1] += dp[i][j] * s[j] * s[max(0,w - j - 2)];
				dp[i+1][j] += dp[i][j] * s[j] * s[w - j - 1];
				dp[i+1][j-1] += dp[i][j] * s[max(0,j-1)] * s[w-j-1];
			}
		}		
	cout<<dp[h][k-1]%mod<<endl;	
	return 0;
}

Measured memory_bytes: 384
n,k=map(int,input().split())
a=list(map(int,input().split()))

b=[1]
Flag=True
now=1
arrived=set(b)
memo=1
while Flag:
    b.append(a[now-1])
    if a[now-1] in arrived:
        Flag=False
        memo=a[now-1]
    arrived.add(a[now-1])
    now=a[now-1]

loop=len(b)-b.index(memo)-1

first=b.index(memo)


if k>first:
    p,q=divmod(k-first,loop)
    print(b[first+q])
else:
    print(b[k])

Measured memory_bytes: 32212
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 5e5 + 5;
char s[MAXN];
int a[MAXN];
int main()
{
	int n = 0;
	while ((s[n] = getchar()) != EOF)
		++n;
	++n;
	memset(a,0,sizeof(a));
	int num = 0;
	for (int i = 0;i < n; ++i)
	{
		if (s[i] == '<')
			++num;
		else num = 0;
		a[i + 1] = num;
	}
	num = 0;
	for (int i = n - 1;i >= 0;--i)
	{
		if (s[i] == '>')
			++num;
		else num = 0;
		a[i] = max(a[i],num);
	}
	LL ans = 0;
	for (int i = 0;i <= n; ++i)
		ans += a[i];
	cout<<ans;
	
} 

Measured memory_bytes: 2688