akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <array>
using namespace std;
typedef long long ll;
#define tr(container, it) \
	for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c,x) ((c).find(x) != (c).end())   //O(log n) 
#define contains(c,x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define Ichar(_x) char _x;scanf("%c",&_x);
#define Iint(_x) int _x;scanf("%d",&_x); 
#define Ill(_x)  ll _x;scanf("%lld",&_x);
#define inc(a,b,x)(x)>a && (x)<b	
#define incE(a,b,x)(x)>=a && (x)<=b	
//freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

int main()
{
	Iint(n);
	string s, t;
	std::cin >> s >>t;
	int mx = 0;
	for (int i = n; i >= 0; --i)
	{
		if(t.substr(0,i)==s.substr(n-i,i))
		{
			mx = i;
			break;
		}
	}
	std::cout << 2*n-mx;

	



}











Measured memory_bytes: 256
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn main() {
    let (a, b): (usize, usize);
    input!(a, b);
    if a * b % 2 == 0 {
        println!("Even");
    } else {
        println!("Odd");
    }
}


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

int main(){
  int N, K;
  cin >> N >> K;
  vector<long long> A(N+1);
  for(int i = 0; i < N; ++i) cin >> A[i+1];
  for(int i = 1; i <= N; ++i) A[i] += A[i-1];
  vector<long long> S;
  vector<int> idx;
  for(int i = 1; i <= N; ++i){
    for(int j = i; j <= N; ++j){
      idx.push_back(S.size());
      S.push_back(A[j]-A[i-1]);
    }
  }
  long long t = 1;
  while(2*t <= A[N]) t *= 2;
  long long ans = 0;
  while(t > 0){
    vector<int> idx_;
    for(int i = 0; i < idx.size(); ++i){
      if(S[idx[i]]&t) idx_.push_back(idx[i]);
    }
    if(idx_.size() >= K){
      ans |= t;
      idx = idx_;
    }
    t /= 2;
  }
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;

int main()
{

    string S;
    cin >> S;
    bool n, w, s, e;
    n = false;
    w = false;
    s = false;
    e = false;
    for (int i = 0; i < S.size(); ++i)
    {
        switch (S[i])
        {
        case 'N':
            n = true;
            break;
        case 'W':
            w = true;
            break;
        case 'S':
            s = true;
            break;
        case 'E':
            e = true;
            break;

        default:
            break;
        }
    }
    if ((n != s) || (w != e))
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }

    return 0;
}


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

void move(int,int);
int ma[1001][101]={};

int main(){
  int n,m,a,p,q,maxh,h;
  while(1){
    maxh=0;
  cin>>n>>m>>a;
  if(n+m+a==0) break;
  for(int i=0;i<m;i++){
    cin>>h>>p>>q;
    ma[h][p]=q;
    ma[h][q]=p;
    if(maxh<h) maxh=h;
  }
  move(a,maxh);
  for(int i=0;i<1002;i++)for(int j=0;j<102;j++) ma[i][j]=0;
  }
  return 0;
}

void move(int x,int i){
  if(i==0) cout<<x<<endl;
  if(ma[i][x]==0 && i>0) move(x,i-1);
  if(ma[i][x]>0) move(ma[i][x],i-1);
  
}

      

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

	int a,b;
	cin >> a>>b;

	int a1 = a + a-1;
	int a2 = a + b;
	int a3 = b + b-1;

	cout << max({a1,a2,a3}) << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	int A,a=0,b=0;
	cin>>A;
	if(A==5)a++;
	if(A==7)b++;
	cin>>A;
	if(A==5)a++;
	if(A==7)b++;
	cin>>A;
	if(A==5)a++;
	if(A==7)b++;
	if(a==2&&b==1)cout<<"YES";
	else cout<<"NO";
}

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

using namespace std;




int main(){
    
    string S;
    cin >> S;
    
    int N = S.length();
    
    int rr = 0;
    int ll = 0;
    
    int ra = -1;
    int la = -1;
    
    vector<int> ans;
    
    for (int i = 0; i < N; i++) {
        
        if (S[i] == 'R' && ll == 0) {
            rr += 1;
            ans.push_back(0);
            
        }else if (ll == 0 && rr != 0 && S[i] == 'L') {
          
            ll += 1;
            ra = i - 1;
            la = i;
            
            ans.push_back(10);
            
            
        }else if(rr != 0 && ll != 0){
            if (S[i] == 'L') {
                ll += 1;
                ans.push_back(0);
                
            }else{
                ll -= 1;
                rr -= 1;
                
                if ((rr + ll)%2 == 0) {
                    ans[ra] = (rr+ll)/2+1;
                    ans[la] = (rr+ll)/2+1;
                }else{
                    
                    if (rr % 2 == 0) {
                        ans[ra] = (rr+ll-1)/2 + 1 +1;
                        ans[la] = (rr+ll-1)/2 +1;
                        
                    }else {
                        ans[la] = (rr+ll-1)/2 + 1+1;
                        ans[ra] = (rr+ll-1)/2+1;
                        
                    }
                    
                    
                    
                }
                
                
                
                
                ans.push_back(0);
                rr = 1;
                ll = 0;
            }
        }
        
        if (i == N-1) {
            ll -= 1;
            rr -= 1;
            
            if ((rr + ll)%2 == 0) {
                ans[ra] = (rr+ll)/2+1;
                ans[la] = (rr+ll)/2+1;
            }else{
                
                if (rr % 2 == 0) {
                    ans[ra] = (rr+ll-1)/2 + 1 +1;
                    ans[la] = (rr+ll-1)/2 +1;
                    
                }else {
                    ans[la] = (rr+ll-1)/2 + 1+1;
                    ans[ra] = (rr+ll-1)/2+1;
                    
                }
                
                
                
            }
            
            
            
            
            
            
        }
        
        
    }
    
    
    for (int i = 0; i < N; i++) {
        cout << ans[i];
        if (i < N-1) {
            cout << " ";
        }else{
            cout << endl;
        }
    }
    
    
    return 0;
    
}


Measured memory_bytes: 1144
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a[1000];
    int n,i;
    scanf("%d",&n);
    for(i=0; i<n; i++){
        scanf("%d",&a[i]);
    }
    for(i=n; i>0;i--){
        printf("%d",a[i-1]);
        if(i != 1){
            printf(" ");
        }
        
    }
    printf("\n");
    return 0;
}

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

using namespace std;

int main(){
        string str[101];
        int H, W;
        cin>>H>>W;
        int cnt[30]={0};
        for(int i=0;i<H;i++){
                cin>>str[i];
                for(int j=0;j<W;j++){
                        cnt[str[i][j]-'a']++;
                }
        }
        int g1, g2, g4;
        if(H%2!=0&&W%2!=0){
                g1=1;g2=H/2+W/2;g4=(H/2)*(W/2);
        }
        else if(H%2!=0){
                g1=0;g2=W/2;g4=(W/2)*(H/2);
        }
        else if(W%2!=0){
                g1=0;g2=H/2;g4=(H/2)*(W/2);
        }
        else{
                g1=0;g2=0;g4=(H/2)*(W/2);
        }
        for(int i=0;i<26;i++){
                if(cnt[i]%2!=0){
                        g1--;
                        cnt[i]--;
                }
                while(cnt[i]>=4&&g4>0){
                        g4--;
                        cnt[i]-=4;
                }
                while(cnt[i]>=2&&g2>0){
                        g2--;
                        cnt[i]-=2;
                }
        }
        if(g1==0&&g2==0&&g4==0){
                cout<<"Yes"<<endl;
        }
        else{
                cout<<"No"<<endl;
        }
        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define repr(i,x,y) for(int i=x;i>=y;i--) 
#define mod 1000000007
using namespace std;

void Onigiri()
{
  int x,y;
  cin>>x>>y;
  if(y>=x)cout<<"unsafe";
  else cout<<"safe";
}
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(NULL);
   #ifdef Zoro
   freopen("in", "r", stdin);freopen("out", "w", stdout);
   #endif  
 
   int t=1; 
   //cin>>t;
 
   while(t--)
   {Onigiri();cout<<"\n";}

   cerr<<"\n"<<(float)clock()/CLOCKS_PER_SEC*1000<<" ms"<<endl;
   return 0;
}

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

typedef long long ll;

#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define AA(i) cout << i << endl;
#define AS(i) cout << i << " ";

const int INF = 1001001001;

const double PI = 3.14159;

using namespace std;

vector<ll> memo(1000007, INF);

int main() {

    int a;
    for(int i = 1; i<=5; i++) {
        cin >> a;
        if (a==0) {
            AA(i);
            return 0;
        }
    }
}

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

int main() {
    ll x;
    cin >> x;

    ll ans = 0;

    ans += (x / 11) * 2;
    x = x % 11;
    
    if(x == 0) {
      
    }
    else if (x <= 6) {
        ans += 1;
    }
    else {
        ans += 2;
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

/**
 * AC(一応)
 * 実行速度遅い
 */
int main()
{
    int N; cin >> N;
    map<string, int> map;
    rep (i, 0, N) {
        string in; cin >> in;
        ++map[in];
    }

    int max_v = 0;
    vector<pair<string, int>> vec;
    vec.reserve(map.size());
    for (auto &mp : map) {
        vec.emplace_back(mp.first, mp.second);
        max_v = max(max_v, mp.second);
    }

    sort(vec.begin(), vec.end(), [&vec](pair<string, int> &p1, pair<string, int> &p2) {
        if (p1.second != p2.second) return p1.second > p2.second;
        else return p1.first < p2.first;
    });

    for (auto &v : vec) {
        if (v.second == max_v) {
            cout << v.first << endl;
        }
    }
}

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


int main(){
    int c[3][3]={{0}};
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++)
            cin >> c[i][j];
    }
    
    int a[3]={0}, b[3]={0};
    bool F=false;
    while(!F){
        for(int i=0; i<3; i++){
            b[i] = c[0][i] - a[0];
        }
        for(int i=0; i<3; i++){
            a[i] = c[i][0] - b[0];
        }
        bool f=true;
        for(int i=0; i<3; i++){
            for(int j=0; j<3; j++){
                if(c[i][j]!=a[i]+b[j]){
                    f=false;
                }
            }
        }
        if(f) F=true;
        a[0]++;
        if(a[0]>100) break;
    }
    cout << (F?"Yes":"No") << endl;
}


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


int main(){
    ld a, b, x;
    cin >> a >> b >> x ;
    
    ld ans = 0;

    if(x <= a * a * b / 2){
        ans = 90 - atan(2 * x/ (b * b *a)) * 180 /PI;
    }
    else{
        ans = atan((2 * b - 2 * x / (a * a)) / a) * 180 /PI ; 
    }
    cout << setprecision(16) << ans << endl;
}

/**
 * 断面が直角三角形(x <= a * a * b / 2)を満たす
 * 
 * x = b * b * tan(90 - ans) * a / 2 
 * 
 * 90 - ans = atan(2 * x/ (b * b *a))
 * 
 * ans = 90 - atan(2 * x/ (b * b *a))
 * 
 * 
 * 断面が台形(x > a * a * b / 2)
 * 
 * 
 * x = ((b  - a * tan(ans)) + b) * a * a / 2 
 * 
 * 
 * 
 * 2 * b - a * tan(ans) = 2 * x / (a * a)
 * 
 * (2 * b - 2 * x / (a * a)) = a * tan(ans)
 * 
 * ans = atan((2 * b - 2 * x / (a * a)) / a)
 * 
 * 
 * 
 **/

Measured memory_bytes: 3848
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
using namespace std;
//#define int long long
int n,m;
vector<vector<int>>g(1e5+4);
vector<int>u(1e5+4);
void dfs(int v, int prev){
    u[v]=prev;
    int color = 1;
    for(auto to:g[v]){
        if(!u[to]){
            if(color==prev)
                color++;
            dfs(to,color);
            color++;
        }
    }
    //cout<<"\n";
}
int32_t main() {
    cin >> n;
    vector<int>e;
    for(int i = 0; i < n-1;i++){
        int t,t1;
        cin >> t >> t1;
        t--;t1--;
        g[t].push_back(t1);
        e.push_back(t1);
    }
    dfs(0,0);
    int ans = 0;
    vector<int>ans1;
    for(int i = 0; i < n;++i){
        ans=max(ans,u[i]);
        if(u[i]!=0)
            ans1.push_back(u[i]);
    }
    cout << ans << "\n";
    for(int x=0;x<n-1;x++)
        cout << u[e[x]] << "\n";
    return 0;
}

Measured memory_bytes: 8188
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

ll a[100000];
ll aa[100000];
ll sum[100000]; //a[i]までの和
int main()
{
	int n;
	ll ans=0;
	ll ans2=0;
	
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		aa[i]=a[i];
	}
	
	//a[0]を+にする場合
	//初期化
	if(aa[0]<=0)
	{
		ans+=abs(1-aa[0]);
		aa[0]=1;
	}
	sum[0]=aa[0];
	for(int i=1;i<n;i++)
	{
		//sum[i]を-にする場合
		if(i%2==1)
		{
			if(aa[i]+sum[i-1]>=0)
			{
				ll temp=abs(-1-aa[i]-sum[i-1]);
				ans+=temp;
				aa[i]-=temp;
			}
		}else{
			//sum[i]を+にする場合
			if(aa[i]+sum[i-1]<=0)
			{
				ll temp=abs(1-aa[i]-sum[i-1]);
				ans+=temp;
				aa[i]+=temp;
			}
		}
		sum[i]=sum[i-1]+aa[i];
	}
	//ここまで
	//a[0]を-にする場合
	//初期化
	for(int i=0;i<n;i++)
		aa[i]=a[i];
	if(aa[0]>=0)
	{
		ans2+=abs(-1-aa[0]);
		aa[0]=-1;
	}
	sum[0]=aa[0];
	for(int i=1;i<n;i++)
	{
		//sum[i]を-にする場合
		if(i%2==0)
		{
			if(aa[i]+sum[i-1]>=0)
			{
				ll temp=abs(-1-aa[i]-sum[i-1]);
				ans2+=temp;
				aa[i]-=temp;
			}
		}else{
			//sum[i]を+にする場合
			if(aa[i]+sum[i-1]<=0)
			{
				ll temp=abs(1-aa[i]-sum[i-1]);
				ans2+=temp;
				aa[i]+=temp;
			}
		}
		sum[i]=sum[i-1]+aa[i];
	}
	cout<<min(ans,ans2)<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int X; cin >> X;
  int ans = 0;
  cout << (X/500)*1000 + ((X%500)/5)*5 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define MOD 1e9+7;

using namespace std;

int main(){
    ll N,A,B;
    cin>>N>>A>>B;
    ll count=0;
    count=((N/(A+B)))*A;
    count+=(min(N%(A+B),A));
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 256
bingo = [input().split() for i in range(3)]
card = [[0, 0, 0] for i in range(3)]
n = int(input())
for i in range(n):
    num = str(input())
    for rowNum in range(3):
        for colNum in range(3):
            if bingo[rowNum][colNum] == num:
                card[rowNum][colNum] = 1

#holizonal
for i in range(3):
    s = 0
    for item in card[i]:
        s += int(item)
    if s == 3:
        print('Yes')
        exit()

#vertical
for colNum in range(3):
    s = 0
    for rowNum in range(3):
        s += int(card[rowNum][colNum])
    if s == 3:
        print('Yes')
        exit()
        
#diagonal
if int(card[0][0]) + int(card[1][1]) + int(card[2][2]) == 3:
    print('Yes')
    exit()
elif int(card[0][2]) + int(card[1][1]) + int(card[2][0]) == 3:
    print('Yes')
    exit()

print('No')

Measured memory_bytes: 3064
#define y1 askjdkasldjlkasd
#include <bits/stdc++.h>
#undef y1

using namespace std;

#define pb push_back
#define mp make_pair
#define fi(a, b) for(int i=a; i<=b; i++)
#define fj(a, b) for(int j=a; j<=b; j++)
#define fo(a, b) for(int o=a; o<=b; o++)
#define fdi(a, b) for(int i=a; i>=b; i--)
#define fdj(a, b) for(int j=a; j>=b; j--)
#define fdo(a, b) for(int o=a; o>=b; o--)
#define sz(x) (int)x.size()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<ll> vll;

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while (0)
#endif

double START_TIME;

void exit() {
#ifdef LOCAL	
	cerr << "TIME: " << setprecision(5) << fixed << (clock() - START_TIME) / CLOCKS_PER_SEC << endl;
#endif	
	exit(0);
}

template<typename A, typename B>
ostream& operator<<(ostream& os, pair<A, B> p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}

template<typename T>
ostream& operator<<(ostream& os, vector<T> v) {
	fi(0, sz(v) - 1) {
		os << v[i] << " ";
	}
	return os;
}

template<typename T>
ostream& operator<<(ostream& os, set<T> t) {
	for (auto z : t) {
		os << z << " ";
	}
	return os;
}

template<typename T1, typename T2>
ostream& operator<<(ostream& os, map<T1, T2> t) {
	cerr << endl;
	for (auto z : t) {
		os << "\t" << z.first << " -> " << z.second << endl;
	}
	return os;
}

#ifdef LOCAL
#define dbg(x) {cerr << __LINE__ << "\t" << #x << ": " << x << endl;}
#define dbg0(x, n) {cerr << __LINE__ << "\t" << #x << ": "; for (int ABC = 0; ABC < n; ABC++) cerr << x[ABC] << ' '; cerr << endl;}
#else
#define dbg(x) while(0){}
#define dbg0(x, n) while(0){}
#endif

#ifdef LOCAL
#define ass(x) if (!(x)) { cerr << __LINE__ << "\tassertion failed: " << #x << endl, abort(); }
#else
#define ass(x) assert(x)
#endif

///////////////////////////////////////////////////

const int MAX = 2e3 + 41;
const int MOD = 1e9 + 7;
const int INVTWO = (MOD + 1) / 2;

int add(int a, int b) {
	a += b;
	if (a >= MOD) a -= MOD;
	return a;
}

int sub(int a, int b) {
	a -= b;
	if (a < 0) a += MOD;
	return a;
}

int mul(int a, int b) {
	return (ll) a * b % MOD;
}

int n, k;
int ans;
int a[MAX];

void solve () {
	int q = mul(k - 1, k);
	q = mul(q, INVTWO);	
	fi(0, n - 1) {
		int l = 0;
		fj(i + 1, n - 1) {
			if (a[j] < a[i]) l++;
		}		
		int l1 = 0;
		fj(0, n - 1) {
			if (a[j] < a[i]) l1++;
		}
		int v1 = mul(q, l1);
		int v2 = mul(l, k);
		int v = add(v1, v2);
		ans = add(ans, v);
	}
	printf("%d\n", ans);
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	START_TIME = (double)clock();
#endif
	
	scanf("%d %d", &n, &k);
	fi(0, n - 1) {
		scanf("%d", &a[i]);
		a[i]--;
	}
	solve();

	exit();
	return 0;
}





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

class Program
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());

		var ok = true;
		var time = 0;
		var x = 0;
		var y = 0;
		for (var i = 0; i < n; ++i) {
			var t = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => int.Parse(number));
			var currentTime = t[0] - time;
			var def = Math.Abs(t[1] - x) + Math.Abs(t[2] - y);
			if (def > currentTime) {
				ok = false;
			} else if (def < currentTime) {
				if ((currentTime - def) % 2 == 1) {
					ok = false;
				}
			}

			time = t[0];
			x = t[1];
			y = t[2];
		}

		if (ok) {
			Console.WriteLine("Yes");
		} else {
			Console.WriteLine("No");
		}

		//デバッグ実行での確認用。そのまま提出しても問題なし
		Console.ReadKey();
	}
}


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

int main(){
  int n, i, j = 0;
  string s, t;
  vector<char> ans(n*2);
  
  cin >> n;
  cin >> s >> t;
  
  for(i = 0; i < n*2; i+=2){
    ans.at(i) = s.at(j);
    ans.at(i+1) = t.at(j);
    j++;
  }
  
  for(i = 0; i < n*2; i++){
    cout << ans.at(i);
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int int64_t
using namespace std;
int w[101];
int val[101];
int dp[100001][101];

int solve(int ind,int wt){
	int &ans = dp[wt][ind];
	if(ind == 0 or wt == 0) return 0;

	if(ans != -1) return ans;
	if(wt >= w[ind-1])
		ans = max(val[ind-1] + solve(ind-1,wt - w[ind-1]),solve(ind-1,wt));	
	else
		ans = solve(ind-1,wt);
		
	return ans;
	
}
signed main(){
	int n,W;
	cin>>n>>W;
	for(int i=0;i<=W;i++) for(int j=0;j<=n;j++) dp[i][j] = -1;
	for(int i=0;i<n;i++){
		cin>>w[i]>>val[i];
	}

	
	
	cout<<solve(n,W)<<"\n";
//	for(int i=0; i<n+1; i++) for(int j=0;j< W+1;j++) cout<<dp[i][j]<<"\n";
	
}

Measured memory_bytes: 82340
#include <stdio.h>
#include <iostream>
#include <set>
#include <vector>
using namespace std;

int main() {

  vector<int> primeVec;
  set<int> primeSet;
  primeSet.insert(2);

  for (int i = 3; i <= 10000; i++) {
    int isPrime = 1;
    for(auto itr = primeSet.begin(); itr != primeSet.end(); ++itr) {
      if (i % *itr == 0) { // 割り切れた
          isPrime = 0;
          break;
      }
    }

    if (isPrime == 1) { // 素数発見
      primeSet.insert(i);
    }
  }

  int n;
  cin >> n;

  int counter = 0;

  for (int i = 0; i < n; i++) {
    int someNum;
    cin >> someNum;
    if (primeSet.count(someNum) > 0) {
      counter += 1;
      continue;
    }

    int isPrime = 1;
    for(auto itr = primeSet.begin(); itr != primeSet.end(); ++itr) {
      if (someNum % *itr == 0) { // 割り切れた
          isPrime = 0;
          break;
      }
    }

    if (isPrime == 1) { // 素数発見
      counter += 1;
      continue;
    }
  }

  cout << counter << endl;

}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    sort(A.begin(), A.end());
    REP(i, N-1) {
        if(A[i] == A[i+1]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    
    int N,A,B,now=0,c_b = 0;
    string S;
    cin >> N >> A >> B >> S;
    
    int len = S.size();
    for(int i=0;i<len;i++){
        
        if(S.at(i) == 'a'){
            if(now < A + B){
                now++;
                cout << "Yes" << endl;
            }
            else{
                cout << "No" <<endl;
            }
        }
        else if(S.at(i) == 'b'){
            c_b++;
            if(now < A + B && c_b <= B){
                now++;
                cout << "Yes" << endl;
            }
            else{
                cout << "No" <<endl;
            }
        }
        else{
            cout << "No" <<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3736
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int search(string str)
{
	int i;
	int num = 0;

	for (i = 0; i < str.size(); i++)
	{
		if (str[i] == '-')
		{
			num++;
		}
	}
	return num;
}

int main(void){
	int a, b;
	cin >> a >> b;
	string str;
	cin >> str;
	if (search(str) != 1)
	{
		cout << "No" << endl;
		return 0;
	}
	else{
		if(str[a] == '-' && str.size() == a + b + 1){
			cout << "Yes" << endl;
			return 0;
		}
		else{
			cout << "No" << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct Node{
  int k;
  struct Node *right;
  struct Node *left;
  struct Node *parent;
};

struct Node *root, *NIL;

void Insert(int);
void Inorder(struct Node *);
void Preorder(struct Node *);
struct Node * Find(struct Node *, int);

int main(){
  int str1 = 0, str2 = 0, str3 = 0;
  int i,n,value,findnum;
  char C1[10], C2[10]="insert", C3[10]="print",C4[10]="find";

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    scanf("%s",C1);

    if(strcmp(C1,C2) == 0) str1 = 1;
    if(strcmp(C1,C3) == 0) str2 = 1;
    if(strcmp(C1,C4) == 0) str3 = 1;

    if(str1 == 1){
      scanf("%d",&value);
      Insert(value);
      str1 = 0;
    }
    else if(str2 == 1){
      str2 = 0;
      Inorder(root);
      printf("\n");
      Preorder(root);
      printf("\n");
    }
    else if(str3 == 1){
      str3 = 0;
      scanf("%d",&findnum);
      struct Node *F = Find(root,findnum);
      if(F != NIL) printf("yes\n");
      else printf("no\n");
    }
  }

    return 0;
}

void Insert(int n){
struct  Node *p = root;
struct  Node *q = NIL;
struct  Node *r;

 r = (struct Node *)malloc(sizeof(struct Node));
 r -> k = n;
 r -> left = NIL;
 r -> right = NIL;

 while(p != NIL){
   q = p;
   if(r->k < p->k){
     p = p -> left;
   }
   else{
     p = p -> right;
   }
 }

 r -> parent = q;
  if(q == NIL){
    root = r;
  }
  else{
    if(r->k < q->k){
      q -> left = r;
    }
    else{
      q -> right = r;
    }
  }
}

void Inorder(struct Node *x){
  if(x == NIL) return;
  Inorder(x -> left);
  printf(" %d",x -> k);
  Inorder(x -> right);
}

void Preorder(struct Node *x){
  if(x == NIL) return;
  printf(" %d",x -> k);
  Preorder(x -> left);
  Preorder(x -> right);
}

struct Node * Find(struct Node *x, int n){
  while(x != NIL && n != x -> k){
    if(n < x -> k ) x = x -> left;
    else x = x -> right;
  }
  return x;
}



Measured memory_bytes: 20448
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2") 
#pragma GCC optimization ("unroll-loops")

using namespace std;
using ll = long long;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ff first
#define ss second
#define Ceil(x, y) ((x+y-1)/y)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x);
const int mod = (int) 1000000007;
int n, m;
vector<set<int>> G(2e5+10);
vector<bool> vis(2e5+10);

void dfs(int u, int &cnt)
{
    if(vis[u])
        return;
    cnt++;
    vis[u] = true;
    for(auto v : G[u])
        dfs(v, cnt);
}

void solve()
{
    cin>>n>>m;
    for(int i=0; i<m; i++)
    {
        int e1, e2;
        cin>>e1>>e2;
        G[e1].insert(e2);
        G[e2].insert(e1);
    }
    int ans = 0;
    for(int i=1; i<=n; i++)
    {
        if(not vis[i])
        {
            int cnt = 0;
            dfs(i, cnt);
            ans = max(ans, cnt);
        }
    }
    cout<<ans;
}
 

int main(int argc, char *argv[])
{
    clock_t clk_start = clock();
    fast;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
 
    int cases = 1;
    // cin>>cases;
    for(int i=1; i<=cases; i++)
    {
        // cout<<"Case #"<<i<<": ";
        solve();
    }
    cerr<<"Execution Time: "<<fixed<<double(clock() - clk_start)/double(CLOCKS_PER_SEC)<<setprecision(6)<<" sec\n"; 
}

Measured memory_bytes: 37476
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

int main() {
  int n, t; cin >> n >> t;
  vector<int> c(n), tt(n);
  REP(i, n){
    cin >> c[i] >> tt[i];
  }

  int ans = numeric_limits<int>::max();
  REP(i, n){
    if(tt[i] <= t) ans = min(ans, c[i]);
  }

  if(ans == numeric_limits<int>::max()){
    cout << "TLE" << endl;
  } else {
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		int[] n = new int[9];
		String[] c = new String[9];
		int[][] num = new int[3][9];
		for (int l = 0; l < T; l++) {
			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < 9; j++) {
					num[i][j] = 0;
				}
			}
			for (int i = 0; i < 9; i++) {
				n[i] = sc.nextInt();
			}
			for (int i = 0; i < 9; i++) {
				c[i] = sc.next();
			}
			for (int i = 0; i < 9; i++) {
				switch (c[i].charAt(0)) {
				case 'R':
					num[0][n[i] - 1]++;
					break;
				case 'G':
					num[1][n[i] - 1]++;
					break;
				case 'B':
					num[2][n[i] - 1]++;
					break;
				}
			}
			int count = 0;
			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < 9; j++) {
					if (num[i][j] >= 3) {
						num[i][j] -= 3;
						count++;
					}
					while (j < 7 && num[i][j] > 0 && num[i][j + 1] > 0 && num[i][j + 2] > 0) {
						num[i][j]--;
						num[i][j + 1]--;
						num[i][j + 2]--;
						count++;
					}
				}
			}
			if (count == 3)
				System.out.println(1);
			else
				System.out.println(0);
		}
	}
}

Measured memory_bytes: 28908
#include<stdio.h>
#include<string.h>
#include<math.h>
long a[100001];
long b[100001];
long c;
long n;
long count = 0;
long maxa=0;
long jmaxa = 0;
long maxb = 0;
long jmaxb = 0;
long ia;
long ib;
long na;
long nb;
int main() {
	scanf("%ld", &n);
	for (long i = 0; i < n; i++) {
		scanf("%ld",&c);
		if (i % 2 == 1) {
			a[c]++;
		}
		else {
			b[c]++;
		}
	}
	for (long i = 0; i <= 100000; i++) {
		if (a[i] > maxa) {
			jmaxa = maxa;
			maxa = a[i];
			ia = i;
		}
		else if (a[i] > jmaxa) {
			jmaxa = a[i];
		}
	}
	for (long i = 0; i <= 100000; i++) {
		if (b[i] > maxb) {
			jmaxb = maxb;
			maxb = b[i];
			ib = i;
		}
		else if (b[i] > jmaxb) {
			jmaxb = b[i];
		}
	}
	if (n % 2 == 1) {
		na = n / 2;
		nb = n / 2 + 1;
	}
	else {
		na = n / 2;
		nb = n / 2;
	}
	if (ia == ib) {
		if (maxa > maxb) {
			printf("%ld", na - maxa + nb - jmaxb);
		}
		else if (maxb > maxa) {
			printf("%ld", nb - maxb + na - jmaxa);
		}
		else {
			if (jmaxa > jmaxb) {
				printf("%ld", nb - maxb + na - jmaxa);
			}
			else {
				printf("%ld", na - maxa + nb - jmaxb);
			}
		}
	}
	else {
		printf("%ld", na - maxa + nb - maxb);
	}
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
using ll = long long;

int main() {
    int N, A, B, C, D;
    string S;
    cin >> N >> A >> B >> C >> D;
    cin >> S;
    int flag = 0;
    for (int i = A; i < max(C, D) - 1; ++i) {
        if(S[i] == '#' && S[i+1] == '#') flag = 1;
    }
    if(C > D){
        flag = 1;
        for (int i = B - 2; i <= D - 2; ++i) {
            if(S[i] == '.' && S[i+1] == '.' && S[i+2] == '.') flag = 0;
        }
    }
    if(flag){
        cout << "No";
    }else{
        cout << "Yes";
    }
    return 0;
}

Measured memory_bytes: 640
import Control.Applicative

swap :: [Int] -> Int -> [Int]
swap xs i = (take (i - 1) xs) ++ [xs !! i, xs !! (i - 1)] ++ (drop (i + 1) xs)

bubble :: Int -> [[Int]] -> [[Int]]
bubble n xss = foldl (\yss i -> let ys = head yss in if (ys !! i) < (ys !! (i - 1)) then swap ys i : yss else yss) xss [n - 1, n - 2 .. 1]

solve :: Int -> [Int] -> [[Int]]
solve n xs = loop [xs]
    where
        loop xss = let yss = bubble n xss in if length xss == length yss then xss else loop yss


main :: IO ()
main = do
    n  <- readLn
    xs <- map read <$> words <$> getLine
    let ls = solve n xs
    putStrLn $ unwords $ map show $ head ls
    print $ length ls - 1

Measured memory_bytes: 8660
#include <stdio.h>

#define SIZE 32

int main(int argc, char **argv)
{
    char s[SIZE];
    scanf("%s", s);

    int num[SIZE] = {};
    for (int i = 0; s[i] != '\0'; ++i) {
        num[s[i]-'a']++;
    }
    for (int i = 0; i < SIZE; ++i) {
        if (num[i] > 1) {
            puts("no");
            return 0;
        }
    }
    puts("yes");
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> pipii;
typedef long long ll;
typedef pair<ll,ll> pll;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e9;
const ll MOD=1e9+7;
struct edge{
    int to;
    int cost;
};

int main(){
    int N;cin>>N;
    vector<int> A(N);
    for(int i=0;i<N;++i) cin>>A[i];
    ll ans=0;
    int right=0;
    ll sum=0;
    for(int left=0;left<N;++left){
        while(right<N&&(sum^A[right])==sum+A[right]){
            sum+=A[right];
            right++;
        }
        ans+=right-left;
        if(right==left) right++;
        else sum-=A[left];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4036
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/





int N, A[201010];
//---------------------------------------------------------------------------------------------------
int check(int nc) {
    vector<pair<int, int>> str;
    str.push_back({ A[0], 0 });

    rep(i, 1, N) {
        if (A[i - 1] < A[i]) {
            str.push_back({ A[i] - A[i - 1], 0 });
            continue;
        }

        if (A[i - 1] > A[i]) {
            int len = A[i - 1], lst = -1;
            while (A[i] < len) {
                auto bot = str.back();
                str.pop_back();

                len -= bot.first;
                lst = bot.second;
            }
            if (len < A[i]) str.push_back({ A[i] - len, lst });
        }

        int len = A[i];
        while (!str.empty()) {
            auto bot = str.back();
            str.pop_back();
            len -= bot.first;
            if (bot.second + 1 < nc) {
                if (1 < bot.first) str.push_back({ bot.first - 1, bot.second });
                str.push_back({ 1, bot.second + 1 });
                len += bot.first;
                break;
            }
        }
        
        if (str.empty()) return 0;
        if (len < A[i]) str.push_back({ A[i] - len, 0 });
    }

    return 1;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];

    int ng = 0, ok = inf;
    while (ng + 1 != ok) {
        int md = (ng + ok) / 2;
        if (check(md)) ok = md;
        else ng = md;
    }
    cout << ok << endl;
}

Measured memory_bytes: 4724
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int N; cin >> N;
    long long A[N]; for (int i = 0; i < N; ++i) cin >> A[i];
    sort(A, A+N);
    cout << (A[N-1] - A[0]) << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<char>>A(H, vector<char>(W));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> A.at(i).at(j);
		}
	}
	vector<vector<int>>DP(H, vector<int>(W));
	if (A.at(0).at(0) == '#') DP.at(0).at(0) = 1;
	else DP.at(0).at(0) = 0;
	for (int i = 1; i < H; i++)
	{
		if (A.at(i - 1).at(0) != A.at(i).at(0) && A.at(i).at(0) == '#') {
			DP.at(i).at(0) = DP.at(i - 1).at(0) + 1;
		}
		else {
			DP.at(i).at(0) = DP.at(i - 1).at(0);
		}
	}
	for (int i = 1; i < W; i++) {
		if (A.at(0).at(i - 1) != A.at(0).at(i) && A.at(0).at(i) == '#') {
			DP.at(0).at(i) = DP.at(0).at(i - 1) + 1;
		}
		else {
			DP.at(0).at(i) = DP.at(0).at(i - 1);
		}
	}
	for (int i = 1; i < H; i++){
		for (int j = 1; j < W; j++) {
			if (A.at(i).at(j) == '#') {
				if (A.at(i).at(j - 1) != A.at(i).at(j)) {
					if (A.at(i - 1).at(j) != A.at(i).at(j)) {
						DP.at(i).at(j) = min(DP.at(i - 1).at(j), DP.at(i).at(j - 1)) + 1;
					}
					else DP.at(i).at(j) = min(DP.at(i - 1).at(j) - 1, DP.at(i).at(j - 1)) + 1;
				}
				else {
					if (A.at(i - 1).at(j) != A.at(i).at(j)) {
						DP.at(i).at(j) = min(DP.at(i - 1).at(j), DP.at(i).at(j - 1) - 1) + 1;
					}
					else DP.at(i).at(j) = min(DP.at(i - 1).at(j), DP.at(i).at(j - 1));
				}
			}
			else {
				DP.at(i).at(j) = min(DP.at(i - 1).at(j), DP.at(i).at(j - 1));
			}
		}
	}
	cout << DP.at(H - 1).at(W - 1) << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int N,M;
    cin >>N>>M;
    int K[N],A[N][M];
    int ansv = 0;
    int ans = 0;
    for(int i = 0; i < N;i++){
        cin >>K[i];
        for(int j = 0; j < K[i]; j++){
            cin >> A[i][j];
        }
    }

    for(int i = 0; i < K[0]; i++){
        ansv = 0;

        for(int j = 0; j < N;j++){
            for(int k = 0; k < K[j]; k++){
                if(A[0][i] == A[j][k]){
                    ansv++;
                }
            }

        }
        if(ansv == N){
            ans++;
        }

    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};

void solve(string O, string E) {
  string res(O.size() + E.size(), '.');
  REP(i,O.size()) res[i * 2] = O[i];
  REP(i,E.size()) res[i * 2 + 1] = E[i];
  cout << res << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	string O;
	string E;
	cin >> O;
	cin >> E;
	solve(O, E);
	return 0;
}


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

#define ll long long
#define ii pair<int,int>
#define INF 1e9 + 7
#define vi vector<ll>
#define add emplace_back


int main(){ios_base::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<double> dp(n+1);
    
    double head;
    dp[0] = 1;
    for(int coin=0; coin<n; ++coin){
        cin >> head;
        for(int i=coin+1; i>=0; --i){
            dp[i] = (i == 0 ? 0 : dp[i-1]*head) + dp[i]*(1-head);
        }
    }
    
    double ans = 0;
    for(int i=n/2+1; i<=n; ++i) ans += dp[i];

    cout << setprecision(11) << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using p = pair<int,int>;
int n;
int dfs(string s){
	if(stoll(s)>n) return 0;
	
	long long ans = 0;
  	if(s.find('7') != string::npos   && s.find('5')  != string::npos  && s.find('3')  != string::npos ){
		ans =1;
	}
  
	for(auto i : string("753")){
		ans += dfs(s+i);
	}

	return ans;
}
int main(){
  cin >> n;
  cout << dfs("0");
}


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

int main()
{

        char A, B;
        cin >> A >> B;

        if (B > A) {
                cout << "<" << endl;
        }
        else if (B == A) {
                cout << "=" << endl;
        }
        else {
                cout << ">" << endl;
        }



}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int d,contest_num=26;
vector<int> c(contest_num);
vector<vector<int>> s;

void input(){
    cin>>d;
    s.resize(d);
    rep(i,d)s[i].resize(contest_num);
    rep(i,26)cin>>c[i];
    rep(i,d)rep(j,contest_num)cin>>s[i][j];
}

void output(vector<int> &ans){
    rep(i,d)cout<<ans[i]<<endl;
}

vector<int> calc_score(vector<int> &a){
    vector<int> last(26,0);
    vector<int> score(d);
    int res=0;
    rep(day,d){
        int current_contest = a[day];
        last[current_contest] = day+1;
        
        res+=s[day][current_contest];
        rep(i,contest_num){
            res -= c[i] * (day+1-last[i]);
        }
        score[day] = res;
    }
    return score;
}

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

    vector<int> tmp = calc_score(v);

    rep(i,d)cout<<tmp[i]<<endl;
	return 0;
}

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

typedef long long ll;

int main(){
  ll n;
  cin >> n;
  
  vector<ll> v(3*n);
  for( ll i = 0; i < 3 * n; i++ )
    cin >> v[i];
  
  sort(v.begin(), v.end());
  
  ll ans = 0;
  for ( auto itr = v.begin() + n; itr != v.end(); itr += 2 ) ans += *itr;
    
  cout << ans << endl;
}

Measured memory_bytes: 2688
A,B = map(int,input().split())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
lis = list(factorization(A))
counter = 0
for i in range(len(lis)):
  jud = B/lis[i][0]
  if jud.is_integer():
    counter += 1
if A == 1 or B == 1:
  print(1)
else:
  print(counter+1)

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; ++i) {
    cin >> a.at(i);
  }
  int mx = *max_element(a.begin(), a.end());
  int mn = *min_element(a.begin(), a.end());
  cout << mx - mn << endl;
}


Measured memory_bytes: 256