akhauriyash/Code-Regression huggingface dataset:
// luogu-judger-enable-o2
//Zory-2018
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
#ifdef DEBUG
const int LOCAL=1;
#else
const int LOCAL=0;
#endif

namespace mine
{
    typedef long long ll;
    const int INF=0x3f3f3f3f;
    #define pr pair<int,int>
    #define FR first
    #define SE second
	#define MP make_pair

    const int MAX_N=1e5+10;
	int fa[MAX_N],siz[MAX_N];
	int findfa(int x) {return fa[x]=(fa[x]==x?x:findfa(fa[x]));}
	pr a[MAX_N];bool v[MAX_N];
	ll ans[MAX_N];
    void main()
    {
		int n,m;scanf("%d%d",&n,&m);
		for(int i=1;i<=m;i++)
		{
			int x,y;scanf("%d%d",&x,&y);
			a[i]=MP(x,y);
		}
		for(int i=1;i<=n;i++) fa[i]=i,siz[i]=1;
		ll now=ll(n-1)*n/2;
		for(int i=m;i>=1;i--)
		{
			ans[i]=now;
			
			int x=a[i].FR,y=a[i].SE;
			int fx=findfa(x),fy=findfa(y);
			if(fx!=fy)
			{
				fa[fx]=fy;
				now-=siz[fy]*siz[fx];
				siz[fy]+=siz[fx];
			}
		}
		for(int i=1;i<=m;i++) printf("%lld\n",ans[i]);
    }
};
int main()
{
    srand(time(0));
    mine::main();
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int main(){
	int dp[1002][2][2][2][2]={};
	string n;
	cin>>n;
	dp[0][0][0][0][0]=1;
	for(int i=0;i<n.size();i++)
		for(int smaller=0;smaller<2;smaller++)
			for(int has3=0;has3<2;has3++)
				for(int has5=0;has5<2;has5++)
					for(int has7=0;has7<2;has7++)
						for(int x=3;x<=min(smaller?9:n[i]-'0',7);x+=2)
							(dp[i+1][smaller||x<n[i]-'0'][has3||x==3][has5||x==5][has7||x==7]+=dp[i][smaller][has3][has5][has7])%=mod;
	long long ans=(dp[n.size()][0][1][1][1]+dp[n.size()][1][1][1][1])%mod,pow3=27,pow2=8;
	for(int i=3;i<n.size();i++){
		(ans+=pow3-3*pow2+3+mod)%=mod;
		(pow3*=3)%=mod;
		(pow2*=2)%=mod;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
N, D = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(N)]
res = 0
ans = 0
for i in range(N):
    for j in range(i+1, N):
        res = 0
        for k in range(D):
            res += (x[i][k]-x[j][k])**2
        res = res**0.5
        if res.is_integer():
            ans += 1
print(ans)

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

int main(){
  int N;
  string s, t;
  cin>>N>>s>>t;
  int ans=N;
  for(int i=0; i<N; i++){
    string X=s.substr(i, N-i);
    string Y=t.substr(0, N-i);
  if(X==Y){
    ans=i;
    break;
  }
  }
  // cout<<ans<<endl;
  string Z;
  if(ans==N) Z=s+t;
  else Z=s.substr(0, ans)+t;
  cout<<Z.size()<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
        while(1){
                char c = getchar();
                if(c==EOF) break;
                if('a'<=c && c<='z') printf("%c", c+'A'-'a');
                else if('A'<=c && c<='Z') printf("%c", c+'a'-'A');
                else putchar(c);
        }
        return 0;
}


Measured memory_bytes: 2120
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using System;

public static class Permi
{
    public static IEnumerable<IEnumerable<T>> Perm<T>(this IEnumerable<T> items, int? k = null)
    {
        if (k == null) k = items.Count();
        if (k == 0) yield return Enumerable.Empty<T>();
        else
        {
            var i = 0;
            foreach (var x in items)
            {
                var xs = items.Where((_, index) => i != index);
                foreach (var c in Perm(xs, k - 1))
                    yield return c.Before(x);
                i++;
            }
        }
    }
    public static IEnumerable<T> Before<T>(this IEnumerable<T> items, T first)
    {
        yield return first;
        foreach (var i in items) yield return i;
    }
}

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var p = Console.ReadLine().Trim().Replace(" ", "");
        var q = Console.ReadLine().Trim().Replace(" ", "");
        getAns(n, p, q);
    }
    static void getAns(int n, string p, string q)
    {
        var alist = new List<string>();
        var a = Enumerable.Range(1, n).Perm();
        foreach (var x in a)
        {
            var t = "";
            foreach (var y in x) t += y.ToString();
            alist.Add(t);
        }
        alist.Sort();
        var pc = 0; var qc = 0;
        for (int i = 0; i < alist.Count(); i++)
            if (alist[i] == p) { pc = i; break; }
        for (int i = 0; i < alist.Count(); i++)
            if (alist[i] == q) { qc = i; break; }
        Console.WriteLine(Abs(pc - qc));
    }
}


Measured memory_bytes: 22660
/* author: Tarek */ 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int h,a;
cin>>h>>a;
if(h%a==0)cout<<h/a<<endl;
else cout<<((h/a)+1)<<endl;
	return 0;
}



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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second
#define all(x) x.begin(), x.end()
#define sz(x) (x).size()

ll gcd(ll a, ll b);

ll sum(int n);

int len(int n){
   string nn=to_string(n);
   return nn.size();
}
void go(){
   int n;cin>>n;
   int ans=0;
   for(int i=1;i<=n;i++){
      if(len(i)%2==1) ans++;
   }

   cout << ans;
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

ll gcd(ll a, ll b){     
   if(b == 0) return a;
   
   return gcd(b, a % b);
}

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int main(){
  int N, M;
  while(cin >> N >> M){
    vector<long long> x(N), y(N), z(N);
    for(int i=0;i<N;i++) cin >> x[i] >> y[i] >> z[i];
    long long res = -(1LL << 60);
    for(int sgn=0;sgn<8;sgn++){
      vector<long long> l;
      int sgnX = (sgn&1) ? 1 : -1;
      int sgnY = (sgn&2) ? 1 : -1;
      int sgnZ = (sgn&4) ? 1 : -1;
      for(int i=0;i<N;i++){
        l.push_back(sgnX*x[i] + sgnY*y[i] + sgnZ*z[i]);
      }
      sort(l.rbegin(), l.rend());
      long long sum = 0;
      for(int j=0;j<M;j++) sum += l[j];
      res = max(res, sum);
    }
    cout << res << endl;
  }
}

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

int main()
{
    int n;
    cin >> n;
    if (n / 100 == 7)cout << "Yes" << endl;
    else if ((n %100)/10 == 7)cout << "Yes" << endl;
    else if (n % 10 == 7)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3624
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    string_code(1, S, C),
*/

main:-
    get_string(S),
    (S == "AAA" ; S == "BBB") -> writeln("No") ; writeln("Yes").


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

int main() {
int n,k;
  cin >> n >> k;
  
vector<int> a(n);
rep(i,n) cin >> a.at(i);
sort(a.begin(),a.end());
int sum = 0;
rep(i,k) sum += a.at(i);

cout << sum << endl;
 }

Measured memory_bytes: 3632
import           Data.Char

solve :: String -> Int
solve = g . foldl f (0, 0)
  where f (a, b) c
          | isNumber c = (a, b * 10 + ord c - 0x30)
          | otherwise  = (a + b, 0)
        g (a, b) = a + b

main :: IO ()
main = getContents >>= print . solve

Measured memory_bytes: 3636
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

int n;
int a[100010];

int main() {
    while (cin >> n) {
        int ans = 0;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            --a[i];
        }
        for (int i = 0; i < n; i++) {
            if (a[a[i]] == i) {
                ++ans;
            }
        }
        cout << ans / 2 << endl;
    }
}


Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <vector>

using namespace std;
typedef long long LL;
const int maxn = 600005;

int n,a[maxn][3],p[maxn],sum[maxn],res1,res2;
void modify(int x) {for (int i=x;i;i-=i&-i) sum[i]++;}
int query(int x) {int res=0;for (int i=x;i<=n;i+=i&-i) res+=sum[i];return res&1;}
void ilLegal() {puts("No");exit(0);}
int main()
{
	#ifdef Amberframe
		freopen("agc006e.in","r",stdin);
		freopen("agc006e.out","w",stdout);
	#endif
	scanf("%d",&n);
	for (int j=0;j<=2;j++)
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i][j]);
	for (int i=1;i<=n;i++)
	{
		int o=min(min(a[i][0]/3,a[i][1]/3),a[i][2]/3);bool tag=false;
		if (a[i][0]==o*3+1&&a[i][1]==o*3+2&&a[i][2]==o*3+3) tag=true;
		if (a[i][0]==o*3+3&&a[i][1]==o*3+2&&a[i][2]==o*3+1) tag=true,i&1?res1^=1:res2^=1;
		if (!tag||!((i^o)&1)) ilLegal();else p[i]=o+1;
	}
	
	for (int i=1;i<=n;i+=2)
		res2^=query(p[i]),modify(p[i]);
	memset(sum,0,sizeof sum);
	for (int i=2;i<=n;i+=2)
		res1^=query(p[i]),modify(p[i]);
	printf("%s\n",res1||res2?"No":"Yes");
	return 0;
}

Measured memory_bytes: 6400
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

void b_varied(void) {
	string s;
	int cnt[27] = { 0 };
	string msg = "yes";
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		int ptr = s[i] - 'a';
		cnt[ptr]++;
	}

	for (int i = 0; i < 27; i++) {
		if (cnt[i] > 1) {
			msg = "no";
			break;
		}
	}
	cout << msg << endl;
}


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

Measured memory_bytes: 3616
n,l=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
flag=False
for i in range(0,n-1):
    if not flag:
        if a[i]+a[i+1]>=l:
            cnt=i+1
            flag=True

if not flag:
    print("Impossible")
    exit()

ans=[cnt]

for i in range(cnt-1,0,-1):
    ans.append(i)
for i in range(cnt+1,n):
    ans.append(i)
ans=ans[::-1]
print("Possible")
for i in range(len(ans)):
    print(ans[i])


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

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

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

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

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

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

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

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

fn main() {
    input! {
        s: Chars,
    }

    if is_parin(&s[..]) {
        if is_parin(&s[0..s.len() / 2]) {
            if is_parin(&s[(s.len() + 2) / 2..s.len()]) {
                println!("Yes");
            }
        }
    }
}

fn is_parin(word: &[char]) -> bool {
    for i in 0..word.len() / 2 {
        if word[i] != word[word.len() - i - 1] {
            println!("No");
            return false;
        }
    }
    true
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl;
 
using namespace std;
 
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}
 
typedef pair<ll,ll> Pair;
const ll inf =1000000007;

vector<ll> ans;

void dfs(string a){
    bool ok7=false,ok3=false,ok5=false;
    for(ll i=0;i<a.size();i++){
        if(a[i]=='7') ok7=true;
        if(a[i]=='5') ok5=true;
        if(a[i]=='3') ok3=true;
    }
    if(ok7&&ok5&&ok3) ans.pb(stoll(a));
    if(a.size()>10){
    }
    else{
        dfs(a+'7');
        dfs(a+'5');
        dfs(a+'3');
    }
}



int main(){
    ll n;
    cin >> n;
    dfs("");
    ll score=0;
  sort(ans.begin(),ans.end());
    for(ll i=0;;i++){
        if(ans[i]>n) break;
        score++;
    }
    kaku(score);
}



Measured memory_bytes: 2420
#include <stdio.h>

int main(void)
{
  int num;
  int a,b,c,x,y;
  
  scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);
  
  if(a+b<=2*c){
    printf("%d", a*x+b*y);
    return 0;
  }
  else{
    if(x>y){
      num=x-y;
      if(a>=2*c){
        printf("%d", 2*x*c);
        return 0;
      }
      else{
        printf("%d", 2*y*c+(x-y)*a);
        return 0;
      }
    }
    else{
       num=y-x;
      if(b>=2*c){
        printf("%d", 2*y*c);
        return 0;
      }
      else{
        printf("%d", 2*x*c+(y-x)*b);
        return 0;
      }
    }
  }
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
   int a,b,c;
   scanf("%d%d%d",&a,&b,&c);
   if((a==b&&a!=c)||(a==c&&a!=b)||(b==c&&b!=a)){
      printf("Yes");
   }else{
      printf("No");
   }
   return 0;
}

Measured memory_bytes: 3200
from math import factorial
mod = 1000000007
n,m = (int(i) for i in input().split())
if abs(n-m) >= 2:
    print(0)
    exit()
if n == m:
    ans = factorial(n)*factorial(m)*2
    print(ans%mod)
else:
    ans = factorial(n)*factorial(m)
    print(ans%mod)


Measured memory_bytes: 5184
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

N = int(input())
ans = num2alpha(N)
print(ans.lower())

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

typedef long long ll;
const int INF32 = 1 << 30;
const ll INF64 = 1ll << 60;

const int N = 1005;
int n;

namespace flow {
	const int V = 2 * N, E = 2 * (10 * N);
	int S, T, tot = 1, nxt[E], fst[V], to[E], flow[E], cost[E], pre[V];
	ll dis[V];
	void addedge(int u, int v, int w, int c) {
		nxt[++tot] = fst[u]; fst[u] = tot; to[tot] = v; flow[tot] = w; cost[tot] = c;
		nxt[++tot] = fst[v]; fst[v] = tot; to[tot] = u; flow[tot] = 0; cost[tot] = -c;
	}
	bool bfs() {
		queue<int> q;
		static bool inq[V];
		for (int i = 1; i <= flow::T; i++) dis[i] = INF64;
		q.push(S), inq[S] = true, dis[S] = 0;
		while (!q.empty()) {
			int u = q.front(); q.pop(); inq[u] = false;
			for (int i = fst[u]; i; i = nxt[i])
				if (flow[i] > 0 && dis[to[i]] > dis[u] + cost[i]) {
					dis[to[i]] = dis[u] + cost[i];
					pre[to[i]] = i;
					if (!inq[to[i]]) q.push(to[i]), inq[to[i]] = true;
				}
		}
		return dis[T] != INF64;
	}
	pair<int, ll> mcmf() {
		int f = 0;
		ll c = 0;
		while (bfs()) {
			int mn = INF32;
			for (int i = T; i != S; i = to[pre[i] ^ 1]) mn = min(mn, flow[pre[i]]);
			f += mn, c += mn * dis[T];
			for (int i = T; i != S; i = to[pre[i] ^ 1]) flow[pre[i]] -= mn, flow[pre[i] ^ 1] += mn;
		}
		return make_pair(f, c);
	}
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	flow::S = 2 * n + 5, flow::T = 2 * n + 6;
	for (int i = 1, x, y, c; i <= n; ++i) {
		cin >> x >> y >> c;
		flow::addedge(flow::S, i, c, 0);
		flow::addedge(i, 2 * n + 1, INF32, +x + y);
		flow::addedge(i, 2 * n + 2, INF32, +x - y);
		flow::addedge(i, 2 * n + 3, INF32, -x + y);
		flow::addedge(i, 2 * n + 4, INF32, -x - y);
	}
	for (int i = 1, x, y, c; i <= n; ++i) {
		cin >> x >> y >> c;
		flow::addedge(i + n, flow::T, c, 0);
		flow::addedge(2 * n + 1, i + n, INF32, -x - y);
		flow::addedge(2 * n + 2, i + n, INF32, -x + y);
		flow::addedge(2 * n + 3, i + n, INF32, +x - y);
		flow::addedge(2 * n + 4, i + n, INF32, +x + y);
	}
	cout << -flow::mcmf().second << endl;
}


Measured memory_bytes: 640
import java.io.*;
import java.util.*;

public class Main {


    private void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        long res = Long.MIN_VALUE;
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextLong();
        }
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                res = Math.max(res, Math.abs(arr[i] - arr[j]));
            }

        }
        out.println(res);
    }


    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        try (
                InputReader in = new InputReader(System.in);
                PrintWriter out = new PrintWriter(System.out)) {
            solve(in, out);
        }
    }


    static class InputReader implements AutoCloseable {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        @Override
        public void close() {

        }
    }

}


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

int N, T, H, L;
int t[102], h[102];

int solve(){
  int now = 0;
  int display = 0;

  while(true){
    if(0 < t[now]){
      T++;
      t[now]--;
      display += 10;
    }
    else if(0 < h[now]){
      H++;
      h[now]--;
      display += 100;
    }
    else{
      return now;
    }

    if(L < T){
      return now;
    }
    if(90 <= display){
      int pay = display - 90;
      display = 0;

      if(T < pay / 10){
	return now;
      }

      T -= pay / 10;
      t[now] += pay / 10;
    }

    now = (now + 1) % N;
  }

  return -1;
}

int main(){
  while(cin >> N >> T >> H >> L){
    for(int i = 0; i < N; i++){
      cin >> t[i] >> h[i];
    }

    cout << solve() + 1 << endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b+1 >= c){
    cout << b+c << endl;
  }else{
    cout << a+2*b+1 << endl;
  }
  return 0;
}

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

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

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

int charN(char c) {
    return static_cast<int>(c) - static_cast<int>('a');
}
int main() {
    int N; cin >> N;
    vector<ll> a(N); repp(i, 0, N) cin >> a[i];
    vector<ll> b(N); repp(i, 0, N) cin >> b[i];
    
    ll diff = 0;
    repp(i, 0, N) diff += b[i] - a[i];
    ll count = 0;
    repp(i, 0, N) {
        if (a[i] < b[i]) count += (b[i] - a[i] + 1) / 2;
    }
    if (diff < 0 || count > diff) cout << "No" << endl;
    else cout << "Yes" << endl;
}



Measured memory_bytes: 384
import sys
sys.setrecursionlimit(int(1e7))

N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]

roots = [(i,1) for i in range(N+1)] # root, num_islands_in_group

inconveniences = [0]*(M+1)
inconveniences[-1] = N*(N-1)//2 #すべての橋が崩落するとNC2

def find_root(a, roots=roots):
  if roots[a][0] == a:
    return roots[a]
  else:
    roots[a] = find_root(roots[a][0])
  return roots[a]

def reduce_inconvenience_with_unite(a, b, roots=roots):
  root_a, n_a = find_root(a)
  root_b, n_b = find_root(b)
  if root_a == root_b:
    return 0
  else:
    roots[root_a] = (root_b, n_a + n_b) # 二項目は何でも良い
    roots[root_b] = (root_b, n_a + n_b)
    return n_a * n_b

for i, ab in enumerate(AB[:0:-1]): #実は1個めの橋は全く関係ない
  a, b = ab
  inconveniences[M-1-i] = inconveniences[M-i] - reduce_inconvenience_with_unite(a,b)

for inc in inconveniences[1:]:
  print(inc)


Measured memory_bytes: 56628
import math
a,b,x=map(int,input().split())
if a*a*b <= 2*x:
    b1=(a*a*b-x)/a*2/a
    print(math.degrees(math.atan(b1/a)))
else:
    a1=((x/a)*2)/b
    print(math.degrees(math.atan(b/a1)))

Measured memory_bytes: 38256
n,k,*v=map(int,open(0).read().split())
motimono=[]
ans=[]
v*=2
for j in range(1,min(n,k)+1):
    for i in range(n-j,n+1):
        motimono=v[i:i+j]
        ans.append(sum(motimono))
        motimono.sort()
        for i in range(k-j):
            if len(motimono)>0:
                del motimono[0]
            ans.append(sum(motimono))
print(max(ans))

Measured memory_bytes: 5200
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;


int main () {
	int N;
	cin >> N;
	unsigned long long res;
	vector<unsigned long long> list(87);
	list[0] = 2;
	list[1] = 1;
	for(int i = 2; i <= N; i++){
		list[i] = list[i-1] + list[i-2];
	}
	cout << list[N];

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int cnt = 0;
  rep(i, n) while (a[i] % 2 == 0) {
    a[i] /= 2;
    cnt++;
  }
  cout << cnt << '\n';
  return 0;
}

Measured memory_bytes: 3612
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 3000000;
const int K = 19;
const int mod = 1e9 + 7;
int a[N], r[N], c[N], b[N];
set < int > s1,s2;

main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        r[a[i]] = i;
        s1.insert(a[i]);
    }
    for (int i = 1; i <= m; i++){
        cin >> b[i];
        c[b[i]] = i;
        s2.insert(b[i]);
    }
    if (s1.size() != n || s2.size() != m){
        cout << 0;
        return 0;
    }
    int nr = 0;
    int nc = 0;
    int p = 0;
    int ans = 1;
    for (int i = n * m; i >= 1; i--){
        if (c[i] != 0 && r[i] != 0){
            p = p + nr + nc;
            nr++;
            nc++;
        } else
        if (c[i] != 0){
            ans = ans * nr % mod;
            nc++;
            p += nr - 1;
        } else
        if (r[i] != 0){
            ans = ans * nc % mod;
            nr++;
            p += nc - 1;
        } else{
            ans = ans * p % mod;
            p--;
        }
    }
    cout << ans;
}


Measured memory_bytes: 6528
//Created by Aminul on 6/27/2020.

import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = in.nextInt();
        long[] nod = NOD(n);
        long res = 0;
        for (int i = 1; i <= n; i++) {
            res += i * nod[i];
        }

        pw.println(res);
        pw.close();
    }

    static long[] NOD(int n) {
        long nod[] = new long[n + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = i; j <= n; j += i) {
                nod[j]++;
            }
        }
        return nod;
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }
}

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

#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;


int main(){
  ll n;
  cin >> n;
  
  cout << pow(n,2) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,x,y) for(ll i=x; i<=y; i++)
#define BIT(t) ((long long 1) << t)
#define PER(i,y,x) for(ll i=y; i>=x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
using namespace std;
typedef long long ll;

ll const MAX = 2e5 + 5;

struct unionfind {
       ll max_un;
       vector<ll> parent;
       vector<ll> components;
       vector<bool> flag; 
       unionfind(ll n) {
               max_un = n;
               parent = vector<ll>(n + 1);
               components = vector<ll>(n + 1);
               flag = vector<bool>(n+1, 0);
               for (int i = 0; i <= n; i++) {
                       parent[i] = i;
                       components[i] = 1;
               }
               
       }
       ll find(ll x) {
               if (parent[x] == x) {
                       return x;
               }
               else {
                       parent[x] = find(parent[x]);
                       return parent[x];
               }
       }
       bool same(ll x, ll y) {
               return find(x) == find(y);
       }
       ll comp(ll x) {
               return components[find(x)];
       }
       void unite(ll x, ll y) {
               if (!same(x, y)) {
                       x = parent[x];
                       y = parent[y];
                       if (components[x] <= components[y]) {
                               parent[x] = y;
                               components[y] += components[x];
                       }
                       else {
                               parent[y] = x;
                               components[x] += components[y];
                       }
               }
               flag[x] = flag[y] = flag[x] | flag[y];
       }
       void roop(ll x){
               flag[find(x)] = 1;
       }
       bool getflag(ll x){
               return flag[find(x)];
       }
};

unionfind un(MAX);
struct edge
{
       ll f; ll t; ll val;
       bool operator<(const edge& rhs) const {
                return val < rhs.val;
       }
};

priority_queue<edge> pq;

int main(){
        ll n, h, w;
        cin >> n >> h >> w;
        REP(i,1,n){
                ll r,c,a;
                cin >> r >> c >> a;
                c += h;
                pq.push({r,c,a});      
        }
        ll cnt = 0;
        ll ans = 0;
        while(cnt < 2 * n && !pq.empty()){
                edge e = pq.top();
                pq.pop();
                if(un.same(e.t, e.f) && !un.getflag(e.t)){
                        un.roop(e.t);
                        ans += e.val;
                }else if(!un.same(e.t, e.f) && !(un.getflag(e.t) && un.getflag(e.f))){
                        un.unite(e.t, e.f);
                        ans += e.val;
                }
        }
        cout << ans << endl;
}

Measured memory_bytes: 8052
#include<bits/stdc++.h>
#define MOD (long long)(1e9+7)
using namespace std;
int n,dp[2][105];
int main()
{
	cin >> n;
	for(int i=1; i<=n; i++) cin >> dp[0][i],dp[0][i]+=dp[0][i-1]; 
	for(int i=1; i<=n; i++) cin >> dp[1][i],dp[1][i]+=max(dp[1][i-1],dp[0][i]);
	cout << dp[1][n];
	return 0;
}


Measured memory_bytes: 3576
a=int(input())
b=int(input())
c=int(input())
x=int(input())
count=0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if 500*i+100*j+50*k==x:
        count+=1
print(count)

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

int main( void ) {
  int number;
  int p[20];

  cin >> number;

  for ( int i = 0; i < number; ++i) cin >> p[i];

  int res = 0;

  for ( int j = 1; j < number -1; j++){
    int first = p[j - 1];
    int second = p[j];
    int third  = p[j + 1];

    if (second > first && second < third || second < first && second > third){
      res++;
    }
  }

  cout << res << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cctype>

char convertChar(char c)
{
	if (islower(c)) c = toupper(c);
	else if (isupper(c)) c = tolower(c);
	return c;
}

int main()
{
	char c, ret;
	while (true)
	{
		c = getchar();
		ret = convertChar(c);
		putchar(ret);
		if (c == '\n') break;
	}
	return 0;
}

Measured memory_bytes: 904
#include<stdio.h>
int R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]>N[H[b]]?1:0;
}
//挿入関数
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int main(){
  int n,m,i,s=0,a,b[200010]={};
  scanf("%d %d",&n,&m);
  //m=n-m;
  for(i=0;i<n;i++){
    scanf("%d",&a);
    b[a]++;
  }
  for(i=0;i<200010;i++){
    if(b[i])hin(b[i]);
  }
  for(i=0;i<m&&C-1;i++)s+=N[hout()];
  printf("%d\n",n-s);
  return 0;
}


Measured memory_bytes: 5760
DEBUG = False

N = int(input())
A = [int(i) for i in input().split()]

index_min_abs_val = N-1
flag_zero = not A[N-1]
if DEBUG:
    print("index_max_abs_val: {}, flag_zero: {}".format(index_min_abs_val, flag_zero))
for i in range(N-1):
    if not A[i]:
        flag_zero = True
    if abs(A[index_min_abs_val]) > abs(A[i]):
        index_min_abs_val = i
    if A[i] < 0:
        A[i] *= -1
        A[i+1] *= -1
    if DEBUG:
        print("i: {}, A: {}".format(i, A))
        print("index_max_abs_val: {}, flag_zero: {}".format(index_min_abs_val, flag_zero))

if flag_zero:
    A[N-1] = abs(A[N-1])
elif A[N-1] < 0:
    A[N-1] *= -1
    A[index_min_abs_val] *= -1

if DEBUG:
    print("A: {}".format(A))
print(sum(A))


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

int main() {
	
	int x, y;
	cin >> x >> y;
	
	if(y%2 == 0)
	{
		if(y >= 2*x && y <= 4*x) cout << "Yes\n";
		else cout << "No\n";
	}
	else cout << "No\n";
	
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
char c[2][60];
int n,m;
long long ans=1ll;
const long long Mod=1e9+7;
int main(){
	n=2;
	cin>>m;
	for (int i=0;i<n;i++){
		for (int j=0;j<m;j++){
			cin>>c[i][j];
		}
	}
	for (int i=0;i<m;i++){
		if (c[0][i]==c[1][i]){
			if (i==0){
				ans*=3;
				ans%=Mod;
			}
			else if (c[0][i-1]==c[1][i-1]){
				ans*=2;
				ans%=Mod;
			}
		}
		else{
			if (i==0){
				ans*=6;
				ans%=Mod;
			}
			else if (c[0][i-1]==c[1][i-1]){
				ans*=2;
				ans%=Mod;
			}
			else{
				ans*=3;
				ans%=Mod;
			}
			i++;
		}
		//cout<<ans<<endl;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <utility>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
int li[35];
int main() {
    int n, m;
    cin >> n >> m;
    memset(li, 0, sizeof(li));
    for(int i = 0; i < n; ++i){
    	int j; cin >> j;
    	for(int k = 0; k < j; k++){
    		int x; cin >> x;
    		li[x]++;
    	}
    }
    int ans = 0;
    for(int i = 1; i <= m; ++i){
    	//cout << li[i] << endl;
    	if(li[i] == n) ans++;
    }
    cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    string s;
    cin >> n >> s;
    int r = 0, b = 0;
    for (char c : s){
        if (c == 'R') r++;
        else b++;
    }
    cout << (r > b ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
using namespace std;

int main(){
	int n;
	cin >> n;
	if(n==7 || n==5 || n==3){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;



int main()
{

    int N;
    cin >> N;
    string S;
    cin >> S;
    
    int ans = 0;
    
    reps(i,1,N){
        string X = S.substr(0,i);
        string Y = S.substr(i,N-i);
        
        ve<bool> A(30,false);
        
        rep(j,int(X.length())){
            rep(k,int(Y.length())){
                if(X[j] == Y[k]) A[X[j]-'a'] = true;
            }
        }
        
        int an = 0;
        rep(j,30) if(A[j]) an++;
        ans = max(ans,an);
        
    }
    out(ans);

    return 0;
}


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

using namespace std;

int main() {
	int n;
	int a, b, c;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector< vector<int> > d(10, vector<int>(10, 100000));
		for (int i = 0; i < 10; i++) {
			d[i][i] = 0;
		}
		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			d[a][b] = c;
			d[b][a] = c;
		}
		for (int k = 0; k < 10; k++) {
			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 10; j++) {
					d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
				}
			}
		}
		int hyou[10] = {0};
		int p, q;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				if (i == j) {
					continue;
				} else if (d[i][j] >= 100000) {
					continue;
				}
				hyou[i] += d[i][j];
			}
		}
		p = 0;
		q = hyou[0];
		for (int i = 1; i < 10; i++) {
			if (hyou[i] == 0) {
				break;
			}
			if (q > hyou[i]) {
				p = i;
				q = hyou[i];
			}
		}
		cout << p << ' ' << q << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    string s, t;
    cin >> s >> t;

    int ans = 2 * N;
    for(int i=0;i<N;i++){
        bool ok = true;
        for(int j=0;i+j<N;j++){
            if(s[i+j] != t[j]){
                ok = false;
                break;
            }
        }
        if(ok){
            ans = i + N;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define P(s) printf(s "\n");
int main(void){int m,f,r,s;for(;;){scanf("%d %d %d",&m,&f,&r);if((s=m+f)+r==-3)exit(0);if((m==-1)|(f==-1)|(s<30))P("F")else if(s>=80)P("A")else if(s>=65)P("B")else if((s>=50)|(r>=50))P("C")else P("D")}}

Measured memory_bytes: 580
from functools import reduce
import math

def main():
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    a, b = (int(_) for _ in input().split())  
    print((a+b)%24)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string S;
string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main(){
    cin>>S;

    reverse(S.begin(), S.end());
    for(int i=0;i<4;i++) reverse(divide[i].begin(),divide[i].end());
    bool can = true;
    for(int i=0;i<S.size();){
        bool can2 = false;
        for(int j=0;j<4;j++){
            string d = divide[j];
            if(S.substr(i,d.size())==d){
                can2 = true;
                i += d.size();
            }
        }
        if (!can2){
            can = false;
            break;
        }
    }
    if(can)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

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

signed main(){
  int n; cin >> n;
  n--;
  vector<string> now{"a"};
  while(n--){
    vector<string> next;
    for(const auto &S: now){
      char c = *(max_element(S.begin(), S.end()));
      c++;
      for(char d='a'; d<=c; d++){
        next.push_back(S + d);
      }
    }
    now = next;
  }
  
  for(const auto &S: now){
    cout << S << endl;
  }
  
  return 0;
}

Measured memory_bytes: 9116
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 

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

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int n, num, k;
    string kind;

    cin>>n;
    vector<bool> deck(n, false);
    vector<int> rest;

    rep(i, n) {
        cin>>kind>>num;
        if (kind=="S") k = 0;
        else if (kind=="H") k = 1;
        else if (kind=="C") k = 2;
        else k = 3;

        deck[13 * k + num - 1] = true;
    }
    rep(i, 52) {
        if (!deck[i]) {
            rest.push_back(i);
        }
    }
    sort(rest.begin(), rest.end());
    for (auto v : rest) {
        k = v / 13;
        num = v % 13 + 1;
        if (k == 0) kind = "S";
        else if (k == 1) kind = "H";
        else if (k == 2) kind = "C";
        else kind = "D";
        cout<<kind<<" "<<num<<endl;
    }
}


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

int main() {
  int  n,k; cin>>n>>k;
  ll ans=k*pow(k-1,n-1);
  cout<<ans<<endl;
}
      

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstdio>

using namespace std;

int main() {

	while (true){
		int n,x;
		cin >> n >> x;

		if (n == 0 && x == 0) break;
		int ways = 0;
		for (int i = 1; i <= n - 2; ++i) {
			for (int j = i+1; j <= n ; ++j) {
				for (int k = j+1; k <= n; ++k) {
					//printf("%d %d %d = %d\n", i, j, k, i + j + k);
					if (i + j + k == x) ways += 1;
				}
			}
		}
		cout << ways << endl;
	}
}



Measured memory_bytes: 3092
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;



__int128 parse(string &s) {
    __int128 ret = 0;
    for (int i = 0; i < s.length(); i++)
        if ('0' <= s[i] && s[i] <= '9')
            ret = 10 * ret + s[i] - '0';
    return ret;
}

std::ostream &operator<<(std::ostream &dest, __int128_t value) {
    std::ostream::sentry s(dest);
    if (s) {
        __uint128_t tmp = value < 0 ? -value : value;
        char buffer[128];
        char *d = std::end(buffer);
        do {
            --d;
            *d = "0123456789"[tmp % 10];
            tmp /= 10;
        } while (tmp != 0);
        if (value < 0) {
            --d;
            *d = '-';
        }
        int len = std::end(buffer) - d;
        if (dest.rdbuf()->sputn(d, len) != len) {
            dest.setstate(std::ios_base::badbit);
        }
    }
    return dest;
}


std::istream &operator>>(std::istream &dest, __int128 &value) {
    string s;
    cin>>s;
    value=parse(s);
    return dest;
}

typedef __int128 Int;

int main(){
    Int n,m,a,b,p,q;
    cin>>n>>m>>a>>b>>p>>q;
    if(a==1 && b==1){
        Int sum=p+q;
        Int M=min(m/sum,n);
        Int ans=m-M*sum;
        Int k=m-(M+1)*sum;
        if(k<0){k*=-1;}
        if(M!=n){ans=min(ans,k);}
        cout<<ans<<endl;
    }
    else{
        vector<ll> A;
        Int s=1,t=1;
        int i;
        for(i=0;i<n && s*p+t*q<=m;i++,s*=a,t*=b){
            A.push_back(s*p+t*q);
        }
        if(i<n && s*p+t*q<=m*2){A.push_back(s*p+t*q);}
        vector<ll> B;
        while(A.size()>B.size()){B.push_back(A.back()); A.pop_back();}
        vector<ll> F;
        for(ll i=0;i<(1LL<<A.size());i++){
            ll sum=0;
            for(int t=0;t<A.size();t++){
                if(i>>t&1){sum+=A[t];}
            }
            F.push_back(sum);
        }
        ll ans=m;
        sort(F.begin(),F.end());
        for(ll i=0;i<(1LL<<B.size());i++){
            ll sum=0;
            for(int t=0;t<B.size();t++){
                if(i>>t&1){sum+=B[t];}
            }
            ll rem=m-sum;
            ll idx=lower_bound(F.begin(),F.end(),rem)-F.begin();
            if(idx!=F.size()){ans=min(ans,abs(F[idx]-rem));}
            if(idx!=0){ans=min(ans,abs(rem-F[idx-1]));}
        }
        cout<<ans<<endl;
    }
    
    
    
    return 0;
}



Measured memory_bytes: 11244
import sys
import math
input = sys.stdin.readline


def eratosthenes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, n + 1):
        if i * i > n:
            break
        if is_prime[i]:
            for j in range((n - i * i) // i + 1):
                is_prime[i * i + i * j] = False
    return is_prime


q = int(input())
l = []
r = []
for i in range(q):
    li, ri = map(int, input().split())
    l.append(li)
    r.append(ri)

r_max = max(r)
is_prime = eratosthenes(r_max)
a = [0] * (r_max + 1)
for i in range(3, r_max + 1):
    a[i] = a[i - 1]
    if is_prime[i] and is_prime[(i + 1) // 2]:
        a[i] += 1
# print(a)

for i in range(q):
    print(a[r[i]] - a[l[i] - 1])


Measured memory_bytes: 13360
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e5+5;
const int mod=998244353;
set<string>s;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        string a;
        cin>>a;
        s.insert(a);
    }
    cout<<s.size()<<'\n';


}


Measured memory_bytes: 19208
# with open('in.txt', 'w') as f:
#     f.write('200000 10000 1\n')
#     for _ in range(1, 200001):
#         f.write(str(_)+' '+str(_)+'\n')
n, k = input().split()
n = int(n)
k = int(k)
ls = []
m = {}
for _ in range(n):
    __ = int(input())
    m[__] = m.get(__, 0) + 1
ls = [(0, 0)]
ls.extend(list(m.items()))
ls.sort(key=lambda s: s[0])
for i in range(1, len(ls)):
    ls[i] = (ls[i][0], ls[i-1][1]+ls[i][1])
l, r = 0, 0
ans = 9999999999999999
# print(ls)
while True:
    if r < len(ls) and l < len(ls):
        if ls[r][1] - ls[l][1] < k:
            r += 1
        elif ls[r][1] - ls[l][1] >= k:
            # print(l, r)
            ans = min(ans, ls[r][0] - ls[l+1][0])
            l += 1
    else:
        break
print(ans)


Measured memory_bytes: 24280