akhauriyash/Code-Regression huggingface dataset:
INF = 10**9
H, W = gets.chomp.split.map(&:to_i)
d = 10.times.map{gets.split.map(&:to_i)}
10.times do |k|
  10.times do |i|
    10.times do |j|
      d[i][j] = [d[i][j], d[i][k] + d[k][j]].min
    end
  end
end
ans = 0
H.times do
  gets.split.map(&:to_i).each do |x|
    next if x == -1
    ans += d[x][1]
  end
end
puts ans

Measured memory_bytes: 14428
#include <iostream>
#include <vector> 
#include <cmath>
#include <algorithm>
#include <set>
#include <string>
#include <map>
#include <cerrno>
#include <stdio.h>
#include <stdlib.h>
#include <cfenv>
#include <stack>
#include <math.h>
#include <iomanip>
#include <limits>
#include <queue>
#define ll long long int
#define pb push_back
#define mp make_pair

using namespace std;

int D,G;
vector<pair<int,int> > p;
vector<ll> ans;

/*int zen(){
    for(int i=0;i<(1<<D);i++){
        
    }
}*/

int main(){

    cin >> D >> G;

    int p1,c;

    p = vector<pair<int,int> >(D);

    for(int i=0;i<D;i++){
        cin >> p1 >> c;
        p[i] = make_pair(p1,c);
    }
    
    int sum,cnt,keep;

    for(int i=0;i<(1<<D);i++){
        sum = cnt = 0;
        for(int j=0;j<D;j++){
            if(i&(1<<j)){
                sum += p[j].second;
                sum += p[j].first * 100 * (j+1);
                cnt += p[j].first;
            }
            else{
                keep = j+1;
            }
        }
        if(sum >= G){
            ans.pb(cnt);
        }
        else{
            int tmp = 0;
            int flag = 0;
            while(sum < G){
                if(tmp>=p[keep-1].first){
                    flag = 1;
                    break;
                }
                sum += 100 * keep;
                cnt++;
                tmp++;
            }
            if(flag == 0)ans.pb(cnt);
        }
    }

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

    cout << ans[0] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<numeric>
#include<cstdlib>
#include <iostream>
#define ll long long int
#define all(x) x.begin(),x.end()

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define v vector<long long int> 
#define vv vector< int> 
#define gcd(m,n) __gcd(m,n)
#define vp vector<pair<long long int ,long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define iter vector<int>::iterator
#define pa pair<long long int ,long long int> 
#define f(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,n) for (ll i=a ; i<n ;i+=1)
#define fe(d,e) for(auto d:e)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll,ll>
# define N 100005LL
# define cout1(x) cout<<x<<"\n";
# define  deb(x) cout<<#x<<" "<<x<<"\n";
#define  vii vector<pa>;
using namespace std;

v visited(N);
vector<ll> ans={-1};
v level(N);
v ind(N);
ll sz[N];




// void dfs(ll node, ll par){
    
//     visited[node]=1;
//     if (node==1)level[1]=0;
//     else level[node] = level[par]+1;
//     ans.pb(node);
//     for(auto x:graph[node]){
//         if (!visited[x]){
//             dfs(x,node);
//             sz[node]+=sz[x];

//         }
       
//     }
//      ++sz[node];
    
// }
// map<ll,ll> cnt;
// ll answer(ll ans,ll x){
//     cout<<ans<<" "<<x<<endl;
//     if (cnt[ans%x]==0)return ans;
//     else if (cnt[ans%x==1] && ans>x)return ans;
//     else{
//         cnt[ans%x]-=1;
//         cnt[ans]+=1;
//         answer(ans+1,x);
//     }



// }

int main(){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll ans=1;
    loop(i,1,n){
        if (s[i]!=s[i-1])ans+=1;
    }
    cout1(ans);
}
  
    
    

        


Measured memory_bytes: 5844
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>//////////////////////////////////////////
#define deb(...)/////////////////////////////////////////////////
#define DBP(...)/////////////////////////////////////////////////
#ifdef LOC///////////////////////////////////////////////////////
#include"debuglib.h"/////////////////////////////////////////////
#endif///////////////////////////////////////////////////////////
#define x first//////////////////////////////////////////////////
#define y second/////////////////////////////////////////////////
#define pb push_back/////////////////////////////////////////////
#define sz(x)int((x).size())/////////////////////////////////////
#define each(a,x)for(auto&a:(x))/////////////////////////////////
#define all(x)(x).begin(),(x).end()//////////////////////////////
#define rep(i,b,e)for(int i=(b);i<(e);i++)///////////////////////
using namespace std;using ll=long long;using Pii=pair<int,int>;//
using Vi=vector<int>;void run();int main(){cin.sync_with_stdio///
(0);cin.tie(0);cout<<fixed<<setprecision(18);run();return 0;}////
//-------------------------------------------------------------//

constexpr ll MOD = 1e9+7;

struct Zp {
	ll x;
	Zp(ll a = 0) {
		if (a < 0) a = a%MOD + MOD;
		else if (a >= MOD*2) a %= MOD;
		else if (a >= MOD) a -= MOD;
		x = a;
	}
	Zp operator+(Zp r) const{ return x+r.x; }
	Zp operator-(Zp r) const{ return x-r.x+MOD; }
	Zp operator*(Zp r) const{ return x*r.x; }
	Zp operator/(Zp r) const{return x*r.inv().x;}
	Zp operator-()     const{ return MOD-x; }
	Zp inv() const { return pow(MOD-2); }
	Zp pow(ll e) const {
		Zp t = 1, m = *this;
		while (e) {
			if (e & 1) t = t*m;
			e >>= 1; m = m*m;
		}
		return t;
	}
	#define OP(c) Zp& operator c##=(Zp r){ return *this=*this c r; }
	OP(+)OP(-)OP(*)OP(/)
	void print() { cerr << x; }
};

void run() {
	int n, a, b, c; cin >> n >> a >> b >> c;
	Zp ans = 0;

	vector<Zp> fact(n*2+5);
	fact[0] = 1;
	rep(i, 1, sz(fact)) fact[i] = fact[i-1] * i;
	auto choose = [&](int x, int y) { return fact[x] / (fact[y] * fact[x-y]); };

	Zp fa = Zp(a) / (a+b);
	Zp fb = Zp(b) / (a+b);
	Zp ifc = Zp(100) / (100-c);

	rep(k, n, n*2) {
		Zp tmp = fa.pow(n) * fb.pow(k-n);
		tmp += fb.pow(n) * fa.pow(k-n);
		tmp *= choose(k-1, n-1);
		ans += tmp*ifc*k;
	}

	cout << ans.x << '\n';
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

/*** MOD CALCULATION ***/

const int MOD = 1e9+7;
const int MAX = 1'000'005;

ll addM(ll a, ll b){
	return ((a % MOD) + (b % MOD)) % MOD;
}

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

ll powM(ll a, ll b){
	if(b == 0) return 1;
  	else if(b == 1) return a % MOD;
  	else if(b%2==0) return mulM(powM(a, b/2), powM(a, b/2));
  	else return mulM(a, mulM(powM(a, (b-1)/2), powM(a, (b-1)/2)));
}

// b^{-1} = b^{p-2} (mod p)
// a/b = a*b^{p-2} (mod p)
ll divM(ll a, ll b){ 
  	return mulM(a, powM(b, MOD-2));
}

// n!, (n!)^{-1} のテーブル作成
ll fac[MAX], finv[MAX], inv[MAX];
void COMBinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    rep3(i,2,MAX-1){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

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

/*** MOD CALCULATION ここまで ***/

void Main(){
    int n, m, k; cin >> n >> m >> k;
    COMBinit();
    
    ll t1 = mulM(m, m);
    ll t2 = mulM(mulM(n-1, n), n+1);
    ll tmp1 = divM(mulM(t1, t2), 6);

    t1 = mulM(n, n);
    t2 = mulM(mulM(m-1, m), m+1);
    ll tmp2 = divM(mulM(t1, t2), 6);
    
    // cout << tmp1 << " " << tmp2 << endl;
    // cout << COMB(n*m-2, k-2) << endl;
    ll ans = mulM(addM(tmp1, tmp2), COMB(n*m-2, k-2));
    cout << ans << endl;
    return;
}

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

Measured memory_bytes: 27076
use std::io::stdin;
use std::str::FromStr;

fn main(){
    let n: usize = get_one();
    let xs: Vec<i64> = get_vec();
    let mut mx = 0;
    let mut ans = 0;
    for i in 0..n {
        if mx <= xs[i] { ans+=1 };
        mx = std::cmp::max(mx, xs[i]);
    }
    println!("{}", ans);
}

#[allow(dead_code)]
fn get_line() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn get_vec<T: std::str::FromStr>() -> Vec<T> {
    let line = get_line();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn get_one<T: FromStr + Copy>() -> T {
    let v = get_vec();
    v[0]
}

#[allow(dead_code)]
fn get_pair<T: FromStr + Copy>() -> (T, T) {
    let v = get_vec();
    (v[0], v[1])
}

#[allow(dead_code)]
fn get_triple<T: FromStr + Copy>() -> (T, T, T) {
    let v = get_vec();
    (v[0], v[1], v[2])
}

#[allow(dead_code)]
fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}

#[allow(dead_code)]
fn vec_min(xs: &Vec<i64>) -> i64 {
    xs.iter().map(|&x|x).fold(std::i64::MAX, std::cmp::min)
}

#[allow(dead_code)]
fn vec_max(xs: &Vec<i64>) -> i64 {
    xs.iter().map(|&x|x).fold(std::i64::MIN, std::cmp::max)
}

#[allow(dead_code)]
fn vec_sum(xs: &Vec<i64>) -> i64 {
    xs.iter().fold(0, |acc, &x| acc+x)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define   ll long long int
#define maxn 200005








int main(){

int n;
cin>>n;
vector<int> a(n),b(n);
for(int i=0;i<n;i++)
    cin>>a[i];
for(int i=0;i<n;i++)
    cin>>b[i];
reverse(b.begin(),b.end());
int el=-1;
for(int i=0;i<n;i++){
    if(a[i]==b[i]){
        el=a[i];
    }
}
if(el==-1){
    cout<<"Yes"<<endl;
    for(auto x: b)
        cout<<x<<" ";
    cout<<endl;
    return 0;
}
queue<int> q1;
queue<int> q2;
for(int i=0;i<n;i++){
    if(a[i]==el && b[i]==el)
        q2.push(i);
    if(a[i]!=el && b[i]!=el){
        q1.push(i);
    }
}
if(q2.size()>q1.size()){
    cout<<"No"<<endl;
    return 0;
}
cout<<"Yes"<<endl;
while(!q2.empty()){
    int i1=q2.front();
    q2.pop();
    int i2=q1.front();
    q1.pop();
    swap(b[i1],b[i2]);
}
for(auto x: b)cout<<x<<" ";

cout<<endl;



}


Measured memory_bytes: 5556
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h,w,k;
  cin >> h >> w >> k;
  vector<string> c(h);
  REP(i,h) cin >> c[i];
  int ans = 0;
  for(int bit=0; bit<(1<<(h+w)); bit++){
    vector<int> row, col;
    REP(i,h){
      if(bit & (1<<i)) row.push_back(i);
    }
    REP(j,w){
      if(bit & (1<<(j+h))) col.push_back(j);
    }
    int cnt = 0;
    for(auto r: row){
      for(auto l: col){
        if(c[r][l]=='#') cnt++;
      }
    }
    if(cnt==k) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T lcm(T x,T y){
    return x*y/GCD(x,y);
}
int main(){
    int n; cin >> n; 
    long long a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int q; cin >> q;
    for(int i = 0; i < q; i++){
        int b,e,k; cin >> b >> e >> k;
        int cnt = 0;
        for(int j = b; j < e; j++){
            if (a[j] == k) cnt++;
        }
        cout << cnt << endl;
    }
}
  




Measured memory_bytes: 3116
import sys

htable = [0] * 16777216


def to_int(s):
    if s == 'A':
        return 1
    elif s == 'C':
        return 2
    elif s == 'G':
        return 3
    else:
        return 4


def to_hash(string):
    h = 0
    for i, s in enumerate(string):
        ints = to_int(s)
        h += 4**i * ints

    return h


def insert(string):
    h = to_hash(string)
    htable[h] = 1


def find(string):
    h = to_hash(string)
    if htable[h]:
        print('yes')
    else:
        print('no')


if __name__ == '__main__':

    n = int(input())

    for line in sys.stdin:
        cmd, string = line.strip().split()

        if cmd == 'insert':
            insert(string)

        else:
            find(string)



Measured memory_bytes: 137140
n=int(input())
arr=list(map(int,input().split()))
brr=list(map(int,input().split()))[::-1]
start=end=-1
for i in range(n):
    if arr[i]==brr[i]:
        
        if start==-1:
            start=end=i
        else:
            end=i
if start==-1:


    print('Yes')
    print(*brr)
else:

    i=0
    while i<n and start<=end:
        if brr[i]!=arr[end] and arr[i]!=arr[end]:
            brr[i],brr[start]=brr[start],brr[i]
            start+=1
        i+=1
    if start>end:
        print('Yes')
        print(*brr)
    else:
        print('No')
  

Measured memory_bytes: 105708
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
#define RET(ans) {cout<<ans<<endl;return 0;} 

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s; cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s; cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    int a[5];
    int ans = 0;
    int x = 0;
    rep(i,5){
        cin >> a[i];
        if(a[i]%10>0){
            x = max(x,10-a[i]%10);
            a[i] += 10-a[i]%10;
        }
        ans += a[i];
    }

    ans -= x;
    
    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 256
def main():
  n = int(input())
  a = list(map(int, input().split()))
  a.append(-1)
  num_kabu = 0
  money = 1000
  for i in range(0, n):
    if a[i+1] >= a[i]:
      num_kabu += money//a[i]
      money %= a[i]
    if a[i+1] <a[i]:
      money += num_kabu*a[i]
      num_kabu = 0
  print(money)
  
if __name__ =="__main__":
  main()

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}

int main(){
    string S; cin >> S;
    string res = "";

    sort(all(S));

    REP(i, S.size() - 1) {
        if(S[i] == S[i + 1]) {
            res = "no";
            break;
        }

        if(i == S.size() - 2) {
            res = "yes";
        }
    }

    cout << res << endl;
}

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

public class Main {
static int gcd(int a,int b) {
	if(a%b==0) return b;
	else return gcd(b,a%b);
}
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[] l = new int[n];
		for(int i=0;i<n;i++) {
			l[i]=sc.nextInt();
		}
		int ans = 0;
		for(int i=0;i<n;i++) {
			if(i==0) ans= gcd(l[0],l[1]);
			else ans=gcd(ans,l[i]);
		}
System.out.println(ans);
	}
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);
  
  int n;
  string s;
  cin >> n >> s;
  if (n%2 == 1) {
    cout << "No" << endl;
    return 0;
  }
  rep(i, n/2) {
    if (s[i] != s[n/2+i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

#define    ll     long long int

int main( )
{
    int n, m, k, l, i;
    cin >> n >> m >> k;
    for (i = 0; i < k && i + n <= m; i++) {
        cout << i + n << '\n';
        l = (i + n);
    }
    for (i = k; i > 0; i--) {
        if (m - i + 1 > l) {
            cout << m - i + 1 << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 256
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const s = stdin

const ans = _ => {
  const s01 = s[0] + s[1]
  const s02 = s[2] + s[3]
  const numF = Number(s01)
  const numB = Number(s02)

  let f = '' 
  let b = ''
  if(numF > 12){
    f = 'YY'
  } else if(numF === 0) {
    f = 'YY'
  } else {
    f = 'MM'
  }

  if(numB > 12){
    b = 'YY'
  } else if(numB === 0) {
    b = 'YY'
  } else {
    b = 'MM'
  }

  if(b === f){
    return b === 'MM' ? 'AMBIGUOUS' : 'NA'
  } else {
    return f+b
  }
}

console.log(ans())


Measured memory_bytes: 7372
/*input

*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}


int main(){
	IOS;
	ll a,b,c;
	cin>>a>>b>>c;
	ll tmp=min(a,c);
	a-=tmp;
	c-=tmp;
	tmp=min(b,c);
	b-=tmp;
	c-=tmp;
	cout<<a<<' '<<b;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int a, ans = 0, mini = 100000;

    for (int i=0; i<5; i++){
        cin >> a;
        ans += ((a+9)/10) * 10;
        mini = min(mini, (a-1)%10);
    }

    cout << ans-9+mini << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int k, a, b;
    cin >> k >> a >> b;
    bool ok = false;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            ok = true;
            break;
        }
    }
    if (!ok) {
        cout << "NG" << endl;
    } else {
        cout << "OK" << endl;
    }

    return 0;
}

Measured memory_bytes: 3128
#include <stdio.h>

int main(){
  for(;;){
    int H,W,x,y;
    scanf("%d %d",&H,&W);
    if(H==0 && W==0){
      return 0;
    }
    for(y=0;y<H;y++){
      for(x=0;x<W;x++){
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
}

Measured memory_bytes: 1656
from collections import Counter

def Comb(n,k):
    comb_ans=1
    for i in range(1,k+1):
        comb_ans*=(n-i+1)/i
    comb_ans=int(comb_ans)
    return comb_ans

N=int(input())
A=list(map(int,input().split()))
C=Counter()
C.update(A)
ans=0
L=[0]*N
for i in range(N):
    L[A[i]-1]+=1
Most=C.most_common()
for i in range(len(C)):
    ans+=Comb(Most[i][1],2)
for i in range(N):
    pri=ans
    pri=ans-Comb(L[A[i]-1],2)+Comb(L[A[i]-1]-1,2)
    print(pri)


Measured memory_bytes: 103276
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)n; i++)
#define REPR(i, n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define FORR(i, m, n) for(int i=(int)m-1; i>=(int)n; i--)
#define ASC(v) sort(v.begin(), v.end());
#define DESC(v) sort(v.begin(), v.end(), greater<int>());
#define REVERSE(v) reverse(v.begin(), v.end());
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
typedef long long ll;
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main() {
	string S;
	cin >> S;
	ll res = S.size();

	REP(i, res) cout << "x";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main(){
    int n; cin>>n;
    vector<vector<int>> v(n,vector<int>(n,0));
    rep(i,0,n){
        int u,k;
        cin>>u>>k;
        rep(j,0,k){
            int x;
            cin>>x;
            v[u-1][x-1]=1;
        }
    }
    
    rep(i,0,n){
        rep(j,0,n){
            if(j)cout<<" ";
            cout<<v[i][j];
        }
        cout<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 3152
#include<bits/stdc++.h>
#define IL inline
#define _ 400005
#define ll long long
using namespace std ;

IL int gi(){
    int data = 0 , m = 1; char ch = 0;
    while(ch!='-' && (ch<'0'||ch>'9')) ch = getchar();
    if(ch == '-'){m = 0 ; ch = getchar() ; }
    while(ch >= '0' && ch <= '9'){data = (data<<1) + (data<<3) + (ch^48) ; ch = getchar(); }
    return (m) ? data : -data ; 
}

int n , m , N , A[305][305] , pw[100005] , ID[305] ;
#define mod 998244353

int main() {
	n = gi() ; m = gi() ;
	for(int i = 1; i <= n; i ++) for(int j = 1; j <= m; j ++) A[i][j] = gi() ;
	N = n * m ;
	pw[0] = 1 ; for(int j = 1; j <= N; j ++) pw[j] = 2ll * pw[j - 1] % mod ;
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= m; j ++) {
			if(A[i][j]) {
				if(!ID[j]) {ID[j] = i ; break ; }
				else for(int k = 1; k <= m; k ++) A[i][k] = A[i][k] ^ A[ID[j]][k] ;
			}
		}
	int _cnt = 0 ;
	for(int j = 1; j <= m; j ++) if(ID[j] != 0) ++ _cnt ;
	cout << 1ll * pw[m - 1] * (pw[n] - pw[n - _cnt] + mod) % mod << endl ;
	return 0 ;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF (ll)1e18
#define INF (int)1e9
#define ll_1e9 (ll)1e9
using namespace std;

int main(){
  ll n,cnt = 0;
  cin >> n;
  ll memo = 0,a = 0;
  rep(i,0,n){
    cin >> a;
    cnt += (a+memo)/2;
    memo = (a+memo) % 2;
    if(memo && !a % 2) memo = 0;
  }

  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a,b,c,temp;
    scanf("%d %d %d",&a,&b,&c);
    
    while(1){
        if(a<=b){
            temp = a;
            a = b;
            b = temp;
        }
        if(b<=c){
            temp = b;
            b = c;
            c = temp;
        }
        if(c<=a){
            temp = c;
            c = a;
            a = temp;
        }
        if(a<=b && b<=c)
        break;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}

Measured memory_bytes: 596
#include<iostream>
using namespace std;
int main()
{
	int n, m, x, up = 0, down = 0;
	cin >> n >> m >> x;
	int a[m];
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < m; i++) {
		if (a[i] < x) {
			down++;
		}
		else {
			up++;
		}
	}
	cout << (up < down ? up : down);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<bitset>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)   
typedef long long ll;
const ll mod = 1e9+7;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6+5;
const ll N = 1e3+5;
const double pi = acos(-1.0);
const double eps=1e-9;
using namespace std;

ll a[maxn];
int main(){
    // in;
    // out;
    ll n,m;
    cin>>n>>m;
    for(ll i=0;i<=n;i++){
        a[i]=i;
    }
    ll sum=0;
    for(ll i=m;i<=n+1;i++){
        ll minn=(i-1)*i/2;
        ll maxx=(n)*(n+1)/2;
        ll hh=(n-i)*(n-i+1)/2;
        if(n-i+1<0) hh=0;
        maxx-=hh;
        // cout<<minn<<" "<<maxx<<endl;
        // cout<<maxx-minn+1<<endl;
        sum+=maxx-minn+1;
        sum%=mod;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 5140
#include<algorithm>
#include<complex>
#include<cstdio>
#include<iostream>
#include<queue>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
template<class T> T at(vector<T> v, int i) {return v[i % v.size()];}

#define X real()
#define Y imag()

typedef double D;
typedef complex<D> P;
struct L{P a, b;};
typedef vector<P> Pol;

const D EPS = 1e-8;

// テヲツッツ氾ィツシツεゥツ鳴「テヲツ閉ー
int sig(D a, D b = 0) {return a < b - EPS ? -1 : a > b + EPS ? 1 : 0;}
bool near(P a, P b) {return !sig(norm(a - b));}
namespace std {
  bool operator<(P a, P b) {return sig(a.X, b.X) ? a.X < b.X : a.Y < b.Y;}
}

// テ・ツ、ツ姪ァツゥツ?
D det(P a, P b) {return a.X * b.Y - a.Y * b.X;}

// テァツキツ堙・ツ按?」ツ?ョテ」ツδ凖」ツつッテ」ツδ暗」ツδォ
P vec(L a) {return a.b - a.a;}

// テァツキツ堙・ツ按?bテ」ツ?ォテ・ツッツセテ」ツ?凖」ツつ凝ァツつケcテ」ツ?ョテ、ツスツ催ァツスツョ
enum CCW{FRONT = 1, RIGHT = 2, BACK = 4, LEFT = 8, ON = 16};
int ccw(P a, P b, P c) {
  if (near(a, c) || near(b, c)) return ON;
  int s = sig(det(b - a, c - a));
  if (s) return s > 0 ? LEFT : RIGHT;
  return (a < b) == (b < c) ? FRONT : (c < a) == (a < b) ? BACK : ON;
}

// テ、ツコツ、テ・ツキツョテ・ツ按、テ・ツョツ?
bool iLLs(L a, L b) {return sig(det(vec(a), vec(b)));}
bool iLS(L a, L b) {return sig(det(vec(a), b.a - a.a)) * sig(det(vec(a), b.b - a.a)) <= 0;}
bool iSSs(L a, L b) {
  int cwa = ccw(a.a, a.b, b.a) | ccw(a.a, a.b, b.b);
  int cwb = ccw(b.a, b.b, a.a) | ccw(b.a, b.b, a.b);
  return (cwa & cwb) == (LEFT | RIGHT);
}

// テ、ツコツ、テァツつケ
P pLL(L a, L b) {return a.a + vec(a) * (det(vec(b), b.a - a.a) / det(vec(b), vec(a)));}

// テ・ツ、ツ堙ィツァツ津・ツスツ「テ」ツ?ョテ・ツ??・ツ、ツ姪・ツ按、テ・ツョツ?テ・ツ??ゥツδィ:1テ」ツ??・ツ堕ィテ、ツクツ?0テ」ツ??・ツ、ツ姪ゥツδィ:-1
int sGP(Pol pol, P p) {
  int side = -1;
  rep (i, pol.size()) {
    P p0 = pol[i] - p, p1 = at(pol, i + 1) - p;
    if (ccw(p0, p1, 0) == ON) return 0;
    if (p0.Y > p1.Y) swap(p0, p1);
    if (sig(p0.Y) <= 0 && 0 < sig(p1.Y) && sig(det(p0, p1)) > 0) side *= -1;
  }
  return side;
}

int main() {
  for (int iii = 1; ; ++iii) {
    int n;
    cin >> n;
    if (n == 0) break;
    Pol pol(n);
    rep (i, n) cin >> pol[i].X >> pol[i].Y;
    D res = 0;
    rep (i, n) rep (j, i) {
      L l = (L){pol[i], pol[j]};
      vector<P> vp;
      vp.push_back(pol[i]);
      vp.push_back(pol[j]);
      int pre = 0;
      rep (k, n) {
	L s = (L){pol[k], at(pol, k + 1)};
	if (iLS(l, s) && iLLs(l, s)) {
	  if (iSSs(l, s)) goto next;
	  vp.push_back(pLL(l, s));
	}
      }
      sort(vp.begin(), vp.end());
      vp.erase(unique(vp.begin(), vp.end(), near), vp.end());
      rep (i, vp.size() - 1) {
	if (sGP(pol, (vp[i] + at(vp, i + 1)) / (D)2) < 0) {
	  res = max(res, abs(vp[pre] - vp[i]));
	  pre = i + 1;
	}
      }
      res = max(res, abs(vp[pre] - vp.back()));
    next:;
    }
    printf("Case %d: %.12f\n", iii, res);
  }
  return 0;
}

Measured memory_bytes: 1280
#include<iostream>

using namespace std;

void solve2() {
	int N, K;
	cin >> N >> K;
	long long ans = 0;
	ans = K;
	for (int i = 0; i < N-1; i++)
	{
		ans *= K - 1;
	}
	cout << ans << endl;
}

void solve1() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b &&b== c) {
		cout << 1 << endl;

	}
	else if (a == b || b == c || a == c) {
		cout << 2 << endl;
	}
	else
		cout << 3 << endl;
}

int main() {
	solve2();
	return 0;
}

Measured memory_bytes: 256
S = gets.chomp.chars.map(&:to_i)

count = 0
pre = nil
S.each do |s|
  if pre == nil
    pre = s
    next
  else
    if pre == s
      count += 1
      pre = s == 0 ? 1 : 0
    else
      pre = s
    end
  end
end

puts count

Measured memory_bytes: 7676
import java.util.Scanner;

public class Main {
	public static void main(String[] args){



		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int k = sc.nextInt();

		if(n==k) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}


	}

}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/


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

void print( vector<int> v )
{
    int n = v.size();
    for( int i = 0; i < n - 1; i++ )
    {
        cout << v[i] << " ";
    }
    cout << v[n-1] << endl;
}

int main()
{
    int n;
    vector<int> v;

    cin >> n;

    for( int i = 1; i <= n; i++ )
    {
        v.push_back(i);
    }

    bool tf = true;
    while( tf )
    {
        print(v);
        if( next_permutation( v.begin(), v.end() ) == true );
        else
            tf = false;
    }
    return 0;
}


Measured memory_bytes: 3144
S = input()
K = int(input())

S += "1"
l = len(S)
pair = []
current = S[0]
seq = 1
for i in range(1, l):
    if(i == l):
        pair.append(seq)
    elif(S[i] == current):
        seq += 1
    else:
        pair.append(seq)
        seq = 1
        current = S[i]

ans = 0
#print(pair)
if(len(pair) == 1):
    ans += (K * pair[0])//2
elif(S[0] != S[l-2]):
    for i in range(len(pair)):
        ans += K * (pair[i]//2)
else:
    for i in range(1, len(pair)-1):
        ans += K * (pair[i]//2)
    ans += (pair[0]//2) + (pair[i+1]//2) + ((pair[0]+pair[i+1])//2)*(K-1)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n;
  cin >> n;
  loop(i, n, 1000) {
    string s;
    s = to_string(i);
    bool f = true;
    rep(j, s.size() - 1) {
      if (s[j] != s[j + 1]) f = false;
    }
    if (f) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	vector<int>num(100001);
	vector<int>mod(M);
	for (int i = 0; i < N; i++) {
		cin >> K;
		num[K]++;
		mod[K%M]++;
	}
	int ans = 0;
	ans += mod[0] / 2;
	if (M % 2 == 0) {
		ans += mod[M / 2] / 2;
	}
	for (int i = 1; i < (M+1) / 2; i++) {
		K= min(mod[i], mod[M - i]);
		ans += K;
		vector<int>box;
		vector<int>bag;
		for (int j = i; j <= 100000; j += M) {
			box.push_back(num[j]);
		}
		for (int j = M - i; j <= 100000; j += M) {
			bag.push_back(num[j]);
		}
		L = 0;
		R = 0;
		for (int j = 0; j < box.size(); j++) {
			if (L == K) {
				break;
			}
			if (box[j] % 2) {
				box[j]--;
				L++;
			}
		}
		for (int j = 0; j < bag.size(); j++) {
			if (R == K) {
				break;
			}
			if (bag[j] % 2) {
				bag[j]--;
				R++;
			}
		}
		sort(box.begin(), box.end());
		reverse(box.begin(), box.end());
		sort(bag.begin(), bag.end());
		reverse(bag.begin(), bag.end());
		for (int j = 0; j < box.size(); j++) {
			if (L == K) {
				break;
			}
			int fig = min((long long int)box[j], K - L);
			L += fig;
			box[j] -= fig;
		}
		for (int j = 0; j < bag.size(); j++) {
			if (R == K) {
				break;
			}
			int fig = min((long long int)bag[j], K - R);
			R += fig;
			bag[j] -= fig;
		}
		for (int j = 0; j < box.size(); j++) {
			ans += box[j] / 2;
		}
		for (int j = 0; j < bag.size(); j++) {
			ans += bag[j] / 2;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1148
///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
using namespace std;
#define f first
#define s second
#define endl '\n'
#define PB pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef map<string , int> msi;
string s , t , ans;
int n;
int32_t main()
{
	cin >> n >> s >> t;
	for(int i = 0 ; i < n ; i ++)
		ans += s[i] , ans += t[i];
	return cout << ans << endl , 0;
}
	


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

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> n >> m;
	int a[55], b[55];
	rep(i, m) cin >> a[i] >> b[i];
	int c[55] = {0};
	rep(i, m){
		c[a[i]-1]++;
		c[b[i]-1]++;
	}
	rep(i, n){
		cout << c[i] << endl;
	}
}

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

public class Main {

	public static void main(String[] args)throws IOException{
		// TODO ?????????????????????????????????????????????

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		 
        String str = br.readLine();
        String strArray[] = str.split(" ", 0);
        int num[] = new int[strArray.length];
 
        for(int i=0; i<strArray.length; i++){
            num[i] = Integer.parseInt(strArray[i]);
        }
        for(int s=0; s<num.length; s++){
            for(int t=s+1; t<num.length; t++){
                if(num[t] < num[s]){
                    int tmp = num[t];
                    num[t] = num[s];
                    num[s] = tmp;
                }
            }
        }
        System.out.println(num[0] + " " + num[1] + " " + num[2]);
		
	}

}

Measured memory_bytes: 24160
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin>>N;
    int W[N];
    int sum=0;
    for(int i=0;i<N;i++) cin>>W[i];
    for(int i=0;i<N;i++) sum+=W[i];
    int min=sum;
    for(int i=0;i<N;i++){
        int suma=0,sumb;
        for(int j=0;j<=i;j++) suma+=W[j];
        sumb=sum-suma;
        if(abs(suma-sumb)<min) min=abs(suma-sumb);
    }
    cout<<min;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
ll N,M;
vector<vector<ll> > G;
vector<bool> seen;
void dfs(ll v){
    seen[v] = 1;

    rep(i,G[v].size()){
        if(seen[G[v][i]] == 0){
            dfs(G[v][i]);
        }
    }

}

int main() {
    
    cin >>N>>M;
    vector<bool>m(N);
    G.resize(N);
    seen.resize(N);
    ll ans = 0;
    rep(i,M){
        ll x,y,z;
        cin>>x>>y>>z;
        x--;y--;
        G[x].pb(y);
        G[y].pb(x);
    }

    rep(i,N){
        if(seen[i]==0){
            ans++;
            dfs(i);
        }
    }
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 13380
#include<bits/stdc++.h>
#define ll long long int 
#define w(x) int x; cin>>x; while(x--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
using namespace std;
int main(){
#ifndef ONLINE_JUDGE 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll n;
	cin>>n;
	ll a[n],mx=0,c=0;
	for(ll i=0; i<n; i++){
		cin>>a[i];
	}
	for(ll i=0; i<n-1; i++){
		if(a[i]>=a[i+1])
			c++;
		else{
			mx=max(mx,c);
			c=0;
		}
	}
	cout<<max(mx,c);
}

Measured memory_bytes: 4424
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>

using namespace std;
int c = 0;

void func(vector<int> v) {
    int n = v.size();
    int m = *min_element(v.begin(), v.end());
    // cout << "m" << m << endl;
    c += m;
    // cout << "here" << endl;
    for(size_t i = 0; i < n; i++)
    {
        v[i] -= m;
    }
    // for(size_t i = 0; i < n; i++)
    // {
    //     cout << v[i] << " ";
    // }
    // cout << endl;

    for(size_t q = 0; q < n; q++)
    {
        vector<int> w;
        size_t i;
        for(i = q; i < n; i++)
        {
            if(v[i] != 0) {
                w.push_back(v[i]);
            } else {
                q = i;
                break;
            }
        }
        if(!w.empty()) func(w);
        if(i == n) break;
    }
}

int main() {
    int n;
    cin >> n;
    vector<int> v(n+1);
    for(size_t i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    func(v);
    cout << c << endl;
}


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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define eb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define output(x) cout<<x<<endl;
#define fre(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define frd(i, a, b) for (int i = (int)(a); i >= b; --i)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<pair<int,int> > vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

const int maxn = 110000;

ll dp[101][maxn];

int main(){
	cin.tie(0);ios_base::sync_with_stdio(0);	
	int n,w;
	cin>>n>>w;
	int a[n+2];
	ll v[n+2];
	fre(i,1,n){
		cin>>a[i]>>v[i];
	}
	fre(i,1,n){
		fre(j,0,maxn-1){
			dp[i][j]=dp[i-1][j];
		}
		fre(j,0,maxn-1){
			if(a[i]+j > w) break;
			dp[i][j+a[i]]=max(dp[i][j+a[i]],dp[i-1][j]+v[i]);
		}
	}
	ll ans=0;
	fre(i,0,w){
		ans=max(ans,dp[n][i]);
	}
	output(ans);
	return 0;
}

Measured memory_bytes: 86144
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    string S; cin >> S;
    vector<vector<int>> vec(N, vector<int>(3, 0));
    for(int i = 0; i < N; ++i) {
        if(S[i] == 'R') vec[i][0]++;
        if(S[i] == 'G') vec[i][1]++;
        if(S[i] == 'B') vec[i][2]++;
        if(i == 0) continue;
        vec[i][0] += vec[i-1][0];
        vec[i][1] += vec[i-1][1];
        vec[i][2] += vec[i-1][2];
    }
    long long ans = 0;
    for(int i = 0; i < N; ++i) {
        for(int j = i+1; j < N-1; ++j) {
            if(S[i] == S[j]) continue;
            if(S[i] != 'R' && S[j] != 'R'){
                ans += vec[N-1][0] - vec[j][0];
                if(2*j - i < N && S[2*j - i] == 'R') ans--;
            }
            if(S[i] != 'G' && S[j] != 'G'){
                ans += vec[N-1][1] - vec[j][1];
                if(2*j - i < N && S[2*j - i] == 'G') ans--;
            }
            if(S[i] != 'B' && S[j] != 'B'){
                ans += vec[N-1][2] - vec[j][2];
                if(2*j - i < N && S[2*j - i] == 'B') ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3876
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<(n); ++i)
#define rep1(i,n) for(ll i=1; i<=(n); ++i)
#define repi(i,a,b) for(ll i=a; i<=(b); ++i)
#define rrep(i,n) for(ll i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define print(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
using Edge = pair<ll,ll>;
using Graph = vector<vector<Edge>>;
typedef pair<ll,ll> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}

ll solve(ll N, vector<ll> P){
    ll ct = 0;
    repi(i,1,N-2){
        ll mx = max({P[i-1],P[i],P[i+1]});
        ll mn = min({P[i-1],P[i],P[i+1]});
        if(P[i] != mx && P[i] != mn) ct++;
    }
    return ct;
}

int main(){
    ll N; cin >> N;
    vector<ll> p(N);
    rep(i,N) cin >> p[i];
    print(solve(N,p));
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * @author SS-1029
 *
 */
public class Main {

	public static void main(String[] args) {

		//??\??????????????????????????????Scanner???????????§???????????????
		Scanner scan = new Scanner(System.in);


		while(true){
			//??????????????????
			String x = scan.nextLine();
			//???????????¶
			if(x.charAt(0) == '0'){
				break;
			}
			//???????????¨???
			System.out.println(getSum(x));
		}
	}

	/*
	 * ?¨??????????????????????
	 * @param String x
	 * @param return int sum
	 */
	public static int getSum(String x) {

		//??????????????£?¨?
		int sum = 0;
		//char?????????????????°?????????
		for(int i = 0; i < x.length(); i++){
			//String?????????????????°?????????
			sum += Integer.parseInt(String.valueOf(x.charAt(i)));
		}
		return sum;
	}

}

Measured memory_bytes: 27032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = -10000;

int main(){
  int N,Q;
  cin >> N >>Q;
  string str;
  cin >> str;
  //累積和
  vector<int> s(N+1,0);
  for(int i = 0;i<N;i++){
    if(i+1<N && str[i] == 'A' && str[i+1] == 'C') s[i+1] = s[i] + 1;
    else s[i+1] = s[i];
  }
  
  //クエリ
  for(int q = 0;q<Q;q++){
    int l,r;
    cin >> l >> r;
    cout << s[r-1] -s[l-1] << endl;
  }
}

Measured memory_bytes: 1408
def main():
    n, *p = map(int, open(0).read().split())

    p_sort = sorted(p)

    cnt = 0
    for cur_p, cur_p_sort in zip(p, p_sort):
        if cur_p != cur_p_sort:
            cnt += 1
        if cnt > 2:
            print('NO')
            return()
    print('YES')
    return()

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
a[200],b[200],c[1000],d[1000],n,m,i,j,k,t;main(){for(;scanf("%d",&n)&&n;){for(i=0;i<n;i++){scanf("%d%d",&a[i],&b[i]);}scanf("%d",&m);for(i=0;i<m;i++){scanf("%d%d",&c[i],&d[i]);}for(i=0;i<m;i++){for(j=1;j<n;j++){for(k=0;k<m;k++){if(a[j]+c[i]-a[0]==c[k]){if(b[j]+d[i]-b[0]==d[k]){t++;}}}}if(t>n-2){printf("%d %d\n",c[i]-a[0],d[i]-b[0]);t=0;break;}t=0;}}return 0;} 

Measured memory_bytes: 608