akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

int main(){
    ll h,w;
    cin >> h >> w;
    ll m;
    cin >> m;
    map<ll,ll> cw,ch;
    map<pair<int,int>,bool> sur;
    for(ll i = 0; i < m; i++){
        ll y,x;
        cin >> y >> x;
        y--;x--;
        cw[x]++;
        ch[y]++;
        sur[{y,x}] = true;
    }

    ll mh = -1,mw = -1;
    ll zh,zw;

    vector<ll> lh,lw;
    
    for(ll i = 0; i < h; i++){
        if(mh < ch[i]){
            mh = ch[i];
            zh = i;
            vector<ll> emp;
            swap(lh,emp);
            lh.push_back(zh);
        } else if(mh == ch[i]) lh.push_back(i);
    }
    for(ll i = 0; i < w; i++){
        if(mw < cw[i]){
            mw = cw[i];
            zw = i;
            vector<ll> emp;
            swap(lw,emp);
            lw.push_back(zw);
        } else if(mw == cw[i]) lw.push_back(i);
    }

    ll ans = -1;


    for(ll i = 0; i < (ll)lh.size(); i++){
        for(ll j = 0; j < (ll)lw.size(); j++){
            ll d = 0;
            if(!sur[{lh[i],lw[j]}]){
                cout << mh+mw << endl;
                return 0;
            } else ans = max(ans,mh+mw-1);
        }
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 67724
#include <bits/stdc++.h>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

const double PI  = 3.141592653589793238463;
const int MOD = 1000000007;
const Int INF = numeric_limits<Int>::max() / 3;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec){
        is >> x;
    }
    return is;
}

bool solve(int n){
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            if(i * j == n){
                return true;
            }
        }
    }
    return false;
}
int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int n;
    cin >> n;
    cout << (solve(n) ? "Yes" : "No") << "\n";

    return 0;
}


Measured memory_bytes: 256
# import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

H, W = map(int, input().split())
aHW = [list(input()) for _ in range(H)]

res = []
for h in aHW:
    if '#' in h:
        res.append(h)

res = list(zip(*res))
res2 = []
for h in res:
    if '#' in h:
        res2.append(h)

res2 = list(zip(*res2))

for h in res2:
    print(''.join(h))

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


int main()
{
	////////input///////

	ll x, y, z, k;
	cin >> x >> y >> z >> k;

	std::vector<ll> A(4000, 0);
	std::vector<ll> B(4000, 0);
	std::vector<ll> C(4000, 0);

	rep(i, x) cin >> A[i];
	rep(i, y) cin >> B[i];
	rep(i, z) cin >> C[i];

	////////sort/////////

	sort(A.begin(), A.end(), greater<ll>());
	sort(B.begin(), B.end(), greater<ll>());
	sort(C.begin(), C.end(), greater<ll>());

	/////////set//////////

	std::vector<ll> Score;

	for (int i = 0; i < x; ++i)
	{
		for (int j = 0; j < y; ++j)
		{
			for (int l = 0; l < z; ++l)
			{
				if ( (i + 1) * (j + 1) * (l + 1) <= k)
				{
					Score.push_back(A[i] +  B[j] + C[l]);
				}
				else
				{
					break;
				}	
			}
		}
	}

	sort(Score.begin(), Score.end(), greater<ll>());

	for (int i = 0; i < k; ++i) cout << Score[i] << endl;

	return 0;




}

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

int main() {
  int a[6];
  for(int i=0; i<6; i++) cin >> a[i];
  sort(a,a+4);
  sort(a+4,a+6,greater<int>());
  int ans=0;
  for(int i=1; i<5; i++) ans+=a[i];
  cout << ans << endl;
  return 0;
}

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

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	cout << min(b/a, c) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
	string S;
	cin>>S;
	int strLen=S.size();
	int strLen1=strLen/2;
	int ans=0;
	for (int i=0;i<strLen1;i++){
		int j=strLen-1-i;
		if (S[i]!=S[j]){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  cout << min(a,b) SP max(a+b-n,0) << endl;
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int64_t> A(n), S(n + 1);
    copy_n(istream_iterator<int64_t>(cin), n, A.begin());
    for (int i = 0; i < n; i++)
        S[i + 1] = S[i] + A[i];
    map<int64_t, int> C;
    int64_t ans = 0;
    for (const auto &s: S){
        ans += C[s];
        C[s]++;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 15872
n=int(input())
l=list(map(int,input().split()))
if len(set(l))==1:print(1);exit()
from itertools import groupby as gb
l=[a for a,b in gb(l)]
ans=1
now=0  if l[0]<l[1] else 1
pre=l[0]
n=len(l)
for i in range(n):
    if pre<l[i] and now:
        if i==n-1:print(ans+1);exit()
        else:
            now=0  if l[i]<l[i+1] else 1
            ans+=1
    elif pre>l[i] and 1-now:
        if i==n-1:print(ans+1);exit()
        else:
            now=0  if l[i]<l[i+1] else 1
            ans+=1
    pre=l[i]
print(ans)


Measured memory_bytes: 14736
#include <stdio.h>

int main(){

  int n,q,i,j,S[10000],T[500],count = 0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }

  for(j=0;j<q;j++){
    i=0;
    S[n] = T[j];
    while(S[i] != T[j]){
      i++;
    }
    if(i != n){
      count++;
    }
  }

  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define maxn 3200
using namespace std;
typedef long long LL;
LL f[maxn][maxn];
LL a[maxn];
int main(){
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	for(int i = 1; i <= N; i += 1) cin >> a[i];
	for(int L = 0; L < N; L += 1)
		for(int i = 1; i + L <= N; i += 1){
			f[i][L] = L ? max(- f[i + 1][L - 1] + a[i], - f[i][L - 1] + a[i + L]) : a[i];
		}
	cout << f[1][N - 1];
} 

Measured memory_bytes: 76032
sx, sy, tx, ty = gets.split.map(&:to_i)

x = tx - sx
y = ty - sy

puts "U"*y + "R"*x + "D"*y + "L"*(x+1) + "U"*(y+1) + "R"*(x+1) + "DR" + "D"*(y+1) + "L"*(x+1) + "U"

Measured memory_bytes: 1916
#include <stdio.h>
#define MAXSIZE 100

int main(void){
    int n, a[MAXSIZE];
    scanf("%d", &n);
    int sum = 0;
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
        sum += a[i];
    }
    
    int diff, diff_min = 1024;
    int num_out = 0;
    for(int i = 0; i < n; i++){
        diff = (sum > a[i] * n)? sum - n * a[i] : n * a[i] - sum;
        
        if(diff < diff_min){
            diff_min = diff;
            num_out = i;
        }
    }

    printf("%d\n", num_out);
    return 0;
}

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

int main()
{
    int n, ans = 0;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    sort(p.begin(), p.end());
    rep(i, n - 1)
        ans += p[i];
    ans += p[n - 1] / 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <vector>
using namespace std;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<vector<int>> g(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<int> color(n, -1);

  int sz = 0;
  function<bool(int, int)> Dfs = [&](int x, int c) {
    color[x] = c;
    sz++;
    bool res = true;
    for (int u : g[x]) {
      if (color[u] == -1) {
        if (!Dfs(u, c ^ 1)) res = false;
      } else {
        if (color[u] == color[x]) res = false;
      }
    }
    return res;
  };

  int iso = 0, bip = 0, oth = 0;
  for (int i = 0; i < n; ++i) {
    if (color[i] >= 0) continue;
    sz = 0;
    if (g[i].empty()) {
      ++iso;
    } else if (Dfs(i, 0)) {
      ++bip;
    } else {
      ++oth;
    }
  }
  long long ans = oth + 2 * bip + 1LL * oth * (oth - 1) +
                  1LL * bip * (2 * bip - 2) + 2LL * oth * bip +
                  1LL * iso * iso + 2LL * iso * (n - iso);
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 11776
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int ans[100000+5],turn[2];memset(ans,0,sizeof(ans));
	string s;
	cin>>s;
	for(int i=0;i<s.size()-1;i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			memset(turn,0,sizeof(turn));
			for(int j=i;j>=0;j--){
				if(s[j]=='R') turn[(i-j)%2]++;
			    else break;
			}
			
			for(int j=i+1;j<s.size();j++)
			{
				if(s[j]=='L')turn[(j-i)%2]++;
				else break;
			}
			ans[i]=turn[0];
			ans[i+1]=turn[1];
			
		}
	}
	for(int i=0;i<s.size();i++)cout<<ans[i]<<' ';
	return 0;
}

Measured memory_bytes: 1024
/* ex 9_1
   riverstone */

#include <stdio.h>
#include <stdlib.h>
//スタックに格納するデータの数(余分に取る)
#define SIZE 20
//プロトタイプ宣言
typedef struct stack stack;
void initialize_stack(stack *stk);
void push(stack *stk, char elem);
char pop(stack *stk);
void print_stuck(stack *stk);
 
//スタックの定義
typedef struct stack{
    int size;
    int count;
    char data[SIZE];
    char *top;
} stack;

//スタックの初期化
void initialize_stack(stack *stk){
    stk->count = 0;
    stk->size = SIZE;
    stk->top = &(stk->data[SIZE]);
}

//データの追加
void push(stack *stk, char elem){
    if(stk->count >= stk->size){
        fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
        exit(1);
    }
    else{
        stk->top--;
        *(stk->top) = elem;
        stk->count++;
    }
}

//データの取り出し
char pop(stack *stk){
    char latest;
    if(stk->count <= 0){
        fprintf(stdout, "Error: stack underflow.\n");
        exit(1);
    }
    else{
        latest = *(stk->top);
        stk->top++;
        stk->count--;
        return latest;
    }
}
 
//出力
void print_stuck(stack *stk){
    int i;
    for (i=0;i < stk->count;i++){
        printf("%c",stk->data[SIZE-i-1]);
    }
    printf("\n");
}

int main(void){
    stack stk;
    char keyboard_input[20];
    char *str;
 
    //スタックを初期化（ポインタ渡しで関数にわたすこと）
    initialize_stack(&stk);
 
    scanf("%s",keyboard_input);
    str = keyboard_input;
 
    //キーボード操作
    while(*str){
        
        if(*str != 'B'){
            //スタックにデータを追加
            push(&stk, *str);
        }
        else{
                if (stk.count >=1){ //->でやると大小比較などの演算子と間違えてエラー
                    //スタックからデータを取り出す
                    pop(&stk);
            }
        }
        str++;
    }
    print_stuck(&stk);
    return 0;
}
 


Measured memory_bytes: 1632
#include <iostream>
using namespace std;
#define MAX_AB 100000 + 10

int main() {
  long N, K;
  cin >> N >> K;

  long count[MAX_AB];
  for (int i = 0; i < MAX_AB; i++) {
    count[i] = 0;
  }

  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;

    count[a] += b;
  }


  long skip = 0;
  for (int i = 1; i < MAX_AB; i++) {
    skip += count[i];
    if (skip >= K) {
      cout << i << endl;
      return 0;
    }
  }


  return 0;
}


Measured memory_bytes: 1024
N,X = map(int,input().split())
L = list(map(int,input().split()))
zahyou = 0
count = 0

for i in range(N):
  if zahyou <= X:
    zahyou +=  L[i]
    count += 1
if zahyou <= X:
  count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch MustBeRectangular | diff MustBeRectangular.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address MustBeRectangular.cpp && ./a.out

/*
 
 6/22/2019
 
 6:23-6:40 give up
 
 6/23/2019
 
 14:40-15:20 read editorials and got AC
 
 
 
 */

const int MAX_N=1e5+1;
int X[MAX_N],Y[MAX_N];
int N;

int viz[2*MAX_N];
VI G[2*MAX_N];

set<int> A,B;
void dfs(int u) {
  if(viz[u]) return;
  viz[u]=1;
  if(u<MAX_N) A.emplace(u);
  else B.emplace(u);
  FORR(v, G[u]) dfs(v);
}

void solve() {
  REP(i,N) {
    int x=X[i],y=Y[i];
    G[MAX_N+x].push_back(y);
    G[y].push_back(MAX_N+x);
  }
  LL res=0;
  REP(i,MAX_N) if(!viz[i]) {
    A.clear(),B.clear();
    dfs(i);
    /*
    if(SZ(A)>1&&SZ(B)>1) {
      LL a=(LL)SZ(A)*SZ(B);
      FORR(x,A) a-=SZ(G[x]);
      res+=a;
    }*/
    res+=(LL)SZ(A)*SZ(B);
  }
  res-=N;
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  REP(i,N) {
    cin>>X[i]>>Y[i];
    --X[i],--Y[i];
  }
  solve();
  
  return 0;
}


Measured memory_bytes: 18944
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
    n,a,b = LI()
    s = S()
    cnt = 1
    cntb = 1

    for i in s:
        if i == "a":
            if cnt<=a+b:
                print("Yes")
                cnt+=1
            else:
                print("No")
        elif i == "b":
            if cnt<=a+b and cntb<=b:
                print("Yes")
                cnt+=1
                cntb+=1
            else:
                print("No")
        else:
            print("No")
main()

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

int n, m, k, add, ans, A[200001];
pair<int, int> pi[200001];
int main() {
	cin >> n >> k;
	rep(i, n) {
		cin >> m;
		A[m]++;
	}
	rep(i, 200001) {
		if (A[i] > 0) {
			pi[add] = make_pair(A[i], i);
			add++;
		}
	}
	sort(pi, pi + add);
	rep(i, add - k) ans += pi[i].first;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
typedef long long int lli;
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int a,b,c,min,max,minc,maxc;
    lli cost1,cost,x,y;
    cin>>a>>b>>c>>x>>y;
    
    if(x<y){
        min=x;
        max=y;
        minc=a;
        maxc=b;
    }
    else{
        min=y;
        max=x;
        minc=b;
        maxc=a;
        
    }
    
    
     if(2*c*max <= 2*c*min+(max-min)*maxc){
            cost1=2*c*max;
        } 
        else 
        cost1=2*c*min+(max-min)*maxc;
        if(max*maxc+min*minc <= cost1)
            cost=max*maxc+min*minc;
        else cost=cost1;
        
        cout<<cost;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
int main() {
    ll N;
    cin >> N;
    
    ll sum = (1+N)*N/2;
   
    cout << sum-N << endl;
   
    return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;

using ipair = pair<int, int>;

ll INF = 1e16+7;
ll mod = 998244353;

bool operator>(const ipair a,const ipair b){return a.first > b.first;}

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  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;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);

int main(){
  ll N, M, K;
  cin >> N >> M >> K;

  mint ans = 0;
  mint mul = M;
  for(int k=N-1; k>=0; --k){
    mint now = mul;
    now *= c(N-1, k);
    if(k <= K) ans += now;
    mul *= M-1;
  }

  cout << ans.x << endl;

  return 0;
}


Measured memory_bytes: 6248
import java.util.*;

class Dice
{
      String  top = "top";
      String  front = "front";
      String  left = "left";
      String  right= "right";
      String  back = "back";
      String  bottom = "bottom";
     void Dice()
     {
        
     }
     public String getTop()
     {
         return top;
     }
     public int proper(String a)
     { 
         if(a.compareTo("top")==0)
         {
             return 0;
         }
         if(a.compareTo("bottom")==0)
         {
             return 5;
         }
          if(a.compareTo("front")==0)
         {
             return 1;
         }
           if(a.compareTo("back")==0)
         {
             return 4;
         }
            if(a.compareTo("left")==0)
         {
             return 2;
         }
             if(a.compareTo("right")==0)
         {
             return 3;
         }
             return 0;
     }

    public void south()
    {
         String temp1 = top;
        String temp2 = bottom;
        top = back;
        bottom = front;
        front = temp1;
        back = temp2;
        
       
    }
    public void north()   //{"top", "front", "left", "right", "back", "bottom"};
    {
        String temp1 = bottom;
        String temp2 = top;
        top = front;
        bottom = back;
        front = temp1;
        back = temp2;
    }
    public void east()
    {
        String temp1 = top;
        String temp2 = bottom;
        top = right;
        bottom = left;
        left= temp1;
        right= temp2;
    }
    public void west()
    {
        String temp1 = top;
        String temp2 = bottom;
        top = left;
        bottom = right;
        left= temp2;
        right= temp1;
    }
}
class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        String [] arr = new String [6];
        
        for(int i = 0; i<6; i++)
        {
           arr[i] = sc.next();
        }
        String cmd = sc.next();
        char ch [] = cmd.toCharArray();
        Dice dc = new Dice();
       
        for(int i = 0; i<ch.length;i++)
        {
            switch(ch[i])
            {
                case 'S':
                dc.south();
                break;    
                
                case 'W':
                dc.west();
                break;    
                
                case 'N':
                dc.north();
                break;    
                
                case 'E':
                dc.east();
                break;    
            }
        }
        System.out.println(arr[dc.proper(dc.getTop())]);
    }
}




Measured memory_bytes: 26244
// B - Around Square

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	int ans = 0;

	for (ll i=1; i*i <= N; i++) {
		ans = i*i;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	long long a[10000], x, y, n, c;
	c = 0;
	while (1) {
		cin >> n;
		if (n == 0) { break; }
		for (int k = 0; k < n; k++) {
			cin >> a[k];
		}
		//sort(a,a+n);
		for (int j = 0; j < n; j++) {
			for (int i = 0; i < n -1; i++) {
				if (a[i] > a[i + 1]) {
					x = a[i];
					y = a[i + 1];
					a[i] = y;
					a[i + 1] = x;
				}
			}
		}
		for (int k = 0; k < n; k++) {
			c = c + a[k] * (n - (k + 1));
		}
		//cout << a[0] << a[1] << a[2] << a[3] << a[4] << endl;
		cout << c << endl;
		c = 0;
	}
	return 0;
}

Measured memory_bytes: 3144
#include<bits/stdc++.h>
#define Mo 1000000007
#define N 100000
#define pb push_back
#define mp make_pair
typedef long long LL;
typedef long double LD;
using namespace std;
struct nd {
	int u, v, l;
};
vector<nd> v;
int L;

int main() {
	cin >> L; int tmp = 1, d = 1;
	while (tmp * 2 <= L) tmp = tmp * 2, d++;
	for(int i = 1; i <= d - 1; i++) 
		v.pb(nd{i, i + 1, 0}), v.pb(nd{i, i + 1, 1 << (i - 1)});
	LL now = (1 << (d - 1)) - 1;
	for(int i = d - 2; i >= 0; i--)
		if (L & (1 << i)) {
			v.pb(nd{i + 1, d, now + 1});
			now += (1 << i);
		}
	cout << d  << " " << v.size() << endl;
	for(int i = 0; i < v.size(); i++)
		cout << v[i].u << " " << v[i].v << " " << v[i].l << endl;
} 


Measured memory_bytes: 256
import java.util.*;
public class Main {

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

		int n=in.nextInt(),r=in.nextInt(),q=in.nextInt();

		for(int i=0;i<n;i++)ls.add(i);
		ls.build();
		//ls.dump();

		for(int i=0;i<r;i++) {
			int a=Integer.parseInt(in.next());
			if(a%2==0) {
				for(int j=0;j<a;j++)ls.next();
			}
			else {
				for(int j=0;j<a;j++)ls.prev();
			}
			ls.remove();
			//ls.dump();
		}
		
		for(int i=0;i<q;i++) {
			System.out.println((ls.contains(Integer.parseInt(in.next()))? 1:0));
		}

	}

}

class node{
	int id;
	node prev,next;
	node(int v){
		id=v;
	}
}

class myRoopList{
	node EDG,NOW;
	int size=0,p=0;

	myRoopList(){
		EDG=new node(-1);
		EDG.prev=EDG;
		EDG.next=EDG;
	}

	void add(int v) {
		node NEW=new node(v);

		NEW.next=EDG;
		NEW.prev=EDG.prev;

		if(size==0)EDG.next=NEW;
		EDG.prev.next=NEW;
		EDG.prev=NEW;
		size++;
	}

	void build() {
		EDG.prev.next=EDG.next;
		EDG.next.prev=EDG.prev;
		NOW=EDG.next;
	}

	void next() {
		NOW=NOW.next;
	}

	void prev() {
		NOW=NOW.prev;
	}
	
	boolean contains(int v) {
		node now=EDG.next;
		int i=0;
		while(i<size) {
			if(now.id==v)return true;
			now=now.next;
			i++;
		}
		return false;
	}

	void remove() {
		NOW.prev.next=NOW.next;
		NOW.next.prev=NOW.prev;
		if(NOW==EDG.next)EDG.next=NOW.next;
		if(NOW==EDG.prev)EDG.prev=NOW.prev;
		NOW=NOW.next;
	
		size--;
	}

	void dump() {
		node now=EDG.next;
		System.out.print("[");
		int i=0;
		while(i<size) {
			System.out.print(" "+now.id);
			now=now.next;
			i++;
		}
		System.out.println("]");
	}
}


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

using namespace std;
typedef long long LL;

// count # (<= X)
LL check(const LL N, const LL X){
    LL right = N;
    LL p2 = 1;
    LL res = 0;
    LL mid = X;
    // printf("n = %lld x = %lld\n", N, X);
    while(right > 2){
        // [left, right]
        LL left = right / 3 + 1;
        if(left <= 2) left = 3;

        // [left, mid] (mid, right]
        if(mid > right) mid = right;
        // printf("left = %lld mid = %lld right = %lld\n", left, mid, right);

        // [left, mid]のうち奇数の個数
        if(!(left & 1)) left++;
        LL m = mid;
        if(!(m & 1)) m--;
        if(left <= m){
            res += ((m - left) >> 1) + 1;
        }

        right = right / 3;
        mid >>= 1;
        p2 <<= 1;
    }
    if(p2 <= X) res++;

    // printf("-> %lld\n\n", res);
    return res;
}

LL solve(LL N, LL K){
    if(K > (N + 1) / 2) return -1;
    if(N % 2 == 0) N--;
    LL lb = 0;
    LL ub = N;
    while(ub - lb > 1){
        LL x = (ub + lb) / 2;
        if(check(N, x) >= K){
            ub = x;
        }else{
            lb = x;
        }
    }
    return ub;
}
LL f(LL x, LL n){
    LL q = x;
    LL p2 = 1;
    while(3 * x <= n){
        x *= 3;
        p2 *= 2;
    }
    return q * p2;
}
LL solve2(LL N, LL K){
    if(N <= 2){
        if(K == 1) return 1;
        else return -1;
    }
    if(N % 2 == 0) N --;
    vector<LL> v;
    v.push_back(f(2, N));
    for(LL i = 3; i <= N; i += 2){
        v.push_back(f(i, N));
    }
    sort(v.begin(), v.end());
    if(v.size() < K) return -1;
    return v[K - 1];
}
vector<vector<int>> max(int n){
    int max_l = 0;
    vector< vector<int> > res;
    REP(s, 1 << (n - 1)){
        vector<int> v;
        REP(i, n - 1) if(s >> i & 1){
            v.push_back(i + 2);
        }
        bool ok = true;
        REP(i, v.size()) REP(j, i) if(v[i] % v[j] == 0) ok = false;
        if(ok){
            if(max_l < v.size()) {
                max_l = v.size();
                res.clear();
            }
            if(max_l == v.size()){
                res.push_back(v);
            }
        }
    }
    return res;
}
LL solve3(LL N, LL K){
    cout << N << " " << K << endl;
    if(N <= 2) {
        if(K == 1) return 1;
        else return -1;
    }
    vector<vector<int>> res = max(N);
    if(res[0].size() < K) return -1;
    return res[0][K - 1];
}

int main(){
    int C;
    cin >> C;
    while(C--){
        LL N, K;
        scanf("%lld %lld", &N, &K);
        printf("%lld\n", solve(N, K));
    }
    // for(int n = 1; n < 25; n++){
    //     for(int k = 1; k <= n; k++){
    //         printf("n = %d k = %d\n", n, k);
    //         LL x = solve(n, k);
    //         LL y = solve3(n, k);
    //         printf("x = %lld y = %lld\n", x, y);
    //         if(x != y){
    //             assert(false);
    //         }
    //     }
    // }
    return 0;
}

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

const ll INF = 1e18;

int main(){
  ll N; cin >> N;
  pair<ll, ll> f = make_pair(1, N);
  for(ll i=2; i<=sqrt(N)+1;i++){
    if(N%i==0){
      ll j=N/i;
      if(i+j<f.first+f.second)
        f = make_pair(i,j);
    }
  }
  cout << f.first+f.second -2;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;

using ll = long long;
using Pll = pair<ll, ll>;

ll INF = 1LL << 60;

ll division(ll a, ll b) {
    if(a < 0) {
        return - ((-a + b - 1) / b);
    }
    return a / b;
}

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

int main() {
    ll n, x, d;
    cin >> n >> x >> d;

    if(d == 0) {
        cout << ((x == 0) ? ll(1) : n+1) << endl;
        return 0;
    } else if(d < 0) {
        x *= -1;
        d *= -1;
    }

    map<ll, vector<Pll>> mp;
    for(ll i=0;i<=n;++i) {
        ll l = (i-1) * i / 2, r = (n-i) * i + l;
        mp[modulo(i*x, d)].emplace_back(division(i*x, d) + l, r - l);
    }

    ll ans = 0LL;
    for(auto itr=mp.begin();itr!=mp.end();++itr) {
        vector<Pll> v(itr->second);
        sort(v.begin(), v.end());
        // cerr << (itr->first) << endl;

        ll max_r = -INF;
        for(Pll p: v) {
        //     cerr << p.first * d + (itr->first) << " " << (p.first+p.second) * d + (itr->first) << endl;
            if(max_r < p.first) {
                ans += p.second + 1;
            } else {
                ans += max(0LL, p.second + 1 - (max_r - p.first + 1));
            }
            // cerr << ans << endl;
            max_r = max(max_r, p.first + p.second);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 22144
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define INF 1000 * 1000 * 1000
using namespace std;
int cnt0 = 100000, cnt1 = 1000;
string s;
int main()
{
	cin >> s;
	int n = s.size();
	cnt0 = cnt1 = n;
	for(int i = 0; i < n; i++)
	{
		if(s[i] == '0')
		{
			cnt0 = min(cnt0 , max(n - i - 1 , i));
		}
		else
		{
			cnt1 = min(cnt1 , max(n - i - 1 , i));
		}
		//cout << cnt0 << " " << cnt1 << endl;
	}
	cout << max(cnt0 , cnt1);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
 
#define INT_INF (2 * 1e9)
#define LL_INF  (2LL * 1e18)
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << endl;
#else
#define DBG(X)
#endif
 
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll mod = 1e9 + 7;

void solve()
{
	ld a, b;
	cin >> a >> b;

	cout << fixed << setprecision(12) << (a / b) << endl;
}

int main(int argc, char** argv)
{
	FAST_IO;
	solve();

	return 0;
}


Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define MAPFOR(it,m) for( auto it = (m).begin(); it != (m).end() ; ++it )
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

int main(void){
    string w;
    cin >> w;
    int n;
    n = w.size();
    map<char, int> m;
    REP(i, n) m[w[i]]++;

    MAPFOR(it,m) {
        if(it->second%2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<long> adj[100001];
long height[100001];
long parent[100001];
long size[100001];
long go(long now, long from, long h){
    height[now] = h;
    parent[now] = from;
    long ret= 1;
    for(long i = 0; i<adj[now].size(); i++){
        long to = adj[now][i];
        if(to!=from){
            ret += go(to,now,h+1);
        }
    }
    size[now] = ret;
    return ret;
}
int main() {
    
    std::ios::sync_with_stdio(false);
    
    long n;
    cin >> n;
    for(long i = 1; i<n; i++){
        long a, b;
        cin >> a >> b;
        a--;
        b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    go(0,-1,0);
    long hh = height[n-1];
    hh--;
    long now = n-1;
    for(long i = 0; i<hh/2; i++){
        now = parent[now];
    }
    if(size[now]>=(n+1)/2){
        cout << "Snuke" << endl;
    }
    else{
        cout << "Fennec" << endl;
    }
    
}

Measured memory_bytes: 15872
import sys

na1 = []

for i1 in range(5):
    na1.append(int(input()))

n1 = int(input())

for i2 in range(5):
    for i3 in range(5):
        if i3 <= i2:
            continue
        elif (na1[i3] - na1[i2]) > n1  :
            print(":(")
            sys.exit()

print("Yay!")

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

int main(){
    long long N, K;
    cin >> N >> K;

    long long p[N];
    long long ans = 0;

    for (int i = 0; i < N; i++){
        cin >> p[i];
    }
    sort(p, p+N);
    
    for (int i = 0; i < K; i++){
        ans += p[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)

ll power(ll x, unsigned ll y, unsigned ll m=MOD) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2, m) % m; 
    p = (p * p) % m; 

    return (y%2 == 0)? p : (x * p) % m; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m,y,z,p1,p2;
    cin>>n;
    vi ans(n,1),a(n);
    string s;
    cin>>s;
    reverse(all(s));
    z = 0;
    for(int i=0;i<n;i++){
        z+=(s[i]=='1');
    }
    p1 = z-1;
    p2 = z+1;
    x = 0;y = 0;
    for(int i=0;i<n;i++){
        if(s[i]=='1'){
            if(p1){
                x+=(power(2, i, p1));
                x%=p1;
            }
            y+=(power(2, i, p2));
            y%=p2;
        }
    }
    for(int i=0;i<n;i++){
        if(s[i]=='1'){
            a[i] = x;
            if(p1){
                a[i]-=power(2, i, p1);
                a[i]%=p1;
                if(a[i]<0)a[i]+=p1;
            }
            else{
                ans[i] = 0;
            }
        }
        else{
            a[i] = y;
            a[i]+=power(2, i, p2);
            a[i]%=p2;
            if(a[i]<0)a[i]+=p2;
        }
    }
    for(int i=0;i<n;i++){
        while(a[i]){
            ans[i]++;
            a[i]%=__builtin_popcountll(a[i]);
        }
    }
    reverse(all(ans));
    for(int i=0;i<n;i++){
        cout<<ans[i]<<"\n";
    }
    
    
    
    
    


    return 0;
}

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

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    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 { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    ll n, m;
    cin >> n >> m;
    ll ans;
    if (n >= 3 && m >= 3)
        ans = (n - 2) * (m - 2);
    else if (n == 2 || m == 2)
        ans = 0;
    else if (n == 1) {
        ans = m - 2;
        if (ans < 0)
            ans = 1;
    }
    else {
        ans = n - 2;
        if (ans < 0)
            ans = 1;
    }
    
    cout << ans << endl;
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int N;
	while(~scanf("%d", &N)) {
		if(N == 2) {
			puts("-1");
			continue;
		}
		vector<vi> ans(N);
		rep(i, N) rep(j, N) if(i != j)
			ans[i].push_back(j);
		mt19937 re;
		while(1) {
			bool ok = true;
			rep(j, N - 1) {
				rep(i, N) {
					int k = ans[i][j];
					if(ans[k][j] == i) {
						ok = false;
						swap(ans[i][j], ans[i][re() % (N - 1)]);
						swap(ans[k][j], ans[k][re() % (N - 1)]);
						goto break_;
					}
				}
			}
			break_:;
			if(ok) {
				rep(i, N) {
					rep(j, N - 1) {
						if(j != 0) putchar(' ');
						printf("%d", ans[i][j] + 1);
					}
					puts("");
				}
				break;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	const Int MOD = 1e9 + 7;
	string s;
	cin >> s;

	reverse(s.begin(), s.end());
	s = "." + s;
	vector<vector<Int>> dp(s.size(), vector<Int>(13, 0));
	dp[0][0] = 1;
	Int x = 1;
	for (int i = 1; i < s.size(); ++i) {
		for (int k = 0; k < 10; ++k) {
			if ((s[i] != '?') && (k != (int)(s[i] - '0'))) { continue; }
			for (int j = 0; j < 13; ++j) {
				Int idx = (j + k * x) % 13;
				(dp[i][idx] += dp[i - 1][j]) %= MOD;
			}
		}
		(x *= 10) %= 13;
	}
	cout << dp[s.size() - 1][5] % MOD << endl;

	return 0;
}


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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str[] = br.readLine().split(" ");
        int r = Integer.parseInt(str[0]);
        int c = Integer.parseInt(str[1]);
        int[][] a = new int[r+1][c+1];
        for(int i=0;i<r;i++){
            str = br.readLine().split(" ");
            for(int j=0;j<c;j++){
                a[i][j] = Integer.parseInt(str[j]);
                a[i][c] += a[i][j];
                a[r][j] += a[i][j];
            }
            a[r][c] += a[i][c];
        }
        for(int i=0;i<r+1;i++){
            for(int j=0;j<c+1;j++){
                if(j<c) System.out.print(a[i][j]+" ");
                else System.out.println(a[i][j]);
            }
        }
    }
}

Measured memory_bytes: 30764
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <stdio.h>

int main(void){
  int a,b,m,min=1000000,x,y,c,amin,bmin;
  std::cin >> a >> b >> m;
  std::vector<int> aa(a);
  std::vector<int> bb(b);
  for(int i=0;i<a;i++)std::cin >> aa[i];
  for(int i=0;i<b;i++)std::cin >> bb[i];

  for(int i=0;i<m;i++){
    std::cin >> x >> y >> c;
    min = (min < (aa[x-1] + bb[y-1] - c))?min:(aa[x-1] + bb[y-1] - c);
  }

  amin = *std::min_element(aa.begin(),aa.end());
  bmin = *std::min_element(bb.begin(),bb.end());
  min = (min < amin + bmin)?min:amin + bmin;

  std::cout << min;
  return 0;
}

Measured memory_bytes: 4044
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt(); 
        int[] abc = {1,2,3};
        for(int i = 0; i < 3; i++) {
            if(abc[i] == a || abc[i] == b) {
                continue;
            }else {
                System.out.println(abc[i]);
            }
        }
        
    }
}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
#define mem(x,v) memset(x,v,sizeof(x))
#define low(x) (x & (-x))
#define ll long long
const int N = 300000;
int c[N],d[N],n,k;
ll b[N];
struct node{
    int b;
    ll a;
}p[N];

bool cmp(const node &a, const node &b){
    if (a.a == b.a) return a.b < b.b;
    return a.a < b.a;
}
void add(int x){
    if (x == 0) {
        c[x]++;
        return;
    }
    while(x <= n){
        c[x]++;
        x += low(x);
    }
    return;
}
ll sum(int x){
    ll m = c[0];
    while(x > 0){
        m += c[x];
        x -= low(x);
    }
    return m;
}
int main() {
    ll ans = 0;
    int x;
    scanf("%d%d",&n,&k);
    for (int i = 1; i <= n; i++){
        scanf("%d",&x);
        p[i].a = p[i-1].a + x - k;
        p[i].b = i;
    }
    sort(p,p + n + 1,cmp);
    for (int i = 0; i <= n; i++)
        d[p[i].b] = i;
    for (int i = 0; i <= n; i++){
        if (d[i]>0) ans += sum(d[i]);
        add(d[i]);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 7168
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    long long a, b, k;
    cin >> a >> b >> k;

    auto cnt = min(a, k);
    a -= cnt;
    k -= cnt;
    cnt = min(b, k);
    b -= cnt;

    cout << a << " " << b << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long

using namespace::std;

int jo(ll int jxo, ll int jyo){
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){
  return (toxbig-0x20);
}
char tolow(char toxlow){
  return (toxlow+0x20);
}
  


int main(){
  int X,A,B;
  cin>>X>>A>>B;
  if(B<=A) cout<<"delicious";
  else if((B>A)&&(A+X+1>B)) cout<<"safe";
  else cout<<"dangerous";
}
// int *p = new int[N];

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {
	
	ll N;
	cin >> N;
	if (N == 0) {
		cout << 0 << endl; return 0;
	}
	vector<bool> AN;
	ll k = 1;
	while (N != 0) {
		if (N % (2*k) != 0) {
			AN.push_back(true);
			N -= k;
		}
		else {
			AN.push_back(false);
		}
		k *= -2;
	}
	rep(i, AN.size()) {
		cout << AN.at(AN.size() - i - 1);
	}
}

Measured memory_bytes: 3620
#include <stdio.h>
#include<iostream>
using namespace std;
int main()
{
    double a, r, s;
    cin >> a;
    r = a * a * 3.141592653589;
    s = 2 * a*3.141592653589;
    printf("%.6f %.6f\n", r, s);
    return 0;
}


Measured memory_bytes: 3212