akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;


template <typename T> class LazySegmentTree {
private:
    
    int n;
    vector < T > node, lazy;
    
    void  lazy_eval (int l, int r, int k) {
        node[k] += lazy[k];
        if (r - l > 1) {
            lazy[2 * k + 1] += lazy[k] >> 1;
            lazy[2 * k + 2] += lazy[k] >> 1;
        }
        lazy[k] = 0;
    }
    
    void _add (int a, int b, T val, int k, int l, int r) {
        lazy_eval(l, r, k);
        if (b <= l || r <= a) return;
        if (a <= l && r <= b) {
            lazy[k] += (r - l) * val;
            lazy_eval(l, r, k);
        } else {
            _add (a, b, val, 2 * k + 1, l, (l + r) / 2);
            _add (a, b, val, 2 * k + 2, (l + r) / 2, r);
            node[k] = node[2 * k + 1] + node[2 * k + 2];
        }
    }

    T _get_sum (int a, int b, int k, int l, int r) {
        lazy_eval (l, r, k);
        if (b <= l || r <= a) return 0;
        if (a <= l && r <= b) return node[k];
        T vl = _get_sum (a, b, 2 * k + 1, l, (l + r) / 2);
        T vr = _get_sum (a, b, 2 * k + 2, (l + r) / 2, r);
        return vl + vr;
    }
    
public:
    
    LazySegmentTree (int _n) : n(1) {
        while (n < _n) n <<= 1;
        node.resize (2 * n, 0);
        lazy.resize (2 * n, 0);
    }
    
    void add (int l, int r, T val) {
        _add (l, r, val, 0, 0, n);
    }
    
    T get_sum (int l, int r) {
        return _get_sum (l, r, 0, 0, n);
    }
    
};

int main() {
    
    int n,q; cin >> n >> q;
    
    LazySegmentTree < ll > inst(100010);
    
    REP(i,q) {
        int a,l,r;
        cin >> a >> l >> r;
        if (a == 0) {
            ll x; cin >> x;
            inst.add(l, r + 1, x);
        } else {
            cout << inst.get_sum(l, r + 1) << endl;
        }
    }

    return 0;
}





Measured memory_bytes: 7028
x = int(input())
facts = [i ** 5 for i in range(120)]
for a, a5 in enumerate(facts):
    for b, b5 in enumerate(facts):
        if a5 + b5 == x:
            print(a, -b)
            break
        if a5 - b5 == x:
            print(a, b)
            break
    else:
        continue
    break


Measured memory_bytes: 9168
L = 1000000

table = []
(0..19).each do |a|
  table << (x1 = 2 ** a)
  (1..12).each do |b|
    table << (x2 = 3 ** b)
    y1 = x1 * x2
    table << y1 if y1 <= L
    (1..8).each do |c|
      table << (x3 = 5 ** c)
      y2 = x2 * x3
      y3 = x1 * x3
      y4 = y1 * x3
      table << y2 if y2 <= L
      table << y3 if y3 <= L
      table << y4 if y4 <= L
    end
  end
end
table.uniq!.sort!

until (n = $<.gets.chomp) == "0"
  m, n = n.split.map(&:to_i)
  a = table.bsearch_index {|x| x >= m}
  b = table.bsearch_index {|x| x > n}
  b = b ? b : table.size
  puts b - a
end



Measured memory_bytes: 6900
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) (a<<b)
#define Rshift(a,b) (a>>b)
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;

string s;

int seg[2000000][3];

void construct(int now, int l, int r) {
    seg[now][0] = l;
    seg[now][1] = r;
    seg[now][2] = 0;
    if (l != r) {
        int mid = (l + r) >> 1;
        construct(Lshift(now, 1) + 1, l, mid);
        construct(Lshift(now, 1) + 2, mid+1, r);
    }
}

void insert(int now, int idx, int val) {
    int l = seg[now][0];
    int r = seg[now][1];
    if (l == r) {
        seg[now][2] = val;
        return;
    }

    int mid = (l + r) >> 1;
    if (idx <= mid) {
        insert(Lshift(now, 1)+ 1, idx, val);
    } else {
        insert(Lshift(now, 1)+ 2, idx, val);
    }
    seg[now][2] = seg[Lshift(now, 1)+1][2] | seg[Lshift(now, 1)+2][2];
}

int query(int now, int l, int r) {
    int ll = seg[now][0];
    int rr = seg[now][1];
    if (ll >= l && rr <= r) {
        return seg[now][2];
    }
    int mid = (ll + rr) >> 1;
    int ans = 0;
    if (l <= mid) {
        ans |= query(Lshift(now, 1)+ 1, l, min(r, mid));
    } if (r > mid) {
        ans |= query(Lshift(now, 1)+ 2, max(mid + 1, l), r);
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, q, qt;
    cin >> n >> s >> q;
    int i;
    construct(0, 1, n);
    rep(i, int(s.length())) {
        insert(0, i+1, (1 << (s[i] - 'a')));
    }
    rep(i, q) {
        cin >> qt;
        if (qt == 1) {
            int idx;
            char c;
            cin >> idx >> c;
            insert(0, idx, (1 << (c - 'a')));
        } else {
            int l, r;
            cin >> l >> r;
            int w = query(0, l, r);
            int cnt(0);
            // cout << w << endl;
            while(w) {
                if (w & 1) {
                    cnt++;
                }
                w >>= 1;
            }
            cout << cnt << endl;
        }
    }
}


Measured memory_bytes: 15260
def resolve():
    n, a, b = map(int, input().split())
    if a==0:
        print(0)
    else:
        i = n//(a+b)
        if (n-(a+b)*i) >= a:
            print(i*a+a)
        else:
            print(i*a+(n-(a+b)*i))
resolve()

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

int main(){
	bool prime[1000001];
	for(int i = 0; i < 1000001; i++) prime[i] = true;
	prime[0] = false;
	prime[1] = false;
	for(int i = 2; i < 1000; i++){
		for(int j = i*2; j < 1000001; j += i){
			prime[j] = false;
		}
	}

	int n;
	while(cin >> n){
		int count = 0;
		for(int i = 0; i <= n; i ++){
			if(prime[i]) count++;
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 2136
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	int a [3];
	int b [2];
	cin >> a[1] >> a[2] >> a[3] >> b[1] >> b[2];
	int c[6]= {a[1] + b[1], a[1] + b[2], a[2] + b[1], a[2] + b[2], a[3] + b[1], a[3] + b[2]};
	sort(c, c + 6);
	{for (int i = 0; i < 1; i++)
	    cout << c[i] - 50 << endl;
	}
	return 0;
}

Measured memory_bytes: 1176
//This disgusting code is wriiten by Juruo D0zingbear
//Please don't hack me! 0v0 <3
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string.h>
#include <stdio.h>
#define LL long long
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define piii pair<int, pii >
#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define vi vector<int>
#define vpi vector< pii >
#define INF 2147483647
#define big 19260817
#define pb push_back
#define mp make_pair
using namespace std;
const int Maxk=1005;
string mul(string a,string b){
	int res[Maxk];
	memset(res,0,sizeof(res));
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	for (int i=0;i<a.length();i++){
		for (int j=0;j<b.length();j++){
			res[i+j]+=(a[i]-'0')*(b[j]-'0');
		}
	}
	for (int i=0;i<Maxk;i++){
		if (res[i]>=10) {
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	string ret;
	bool flag=false;
	for (int i=Maxk-1;i>=0;i--){
		if (flag || res[i]){
			flag=true;
			ret=ret+(char)(res[i]+'0');
		}
	}
	if (ret=="") ret="0";
	return ret;
}
string add(string a,string b){
	if (a.length()<b.length()) swap(a,b);
	while (a.length()!=b.length()){
		b='0'+b;
	}
	for (int i=a.length()-1;i>=0;i--){
		a[i]+=(b[i]-'0');
		if (a[i]>'9' && i){
			a[i]-=10;
			a[i-1]++;
		}
	}
	if (a[0]>'9'){
		a[0]-=10;
		a='1'+a;
	}
	return a;
}

// cf IO: I64d
// atcoder IO: ｌｌｄ
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
int main(){
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	int n;
	scanf("%d",&n);
	if (a*2<b) b=a*2;
	if (b*2<c) c=b*2;
	if (c*2<d) d=c*2;
	long long cost=n/2;
	cost*=(LL)d;
	if (n%2==1){
		cost+=c;
	}
	printf("%lld\n",cost);
	return 0;
}

Measured memory_bytes: 256
import math
from itertools import accumulate

INF = float("inf")


def main():
    N, K = map(int, input().split())
    S = input()
    zero_list = []
    A = []
    one = 0
    zero = 0

    for i in range(N):
        if S[i] == '1':
            one += 1
            if zero != 0:
                A.append(zero)
                zero_list.append(zero)
                zero = 0
        else:
            zero += 1
            if one != 0:
                A.append(one)
                one = 0

    if one != 0:
        A.append(one)
    elif zero != 0:
        A.append(zero)
        zero_list.append(zero)

    if len(zero_list) <= K:
        print(N)
        return

    section = 0
    if S[0] == '1':
        section = 3 + (K-1) * 2
    else:
        section = 2 + (K-1) * 2

    B = list(accumulate([0] + A))
    # print(B)
    if S[0] == '1':
        # print(*A, section)
        m = 0
        i = 0
        while True:
            if i % 2 == 0:
                section = 3 + (K-1) * 2
                end = min(i+section, len(B) - 1)
                # print(B[end] - B[i])
                # print(end)
                m = max(m, B[end] - B[i])
                if len(B) - 1 <= end:
                    break
            else:
                section = 2 + (K-1) * 2
                end = min(i+section, len(B) - 1)
                # print(B[end] - B[i])
                # print(end)
                m = max(m, B[end] - B[i])
                if len(B) - 1 <= end:
                    break
            i += 1
        print(m)
    else:
        m = 0
        i = 0
        while True:
            if i % 2 == 0:
                section = 2 + (K-1) * 2
                end = min(i+section, len(B) - 1)
                # print(B[end] - B[i])
                # print(end, len(B) <= end - 1)
                m = max(m, B[end] - B[i])
                if len(B) - 1 <= end:
                    break
            else:
                section = 3 + (K-1) * 2
                end = min(i+section, len(B) - 1)
                # print(B[end] - B[i])
                # print(end, len(B) <= end - 1)
                m = max(m, B[end] - B[i])
                if len(B) - 1 <= end:
                    break
            i += 1
        print(m)


if __name__ == '__main__':
    main()


Measured memory_bytes: 49008
#include <iostream>
    #include <vector>
    #include <algorithm>
    #include <numeric>
     
    using namespace std;
     
    int main() {
      long long a,b,c;
      cin >> a >> b >> c;

	  long long ans=0;
      ans = (a - b + 1)/2;
      ans = (ans - 1) * (c-b);
      ans = ans + c + (a - b + 1)%2;

      long long d;
      d = a+1;
      if(ans > d){
        cout << ans << endl;
      } else {
        cout << d << endl;
      }
      return 0;
    }

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;

ll C[2100][2100];

int main(){
  for(int i=0;i<2100;i++){
    for(int j=0;j<=i;j++){
      if(j==0) C[i][j]=1;
      else C[i][j]=C[i-1][j]+C[i-1][j-1];
      C[i][j]%=MOD;
    }
  }

  int N,K;
  cin>>N>>K;

  for(int i=1;i<=K;i++){
    cout<<C[K-1][i-1]*C[N-K+1][i]%MOD<<endl;
  }
}


Measured memory_bytes: 33280
S = input()
T = input()

result = 10000
for i in range(len(S) - len(T) + 1):
  # print(i)
  start = i
  count = 0
  for j in range(len(T)):
    if T[j] != S[i + j]:
      count += 1
  result = min(count, result)

print(result)  
  

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define loop(i,start,n) for(int i=start;i<n;++i)
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v,f) sort(v.begin(), v.end(),f);
#define vint vector<int>
#define vvint vector<vector<int>>

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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}

int tendiff(int n){
  if(n%10==0) return n;
  rep(i,10){
    if((n+i)%10 == 0) return n+i;
  }
}

int main(){
  int ans=0;
  vint v(5);rep(i,5) cin >> v[i];
  VSORT(v,[](int x,int y) -> int {
          return ( tendiff(x)-x < tendiff(y)-y );
          }  );
  ans+=v[4];
  rep(i,4) ans+=tendiff(v[i]);
  

  cout << ans << endl;
  


  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		
		int a;
		int num=0;
		for(int i=0;i<N;i++){
			a = Integer.parseInt(sc.next());
			if(isPrime(a)) num++;
		}
		System.out.println(num);

	}
	
	public static boolean isPrime(int a){
		boolean warenai=true;
		for(int i=2;i<=Math.sqrt(a);i++){
			if(a%i==0) {
				warenai=false;
				break;
			}
		}
		return warenai;
	}

}

Measured memory_bytes: 40664
#include<stdio.h>
 
struct DICE {
    int top;
    int north;
    int south;
    int east;
    int west;
    int bottom;
};
 
struct DICE dice;
 
void N() {
    int num[6];
    num[0] = dice.top; num[1] = dice.south; num[2] = dice.east;
    num[3] = dice.west; num[4] = dice.north; num[5] = dice.bottom;
    dice.top = num[1]; dice.south = num[5]; dice.east = num[2];
    dice.west = num[3]; dice.north = num[0]; dice.bottom = num[4];
}
 
void S() {
    int num[6];
    num[0] = dice.top; num[1] = dice.south; num[2] = dice.east;
    num[3] = dice.west; num[4] = dice.north; num[5] = dice.bottom;
    dice.top = num[4]; dice.south = num[0]; dice.east = num[2];
    dice.west = num[3]; dice.north = num[5]; dice.bottom = num[1];
}
 
void E() {
    int num[6];
    num[0] = dice.top; num[1] = dice.south; num[2] = dice.east;
    num[3] = dice.west; num[4] = dice.north; num[5] = dice.bottom;
    dice.top = num[3]; dice.south = num[1]; dice.east = num[0];
    dice.west = num[5]; dice.north = num[4]; dice.bottom = num[2];
}
 
void W() {
    int num[6];
    num[0] = dice.top; num[1] = dice.south; num[2] = dice.east;
    num[3] = dice.west; num[4] = dice.north; num[5] = dice.bottom;
    dice.top = num[2]; dice.south = num[1]; dice.east = num[5];
    dice.west = num[0]; dice.north = num[4]; dice.bottom = num[3];
}
 
int main() {
    int nums[6];
    char command[101];
    for (int i = 0; i < 6; i++) {
        scanf("%d", &nums[i]);
    }
    dice.top = nums[0]; dice.south = nums[1]; dice.east = nums[2];
    dice.west = nums[3]; dice.north = nums[4]; dice.bottom = nums[5];
    scanf("%s", command);
    for (int i = 0; command[i] != '\0'; i++) {
        if (command[i] == 'N') N();
        else if (command[i] == 'S') S();
        else if (command[i] == 'E') E();
        else if (command[i] == 'W') W();
    }
 
    printf("%d\n", dice.top);
    return 0;
}


Measured memory_bytes: 2132
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
int main(){
  const int D=365,A=26;
  int z;
  scanf("%d",&z);
  vector<int> C(A);
  for(int i=0;i<A;i++){
    scanf("%d",&C[i]);
  }
  vector<vector<int>> S(D,vector<int>(A));
  for(int i=0;i<D;i++){
    for(int j=0;j<A;j++){
      scanf("%d",&S[i][j]);
    }
  }
  vector<int> X(A,0);
  vector<int> XX(A,0);
  vector<vector<pair<int,int>>> Q(D,vector<pair<int,int>>(A));
  for(int i=0;i<D;i++){
    for(int j=0;j<A;j++){
      X[j]+=C[j];
      XX[j]+=X[j];
      Q[i][j]=make_pair(-S[i][j]-X[j],j);
    }
    sort(Q[i].begin(),Q[i].end());
    XX[Q[i][0].second]-=X[Q[i][0].second];
    X[Q[i][0].second]=0;
  }
  vector<vector<int>> P(D,vector<int>(A));
  for(int i=0;i<D;i++){
    for(int j=0;j<A;j++){
      P[i][j]=Q[i][j].second;
    }
  }
  int SC=0,SC2;
  for(int i=0;i<D;i++){
    SC+=S[i][P[i][0]];
  }
  vector<int> Y;
  vector<int> YY;
  int Z;
  int SX,SY;
  z=-1;
  for(int l=0;l<169;l++){
    for(int k=0;k<25;k++){
      while(k==z){
        k=rand()%25;
      }
      z=k;
      for(int i=0;i<D;i++){
        SC2=SC;
        YY=XX;
        Y=X;
        SC2-=S[i][P[i][0]];
        SC2+=S[i][P[i][k+1]];
        for(int j=0;j<A;j++){
          Y[j]=0;
        }
        YY[P[i][0]]=0;
        YY[P[i][k+1]]=0;
        for(int j=0;j<D;j++){
          if(i==j){
            Z=P[j][k+1];
          }else{
            Z=P[j][0];
          }
          Y[P[i][0]]+=C[P[i][0]];
          Y[P[i][k+1]]+=C[P[i][k+1]];
          Y[Z]=0;
          YY[P[i][0]]+=Y[P[i][0]];
          YY[P[i][k+1]]+=Y[P[i][k+1]];
        }
        SX=0;
        SY=0;
        for(int j=0;j<A;j++){
          SX+=XX[j];
          SY+=YY[j];
        }if((SC2-SY+rand()%(int(3500-10.0302*l)))>(SC-SX)){
          P[i].insert(P[i].begin(),P[i][k+1]);
          P[i].erase(P[i].begin()+k+2,P[i].begin()+k+3);
          XX=YY;
          SC=SC2;
        }
      }
    }
  }
  /*
  int uku=0;
  for(int i=0;i<A;i++){
    X[i]=0;
  }
  for(int i=0;i<D;i++){
    uku+=S[i][P[i][0]];
    for(int j=0;j<A;j++){
      X[j]+=C[j];
    }
    X[P[i][0]]=0;
    SX=0;
    for(int i=0;i<A;i++){
      SX+=X[i];
    }
    uku-=SX;
  }
  cout<<uku<<endl;
  */
  for(int i=0;i<D;i++){
    cout<<P[i][0]+1<<"\n";
  }
}

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


int main(){

    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    ll ans = 1<<30;
    for(int i=0;i<=100000;i++){
        ll n = i*2*C+max(0, X-i)*A+max(0, Y-i)*B;
        ans = min(ans, n);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;

#define dlog(str) cout << "====" << str << endl;
#define INF 999999999
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define REPR(i, n) for(int i = n-1; 0 <= i; i--)
#define FOR(i, s, e) for(int i = s; i <= e; i++)
#define FORR(i, s, e) for(int i = s; e <= i ; i--)
#define LLI long long int
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main(){
    string s;
    cin>>s;
    int cnt=0;
    REP(i,s.length()){
        if(s[i]=='o'){
            cnt++;
        }
    }
    if(7<15-s.length()+cnt){
        cout<<"YES";
    }else{
        cout<<"NO";
    }
    return 0;
}

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

ll inf=1ll<<60;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll a,b;
	cin>>a>>b;
	if (a+b<10){
		cout<<a+b;
	}
	else {
		cout<<"error";
	}
	return 0;
}

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

int main() {
  int h,w;
  cin >> h >> w;
  vector<vector<char>> vec(h,vector<char>(w));
  int a = 0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
    cin >> vec.at(i).at(j);
    }
  }
  for(int i=0;i<h+w-1;i++){
    int k=0;
    for(int j=max(0,i-w+1);j<=min(i,h-1);j++){
      if(vec.at(j).at(i-j)=='#'){
        k++;
      }
      if(k==2){
        a = 1;
        break;
      }
    }
  }
  if(a==0)
        cout << "Possible" << endl;
  else
        cout << "Impossible" << endl;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0; i < (end); i += 1)
#define all(x) (x).begin(),(x).end()
//#define len(array)  (sizeof(array)/sizeof((array)[0]))
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;
void _mod(ll &x){x = mod(x, MOD);}
//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}


#define int ll

class CRectangleCutting {
public:
void solve(std::istream& cin, std::ostream& cout) {
    int W, H ,x , y;
    cin >> W >> H >> x >> y;
    cout << setprecision(10) << fixed << W*H/2. << " " << (2*x==W && 2*y == H) << endl;
}
};


#undef int
int main() {
	CRectangleCutting solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
 int i,j,cd,cr;
 while(1)
 {
   scanf("%d%d", &cd, &cr);
   if(cd==0 && cr==0)
    return 0;
   for(i=0; i<cd; i++)
   {
    for(j=0; j<cr; j++)
    {
     if(((i+j)%2!=0))
      printf(".");
     else printf("#");
    }
    printf("\n");
   }
   printf("\n");
  }
return 0;
}

Measured memory_bytes: 572
#include<cstdio>
#include<cstring>
const int INF=1e9+7;
int main()
{
    int m;
    int a[100004];
    while(scanf("%d",&m)!=EOF)
    {
    	memset(a,0,sizeof(a));
        for(int i=1;i<=m;i++)
        {
        	int b;
        	scanf("%d",&b);
            a[b]++;
		}
        if(m%2==1)
        {
        	int ant=0;
        	for(int i=2;i<=m;i+=2)
        	{
        		if(a[i]==2)
        		ant++;
			}
			if(ant==(m-1)/2&&a[0]==1)
			{
				int ans=1;
				for(int i=1;i<=ant;i++)
				ans*=2,ans=ans%INF;
				printf("%d\n",ans);
			}
			else
			printf("0\n");
		}
		else
		{
			int ant=0;
        	for(int i=1;i<=m;i+=2)
        	{
        		if(a[i]==2)
        		ant++;
			}
			if(ant==m/2&&a[0]==0)
			{
				int ans=1;
				for(int i=1;i<=ant;i++)
				ans*=2,ans=ans%INF;
				printf("%d\n",ans);
			}
			else
			printf("0\n");
		}
	}
return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define N 200001
using namespace std;
int n,a[N],size[N],jp[N];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		a[x]=i;
	}
	for(int i=1;i<=n;i++)
		size[i]=0,jp[i]=i;
	set<int> s;s.clear();
	for(int i=1;i<=n;i++)
		s.insert(i);
	long long ans=0;
	for(int i=1;i<n;i++)
	{
		s.erase(a[i]);
		long long sum=0,l,r;
		if(s.upper_bound(a[i])!=s.end())
			r=*s.upper_bound(a[i]);
		else
			r=0;
		if(s.upper_bound(a[i])!=s.begin())
			l=*--s.upper_bound(a[i]);
		else l=0;
		if(l)
			sum+=1ll*(size[l-1]+1)*(size[a[i]+1]+1);
		if(r)
			sum+=1ll*(size[a[i]-1]+1)*(size[r+1]+1);
		int _l=jp[a[i]-1],_r=jp[a[i]+1];
		if(!size[_l]) _l++;if(!size[_r]) _r--;
		int _sz=size[_l]+size[_r]+1;
		size[_l]=size[_r]=_sz;jp[_l]=_r;jp[_r]=_l;
		ans+=1ll*sum*i;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6144
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };

    let ans = (N - 1) / 2;

    println!("{}", ans);
}


Measured memory_bytes: 4352
import math


def num_divisors_table(n):
    table = [0] * (n + 1)

    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1

    return table

N = int(input())


summ = 0

summ = sum(num_divisors_table(N-1))
print(summ)

Measured memory_bytes: 16500
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)


int main(){
    int N;
    cin>>N;
    ll A[110000],X[110000],S=0;
    for(int i=1;i<=N;i++){
        cin>>A[i];
        S+=A[i];
    } 
    for(int i=2;i<=N;i+=2){
        S-=A[i]*2;
    }
    X[1]=S;
    X[N+1]=S;
    for(int i=1;i<N;i++){
        X[i+1]=(A[i]-X[i]/2)*2;
    }
    for(int i=1;i<=N;i++){
        if(i!=1) cout<<" ";
        cout<<X[i];
    }
    cout<<endl;

}



Measured memory_bytes: 2944
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;

int main() {
    int n; cin >> n;
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        int p; cin >> p;
        if (i != p) cnt++;
    }
    cout << (cnt == 2 || cnt == 0 ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
S = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'
S = S.replace(', ', ' ').split()
K = int(input())
print(int(S[K-1]))

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int A,B;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B;
	if(A>=13) cout<<B<<endl;
	else if(A>=6) cout<<B/2<<endl;
	else cout<<0<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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


int main() {
 #define int long long
  int N,K;
  
  cin >> K >> N;
  vector<int>A(N);
  vector<int>B(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  B[0]=K-A[N-1]+A[0];
  for(int i=1;i<N;i++){
    B[i]=A[i]-A[i-1];
  }
  std::sort(B.begin(), B.end());
  
  cout << K-B[N-1]<< endl;

}

Measured memory_bytes: 3328
#include <iostream>

int main() {
  long long a, b, k;
  std::cin >> a >> b >> k;
  if (a <= k) {
    k -= a;
    a = 0;
    b = std::max(0LL, b-k);
  } else {
    a -= k;
  }
  std::cout << a << " " << b << std::endl;
  
  return 0;
} 

Measured memory_bytes: 3600
import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)

X = ni()

a = X // 500
b = (X % 500 ) //5 

print(a * 1000 + b * 5 )


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
//#define scanf scanf_s

int main()
{
	vector<int> v;
	int n;
	while (cin >> n)
	{
		if (n != 0) v.push_back(n);
		else
		{
			cout << v.back() << endl;
			v.pop_back();
		}
	}
	return 0;
}

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

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

  int N; cin >> N;
  vector<ll> P(N); for (ll i = 0; i < N; i++) cin >> P[i];
  vector<int> A(N, 1);
  ll m = P[0];
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    if (P[i] <= m) ans++;
    m = min(m, P[i]);
  }
  cout << ans << '\n';
  return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	string s;
	set<int> Set;
	cin>>s;
	for(char c:s) 
		Set.insert(c);
	cout<<(int(Set.size())==int(s.size())?"yes\n":"no\n");
}




Measured memory_bytes: 3612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            List<String> input = Arrays.asList(br.readLine().split(" "));
            int normalAppleCount = Integer.parseInt(input.get(0));
            int errorAppleCount = Integer.parseInt(input.get(1));

            int applePieCount = (normalAppleCount * 3 + errorAppleCount) / 2;

            System.out.println(applePieCount);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 20308
#define _CRT_SECURE_NO_WARNINGS 
#include <stdio.h>

main() {
	int cnt;
	long int seed, min, max, sum;

	scanf("%d", &cnt);
	if (cnt < 0 || cnt>10000) return 1;

	sum = 0;
	for (int i = 0; i<cnt; i++) {
		scanf("%ld", &seed);
		if (seed < -1000000 || seed > 1000000) { return 1; }
		if (i == 0) min = max = seed;
		if (max < seed) max = seed;
		if (min > seed) min = seed;
		sum = sum + seed;
	}
	printf("%ld %ld %ld\n", min, max, sum);

	return 0;
}


Measured memory_bytes: 2104
import java.util.Scanner;

public class Main {

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

        int N = sc.nextInt();
        int[] a = new int[N+2];
        for (int i=0; i<N; i++) {
            a[i+1] = sc.nextInt();
        }

        int[] ans = solve(N, a);

        for (int i=0; i<N; i++) {
            System.out.println(ans[i]);
        }
    }

    private static int[] solve(int N, int[] a) {
        int[] ans = new int[N];
        int total = 0;

        for (int i=0; i<N+1; i++) {
            total += Math.abs(a[i+1] - a[i]);
        }

        for (int i=1; i<N+1; i++) {
            ans[i-1] = total - Math.abs(a[i] - a[i-1]) - Math.abs(a[i] - a[i+1]) + Math.abs(a[i+1] - a[i-1]);
        }

        return ans;
    }
}

Measured memory_bytes: 69576
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  string N;
  cin>>N;
  bool f=true;
  REP(i,N.size())if(N[i]!=N[N.size()-1-i])f=false;
  cout<<(f?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<long long,long long> pll;

int main() {
    fastIO;
    int a, b, aux = 1, rta = 0;
    cin >> a >> b;
    a--;
    while(aux < b){
        aux += a;
        rta++;
    }
    cout << rta << endl;
    return 0;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 1e17;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;
bool compare(pll a, pll b){

}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, m;
    cin >> n >> m;
    vector<pll> baito(n);
    rep(i,n){
        ll a, b;
        cin >> a >> b;
        baito[i] = mp(a, b);
    }
    sort(all(baito));
    int idx = 0;
    multiset<ll> cando;
    ll ans = 0;
    repr(i,m-1,-1){
        while (idx<n && baito[idx].F<=(m-i)){
            cando.insert(baito[idx].S);
            idx++;
        }
        if (cando.empty())
            continue;
        auto itr = cando.end();
        itr--;
        ans += *itr;
        cando.erase(itr);
    }
    cout << ans << ENDL;
}

Measured memory_bytes: 6528
def solve(s):
    n = len(s)
    l = [0] * (n+1)
    r = [0] * (n+1)
    for i in range(n):
        l[i+1] = l[i]
        if s[i] == ">":
            l[i+1] = 0
        else:
            l[i+1] += int(s[i] == "<")
    for i in range(n-1, -1, -1):
        r[i] = r[i+1]
        if s[i] == "<":
            r[i] = 0
        else:
            r[i] += int(s[i] == ">")
    return sum([max(l[i], r[i]) for i in range(n+1)])

s = input()
print(solve(s))

Measured memory_bytes: 31904
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

int ctoi(char c){return c - '0';}

bool isOk(ll key,ll value){
  return key >= value;
}

ll binary_search(vector<ll> a,ll key){
  ll ok = a.size()-1;
  ll ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

bool isPrime(ll n) {
	for (int i = 2; n >= i * i; ++i) {
		if(!(n % i))return false;
	}
  return true;
}
vector<ll> primes(ll n){
  vector<ll> v(1,1);
  for (ll i = 2; n >= i * i; ++i) {
		if(!(n % i)){
      v.pb(i);
	  }
  }
  if(v.size()==1)v.pb(n);
  return v;
}


int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  ll n,m;cin>>n>>m;

  ll ans = 1;
  for(ll i = 2;i*i <= m;++i){
    int cnt = 0;
    while(m%i==0){
      if(++cnt == n){
        ans*=i;
        cnt = 0;
      }
      m/=i;
    }
  }
  if(n==1)ans*=m;
  print(ans);
  return 0;
} 

Measured memory_bytes: 256
n,m = map(int, input().split())
neighbors = {key:[] for key in range(1, n+1)}
answers = {key:0 for key in range(1, n+1)}
answers[1] = 1
for i in range(m):
    a,b = map(int, input().split())
    neighbors[a].append(b)
    neighbors[b].append(a)

def register(hs):
    newhs = []
    for h in hs:
        for i in neighbors[h]:
            if answers[i] == 0:
                answers[i] = h
                newhs.append(i)
    return newhs

hosts = [1]
while True:
    hosts = register(hosts)
    if len(hosts) == 0:
        break

flag = 0
for key, item in answers.items():
    if item == 0:
        flag = 1
if flag == 0:
    print("Yes")
    for key, item in answers.items():
        if key != 1:
            print(item)
else:
    print("No")

Measured memory_bytes: 104632
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)
	L := make([]int, 2*N)
	for i := range L {
		fmt.Scan(&L[i])
	}
	sort.Ints(L)
	ans := 0
	for i := 0; i < len(L)-1; i += 2 {
		ans += min(L[i], L[i+1])
	}
	fmt.Println(ans)
}

func min(a, b int) int {
	if a >= b {
		return b
	}
	return a
}


Measured memory_bytes: 512
package main

import (
	"fmt"
	"math"
)

var mod = pow(10, 9) + 7
var A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z int
var ans int = 0

func main() {
	m := make(map[string]int)
	var str string
	fmt.Scan(&str)

	for i := 0; i < len(str); i++ {
		m[string(str[i])]++
	}

	var cnt int
	for _, value := range m {
		if value != 2 {
			fmt.Println("No")
			return
		}
		cnt++
	}
	if cnt == 2 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

/*  ----------------------------------------  */

func lcm(x, y int) int {
	return (x / gcd(x, y)) * y
}

func gcd(x, y int) int {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans, cnt int = 1, 0
	for cnt < y {
		ans *= (x - cnt)
		cnt++
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }
func ceil(x int) int   { return int(math.Ceil(float64(x))) }

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i] > a[j] }


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<algorithm>
#include<list>
#include<cmath>
#include<iomanip>
#include<queue>
#include<functional>
#include<climits>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<set>
#include<typeinfo>
 
#include<chrono>
#include<initializer_list>
using namespace std;
 
const double pi=4*atan(1.0);
 
constexpr long long mod=static_cast<long long>(1e9+7);
 
int main() {
	long long N,K,A;
 
	cin >> N >> K ;
        
        A=K;
        
	for(int i=1;i<N;i++)
		A*=(K-1);
	
	
	cout<<A<<endl;
 
	
 
	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_utility.hpp>
#include <utility>
#include <boost/foreach.hpp>
#include <cmath>

class UnionFind {
public:
  std::vector<int> parent, height, count;
  UnionFind(const int node_size) : parent(node_size), height(node_size, 0), count(node_size, 1) {
    for (int i = 0; i < node_size; i++) {
      parent[i] = i;
    }
  }
  // O(α(N))
  int Find(const int x) {
    if (parent[x] == x) {
      return x;
    }
    else {
      // 経路圧縮
      return parent[x] = Find(parent[x]);
    }
  }
  // O(α(N))
  void Union(int x, int y) {
    x = Find(x), y = Find(y);
    if (x == y) {
      return;
    }
    // ランク
    if (height[x] < height[y]) {
      parent[x] = y;
      count[y] += count[x];
    }
    else {
      parent[y] = x;
      count[x] += count[y];
      if (height[x] == height[y]) {
        ++height[x];
      }
    }
  }
};

long long int N, M, first;
long long int A[100000 + 1], B[100000 + 1];
std::vector<long long int> ans;

void func1() {
  long long int tmp = 1;
  tmp = N * (N - 1);
  tmp /= 2;
  first = tmp;
  ans.push_back(tmp);
}

void func2() {
  UnionFind uf(N);
  for (long long int i = M; i >= 2; i--) {
    if (uf.Find(A[i] - 1) != uf.Find(B[i] - 1)) {
      first -= uf.count[uf.Find(A[i] - 1)] * uf.count[uf.Find(B[i] - 1)];
    }
    ans.push_back(first);
    uf.Union(A[i] - 1, B[i] - 1);
  }
}

int main() {
  std::cin >> N >> M;
  for (int i = 1; i <= M; i++) {
    std::cin >> A[i] >> B[i];
  }

  func1();
  func2();

  for (long long int i = ans.size() - 1; i >= 0; i--) {
    std::cout << ans[i] << std::endl;
  }

  return 0;
}

Measured memory_bytes: 6920
N = 100

class Problem
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  def initialize
    @a,@b = gets.split.map(&:to_i)
    @g = Array.new(N) do |i|
      Array.new(N) do |i|
        i < N / 2 ? 1 : 0
      end
    end
  end

  def plot(left,n,color)
    n.times do |i|
      y = i / (N/5)
      x = i % (N/5)
      g[y*2][x*2+left] = color
    end
  end

  def solve
    plot(0, a-1, 0)
    plot(N/2+1, b-1, 1)
    g
  end

  def show(ans)
    puts [N,N].join(" ")
    ans.each do |row|
      puts row.join.tr("10","#.")
    end
  end
end

Problem.new.instance_eval do
  show(solve)
end

Measured memory_bytes: 14376
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  ll sum = 0;
  rep(i,n){
    ll x;
    cin >> x;
    a[i] = x;
    sum ^= x;
  }
  rep(i,n){
    cout << (sum^a[i]);
    if(i < n-1) cout << " ";
    else cout << endl;
  }
}

Measured memory_bytes: 4796
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
 
int main() {
  int N , K , Q ;
  cin >> N >> K >> Q ;
  vector<int> A(Q);
  rep(i,Q) cin >> A.at(i) ;
  map<int,int> mp;
  rep(i,N) mp[i+1] = 0 ;
  rep(i,Q) mp[A.at(i)] = mp[A.at(i)] +1 ;
  for (auto p : mp ){
    int key = p.first ;
    int value = p.second ;
    //cout  << key << "の出た回数は" <<value << endl;
    if( K - Q + value >= 1) cout << "Yes" << endl;
    else cout << "No" << endl;
    
  }
}
  

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

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int a, b, c; cin >> a >> b >> c;
	int k; cin >> k;
	for(int i = 0; i < k; i++){
		if(a >= b) b *= 2;
		else c *= 2;
	}
	if(a < b && b < c) cout << "Yes" << endl;
	else cout << "No" << endl;
} 

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

int m[200000+20+1];

int main() {

    int n;

    scanf("%d", &n);

    while (n--) {
        int a, b;
        scanf(" %d %d",&a,&b);
        m[a+b]++;
    }

    for(int i=0;i<200000+20;i++){
        m[i+1] += m[i]/2;
        m[i] = m[i]%2;
        if(m[i]>0){
            cout << i << " " << 0 << endl;
        }
    }



    return 0;
}

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

int main() {
	int N,sum,w,t;
	cin >> N;
	sum = 0;
	w = 1;
	for(int i=0; i<8; i++){
		t = N / w;
		sum += t % 10;
		w = w*10;
	}
	if( N % sum == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;using int32=int_fast32_t;using uint32=uint_fast32_t;using int64=int_fast64_t;using uint64=uint_fast64_t;using pi=pair<int32,int32>;using pll=pair<int64,int64>;using vi=vector<int32>;using vvi=vector<vector<int32>>;using vll=vector<int64>;using ll=int64;using ull=uint64;
#define all(x) x.begin(),x.end()
inline int read(){int x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
struct A{
    ll t,d;
    int s=0;
};
void Main(){
    int N = read();
    int K = read();
    vector<struct A> a(N);
    for(int i=0;i<N;i++){
        a[i].t = read();
        a[i].d = read();
    }
    sort(all(a), [](const auto& lhs, const auto& rhs) {return lhs.d > rhs.d;});
    vi U(N+1,0);
    ll D=0;
    for(int i=0;i<N;i++) if(U[a[i].t] == 0){
        if(i<K) D++;
        U[a[i].t]++;
        a[i].s++;
    }
    vi C1(N,0), C2(N,0);
    int j=0;
    for(int i=K-1;i>0;i--) if(a[i].s==0) C1[j++]=i;
    j=0;
    for(int i=K;i<N;i++) if(a[i].s==1) C2[j++]=i;
    ll ans, T = 0;
    for (int h = 0; h < K; h++) T += a[h].d;
    ans = T + D * D;
    ll Ans = ans;
    for(int i=0;i<=K;i++) if((C1[i]==0)||(C2[i]==0)) break;
    else{
        swap(a[C1[i]], a[C2[i]]);
        ans += D*2+1+a[C1[i]].d-a[C2[i]].d;
        Ans = max(Ans, ans);
        D++;
    }
    printf("%lld\n", Ans);
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}


Measured memory_bytes: 4992
#include <bits/stdc++.h> 
using namespace std;
typedef vector<int> int_vector;
typedef vector< vector<int> > int_matrix;
typedef vector<string> string_vector;
typedef vector< vector<string> > string_matrix;

int main(){
    int h, n, sum=0;
    cin >> h >> n;
    for (int i=0; i<n; i++){
        int a;
        cin >> a;
        sum+=a;
        if (sum >= h) break;
    }
    if (h>sum) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);

		int a=sc.nextInt();
		String op=sc.next();
		int b=sc.nextInt();

		if(op.equals("-")) {
			System.out.println(a-b);
		}

		else if(op.equals("+")) {
			System.out.println(a+b);
		}
	}
}

Measured memory_bytes: 24148