akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){ 
  int n,m;
  cin >> n >> m;
  vector<int> a(n),b(m);
  rep(i,n){ cin>>a[i]; }
  rep(i,m){ cin>>b[i]; }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());

  int ch=-1;
  rep(i,n){ if(ch==a[i]){cout << 0 << endl; return 0;} ch=a[i];}
  ch=-1;
  rep(i,m){ if(ch==b[i]){cout << 0 << endl; return 0;} ch=b[i];}
  
  int cnt=n*m;
  auto itma = lower_bound(a.begin(),a.end(),cnt);
  auto itmb = lower_bound(b.begin(),b.end(),cnt);
  if((itma != a.end() && *itma == cnt) && (itmb != b.end() && *itmb == cnt)){}else{cout << 0 << endl; return 0;}
  auto itna = lower_bound(a.begin(),a.end(),cnt-1);
  auto itnb = lower_bound(b.begin(),b.end(),cnt-1);
  if((itna != a.end() && *itna == cnt-1) || (itnb != b.end() && *itnb == cnt-1)){}else{cout << 0 << endl; return 0;}
  
  mint ans=1;
  
  while(cnt>=a[0] || cnt >=b[0]){
    auto ita = lower_bound(a.begin(),a.end(),cnt);
    auto itb = lower_bound(b.begin(),b.end(),cnt);
    if((ita != a.end() && *ita == cnt) && (itb != b.end() && *itb == cnt)){//both
      cnt--;
      continue;
    }
    if(ita != a.end() && *ita == cnt){//only a
      int pos = b.end()-itb;
      ans *= pos;
      cnt--;
      continue;
    }
    if(itb != b.end() && *itb == cnt){//only b
      int pos = a.end()-ita;
      ans *= pos;
      cnt--;
      continue;
    }
      int pos = (a.end()-ita)*(b.end()-itb)-(n*m-cnt);        // neither
      ans *= pos;
      cnt--;
      continue;
  }
  
  while(cnt>0){ ans *= cnt; cnt--;}
  cout << ans.x << endl;
  return 0;
}

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

int main( void )
{
    int a, b, c;
    cin >> a >> b >> c;
    if ( b / a >= c )
    {
        cout << c << endl;
    }
    else
    {
        cout << b / a << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n; cin>>n;
    vector <pair <int,int>> d(n);
    for(int i=0;i<n;i++){
        int a,b; cin>>a>>b;
        d[i]=make_pair(a,b);
    //    cout<<d[i].first<<' '<<d[i].second<<endl;
    }
    sort(d.begin(),d.end());
    int ans=0;
    ans+=d[0].first-1;
    //cout<<ans<<endl;
    for(int i=d[0].first;i<=d[n-1].first;i++) ans++;
    //cout<<ans<<endl;
    ans+=d[n-1].second;
    cout<<ans<<endl;
}

Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int m = sc.NextInt();

        List<int>[] from = new List<int>[n];
        for (int i = 0; i < n; i++)
        {
            from[i] = new List<int>();
        }

        for (int i = 0; i < m; i++)
        {
            int a = sc.NextInt() - 1;
            int b = sc.NextInt() - 1;
            from[a].Add(b);
            from[b].Add(a);
        }

        bool ok = false;
        foreach (var a in from[0])
        {
            if (from[a].Contains(n - 1))
            {
                ok = true;
            }
        }

        string answer = ok ? "POSSIBLE" : "IMPOSSIBLE";

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 39748
n = int(input())
alp = ["a","b","c","d","e","f","g","h","i","j"]
ans = []
cnt = 0
def dfs_rec(prev,cnt): # prev は前までの文字列 cntは文字種数を持つ
    if len(prev) == n:
        ans.append("".join(prev))
        return
    for i in range(cnt+1):
        dfs_rec(prev+[alp[i]],cnt+(i//cnt)) # この再帰呼び出しの際にprevが書き換わる？


dfs_rec(["a"],1)
ans.sort()
for s in ans:
    print(s)


Measured memory_bytes: 12656
#include<stdio.h>
int main(){
	int fami,kind,need[100],chi[100];
	int i,j,judge=0,temp;
	
	for(;;judge=0){
		for(i=0;i<100;i++){
			need[i]=0;
			chi[i]=0;
		}
		
		scanf("%d%d", &fami, &kind);
		
		if(fami==0&&kind==0)break;
		
		for(i=0;i<kind;i++)scanf("%d", &chi[i]);
		
		for(i=0;i<fami;i++){
			for(j=0;j<kind;j++){
				scanf("%d", &temp);
				need[j]+=temp;
			}
		}
		
		for(i=0;i<kind;i++){
			if(chi[i]-need[i]<0){
				judge=1;
				break;
			}
		}
		if(judge==0)puts("Yes");
		else puts("No");
	}
	return 0;
}

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

int main() {
    char c;
    cin >> c;
    int det = c - 'A';
    if (det >= 0 && det < 26) {
        cout << 'A' << endl;
    } else {
        cout << 'a' << endl;
    }
}

Measured memory_bytes: 3592
n=gets.to_i
x = gets.split(' ').map(&:to_i)

min=100000000000000000000
min_can=0

for i in 1..100
  min_can=0
  for j in 0..n-1
    min_can+=((i-x[j])**2).abs
  end
  min = min_can if min_can < min
end

puts min


Measured memory_bytes: 1788
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int N = Integer.parseInt(scan.next());

        int ans = 0;
        for(int i = 0; i < N; i++){
            ans += Integer.parseInt(scan.next()) -1;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 26324
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}
//---------------------------------------------------
int n, m;
string s;
H a[300000];
vector<int>e[300000];
bool b[300000];
signed main() {
	cin >> n >> m >> s;
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		e[u].push_back(v);
		e[v].push_back(u);
		if (s[u - 1] == 'A') a[v].fs++;
		else a[v].sc++;
		if (s[v - 1] == 'A') a[u].fs++;
		else a[u].sc++;
	}
	queue<int>q;
	for (int i = 1; i <= n; i++) {
		if (a[i].fs == 0 || a[i].sc == 0) {
			q.push(i);
		}
	}
	int ans = n;
	while (!q.empty()) {
		int t = q.front(); q.pop();
		if (b[t]) continue;
		b[t] = 1; n--;
		for (auto g : e[t]) {
			if (s[t - 1] == 'A') a[g].fs--;
			else a[g].sc--;
			if (a[g].fs == 0 || a[g].sc == 0) q.push(g);
		}
	}
	if (n == 0) cout << "No\n";
	else cout << "Yes\n";
}

Measured memory_bytes: 20228
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word
// also tink all answers possible for a question
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
#define sz 100005
ll inf = 1e9;
ll power(ll x, ll n, ll mod)
{
  ll res = 1;
  x %= mod;
  while (n)
  {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res%mod;
}
int main()
{
 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  ll n;
  cin>>n;
  string str;
  map<string,ll> m;
  for(ll i=0;i<n;i++)
  {
    cin>>str;
    m[str]++;
  }
  ll maxm=-1*(1e9);
  for(auto i=m.begin();i!=m.end();i++)
  {
    maxm=max(maxm,i->second);
  }
  for(auto i=m.begin();i!=m.end();i++)
  {
    if(i->second==maxm)
      cout<<i->first<<'\n';
  }
  return 0;
}

Measured memory_bytes: 19212
A, B, C = map(int, input().split())

mod = []
a = A
i = 1
while a*i % B not in mod:
    mod.append(a*i % B)
    i += 1
# ここまでAの倍数をBで割ったときに得られる余りを全てリストに追加した。

if C in mod:
    print('YES')
else:
    print('NO')

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

int main()
{
  int n;
  while(cin >> n,n)
    {
      deque<long long> p,j;
      p.resize(n),j.resize(n-1);     
      long long sum = 0;
      for(int i=0;i<n;i++)
	cin >> p[i],sum += p[i];
      for(int i=0;i<n-1;i++)
	cin >> j[i];
      sort(j.begin(),j.end(),greater<long long>());
      long long mex = n*sum;
      while(!j.empty())
	{
	  --n;
	  long long renew = 0;
	  sum -= p.front(), renew += p.front(); p.pop_front();
	  sum -= p.front(), renew += p.front(); p.pop_front();
	  renew += j.front(); j.pop_front();
	  sum += renew;
	  p.push_front(renew);
	  if(mex <= n*sum)
	    {
	      mex = max(mex,n*sum);
	    }
	 
	}
      cout << mex << endl;
    }
  return 0;
}

Measured memory_bytes: 2296
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;

int gcd(int a, int b){
    if(a == 0 || b == 0) return a + b;
    return gcd(b, a % b);
}

void solve(){
    int n;
    cin >> n;
    int ans;
    cin >> ans;
    for(int i = 1; i < n; i++){
        int x;
        cin >> x;
        ans = gcd(ans, x);
    }
    cout << ans;
}


int main(){
    int q = 1;
    //cin >> q;
    while(q--) solve();
}
// vse dolzhny vyiti v internet po hhtp


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define int long long
#define ll long long
#define mod (int)1000000007
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define all(V) V.begin(),V.end()
#ifdef int
constexpr int INF = LLONG_MAX / 10;
#else
constexpr int INF = INT_MAX / 10;
#endif
constexpr double eps = DBL_EPSILON;
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
using namespace std;
inline int gcd(int a, int b) {
	while (b) {
		int c = a;
		a = b; b = c % b;
	}
	return a;
}
inline int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
bool isprime(int n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
int mypow(int a, int b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	int memo = mypow(a, b >> 1);
	return memo * memo;
}
int modpow(int a, int b, int m = mod) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	int memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
string s;
int q, t, f;
char c;
deque<char> deq;
signed main() {
	cin >> s >> q;
	rep(i, s.size())deq.push_back(s[i]);
	int inv = 0;
	rep(i, q) {
		cin >> t;
		if (t == 1)inv ^= 1;
		else {
			cin >> f >> c;
			if ((f + inv) % 2)deq.push_front(c);
			else deq.push_back(c);
		}
	}
	if (inv)reverse(all(deq));
	rep(i, deq.size()) {
		cout << deq[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 896
N, K = map(int, input().split())
A = list(map(int, input().split()))

mi = 0
ma = 10**9
while(ma - mi != 1):
    c = 0
    mid = (ma + mi) // 2
    for i in range(N):
        c += A[i] // mid - (A[i] % mid == 0)
    if c > K:
        mi = mid
    else:
        ma = mid
print(ma)

Measured memory_bytes: 93956
import sys,math,collections,itertools
input = sys.stdin.readline

N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
cd = A[0]
for a in A:
    cd = math.gcd(cd,a)
if K<=max(A) and K%cd == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 21132
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=1e9;
const long long LINF=1e18;
#define int long long
//template
template <typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
//main
signed main(){
  int a,b;cin>>a>>b;
  int now=1;
  for(int i=0;;i++){
    if(now>=b)fin(i);
    now+=a-1;
  }
}


Measured memory_bytes: 256
from collections import defaultdict
def solve(points):
    N = len(points)
    X = defaultdict(list)
    Y = defaultdict(list)

    for i,(x,y) in enumerate(points):
        X[x].append(i)
        Y[y].append(i)
    
    res = 0
    visited = [False]*N
    for p0 in range(N):
        if visited[p0]:
            continue
        stack = [p0]
        visited[p0] = True
        xx = set()
        yy = set()
        while stack:
            p = stack.pop()
            x,y = points[p]
            xx.add(x)
            yy.add(y)

            for q in X[x]:
                if not visited[q]:
                    visited[q] = True
                    stack.append(q)
            for q in Y[y]:
                if not visited[q]:
                    visited[q] = True
                    stack.append(q)
        res += len(xx)*len(yy)
    return res-N




if __name__ == '__main__':
    N = int(input())
    points = [tuple(map(int,input().split())) for _ in range(N)]
    print(solve(points))

Measured memory_bytes: 116976
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<fstream>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
class node {
public:
	vector<int> edge_to;
	vector<int> edge_idx;
};
class tmp {
public:
	int node_idx;
	int from_node_idx;
	int edge_col_idx;
	tmp(int node_idx, int from_node_idx, int edge_col_idx) :
		node_idx(node_idx),
		from_node_idx(from_node_idx),
		edge_col_idx(edge_col_idx)
	{};
};
int main() {
	int n;
	cin >> n;
	vector<node> nodes(n);
	REP(i, n - 1) {
		int a, b;
		cin >> a >> b;
		nodes[a - 1].edge_to.push_back(b - 1);
		nodes[a - 1].edge_idx.push_back(i);
		nodes[b - 1].edge_to.push_back(a - 1);
		nodes[b - 1].edge_idx.push_back(i);
	}
	int max_idx = 0;
	int max_col = 0;
	REP(i, n) {
		if (nodes[i].edge_to.size() > max_col) {
			max_col = nodes[i].edge_to.size();
			max_idx = i;
		}
	}
	vector<int> color(n - 1);
	deque<tmp> deq;
	deq.push_back(tmp(max_idx,-1,-1));
	while (deq.size() > 0) {
		int node_idx = deq.front().node_idx;
		node now_node = nodes[node_idx];
		int from_idx = deq.front().from_node_idx;
		int edge_col = deq.front().edge_col_idx;
		deq.pop_front();
		int col_idx = 0;
		REP(i, now_node.edge_to.size()) {
			if (now_node.edge_to[i] != from_idx) {
				if (col_idx == edge_col)
					col_idx++;
				color[now_node.edge_idx[i]] = col_idx;
				deq.push_back(tmp(now_node.edge_to[i], node_idx, col_idx));
				col_idx++;
			}
		}
	}
	cout << max_col << endl;
	REP(i, n - 1) {
		cout << color[i] + 1 << endl;
	}
	return 0;
}


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


unsigned long long gcd(int p, int q){
  if(p % q == 0) return q;
  return gcd(q, p%q);
}

unsigned long long lcm(int p, int q){
  return p / gcd(p,q) * q;
}

int main(){
  int A,B;
  cin >> A >> B ;

cout << lcm(A,B) << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin >> N;
    rep(i, 1, 10) {
        rep(j, 1, 10) {
            if (i * j == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return (0^_^0);
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# IMPORT ###############################################################################################################
import sys                                                      # システム
sys.setrecursionlimit(10**6)                                    # 再帰処理の上限変更
from collections import deque, Counter                          # キュー・個数カウント
from itertools   import accumulate, permutations, combinations  # 累積和・順列・組み合わせ
from operator    import itemgetter                              # ソート補助
from bisect      import bisect_left, bisect_right, bisect       # 二分探索
from heapq       import heappop, heappush                       # プライオリティキュー
from fractions   import gcd                                     # 最大公約数
from math        import ceil, floor, sqrt, cos, sin, tan, pi    # 数学処理
from copy        import deepcopy                                # オブジェクトコピー
import numpy         as np                                      # 数値計算

# MAIN #################################################################################################################
def main():
    # Init #############################################################################################################
    im = InputManager()
    # Input ############################################################################################################
    n, k = im.inputMultiple()
    s = im.inputSingle(dtype=str)
    # Logic ############################################################################################################
    if s[k-1] == 'A':
        s = s[:k-1] + 'a' + s[k:]
    if s[k-1] == 'B':
        s = s[:k-1] + 'b' + s[k:]
    if s[k-1] == 'C':
        s = s[:k-1] + 'c' + s[k:]
    # Output ###########################################################################################################
    print(s)
    # Return ###########################################################################################################
    return

# INPUT MANAGER ########################################################################################################
class InputManager(object):
    def __init__(self):
        pass

    @staticmethod
    def inputSingle(dtype=int):
        return dtype(input())
    
    @staticmethod
    def inputMultiple(dtype=int, aslist=False):
        if aslist:
            return list(map(dtype, input().split()))
        else:
            return map(dtype, input().split())

    @staticmethod
    def input2D(h, dtype=int):
        return [list(map(dtype, input().split())) for i in range(h)]

# CALL MAIN ############################################################################################################
main()

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

int n, m;
int deg[100010];

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()
{
	n = read();
	m = read();

	for(int i = 1; i <= m; i ++)
	{
		int x, y;
		x = read();
		y = read();
		deg[x] ++;
		deg[y] ++;
	}

	for(int i = 1; i <= n; i ++)
		if(deg[i] % 2 == 1) {cout << "NO" << endl; return 0;}
	cout << "YES" << endl;

	return 0;
}


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

namespace lisson2
{
    class Program
    {
        static void Main(string[] args)
        {
            // 整数の入力
            int N = int.Parse(Console.ReadLine());
            if (!(0 <= N && N <= 100)) return;
            string[] arare = Console.ReadLine().Split(' ');
            var set = new HashSet<string>(); 
            for(int i = 0; i< N; i++)
            {
                set.Add(arare[i]);
            }
            if (set.Count == 3)
            {
                Console.WriteLine("Three");
            }else if(set.Count ==4)
            {
                Console.WriteLine("Four");
            }
        }
    }
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

int n;
char str[2333];
bool t[4];

int main()
{
	scanf("%s", str + 1); n = strlen(str + 1);
	for (int i = 1; i <= n; ++i)
	{
		if (str[i] == 'W') t[0] = 1;
		if (str[i] == 'E') t[1] = 1;
		if (str[i] == 'N') t[2] = 1;
		if (str[i] == 'S') t[3] = 1;
	}
	puts(t[0] == t[1] && t[2] == t[3] ? "Yes" : "No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  string s;
  cin >> s;

  int n = s.size();
  rep(i, n) cout << (s[i] == ',' ? ' ' : s[i]);
  cout << endl;

  
  return 0;
}

Measured memory_bytes: 256
K, N = map(int, input().split())
A = list(map(int, input().split()))
diff = [A[i+1] - A[i] for i in range(N-1)]
if 0 in A:
    diff.append(K- A[-1])
else:
    diff.append(A[0] + K - A[-1])


print(sum(diff) - max(diff))

Measured memory_bytes: 26420
n, x, y = map(int, input().split())
c = [0 for _ in range(1, n)]
for i in range(1, n+1):
  for j in range(1, n+1):
    if i <= j:
      continue
    a = i - j
    b = abs(j - x)+1+abs(i - y)
    if a < b:
      c[a-1] += 1
    else:
      c[b-1] += 1
for e in c:
  print(e)

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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)

int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int cnt=0;
    for(int i=1;i<n-1;i++)
    {
        if(max3(a[i-1],a[i],a[i+1])==a[i] or min3(a[i-1],a[i],a[i+1])==a[i])continue;
        else cnt++;
    }
    cout<<cnt;

}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int a,b,c;
  cin >> a >> b >> c;
  cout << a*b/2 << endl;
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))


def f(x):
    if all([a == 0 for a in x]):
        return 0
    elif min(x) == 0:
        x0 = x.index(0)
        if x0 == 0:
            return f(x[1:])
        elif x0 == len(x) - 1:
            return f(x[:-1])
        else:
            return f(x[:x0]) + f(x[x0 + 1:])
    else:
        return f([a - 1 for a in x]) + 1


print(f(h))

Measured memory_bytes: 42220
import math
N,W = list(map(int, input().split(" ")))

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


dp = [[0 for _ in range(W+1)] for _ in range(N + 1) ]
#dp[今何個目か][重さ何キロ持つか] = その時の価値の最大値
dp[0][0] = 0

for i in range(W+1): #重さ i のときに得られる価値
    for j in range(N):  # j 個目の荷物で
        w,v = items[j]
        if i >= w: # w > i だと前提が破綻するので
            #遷移 d[j + 1][i] =  (d[j][i - w] + v ) 新しい荷物を選んだ場合
            dp[j + 1 ][i] = dp[j][i - w]  + v  # dp[j][i - w]  + v → j 個持ったところに、更に 価値v のitemが追加されて j+ 1になった
        dp[j + 1][i] =  max(dp[j + 1][i] ,dp[j][i]) #選ばなかった場合

print(dp[N][W])

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

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    vector<pair<int,int> > tenbou(M);
    vector<bool> good(N, true);
    rep(i,M){
        cin >> tenbou[i].first >> tenbou[i].second;
        tenbou[i].first--;
        tenbou[i].second--;
        if (vec[tenbou[i].first] >= vec[tenbou[i].second]){
            good[tenbou[i].second] = false;
        }
        if (vec[tenbou[i].first] <= vec[tenbou[i].second]){
            good[tenbou[i].first] = false;
        }
    }
    int ans = 0;
    rep(i,N){
        if (good[i]) ans++;
    }
    cout << ans << endl;
}


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

 
int main() {
   int n;
   cin>>n;
   vector<int> p(n);
   rep(i,n)cin>>p[i];
   int count=0;
   rep(i,n-2){
       if((p[i]<p[i+1]&&p[i+1]<p[i+2])||(p[i]>p[i+1]&&p[i+1]>p[i+2]))count++;
   }
   cout<<count<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int asc(const void *n, const void *m){
    return *(long long*) n-*(long long*)m;
}
long long gcd(long long x,long long y){
    if(x%y==0) return y;
    else return gcd(y,x%y);
}
int main(void){
    long long n,i,j;
    scanf("%lld",&n);
    long long a[n];
    for(i=0;i<n;i++) scanf("%lld",&a[i]);
    qsort(a,n,sizeof(a[0]),asc);
    long long min = a[0];
    for(i=1;i<n;i++) min = gcd(min,a[i]);
    printf("%lld",min);
}

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

struct edge {
  edge () {}
  edge (int to, int cost) : to(to), cost(cost) {}

  int to, cost;
};

vector<long long> Dijkstra(int s, const vector<vector<edge>> &G) {
  const long long linf = 1001001001001001001ll;
  vector<long long> d(G.size(), linf);
  priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q;

  d[s] = 0;
  q.push(make_pair(0, s));

  while (!q.empty()) {
    pair<long long, int> p = q.top();
    q.pop();

    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i = 0; i < G[v].size(); ++i) {
      edge e = G[v][i];
      if (d[e.to] > p.first + e.cost) {
        d[e.to] = p.first + e.cost;
        q.push(make_pair(d[e.to], e.to));
      }
    }
  }

  return d;
}

int main() {
  int n, m, r;
  cin >> n >> m >> r;

  vector<vector<edge>> G(n);
  for (int i = 0; i < m; ++i) {
    int u, v, c;
    cin >> u >> v >> c;

    G[u].push_back(edge(v, c));
    // G[v].push_back(edge(u, c));
  }

  vector<long long> d = Dijkstra(r, G);
  for (int i = 0; i < d.size(); ++i) {
    if (d[i] == 1001001001001001001ll) cout << "INF" << endl;
    else cout << d[i] << endl;
  }
}

Measured memory_bytes: 14344
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <string>
#include <string.h>
#include <map>
#include <math.h>
#include <vector>
#include <set>
#include <map>
#include <deque>
using namespace std;
typedef long long ll;
const int N=1e5+9;
struct sa
{
    int x;
    int y;
};
int l,r;
map<int,int>mp;
int main()
{
    int n,m;
    while(scanf("%d %d",&n,&m)!=-1)
    {
        int p,q;
        scanf("%d %d",&l,&r);
        if(m==1)
        {
            cout<<r-l+1<<endl;
            continue;
        }
        for(int i=2;i<=m;i++) {
            scanf("%d %d", &p, &q);
            if(p>l)
                l=p;
            if(q<r)
                r=q;
        }
        if(l>r)
            cout<<0<<endl;
        else
        cout<<r-l+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define X first
#define Y second
#define PB push_back
#define ll long long
#define pii pair<ll,ll>
#define MEM(x,y) memset(x,y,sizeof(x))
#define bug(x) cout<<"debug "#x" is "<<x<<endl;
#define FIO ios::sync_with_stdio(false);
#define ALL(x) x.begin(),x.end()
#define LOG 20
#define lson(x) ((x)<<1)
#define rson(x) ((x)<<1|1)
using namespace std;
#define vi vector<int>
const int maxn = 2e5+7;
const ll mod=998244353;
ll a[maxn],b[maxn],c[maxn];
int main(){
    FIO
    ll n,k,ans=0;
    cin>>k>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=1;i<n;i++) ans=max(a[i]-a[i-1],ans);
    ans =max(ans,k+a[0]-a[n-1]);
    cout<<k-ans<<endl;
	return 0;
}


Measured memory_bytes: 2944
from collections import deque

N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())
ifUsed = deque()

s = 0
p = 0
r = 0
for i in range(K):
    ifUsed.append(1)
    if T[i] == 'p':
        p += 1
    elif T[i] == 'r':
        r += 1
    elif T[i] == 's':
        s += 1

for i in range(K, N):
    isUsed = ifUsed.popleft()
    if T[i] == T[i-K] and isUsed:
        ifUsed.append(0)
    else:
        ifUsed.append(1)
        if T[i] == 'p':
            p += 1
        elif T[i] == 'r':
            r += 1
        elif T[i] == 's':
            s += 1

print(S*p + R*s + P*r)


Measured memory_bytes: 4764
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)

    val n, m = sc.nextInt()
    val hs = Array.fill(n)(sc.nextInt())
    val map = Array.fill(n)(Set.empty[Int])

    (0 until m).foreach { _ =>
      val a, b = sc.nextInt()
      map(a - 1) = map(a - 1) + (b - 1)
      map(b - 1) = map(b - 1) + (a - 1)
    }

    var ans = 0L

    hs.zipWithIndex.foreach {
      case (elem, index) =>
        if (map(index).isEmpty) ans += 1
        else if (elem > map(index).map(j => hs(j)).max) ans += 1
    }

    println(ans)

  }

  def debug(args: Any*): Unit = {
    Console.err.println(args.mkString(" "))
  }

  def printExecTime(process: => Unit): Unit = {
    val start = System.currentTimeMillis
    process
    debug("処理時間： " + (System.currentTimeMillis - start) + " ミリ秒")
  }

}


Measured memory_bytes: 87120
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 1000000007
#define ll long long int
#define pair <ll, ll> pi
#define vector <ll> vi
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define SQ(a) (a) * (a)
#define ordered_set tree<ll, null_type, greater_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> //greater_equal<ll> or less<ll>
// find_by_key()   order_of_key()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
/*bool comp(string a, string b) {
if (a.size() != b.size()) return a.size() < b.size();
return a < b;
}*/

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen('input.txt', 'r', stdin);
    //freopen('output.txt', 'w', stdout);
    ll i, j, k, n, m, b, d, t, ans = 0,a,x,y;
    cin>>n>>m>>k;
    if(n-k>=0){
        n-=k;
        cout<<n<<" "<<m<<endl;
    }
    else{
        
        k=k-n;
        n=0;
        if(m-k>=0){
            m=m-k;
        }
        else{
            m=0;
        }
        cout<<n<<" "<<m<<endl;
    }
    return 0;
}

Measured memory_bytes: 3656
#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>;

const int MOD = 998244353;
const int N = 200000, K = 10;

int n, k, l[K], r[K];
int dp[2 * N];

int main() {
  cin >> n >> k;
  rep(i, k) cin >> l[i] >> r[i];
  for (int i = 1; i <= n; i++) dp[i] = 0;
  dp[1] = 1;
  dp[2] = -1;
  for (int i = 1; i < n; i++) {
    rep(j, k) {
      dp[i + l[j]] = (dp[i + l[j]] + dp[i]) % MOD;
      dp[i + r[j] + 1] = (dp[i + r[j] + 1] - dp[i]) % MOD;
    }
    dp[i + 1] = (dp[i + 1] + dp[i]) % MOD;
  }
  if (dp[n] < 0) dp[n] += MOD;
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 5144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
/* REPmacro */
#define rep(i, a, n) for (ll i = (a); i < (ll)(n); ++i)

signed main() 
{
    int h,w,d;
    cin >> h >> w >> d;
    ll dp[90001];
    int px[90001],py[90001];
    rep(i,0,h) rep(j,0,w)
    {
        int tmp; cin >> tmp;
        px[tmp]=j,py[tmp]=i;
    }
    int q; cin >> q;
    for(ll i=d+1;i<=h*w;++i)
    {
        dp[i]=dp[i-d]+abs(px[i]-px[i-d])+abs(py[i]-py[i-d]);
    }
    rep(i,0,q)
    {
        int l,r;
        cin >> l >> r;
        cout << dp[r]-dp[l] << endl;
    }
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};

const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

vector< vector<int> > Graph;
vector< int > value;





int main(int argc, const char * argv[]) {
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
   
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    rep(i,n) ans += a[i]-1;
    
    cout << ans << endl;
    
}



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

int main() {
  int n, m;
  cin >> n >> m;
  
  ll ans = 1;
  for(int i=0; i<n; i++) {
    if(i==0) ans *= m;
    else ans *= m-1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

int n;

string a[11],b[11];
string s,t;

int solve(){
	set<string> st;
	queue<pair<string,int>> q;
	q.push({s,0});
	st.insert(s);
	while(q.size()){
		auto p=q.front(); q.pop();
		if(t==p.first)return p.second;
		string ss=p.first;
		for(int i=0;i<n;i++){
			string r="";
			for(int j=0;j<ss.size();j++){
				if(a[i]==ss.substr(j,a[i].size())){
					r+=b[i];
					j+=(int)(a[i].size()-1);
				}
				else{
					r+=ss[j];
				}
			}
			if(t.size()<r.size())continue;
			if(st.find(r)==st.end()){
				st.insert(r);
				q.push({r,p.second+1});
			}
		}
	}
	return -1;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	while(cin >> n,n){
		for(int i=0;i<n;i++){
			cin >> a[i] >> b[i];
		}
		cin >> s >> t;
		printf("%d\n",solve());
	}
}


Measured memory_bytes: 3512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
    int to;
    int cost;
};

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<edge>> v(n);
    rep(i, m)
    {
        int l, r, d;
        cin >> l >> r >> d;
        l--;
        r--;
        edge e;
        e.cost = d;
        e.to = r;
        v[l].push_back(e);
        e.to = l;
        e.cost = -d;
        v[r].push_back(e);
    }
    vector<ll> dp(n, 1e18);
    queue<int> que;
    for (int i = 0; i < n; i++)
    {
        if (dp[i] != 1e18)
        {
            continue;
        }
        dp[i] = 0;
        que.push(i);
        while (!que.empty())
        {
            int it = que.front();
            que.pop();
            for (auto e : v[it])
            {
                if (dp[e.to] == 1e18)
                {
                    dp[e.to] = dp[it] + e.cost;
                    que.push(e.to);
                }
                else
                {
                    if (dp[e.to] != dp[it] + e.cost)
                    {
                        cout << "No" << endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 9728
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int N = s.nextInt();
        int a = 0, w = 0, t = 0, r = 0;
        for (int i = 0; i < N; i++ ){
            String str = s.next();
            if(str.equals("AC")) a++;
            if(str.equals("WA")) w++;
            if(str.equals("TLE")) t++;
            if(str.equals("RE")) r++;
        }

        System.out.println("AC x " + a);
        System.out.println("WA x " + w);
        System.out.println("TLE x " +t);
        System.out.println("RE x " + r);
    }
}

Measured memory_bytes: 58940
#include <iostream>

using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[],int n,int left, int mid, int right) {
  int n1 = mid -left;
  int n2 = right - mid;
  for(int i=0;i<n1;i++) L[i] = A[left + i];
  for(int i=0;i<n2;i++) R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  int i=0, j=0;
  for(int k=left; k<right; k++) {
    cnt++;
    if(L[i]<=R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[],int n,int left,int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int main(void) {
  int A[MAX], n, i;
  cnt = 0;

  cin >> n;
  for(i=0;i<n;i++) cin >> A[i];

  mergeSort(A, n, 0, n);
  for(i=0;i<n;i++) {
    if(i)cout << " ";
    cout << A[i];
  }
  cout << endl;

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 6892
#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define forr(i,p,n) for(ll i=p;i<n;i++)
#define tam 310010
#define offset 30010
using namespace std;
typedef long long  ll;
typedef pair<ll,ll> ii;
typedef pair<map<int,int> ,int> mi;
typedef pair<ii,ii> iiii;
typedef vector<ll> vi;
const ll MOD=1e9+7;
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    string txt;
    cin>>txt;
    int tot=0;char ant='$';
    forr(i,0,txt.size())
    {
        if (txt[i]==ant)
            continue;
        tot++;
        ant=txt[i];
    }
    cout<<tot-1<<endl;

}

Measured memory_bytes: 512
N = gets.chomp.to_i
AS = gets.chomp.split(" ").map(&:to_i)
BS = []
1.upto(AS.size) do |i|
  BS << [i, AS[i - 1]]
end

BS.sort! { |a, b| a[1] <=> b[1] }

puts BS.map{ |b| b[0] }.join(" ")


Measured memory_bytes: 19952
li=list(map(int,input().split()))
li.sort()
if (li[1]-li[0])%2==1:
    print(int(li[2]-li[1]+1+(li[1]-li[0]+1)/2))
else:
    print(int(li[2]-li[1]+(li[1]-li[0])/2))
    
        



Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String[] data1 = (sc.nextLine()).split(" ");
        String[] data2 = (sc.nextLine()).split(" ");
        int n1 = Integer.parseInt(data2[0]);
        int n2 = Integer.parseInt(data2[1]);
        String str = sc.nextLine();
        if(str.equals(data1[0])){
            n1--;
        } else {
            n2--;
        }
        System.out.println(n1 + " " + n2);
    }
}


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

using ll=long long;
using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> a(n+1,0),cnt(n+1,0);
    
    rep(i,n+1){
        cin>>a[i];
        cnt[a[i]]=i;
    }
    
    rep(i,n+1) cout<<cnt[i]<<' ';
    return 0;
}

Measured memory_bytes: 3864