akhauriyash/Code-Regression huggingface dataset:
#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;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> s = a;
  sort(s.rbegin(), s.rend());
  rep(i, n) {
    int ans = s[0];
    if (a[i] == s[0]) ans = s[1];
    cout << ans << '\n';
  }
  return 0;
}

Measured memory_bytes: 4812
#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
const ll 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
//priority_queue<ll, vector<ll>, greater<ll>> q;
const int D = 60;
ll to[D][200005];

signed main(){
	cout << fixed << setprecision(10);
	double a,b; cin>>a>>b;
	int n=a,m=b;
	cout<<n/m<<endl;
	cout<<n%m<<endl;
	cout<<a/b<<endl;


	return 0;
}


Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef pair<int,int>   ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef set<int>        si;
typedef set<ii>         sii;

#define all(x) x.begin(),x.end()
#define clr(x,v) memset(x,v,sizeof x)
#define sz(x) (int)x.size()
#define re return

template<typename T> T sgn (T x)      {re x<0? -1:(x>0? 1:0); }
template<typename T> T gcd (T a, T b) {re a ? gcd (b % a, a) : b; }
template<typename T> T abs (T x)      {re x < 0 ? -x : x; }
template<typename T> T sqr (T x)      {re x*x;}

#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define ins insert
#define y second
#define x first
#define endl "\n"
#define MOD (int)1e9+7
#define N (int)2e5+123

ll n,a,b, i = 0;

void solve(){
	cin >> a >> b >> n;
	i = min(b-1,n);
	cout << floor((a*i)/b) - a * floor(i/b) << endl;
}

int main(){_
    solve();
}

Measured memory_bytes: 3808
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int count = 0;
		boolean boo = true;

		if (s.length()==1){
			count = 0;
		}
		else{
			char[] c = s.toCharArray();
			char index = c[0];
			for (int i=1;i<c.length;i++){
				if (c[i]!=index){
					boo = false;
				}
			}
			if (boo==true){
				count=0;
			}			
			else{

				for (int i=1;i<c.length;i++){					
					
					if (c[i]!=c[i-1]){
						count++;
					}		
				}
			}
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 13904
#include <stdio.h>

int main(void)
{	
	float time[2];
	
	while (scanf("%f ", &time[0]) != EOF){
		scanf("%f", &time[1]);
		
		if (time[0] < 35.50 && time[1] < 71.00){
			puts("AAA");
		}
		else if (time[0] < 37.50 && time[1] < 77.00){
			puts("AA");
		}
		else if (time[0] < 40.00 && time[1] < 83.00){
			puts("A");
		}
		else if (time[0] < 43.00 && time[1] < 89.00){
			puts("B");
		}
		else if (time[0] < 50.00 && time[1] < 105.00){
			puts("C");
		}
		else if (time[0] < 55.00 && time[1] < 116.00){
			puts("D");
		}
		else if (time[0] < 70.00 && time[1] < 148.00){
			puts("E");
		}
		else {
			puts("NA");
		}
	}
	
	return (0);
}

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

int main(){

  string s;
  char c;
  int n = 'a' - 'A';

  while(true){
    cin >> s >> c;
    if(c == 'X') break;

    string ss = "";

    if(c == 'U'){
      if(s[0] <= 'z' && s[0] >= 'a') s[0] -= n;
      for(int i=0;i<s.size();i++){
	if(s[i] == '_'){
	  s[i+1] -= n;
	  continue;
	}
	ss += s[i];
      }
    }

    if(c == 'L'){
      if(s[0] <= 'Z' && s[0] >= 'A') s[0] += n;
      for(int i=0;i<s.size();i++){
	if(s[i] == '_'){
	  s[i+1] -= n;
	  continue;
	}
	ss += s[i];
      }
    }

    if(c == 'D'){
      if(s[0] <= 'Z' && s[0] >= 'A') s[0] += n;
      for(int i=0;i<s.size();i++){
	if(s[i+1] <= 'Z' && s[i+1] >= 'A'){
	  ss += s[i];
	  ss += '_';
	  s[i+1] += n;
	  continue;
	}
	ss += s[i];
      }
    }

    cout << ss << endl;

  }
}

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

using namespace std;

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

  long long ans = 0;
  if (n % 2 == 0) {
    for (long long i = 5; i <= n; i *= 5) {
      ans += n / (i * 2);
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl

typedef long long LL;

const int N = 200009, MOD = 998244353;

struct mint {
    int val;
 
    mint(int v = 0) {
        val = v % MOD;
        if(val < 0) val += MOD;
    }
 
    static int mod_inv(int a, int m = MOD) {
        int g = m, r = a, x = 0, y = 1;
 
        while (r != 0) {
            int q = g / r;
            g %= r; swap(g, r);
            x -= q * y; swap(x, y);
        }
 
        return x < 0 ? x + m : x;
    }
 
    explicit operator int() const {
        return val;
    }
 
    mint& operator+=(const mint &other) {
        val += other.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
 
    mint& operator-=(const mint &other) {
        val -= other.val;
        if (val < 0) val += MOD;
        return *this;
    }
 
    mint& operator*=(const mint &other) {
        val = ((uint64_t) val*other.val)%MOD;
        return *this;
    }
 
    mint& operator/=(const mint &other) {
        return *this *= other.inv();
    }
 
    friend mint operator+(const mint &a, const mint &b) { return mint(a) += b; }
    friend mint operator-(const mint &a, const mint &b) { return mint(a) -= b; }
    friend mint operator*(const mint &a, const mint &b) { return mint(a) *= b; }
    friend mint operator/(const mint &a, const mint &b) { return mint(a) /= b; }
 
    mint& operator++() {
        val = val == MOD - 1 ? 0 : val + 1;
        return *this;
    }
 
    mint& operator--() {
        val = val == 0 ? MOD - 1 : val - 1;
        return *this;
    }
 
    mint operator++(int32_t) { mint before = *this; ++*this; return before; }
    mint operator--(int32_t) { mint before = *this; --*this; return before; }
 
    mint operator-() const {
        return val == 0 ? 0 : MOD - val;
    }
 
    bool operator==(const mint &other) const { return val == other.val; }
    bool operator!=(const mint &other) const { return val != other.val; }
 
    mint inv() const {
        return mod_inv(val);
    }
 
    mint pow(int p) const {
        mint a = *this, result = 1;
 
        while (p > 0) {
            if (p & 1)
                result *= a;
 
            a *= a;
            p >>= 1;
        }
 
        return result;
    }
 
    friend ostream& operator<<(ostream &stream, const mint &m) {
        return stream << m.val;
    }
};

int n, m, k;

int sz;
mint f[N];

mint fac(int a) {
    while(a >= sz) {
        f[sz] = f[sz-1]*sz;
        sz++;
    }
    return f[a];
}

mint choose(int a, int b) {
    return fac(a)/fac(b)/fac(a-b);
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m >> k;

    f[0] = 1;
    sz = 1;
    
    mint ans = 0;

    for(int i = 0; i <= k; ++i) {
        mint c = choose(n-1, i);
        mint cur = mint(m-1).pow(n-1-i);
        ans += cur*c*m;
    }

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


Measured memory_bytes: 4424
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#pragma GCC optimize(2)
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const double eps=1e-5;
const double pi=acos(-1.0);
const int MOD=1e9+7;
const int maxn=1e6+10;
ll pow_mod(ll a,ll i,ll n)
{
    if(i==0)
        return 1%n;
    ll temp=pow_mod(a,i>>1,n);
    temp=temp*temp%n;
    if(i&1)
        temp=(ll)temp*a%n;
    return temp;
}
bool test(ll n,ll a,ll d)
{
    if(n==2) return true;
    if(n==a) return true;
    if((n&1)==0) return false;
    while(!(d&1))
        d=d>>1;
    ll t=pow_mod(a,d,n);
    while((d!=n-1)&&(t!=1)&&(t!=n-1))
    {
        t=(ll)t*t%n;
        d=d<<1;
    }
    return (t==n-1||(d&1)==1);
}
bool isprime(ll n)
{
    if(n<2)
        return false;
    ll tt[46]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199};
    for(int i=0;i<=19;i++)
    {
        if(n<tt[i])
            break;
        if(!test(n,tt[i],n-1))
            return false;
    }
    return true;
}
int main ()
{
    ll n;
    scanf("%lld",&n);
    if(isprime(n)){
        printf("%lld\n",n-1);
    }
    else{
        int x=(int)floor(sqrt(n));
        for(int i=0;i<x;i++)
        {
            ll a=x-i;
            ll b=n/a;
            if(a*b==n){
                printf("%lld\n",a+b-2);
                break;
            }
        }
    }
    return 0;
}

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

long long n,a[100010];

int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    if(n%3!=0){
        if(a[n-1]==0)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
        return 0;
    }
    sort(a,a+n);
    if(a[0]==a[n/3-1] && a[n/3]==a[n/3*2-1] && a[n/3*2]==a[n-1] && a[n/3*2]==(a[0]^a[n/3]))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main() {
  long long n, a, b;
  scanf("%lld %lld %lld", &n, &a, &b);
  
  long long ans = n / (a + b) * a;
  if (n % (a + b) > a)
    ans += a;
  else
    ans += n % (a + b);
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_len=(n); i<i##_len; ++i)
#define FOR(i, a, b) for (int i=(a); i<(b); ++i)
using ll = long long;
using namespace std;

int main()
{
    int N;
    cin >> N;
    int A[N];
    REP(i, N) cin >> A[i];

    ll dp[N][2];
    dp[0][0] = 0;
    dp[0][1] = INT_MIN;
    FOR(i, 1, N+1)
    {
        dp[i][0] = max(dp[i-1][0] + A[i-1], dp[i-1][1] - A[i-1]);
        dp[i][1] = max(dp[i-1][0] - A[i-1], dp[i-1][1] + A[i-1]);
    }

    cout << dp[N][0] << endl;
    return 0;
}

Measured memory_bytes: 2176
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const double PI = acos(-1.0);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

char C[4] = {'A','C','G','T'};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string S; cin >> S;
    int cnt = 0, ans = 0;
    rep(i,S.size()) {
        bool ok = false;
        rep(j,4) {
            if (S[i]==C[j]) ok = true;
        }
        if (ok) cnt++;
        else cnt = 0;
        chmax(ans,cnt);
    }

    cout << ans << ln;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int n;
    vector<int> num(30);
    for(int i = 0; i < 30; i++) {
        num[i] = INF;
    }
    cin >> n;
    while(n--) {
        string s;
        cin >> s;
        vector<int> now(30);
        for(int i = 0; i < s.size(); i++) {
            now[(int)(s[i] - 'a')]++;
        }
        for(int i = 0; i < 30; i++) {
            num[i] = min(num[i], now[i]);
        }
    }
    for(int i = 0; i < 30; i++) {
        for(int j = 0; j < num[i]; j++) {
            cout << (char)('a' + i);
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<set>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;i++)
ll N, A, B;
int main() {
	scanf("%lld%lld%lld", &N,&A,&B);
	printf("%lld", N / (A + B) * A + min(N % (A + B), A));
	return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  if(1 > a || 10000 < a || 1 > b || 10000 < b){
    cout << "error" << endl;
    exit(0);
  }
  if(a * b % 2 == 0)
    cout << "Even" << endl;
  else
    cout << "Odd" << endl;
}

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

#define pb push_back
#define int ll

using ll=long long;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vpii=vector<pii>;
using vvpii=vector<vpii>;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    vi as(n+1);
    vi bs(n+1);
    for (int i=0; i<n+1; ++i)
        cin >> as[i];
    for (int i=0; i<n; ++i)
        cin >> bs[i];
    bs[n] = 0;

    int def = 0;
    int carry = 0;
    for (int i=0; i<n+1; ++i) {
        int last = min(carry, as[i]);
        def += last;
        int here = min(as[i]-last, bs[i]);
        def += here;
        carry = bs[i] - here;
    }
    cout << def << "\n";
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
const int mod=1e9+7;
const int MN=190;
int n,m,a[MN][MN],s[MN][MN],f[MN][MN][MN][15];
char ch[MN][MN];
inline int S(int x,int y,int X,int Y){
	return s[X][Y]-s[X][y-1]-s[x-1][Y]+s[x-1][y-1];
}
int main(){
	scanf("%d%d",&n,&m);
	for(reg int i=1;i<=n;i++){
		scanf("%s",ch[i]+1);
		for(reg int j=1;j<=m;j++){
			a[i][j]=(ch[i][j]=='.');
			s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a[i][j];
		}
	}
	for(reg int i=1;i<=n;i++)
		for(reg int j=1;j<=m;j++)
			for(reg int k=j;k<=m;k++){
				reg int l=i,r=n,mid,res=i-1,tmp;
				while(l<=r){
					mid=(l+r>>1);tmp=S(i,j,mid,k);
					if(!tmp||tmp==(mid-i+1)*(k-j+1))res=mid,l=mid+1;
					else r=mid-1;
				}
				f[i][j][k][0]=res;
			}
	reg int Ans=1;
	for(;f[1][1][m][Ans-1]<n;Ans++)
		for(reg int len=1;len<=m;len++)
			for(reg int i=1;i<=n;i++)
				for(reg int l=1,r=l+len-1;r<=m;l++,r++){
					if(f[i][l][r][Ans-1]==n){
						f[i][l][r][Ans]=n;continue;
					}
					f[i][l][r][Ans]=f[f[i][l][r][Ans-1]+1][l][r][Ans-1];
					if(f[i][l][r][Ans]==n)continue;
					reg int L=l,R=r-1,res=0,mid,x,y;
					while(L<=R){
						mid=(L+R>>1);
						x=f[i][l][mid][Ans-1];
						y=f[i][mid+1][r][Ans-1];
						res=max(res,min(x,y));
						if(x<y)R=mid-1;
						else L=mid+1;
					}
					f[i][l][r][Ans]=max(f[i][l][r][Ans],res);
				}
	printf("%d\n",Ans-1);
	return 0;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long h; cin >> h;
    long long num = 1, cnt = 0;
    while (h > 0) {
        cnt += num; h /= 2; num *= 2;
    }
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 764
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    x = inputInt()
    
    ans = (x // 11) * 2
    if x % 11 > 0:
        ans+=1
    if x % 11 > 6:
        ans+=1
    print(ans)
            
            
if __name__ == "__main__":
	main()


Measured memory_bytes: 39280
#include <bits/stdc++.h>
using namespace std;
#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++)

int main() {
  long long N,D;
  cin>>N>>D;
  long long X[N][D];
  rep(i,N){
    rep(j,D){
      cin>>X[i][j];               
    }
  }
  long long count=0;
  long long kyori=0;
  rep(i,N){
    rep2(j,i+1,N){
      kyori=0;
      rep(k,D){
        kyori+=abs(X[i][k]-X[j][k])*abs(X[i][k]-X[j][k]);
        //cout<<X[i][k]<<" "<<X[j][k]<<endl;
      }
      double d;
      double hantei=modf(sqrt(kyori),&d);
      //cout<<hantei<<endl;
      if(hantei==0)count++;
    }
  }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#define Maxn 200000
char s[Maxn+5],t[Maxn+5];
int n;
int h,w,sx,sy;
int mx(int a,int b){
	return a>b?a:b;
}
int mn(int a,int b){
	return a<b?a:b;
}
int main(){
	scanf("%d%d%d",&h,&w,&n);
	scanf("%d%d",&sx,&sy);
	scanf("%s",t+1);
	scanf("%s",s+1);
	int f=1,e=h;
	for(int i=n;i>0;i--){
		if(s[i]!='L'&&s[i]!='R'){
			if(s[i]=='U'){
				e=mn(e+1,h);
			}
			else{
				f=mx(f-1,1);
			}
		}
		if(t[i]!='L'&&t[i]!='R'){
			if(t[i]=='U'){
				f++;
			}
			else{
				e--;
			}
		}
		if(f>e){
			puts("NO");
			return 0;
		}
	}
	if(sx<f||sx>e){
		puts("NO");
		return 0;
	}
	f=1,e=w;
	for(int i=n;i>0;i--){
		if(s[i]!='U'&&s[i]!='D'){
			if(s[i]=='L'){
				e=mn(e+1,w);
			}
			else{
				f=mx(f-1,1);
			}
		}
		if(t[i]!='U'&&t[i]!='D'){
			if(t[i]=='L'){
				f++;
			}
			else{
				e--;
			}
		}
		if(f>e){
			puts("NO");
			return 0;
		}
	}
	if(sy<f||sy>e){
		puts("NO");
		return 0;
	}
	puts("YES");
	return 0;
}


Measured memory_bytes: 512
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

int solve(vector<int>& s, vector<int>& t){
    vector<vector<int>> dp((int)s.size() + 1, vector<int>((int)t.size() + 1));
    vector<vector<int>> sum((int)s.size() + 1, vector<int>((int)t.size() + 1));
    for(int i = 0; i <= (int)s.size(); i++){
        for(int j = 0; j <= (int)t.size(); j++){
            if(i + 1 <= (int)s.size() && j + 1 <= (int)t.size()){
                if(s[i] == t[j]){
                    dp[i+1][j+1] = sum[i][j] + 1;
                }
                sum[i+1][j+1] = (MOD + sum[i+1][j] + sum[i][j+1] - sum[i][j] + dp[i+1][j+1]) % MOD;
            }
        }
    }

    return (sum[SZ(s)][SZ(t)] + 1) % MOD;
}

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

    int n, m;
    cin >> n >> m;
    vector<int> s(n), t(m);
    rep(i, n) cin >> s[i];
    rep(i, m) cin >> t[i];

    cout << solve(s, t) << endl;

    return 0;
}


Measured memory_bytes: 62976
#include <bits/stdc++.h>
#define taskname "A"

//#define BeztDonkey
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

const int maxN = 51;

int a[maxN], n, Max, Min;
vector<pair<int, int>> ans;

int main()
{
    #ifdef BeztDonkey
    auto start = chrono::steady_clock::now();
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen(taskname".inp", "r", stdin);
    //freopen(taskname".out", "w", stdout);

    cin >> n >> a[Max = Min = 1];
    for (int i = 2; i <= n; ++i)
    {
        cin >> a[i];
        if (a[i] > a[Max]) Max = i;
        if (a[i] < a[Min]) Min = i;
    }
    if (abs(a[Max]) > abs(a[Min]))
    {
        for (int i = 1; i <= n; ++i)
        {
            if (a[i] < 0)
            {
                a[i] += a[Max];
                ans.push_back({Max, i});
            }
        }
        for (int i = 2; i <= n; ++i) ans.push_back({i - 1, i});
    }
    else
    {
        for (int i = n; i >= 1; --i)
        {
            if (a[i] > 0)
            {
                a[i] += a[Min];
                ans.push_back({Min, i});
            }
        }
        for (int i = n - 1; i > 0; --i) ans.push_back({i + 1, i});
    }
    cout << ans.size() << '\n';
    for (auto &t : ans) cout << t.first << ' ' << t.second << '\n';

    #ifdef BeztDonkey
    auto end = chrono::steady_clock::now();
    cerr << "In milliseconds : "
         << chrono::duration_cast<chrono::milliseconds>(end - start).count();
    cerr << '\n' << "In seconds : "
         << chrono::duration_cast<chrono::seconds>(end - start).count() << '\n';
    #endif
    return 0;

}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main(){

    input!{
        a: usize,
        b: usize,
        c: usize,
        k: usize,
    }
    let mut a_tmp = a;
    let mut b_tmp = b;
    let mut c_tmp = c;
    let mut cnt: i64 = k as i64;

    loop {
        if a_tmp >= b_tmp {
            b_tmp = b_tmp*2;
            cnt -= 1;
        } else {
            if cnt<0 {
                println!("No");
                return;
            }
            break;
        }
    }

    loop {
        if b_tmp>=c_tmp {
            c_tmp = c_tmp*2;
            cnt -= 1;
        } else {
            if cnt < 0{
                println!("No");
                return;
            }
            break;
        }
    }

    println!("Yes");

}

Measured memory_bytes: 2164
// Template by [thunder_blade]
// IIIT ALLAHABAD
// includes :)

#include <bits/stdc++.h>
using namespace std;
#define TEST  int test_case; cin>>test_case; while(test_case--)
#define all(v) (v).begin(),(v).end()
#define fi  first
#define se  second
#define pb push_back
#define mp make_pair
#define ll unsigned long long int
#define SPEED ios_base::sync_with_stdio(false);  cin.tie(0);  cout.tie(0);
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define pf(x) printf("%f\n",x)
#define ps(x) printf("%s\n",x)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sf(x) scanf("%f",&x)
#define ss(x) scanf("%s",x)
#define pis(x) cout<<x<<" "//printf("%d ",x)
#define pls(x) printf("%lld ",x)
#define pfs(x) printf("%f ",x)
#define pss(x) printf("%s ",x)
#define FOR(i,a,b) for(i=a;i<b;i++)
#define mod 1000000009
#define tr(container, it)  for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
ll power(ll a, ll n) {
	ll p = 1;
	while (n > 0) {
		if(n&1) {
			p = ((p%mod) * (a%mod))%mod; 
		} 
		n >>= 1; 
		a = ((a%mod)*(a%mod))%mod;
	} 
	return p%mod;
}
ll inf  = 1000;
const long long B = 100000007; 
const long long C = 10010107; 
const int N = 500005;
const int LN = 25;

void arrange(int &a, int &b, int &c)
{
	vector<int>v;
	v.pb(a);
	v.pb(b);
	v.pb(c);
	sort(all(v));
	a = v[0];
	b = v[1];
	c = v[2];
}

int main()
{
	int a, b, c;
	si(a), si(b), si(c);
	arrange(a, b, c);
	int cnt = 0;
	while(a!=c){
		if(a==b && c-1==b){
		    //cout<<a<<" "<<b<<" "<<c<<endl;
			cnt++;
			break;
		}else{
			a+=2;
			cnt++;
		}
		arrange(a, b, c);
	}
	pi(cnt);
}

Measured memory_bytes: 256
N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

seen = [False] * N

def dfs(node, seen, ans):
    seen[node] = True
    #print(node)
    if seen.count(True) == N:
        ans += 1
        seen[node] = False
        return ans

    for todo in edge[node]:
        if not seen[todo]:
            ans = dfs(todo, seen, ans)

    seen[node] = False
    return ans

print(dfs(0, seen, 0))

Measured memory_bytes: 3064
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
long long int dp[3001][3001];
long long int f(long long int arr[],int i,int j)
{
    if(i>j)return 0;
    if(dp[i][j]!=-9999999999)
    return dp[i][j];
    else
    return dp[i][j]= max(arr[j]-f(arr,i,j-1),arr[i]-f(arr,i+1,j));
}

int main() {
	int n,j;
	cin>>n;
	long long int arr[n]={0};
	int i; 
	for(i=0;i<n;i++)
	cin>>arr[i];
	for(i=0;i<n;i++)
	for(j=0;j<n;j++)
	{
	    dp[i][j]=-9999999999;
	}
	long long int x=f(arr,0,n-1);
	cout<<x;
	return 0;
	
}


Measured memory_bytes: 70784
package main

import (
	"fmt"
	"strconv"
)

func isPalindromic(x int) bool {
	s := strconv.Itoa(x)

	j := len(s) - 1
	for i := 0; i < j; i++ {
		if s[i] != s[j] {
			return false
		}
		j--
	}
	return true
}

func main() {
	var A, B int
	fmt.Scan(&A, &B)

	cnt := 0
	for i := range make([]struct{}, B-A+1) {
		if isPalindromic(A + i) {
			cnt++
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    vector<int>a(100000,0);
    int n;cin>>n;
    rep(i,n){
        int tmp;cin>>tmp;a[tmp]+=1;
    }
    int mx=-1;
    rep(i,100000-2){
        mx = max(mx,a[i]+a[i+1]+a[i+2]);
    }
    co(mx);
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define For(i,a,b) for(i=(a);i<=(b);++i)
#define Forward(i,a,b) for(i=(a);i>=(b);--i)
#define Rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define Repe(i,a,b) for(register int i=(a);i>=(b);--i)
#define Chkmax(a,b) a=a>b?a:b
#define Chkmin(a,b) a=a<b?a:b
#define Max(a,b) a>b?a:b
#define Min(a,b) a<b?a:b

using namespace std;
template<typename T>inline void read(T &x)
{
	T s=0,f=1;static char c;
	for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())s=s*10+(c^48);
	x=s*f;
}
const int MAXN=333;

static int n;

static char s[MAXN][MAXN];

inline void get(char &x){for(x=getchar();!islower(x);x=getchar());}

inline void init()
{
	read(n);
	Rep(i,1,n)Rep(j,1,n)get(s[i][j]);
	
}

static int ans;

inline void solve()
{
	Rep(i,0,n)
	{
		static bool flag;flag=true;
		Rep(j,1,n)Rep(k,1,n)if(s[j][(k+i-1)%n+1]!=s[k][(j+i-1)%n+1]){flag=false;break;}
		if(flag)ans+=n-i;
	}
	Rep(i,1,n)
	{
		static bool flag;flag=true;
		Rep(j,1,n)Rep(k,1,n)if(s[(j+i-1)%n+1][k]!=s[(k+i-1)%n+1][j]){flag=false;break;}
		if(flag)ans+=n-i;
	}
	printf("%d\n",ans);
}



int main()
{
	init();
	solve();
	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=(a);i<(n);i++)

int n,a[100010];

int sig(int a,int b) {
	if (a<b) return 1;
	if (a>b) return -1;
	return 0;
}

int main() {
	scanf("%d",&n);
	rep(i,0,n) scanf("%d",&a[i]);
	int l=0,ans=0;
	while (l<n) {
		int st=0;
		int r=l+1;
		while (r<n) {
			int u=sig(a[r-1],a[r]);
			if (st&&u&&st!=u) break;
			if (u) st=u;
			r++;
		}
		l=r;
		ans++;
	}
	printf("%d\n",ans);
}

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  vector<ll> acc = {0};
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    acc.push_back(acc.back()+a);
  }
  ll ans = acc.back();
  for (ll a : acc)
    ans = min(ans, abs(acc.back()-a*2));
  cout << ans << endl;
}


Measured memory_bytes: 2548
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x 2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#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
*/

int main() {
  int n,m,sum=0;
  cin >> n>>m;
  vi a(n);
  rep(i,n){
    cin >> a[i];
    sum += a[i];
  }
  big_sort(a);
  if(a[m-1]*4*m>=sum){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ss second
#define ff first
#define pii pair<int,int> 
#define mp make_pair()
bool   integer(float k){
                  if (k==20000) return false;;
                  if (k==(-20000)) return  false;
 if (k==0)  return true;
   if (k<0)  return integer(k+1);
   else if(k>0)  return integer (k-1);
   return false;
}

int main(){
	 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,d;
  cin>>n>>d;
  float v[n][d];
  for(int i=0;i<n;i++){
  	for(int j=0;j<d;j++){
  		cin>>v[i][j];
  	}
  }
  int ans=0;double x,y;
  for(int i=0;i<n;i++){
  	for(int j=i+1;j<n;j++){
  		x=0.0;
  		for(int k=0;k<d;k++){
  			x+=(v[i][k]-v[j][k])*(v[i][k]-v[j][k]);
  		}
  		y=sqrt(x);
  		if(y-(int)y==0.0) ans++;
  	}
  }
  cout<<ans;
  
}
int mainaa() {
	int n,d;
	cin>>n>>d;
	int a[n][d];
	int i=0,j=0,k=0,c=0;
	float sum=0;
	for(i=0;i<n;i++){
	    for(j=0;j<d;j++){
	        cin>>a[i][j];
	    }
	}
	int ans=0;
    for(i = 0; i < n; i=(i+1)%n ){
        for(j = 0; j <d; j++ ){
            sum = 0;
            sum=sqrt(pow(a[i][j]-a[i+1][j],2) + pow(a[i][j+1]-a[i+1][j+1],2));
            for( k = 0; k < d; k++ ){
               sum += (a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
            }
            
            if(integer(sum)) ans++;
        }
    }
            
            
	
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 0x7fffffff
#define eps 1e-12
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,l,r,d;
int main(){
    int i,j,u,v,f1,f2;
    l=read(),r=read(),d=read();
    cout<<(r/d)-(l-1)/d;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=5e5+9;
int main()
{
    FASTINOUT;
    ll x;
    cin>>x;
    ll m=x/500;
    x%=500;
    cout<<m*1000+x/5*5<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int N;
	int A[101];
	
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin>>A[i];
		
		
	}
	int min = A[0];
	int max = A[0];
	
	for (int i = 1; i < N; i++) {
		if (min > A[i]) {
			min = A[i];
		}
		if (A[i] > max) {
			max = A[i];

		}
	}
	
	cout <<max-min<<endl;
}


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

using namespace std;

map<string, int> memo;

int main() {
    int N;

    cin >> N;

    string S;

    for (int i = 0; i < N; i++) {
        cin >> S;
        
        memo[S] += 1;
    }

    int max_value = 0;

    for (const auto& x : memo) {
        int v = x.second;
        max_value = max(max_value, v);
    }

    for (auto it = memo.begin(); it != memo.end(); it++) {
        if (it->second == max_value) {
            cout << it->first << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 17664
def main():
    n = int(input())
    a = list(map(int, input().split()))
    dp = [[0] * n for _ in range(n)]
    for i in range(n):
        dp[i][i] = a[i]

    for i in range(n - 2, -1, -1):
        for j in range(i + 1, n):
            dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1])
    print(dp[0][n - 1])
main()

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    char c;
    cin >> c;
    if (c >= 'A' && c <= 'Z') {
        cout << "A\n";
    } else {
        cout << "a\n";
    }
    return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int n,m,ans;
int x,y,z;
signed main(){
	
	cin>>x>>y>>z;
	int r;
	r=x;
	x=y;
	y=r;
	r=x;
	x=z;
	z=r;
	cout<<x<<" "<<y<<" "<<z<<endl;
	
	
}

Measured memory_bytes: 256
import math

A, B, H, M = map(int, input().split())

thetaH = 30 * H + 0.5 * M
thetaM = 6 * M

theta = abs(thetaH - thetaM)

if theta >= 180:
    theta = 360 - theta

C2 = A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(theta))

print(math.sqrt(C2))


Measured memory_bytes: 9440
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //e
  int n;
  cin >> n;
  int all = 0;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    all ^= a[i];
  }
  for (int i = 0; i < n; i++) {
    if (i > 0) cout << " ";
    cout << (all ^ a[i]);
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3944
#include <bits/stdc++.h>
#define int long long

using namespace std;

int32_t main()
{
	ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

	string s;
	cin >> s; int ans = 0;
	for(int i = 0 ; i < 3 ; i++){
		int ans2 = 0;
		while(s[i] == 'R'){
			ans2++; i++;
		}
		ans = max(ans, ans2);
	}

	cout << ans;
    

  return 0;
}


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


int main() {

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

    int n;
    cin>>n;
    string s;
    cin>>s;

    int nr = 0;
    int ng = 0;
    int nb = 0; 
    for (int i=0; i<n; i++){
        if(s[i]=='R') nr++;
        else if(s[i]=='G') ng++;
        else if(s[i]=='B') nb++;
    }

    long long int total = 1LL*nr*ng*nb;

    for (int i=0; i<n; i++){
        for (int j=i+1; j<n; j++){
            int k = 2*j-i;
            if (k<n && s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]) total--;
        }
    }
    cout<<total;

}


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

using namespace std;

#define int long long

const int N = 2e5 + 5;
int n, a[N], cnt[N];

main() {
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n;
  for(int i = 1; i <= n; ++i) cin >> a[i], cnt[a[i]]++;
  int tich = 0;
  for(int i = 1; i <= n; ++i) {
    if(cnt[i]) tich += (cnt[i] * (cnt[i] - 1) / 2);
  }
  for(int i = 1; i <= n; ++i) {
    int u = cnt[a[i]];
    if(u == 1) cout << tich << '\n';
    else cout << tich - u * (u - 1) / 2 + (u - 1) * (u - 2) / 2 << '\n';
  }
}


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

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

  int lcost = 0, rcost = 0;
  for(int i = 0; i < m; ++i)
  {
    cin >> a;
    (a < x ? lcost : rcost) += 1;
  }
  cout << min(lcost, rcost);

}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3632
#include"bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
	int N;
	cin >> N;
	for (int i = 1;i <= 46297;++i) {
		if (floor(i * 1.08) == N) {
			cout << i << endl;
			return 0;
		}
	}
	puts(":(");
	return 0;
}

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

using ll = long long;

constexpr int MAX_N = 2000;
int A[MAX_N];

#define USE_MOD
#ifdef USE_MOD
constexpr int MOD = 1e9 + 7;
#endif

template<typename T>
inline T mod(T a) {
#ifdef USE_MOD
  a %= MOD;
#endif
  return a;
}

int main() {
  ll N, K;
  cin >> N >> K;
  K %= MOD;
  for (int i{}; i < N; ++i)
    cin >> A[i];

  ll ans0{};
  for (int i{}; i < N - 1; ++i) {
    for (int j{i + 1}; j < N; ++j) {
      if (A[i] > A[j % N]) {
        ++ans0;
      }
    }
  }
  ans0 %= MOD;

  ll ans1{};
  for (int i{}; i < N; ++i) {
    for (int j{}; j < N; ++j) {
      if (A[i] > A[j]) {
        ++ans1;
      }
    }
  }
  ans1 %= MOD;

  cout << (mod(ans0 * K) + mod(ans1 * mod(K * (K - 1) / 2))) % MOD << endl;
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  char s[n], t[n];
  for(int i=0;i<n;i++) cin >> s[i];
  for(int i=0;i<n;i++) cin >> t[i];
  
  for(int i=0;i<n;i++){
      cout << s[i] << t[i];
  }
  
  
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 

using namespace std;

int main(){

    ll x;
    cin >> x;

    ll ans = x / 11 * 2;

    ll m = x % 11;

    if(1 <= m && m <= 6){
        ans++;
    }else if(7 <= m && m <= 11){
        ans = ans + 2;
    }

    cout << ans << endl;

    return 0;
}

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


int main()
{
	int n;
	cin >> n;
	vector<bool> num(1000000000, false);
	string ans = "YES";
	for (int i = 0; i < n; i++) {
		int a_in;
		cin >> a_in;
		if (num.at(a_in) == false) {
			num.at(a_in) = true;
		} else {
			ans = "NO";
		}		
	}

	cout << ans << endl;
}


Measured memory_bytes: 122368
#include <iostream>
#include<list>
#include<cstring>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define FF first
#define SS second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define PLL pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define LP lower_bound
#define UP upper_bound
#define MP make_pair
#define rep1 for(i=1;i<=n;i++)
#define VLL vector<ll>
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define UMP unordered_map
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll myXOR(unsigned long long int x, unsigned long long int y)
{
    return (x|y)&(~x|~y);
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
int main()
{
    fastio
    ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r, t,u,w,x,y,z;
    string str, ss, str1;
    /*
    **  author : mahiman12
    **  created : 2020-05-06 15:14 
    */
    cin>>n>>k;
    ll arr[n];
    ll dp[n];
    rep(i,0,n)
    {
        cin>>arr[i];
        dp[i] = MAX;
    }
    dp[0]=0;
    rep(i,0,n){
        for(j=i+1;j<i+k+1 && j<n; j++){
            dp[j]= min(dp[j], dp[i]+abs(arr[j]-arr[i]));
        }
        // rep(l,0,n){
        //     cout<<dp[l]<<" ";
        // }
        // cout<<endl;
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
int comp(const void *a,const void *b){
    int c=*(int *)a;
    int d=*(int *)b;
    return c-d;
}
int p[1000000]={0};
int main(void){
    p[0]=p[1]=1;
    for(int i=2;i<=1000;i++){
        if(p[i]==0){
            for(int j=2*i;j<1000000;j+=i)
                p[j]=1;
        }
    }
    while(1){
        int N,P;
        scanf("%d%d",&N,&P);
        if(N+P==-2) break;
        int idx=0; int sosu[200]={0};
        for(int i=N+1;i<1000000;i++){
            if(p[i]==0) sosu[idx++]=i;
            if(idx==2*P) break;
        }
        //rep(i,P) printf("%d ",sosu[i]); puts("");
        int work[100000]={0}; idx=2*P;
        for(int i=0;i<2*P;i++){
            work[i]=2*sosu[i];
        }
        for(int i=0;i<2*P;i++){
            for(int j=i+1;j<2*P;j++){
                work[idx++]=sosu[i]+sosu[j];
            }
        }
        qsort(work,idx,sizeof(int),comp);
        //rep(i,100) printf("%d ",work[i]); puts("");
        printf("%d\n",work[P-1]);
    }
}



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

int main(){
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  
  /*左から*/
  ll cur = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) continue;
    if (a[i] > b[i]) {
      cur += (a[i] - b[i]) * 2;
    } else {
      int d = (b[i] - a[i]) / 2 * 2;
      cur -= d;
    }
  }
  bool ok = (cur <= 0LL);
 
  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
} 

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int a[100], b[100];
int current[100];
bool done[100];
int mn[100];
ll ans;
vector<int> moves;
int seen[100], seen2[100];
int best;
int dp2(int i, int j)
{
	if (seen2[i]) return seen2[i];
	seen2[i] = 100;
	if (i == b[j])
	{
		return 0;
	}
	for (int f = 1; f <= i; f++)
	{
		if (dp2(i%f, j) != 100) return seen2[i] = f;
	}
	return 100;
}
void dp(int i, int j)
{
	if (seen[i]) return;
	seen[i] = 1;
	if (i == b[j])
	{
		mn[j] = -1;
		best = i;
		return;
	}
	int am = dp2(i, j);
	if (am < mn[j])
	{
		mn[j] = am;
		best = i;
	}
	for (auto f : moves)
	{
		dp(i%f, j);
	}
	for (int m = 1; m <= i; m++)
	{
		if (i % m == b[j])
		{
			if (m < mn[j])
			{
				mn[j] = m;
				best = i;
			}
		}
	}
}
int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		current[i] = a[i];
	}
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &b[i]);
	}
	for (int i = 0; i < n; i++)
	{
		if (a[i] == b[i]) continue;
		mn[i] = -1;
		for (int j = 1; j <= 51; j++)
		{
			if (a[i] % j == b[i])
			{
				mn[i] = j;
				break;
			}
		}
		if (mn[i] == -1)
		{
			printf("-1\n");
			return 0;
		}
	}
	while (true)
	{
		bool broken = 0;
		for (int i = 0; i < n; i++)
		{
			if (current[i] != b[i]) broken = 1;
		}
		if (!broken) break;
		pair<int, int> small = { 0, -1};
		for (int i = 0; i < n; i++)
		{
			if (current[i] != b[i]) small = max(small, { mn[i], i});
		}
		best = -1;
		fill_n(seen, 100, 0);
		fill_n(seen2, 100, 0);
	//	printf("%d %d\n", small.first, small.second);
		dp(a[small.second], small.second);
		if (best != -1)
		{
			current[small.second] = best;
			continue;
		}
	//	printf("hi\n");
		ans += (1ll << ((ll)small.first));
		moves.push_back(small.first);

	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 256
H,W = map(int,input().split())
res = 10**100

for (h, w) in [(H, W), (W, H)]:
    for i in range(1, h):
        k, l = [], []
        k.append(w * i)
        k.append(w * ((h - i) // 2))
        k.append(w * ((h - i) - (h - i) // 2))
        l.append(w * i)
        l.append((h - i) * (w // 2))
        l.append((h - i) * (w - w // 2))
        # print(k, l, w, h - i)
        res = min(res, max(k) - min(k))
        res = min(res, max(l) - min(l))

print(res)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using namespace std;

// int gcd(int a, int b){
//     if (a < b){
//         a ^= b;
//         b ^= a;
//         a ^= b;
//     }
//     return b ? gcd(b, a % b) : a;
// }

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

int main(){
    long long n,x=10,ans=0;
    cin >> n;
    if(n%2 == 0){
        while(n/x>0){
            ans += n/x;
            x *= 5;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
S = int(input())

L = [0] * (S + 10)
L[3] = 1
e = 10 ** 9 + 7

for i in range(4, S + 1):
    L[i] += 1
    for j in range(3, i):
        if i - j <= 0:
            break
        L[i] += L[i - j]
        L[i] = L[i] % e

print(L[S])

Measured memory_bytes: 64980
//666yuchen
#include<bits/stdc++.h>
using namespace std;
string st;
char b[500];
int main()
{
  cin>>st;
  b['b']='d';b['d']='b';b['p']='q';b['q']='p';
  for(int i=0;i<st.size();i++)if(b[st[i]]!=st[st.size()-1-i]){cout<<"No"<<endl;return 0;}
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 512