akhauriyash/Code-Regression huggingface dataset:
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

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

// varibable settings
#define int long long
const int INF = 1e18;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (int i = (int)((b)-1); i >= (int)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T>
inline void chmax(T &a, const T &b) {
    if ((a) < (b)) (a) = (b);
}
template <class T>
inline void chmin(T &a, const T &b) {
    if ((a) > (b)) (a) = (b);
}

#define divceil(a, b) ((a) + (b)-1) / (b)
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x)    \
    sort(all(x)); \
    x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int, int> pii;
typedef tuple<int, int, int> iii;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
    }
} fast;
void check_input() {
    assert(cin.eof() == 0);
    int tmp;
    cin >> tmp;
    assert(cin.eof() == 1);
}

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"

vi divisor(int n) {  // 約数全列挙{{{
    vi p, q;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            p.pb(i);
            if (i * i != n) q.pb(n / i);
        }
    }
    reverse(all(q));
    p.insert(p.end(), all(q));
    return p;
}  //}}}

signed main() {
    //input
    int x;cin>>x;

    auto ds = divisor(x);
    dump(ds);

    each(d, ds){
        rep(a, -1000000, 1000000){
            int b = a-d;
            if (a*a*a*a*a - b*b*b*b*b == x){
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }

    return 0; 
}


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

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i=0; i<n; i++) cin >> h[i];

    int i=0;
    int max=0;
    int cnt=0;
    while(i<n-1) {
        // cout << "i:" << i << endl;
        if(h[i] >= h[i+1]) cnt++;
        else {
            cnt=0;
        }
        if(cnt > max) max = cnt;
        i++;
        // cout << "cnt:" << cnt << endl;
        // cout << "max:" << max << endl;

    }
    cout << max << endl;

    return 0;
}


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

using namespace std;

int main()
{
    int n;

    cin >> n;

    vector <int> a(n);

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

    int ans = 0;
    int k = 1;
    for (int i = 0; i < n; i++)
    {
        if (a[i] == k)
            k++;
        else
            ans++;
    }

    if (ans == n)
        ans = -1;
    
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 1024
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
  long long int i, j;
  long long int H, W;

  scanf("%lld %lld", &H, &W);

  long long int minH, minW;
  long long int tempH, tempW;
  if (H % 3 == 0) {
    printf("0");
    return 0;
  }
  if (W % 3 == 0) {
    printf("0");
    return 0;
  }

  tempH = H - H / 3;
  minH = W;
  if (W % 2 == 0) {
    if (minH > (tempH * W / 2 - W * (H - tempH))) {
      minH = (tempH * W / 2 - W * (H - tempH));
    }
  } else {
    if (minH > (tempH * (W + 1) / 2 - W * (H - tempH))) {
      minH = (tempH * (W + 1) / 2 - W * (H - tempH));
    }
  }
  tempH--;
  if (W % 2 == 0) {
    if (minH > -(tempH * W / 2 - W * (H - tempH))) {
      minH = -(tempH * W / 2 - W * (H - tempH));
    }
  } else {
    if (minH > -(tempH * (W - 1) / 2 - W * (H - tempH))) {
      minH = -(tempH * (W - 1) / 2 - W * (H - tempH));
    }
  }

  tempW = W - W / 3;
  minW = H;
  if (H % 2 == 0) {
    if (minW > (tempW * H / 2 - H * (W - tempW))) {
      minW = (tempW * H / 2 - H * (W - tempW));
    }
  } else {
    if (minW > (tempW * (H + 1) / 2 - H * (W - tempW))) {
      minW = (tempW * (H + 1) / 2 - H * (W - tempW));
    }
  }
  tempW--;
  if (H % 2 == 0) {
    if (minW > -(tempW * H / 2 - H * (W - tempW))) {
      minW = -(tempW * H / 2 - H * (W - tempW));
    }
  } else {
    if (minW > -(tempW * (H - 1) / 2 - H * (W - tempW))) {
      minW = -(tempW * (H - 1) / 2 - H * (W - tempW));
    }
  }

  if (minH < minW) {
    printf("%lld", minH);
  }
  else {
    printf("%lld", minW);
  }

  return 0;
}

Measured memory_bytes: 128
from collections import defaultdict as dd

ac = dd(bool);pen,cor=0,0
wc = dd(int)
n,m = map(int,input().split())
for i in range(m):
	l = input().split()
	p = int(l[0]);ans=l[1]
	if ac[p]==False and ans=='WA':
		wc[p]+=1
	elif ac[p]==False and ans=='AC':
		pen+=wc[p]
		cor+=1
		ac[p]=True
		
print(cor,"",pen)


Measured memory_bytes: 21780
#include <stdio.h>
int main(void){
    int N;
    long int ans=1;
    int loop1;
    scanf("%d",&N);
    for(loop1=1;loop1<=N;loop1++){
        ans*=loop1;
        ans%=1000000000+7;
    }
    printf("%ld\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<int,int> P;
typedef long long ll; 

ll mod = 1e9 + 7;

const int MAX = 999999;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++)
	{
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

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

int main()
{

	COMinit();

	int X, Y;
	cin >> X >> Y;
	int n, m;

	if ((2 * X - Y) % 3 != 0 || (2 * X - Y) < 0 || (2 * Y - X) % 3 != 0 || (2 * Y - X) < 0)
	{
		cout << 0 << endl;
	}
	else
	{
		n = (2 * X - Y) / 3;
		m = (2 * Y - X) / 3;
		cout << COM(n + m, m) << endl;
	}
}


Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    string s;
    cin >> s;
    int cnt=0;
    char now = s[0];
    for(int i = 1; i<s.size(); i++){
        if(s[i] != now){
            cnt++;
            now = s[i];
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		int A = sc.nextInt();
		int B = sc.nextInt();
		String U = sc.next();
		sc.close();
		if(U.equals(S)) A--;
		if(U.equals(T)) B--;
		System.out.println(A + " " + B);
	}

}

Measured memory_bytes: 21588
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
#include<climits>
#include<cfloat>
#include<cmath>
#include<map>
#include<complex>

#define f first
#define s second
#define mp make_pair

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

typedef unsigned int uint;
typedef long long ll;

using namespace std;

int b[8][8];
int f[8][8];

void set(int y, int x){
  if(x < 0) return;
  if(y < 0) return;
  if(x > 7) return;
  if(y > 7) return;
  f[y][x] = 1;
}

int main(){
  int n; scanf("%d",&n);
  for(int nn = 1; nn <= n; nn++){
    int x,y;
    REP(i,8){
      char buff[10];
      scanf("%s",buff);
      REP(j,8){b[i][j] = buff[j] - '0'; f[i][j]=0;}
    }
    scanf("%d%d",&x,&y);
    f[y-1][x-1] = 1;
    bool ret = true;
    while(ret){
      ret = false;
      REP(i,8) REP(j,8){
        if(b[i][j] == 1 && f[i][j] == 1){
          ret = true;
          b[i][j] = 2;
          for(int k=-3; k<=3; k++){
            set(i+k,j); set(i,j+k);
          }
        }
      }
    }
    printf("Data %d:\n",nn);
    REP(i,8){
      REP(j,8){
        printf("%d",b[i][j]==1?1:0);
      }
      puts("");
    }
  }
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  
 if ( N % 2 == 0) {
   cout << N / 2 << endl;
  }
  
  else if ( N % 2 == 1) {
    cout << N / 2 + 1 << endl;
  }
}  

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

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int x, y;
    cin >> x >> y;

    if(x != y && abs(x) == abs(y)){
        cout << 1 << endl;
        return 0;
    }

    if(abs(x) < abs(y)){
        int ans = abs(y) - abs(x);
        if(x < 0){
            ans++;
        }
        if(y < 0){
            ans++;
        }
        cout << ans << endl;
        return 0;
    }

    int ans = abs(x) - abs(y);
    if(x > 0){
        ans++;
    }
    if(y > 0){
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100005];
char ch[20];
map<string, int>m;
map<string, int>::iterator it;
int main(void)
{
	int n;
	long long sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> ch;
		sort(ch, ch + 10);
		ch[10] = '\0';
		if (!m.count(ch))
		{
			m[ch] = 0;
		}
		m[ch] += 1;
	}
	for (it = m.begin(); it != m.end(); it++)
	{
		int k = it->second;
		for (int i = 0; i < k; i++)
		{
			sum += i;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 11136
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;

#define INF (1e9)

int N;

int main() {
    cin >> N;

    vb A(1e9 + 10);
    int a;
    for (int i = 0; i < N; i++) {
        cin >> a;
        if (A[a]) {
            cout << "NO" << endl;
            return 0;
        }
        A[a] = true;
    }

    cout << "YES" << endl;
    return 0;
}


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

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
    ll n, m, l;
    cin >> n >> m >> l;
    cout << n+m+l << endl;
}


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

using namespace std;

vector<int>v;

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

    int n,k,i,sum = 0,cur = 0;
    char now;
    string str;
    cin>>n>>k;
    cin>>str;
    now = str[0];
    for(i=0;i<n;i++){
        if(str[i]!=now){
            v.push_back(cur);
            cur = 1;now = str[i];
        }
        else cur++;
    }
    v.push_back(cur);
    for(i=0;i<=min(k*2,(int)v.size()-1);i++)sum+=v[i];
    sum--;
    while(i<v.size()){
        sum+=(v[i]-1);
        i++;
    }
    cout<<sum<<'\n';
    return 0;
}



Measured memory_bytes: 972
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    ll N, D, A;
    cin >> N >> D >> A;
    vector<pll> v(N);
    ll x, h;
    for (int i = 0; i < N; i++) {
        cin >> x >> h;
        v[i] = pll(x, h);
    }
    v.push_back(pll(LINF, 0LL));
    sort(v.begin(), v.end());

    vector<ll> sum(N+1);
    ll times = 0;
    for (int i = 0; i < N; i++) {
        x = v[i].first, h = v[i].second;
        h -= sum[i];
        if (h <= 0LL) {
            sum[i+1] += sum[i];
            continue;
        }
        ll mul = (h + A - 1) / A;
        times += mul;
        ll bom = A * mul;
        sum[i] += bom;
        int ind = lower_bound(v.begin(), v.end(),
                    pll(x + 2*D + 1, 0)) - v.begin();
        sum[ind] -= bom;
        sum[i+1] += sum[i];
    }

    cout << times << '\n';
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

vec<int> getCoef(int n, int sign) {
   vec<int> res(n);
   rep (i, n) {
      int c = (i == 0 || i == n-1) ? 1 : 2;
      c *= (i & 1) ? sign : -sign;
      res[i] = c;
   }
   return res;
}

signed main() {
   // 入力
   int n;
   cin >> n;
   vec<int> a(n);
   rep (i, n) { cin >> a[i]; }

   sort(all(a));

   int ans = 0;
   for (int sign = -1; sign <= 1; sign += 2) {
      auto c = (getCoef(n, sign));
      sort(all(c));

      int sum = 0;
      rep (i, n) sum += a[i] * c[i];
      chmax(ans, sum);
   }
   cout << ans << endl;

   return 0;
}

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

int h,w;
char maps[150][150];
int check[150][150];
int x=0,y=0;

int tansaku();

int main(){
  while(1){
  cin>>h>>w;
  if(!(h||w))break;
 
  //init
  memset(check,0,sizeof(check));

  //input
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>maps[i][j];
    }
  }
  if(tansaku())cout<<"LOOP"<<endl;
  else cout<<x<<" "<<y<<endl;
  }
}

int tansaku(){
  x=0;y=0;
  check[0][0]++;
  while(maps[y][x]!='.'){
    if(maps[y][x]=='>')x++;
    else if(maps[y][x]=='<')x--;
    else if(maps[y][x]=='v')y++;
    else if(maps[y][x]=='^')y--;
    check[y][x]++;
    if(check[y][x]>=2){
      return 1;
    }
  }
  return 0;
}

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

int main(){
	int n,q;
	string s;
	cin>>n>>q>>s;
	int cnt[100000];
	 cnt[0]=0;
	for(int i=1;i<n;i++){
	    if(s[i-1]=='A'&&s[i]=='C')cnt[i]=cnt[i-1]+1;
	    else cnt[i]=cnt[i-1];
	  }
	  for(int i=0;i<q;i++){
		  int l,r;
		  cin>>l>>r;
		  if(l==0)cout<<cnt[r-1]<<endl;
		  else{
			  int ans=cnt[r-1]-cnt[l-2];
			  if(s[l-1]=='C'&&s[l-2]=='A')ans--;
			  cout<<ans<<endl;
			  }
	  }
}


Measured memory_bytes: 1408
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#include <bits/stdc++.h>
//~ #include <atcoder/all>
using namespace std;
using ll = long long;
//~ using P = pair<int, int>;

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;
}
//~ int A = (1<<2) | (1<<3) | (1<<5) | (1<<7);
//~ for (int bit=A; ; bit=(bit-1)&A){
//~ if (!bit) break;
//~ }
int next_combination(int sub)
{
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}
//~ int n=5;
//~ int k=3; // nCkの組み合わせ、ただしk=0には対応してない
//~ int bit=(1<<k)-1; // 1000 -> 0111
//~ for(; bit < (1<<n); bit=nex_combination(bit){
//~ }
bool isPrime(int a)
{
    if (a == 2)
        return true;
    if (a <= 1 || a % 2 == 0)
        return false;

    for (int i = 3; i * i <= a; i += 2)
    {
        if (a % i == 0)
            return false;
    }
    return true;
}
//~ vector<int> a = {1, 14, 32, 51, 51, 51, 243, 419, 750, 910};
vector<int> a;
// index が条件を満たすかどうか
bool isOK(int index, int key)
{
    if (a[index] >= key)
        return true;
    else
        return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key)
{
    int ng = -1;            //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1)
    {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key))
            ok = mid;
        else
            ng = mid;
    }
    return ok;
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//~ int v[100100];
//~ int INF = 1 << 30;
//~ vector<vector<int>> dp(310, vector<int>(310));
//~ ll dp[110][100100];
//~ vector<int> dp(100100, 0));

//~ int seen[110];
//~ int ans[110][2];
//~ ll MOD = 1e9 + 7;

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

    // 切り下げ
    int ans1 = N * 100 / 108;
    // 切り上げ
    int ans2 = (N * 100 + 108 - 1) * 100 / 10800;

    if ((ans1*108/100) == N)
    {
        cout << ans1 << endl;
    }
    else if ((ans2*108/100) == N)
    {
        cout << ans2 << endl;
    }
    else
    {
        cout << ":(" << endl;
    }

    return 0;
}


Measured memory_bytes: 3640
#include<stdio.h>
#include<algorithm>
using namespace std;
int p[500];
int q[250][500];
int r[250][500];
int ret[500];
int s[500];
int t[250][500];
int u[500];
int v[250][500];
int w[250][500];
int ABS(int a){return max(a,-a);}
int LIM=240;
int main(){
	int a;
	scanf("%d",&a);
	for(int i=0;i<a;i++)p[i]=i;
	for(int i=0;i<LIM;i++){
		random_shuffle(p,p+a);
		printf("?");
		for(int j=0;j<a;j++)printf(" %d",p[j]+1);
		for(int j=0;j<a;j++)q[i][j]=p[j];
		printf("\n");fflush(stdout);
		for(int j=0;j<a;j++)scanf("%d",&r[i][j]);
	}
	for(int i=0;i<a;i++)ret[i]=i;
	random_shuffle(ret,ret+a);
	int score=0;
	for(int i=0;i<a;i++)s[ret[i]]=i;
	for(int i=0;i<LIM;i++){
		for(int j=0;j<a;j++){
			t[i][q[i][j]]=j;
		}
		for(int j=0;j<a;j++)u[j]=ABS(s[j]-t[i][j]);
		for(int j=0;j<a;j++){
			v[i][r[i][j]]++;
			w[i][u[j]]++;
		}
		for(int j=0;j<a;j++)score+=min(v[i][j],w[i][j]);
	}
	while(score<LIM*a){
		int cl=rand()%a;
		int cr=rand()%a;
		if(cl==cr)continue;
		int nl=ret[cl];
		int nr=ret[cr];
	//	swap(s[ret[cl]],s[ret[cr]]);
	//	swap(ret[cl],ret[cr]);
		int tmp=score;
		for(int i=0;i<LIM;i++){
			int at[4];
			at[0]=ABS(s[nl]-t[i][nl]);
			at[1]=ABS(s[nl]-t[i][nr]);
			at[2]=ABS(s[nr]-t[i][nl]);
			at[3]=ABS(s[nr]-t[i][nr]);
			if(w[i][at[0]]<=v[i][at[0]])tmp--;
			w[i][at[0]]--;
			if(w[i][at[3]]<=v[i][at[3]])tmp--;
			w[i][at[3]]--;
			if(w[i][at[1]]<v[i][at[1]])tmp++;
			w[i][at[1]]++;
			if(w[i][at[2]]<v[i][at[2]])tmp++;
			w[i][at[2]]++;
			
			w[i][at[0]]++;w[i][at[1]]--;w[i][at[2]]--;w[i][at[3]]++;
			if(tmp<score-10)break;
		}
		if(tmp>=score){
			score=tmp;
			for(int i=0;i<LIM;i++){
				int at[4];
				at[0]=ABS(s[nl]-t[i][nl]);
				at[1]=ABS(s[nl]-t[i][nr]);
				at[2]=ABS(s[nr]-t[i][nl]);
				at[3]=ABS(s[nr]-t[i][nr]);
				w[i][at[0]]--;w[i][at[1]]++;w[i][at[2]]++;w[i][at[3]]--;
			}
			swap(ret[cl],ret[cr]);
			swap(s[nl],s[nr]);
		}
	}
	printf("!");
	for(int i=0;i<a;i++)printf(" %d",ret[i]+1);
	printf("\n");
	fflush(stdout);
}

Measured memory_bytes: 3384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ((a+b)>(c+d)) {
    cout << "Left" << endl;
  }
  else if ((a+b)==(c+d)) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll      int
#define ld      long double
#define pii     pair<int ,int>
#define pld     pair<ld ,ld>
#define all(v)  v.begin(),v.end()
#define F       first
#define S       second
#define mod     1000000007
#define pb      push_back
#define MP      make_pair
#define mset(x) memset(x, 0, sizeof(x));
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inf     10000000000000007
const int N=300004;

void run(){
    ll n,i,x,y;
    cin>>n;
    for(i=1;i<=9;i++)
    {
        if(n%i==0)
        {
            x=i;
            y=n/i;
            if(x<=9 && y<=9){
                cout<<"Yes";
                return;
            }
        }
    }
    cout<<"No";
}
 
 
void setup(){
    ios;
    //cout << setprecision(20);
    // #ifndef ONLINE_JUDGE
    // freopen("input", "r", stdin);
    // freopen("output", "w", stdout);
    // #endif
}
 
signed main(){
    setup();
    int tests = 1;
    //cin >> tests;
    for(int i = 1; i <= tests; i++) run();
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 62) - 1;

ll d[110][110];
int V;

bool warshal_floyd()
{
    int i, j, k;
    rep(k, 0, V)
    {
        rep(i, 0, V)
        {
            rep(j, 0, V)
            {
                if (d[i][k] != INF && d[k][j] != INF)
                {
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }
    }

    rep(i, 0, V)
    {
        if (d[i][i] < 0)
        {
            return false;
        }
    }

    return true;
}

int main(void)
{
    int E;
    int i, j;
    int x, y, z;

    cin >> V >> E;

    rep(i, 0, V)
    {
        rep(j, 0, V)
        {
            if (i == j)
            {
                d[i][j] = 0;
            }
            else
            {
                d[i][j] = INF;
            }
        }
    }

    rep(i, 0, E)
    {
        cin >> x >> y >> z;
        d[x][y] = z;
    }

    if (warshal_floyd())
    {
        rep(i, 0, V)
        {
            rep(j, 0, V)
            {
                if (d[i][j] == INF)
                {
                    printf("INF");
                }
                else
                {
                    printf("%lld", d[i][j]);
                }

                if (j < V - 1)
                {
                    printf(" ");
                }
            }
            printf("\n");
        }
    }
    else
    {
        cout << "NEGATIVE CYCLE" << endl;
    }
}


Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);
static const int BMAX = 60;

int bit[BMAX];
int N;
long long K;
vector<long long> pre_ans;

void dfs(int digit, bool choose1, long long bit_now) {

  if (digit < 0) {
    pre_ans.push_back(bit_now);
    return;
  }

  long long nbit;
  bool flag_k = K & (1LL<<digit);

  if (choose1 && !flag_k) {
    dfs(digit-1, true, bit_now);
  }
  else if (choose1) {
    nbit = bit_now | (1LL<<digit);
    dfs(digit-1, true, nbit);
    dfs(digit-1, false, bit_now);
  }
  else {
    if (bit[digit]*2 > N) nbit = bit_now;
    else nbit = bit_now | (1LL<<digit);
    dfs(digit-1, false, nbit);
  }
}


int main() {
  cin >> N >> K;
  rep(i, N) {
    long long tmp;
    cin >> tmp;
    rep(j, BMAX) {
      if (tmp & (1LL<<j)) bit[j]++;
    }
  }

  dfs(BMAX-1, true, 0LL);
  
  long long ans = 0LL;
  for (auto elem : pre_ans) {
    //int x[BMAX];
    long long x = 0LL;
    rep(i, BMAX) {
    //if (elem & (1LL<<i))  x[i] = N - bit[i];
    //else x[i] = bit[i];
      if (elem & (1LL<<i))  x += (long long)pow(2, i) * (N - bit[i]);
      else x += (long long)pow(2, i) * bit[i];
    }

  //rep(i, BMAX-1) {
  //  x[i+1] += x[i] / 2;
  //  x[i] = x[i] % 2;
  //}

  //long long y = 0LL;
  //rep(i, BMAX) {
  //  if (x[i] == 1) y = y | (1LL<<i);
  //}

  //ans = max(ans, y);
    ans = max(ans, x);
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;
using ll = long long;

const int N = 100005;

int ans[N];

int n;
vector<pair<int, int>> g[N];

void dfs(int u, int p, int cp) {

	int cnt = 1;
	for(auto e : g[u]) if(e.first != p) {
		if(cnt == cp) cnt++;
		ans[e.second] = cnt;
		dfs(e.first, u, cnt);
		cnt++;
	}
}

int main() {

	scanf("%d", &n);

	for(int i = 1; i < n; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		g[a].emplace_back(b, i);
		g[b].emplace_back(a, i);
	}

	int root = 1;
	for(int i = 1; i <= n; i++) {
		if(g[i].size() > g[root].size()) {
			root = i;
		}
	}

	dfs(root, root, 0);

	int k = 0;

	for(int i = 1; i < n; i++) k = max(k, ans[i]);

	printf("%d\n", k);

	for(int i = 1; i < n; i++) {
		printf("%d\n", ans[i]);
	}
}


Measured memory_bytes: 9344
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if (s == u)
    {
        a--;
    }
    else
    {
        b--;
    }

    cout << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
   int c[10], key = 1, C, i, j;
   while(scanf("%d,%d,%d,%d,%d", &c[1], &c[2], &c[3], &c[4], &c[5]) != EOF){
       key = 1;
       for ( i = 1; key; i++ ) {
           key = 0;
           for ( j = 5; j > i; j-- ) {
               if ( c[j] < c[j - 1]) {
                   C = c[j];
                   c[j] = c[j - 1];
                   c[j - 1] = C;
                   key = 1;
                }
            }
        }
        /*for ( i = 1; i <= 5; i++) printf("%d ", c[i]);*/
        if ( c[1] == c[4] || c[2] == c[5] ) printf("four card\n");
        else if ( c[1] == c[2] && c[3] == c[5] ) printf("full house\n");
        else if ( c[1] == c[3] && c[4] == c[5] ) printf("full house\n");
        else if ( c[2] == c[1] + 1 && c[3] == c[2] + 1 && c[4] == c[3] + 1 && c[5] == c[4] + 1 ) printf("straight\n");
        else if ( c[1] == 1 && c[2] == 10 && c[3] == 11 && c[4] == 12 && c[5] == 13 ) printf("straight\n");
        else if ( c[1] == c[3] || c[2] == c[4] || c[3] == c[5] ) printf("three card\n");
        else if ( c[1] == c[2] && c[3] == c[4] ) printf("two pair\n");
        else if ( c[1] == c[2] && c[4] == c[5] ) printf("two pair\n");
        else if ( c[2] == c[3] && c[4] == c[5] ) printf("two pair\n");
        else if ( c[1] == c[2] || c[2] == c[3] || c[3] == c[4] || c[4] == c[5] ) printf("one pair\n");
        else printf("null\n");
    }

   return 0;
}

Measured memory_bytes: 1756
import math

k=int(input())

x=[0]*201

for i in range(1,k+1):
    for j in range(1,k+1):
        v=math.gcd(i,j)
        x[v]+=1

ans=0
for i in range(1,201):
    for j in range(1,k+1):
        w=math.gcd(i,j)
        ans+=w*x[i]
print(ans)

Measured memory_bytes: 65012
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, ans = 1, r = 0, o = 0;
    string s;
    cin >> n >> s, n--;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
        a[i] = abs(s[i] - s[i + 1]), o += a[i] == 1;
    if (!o)
    {
        ans *= 2;
        for (ll &e : a)
            e /= 2;
    }
    for (ll i = 0; i < n; i++)
        if (((n - 1) & i) == i)
            r ^= a[i];
    cout << (r % 2 ? ans : 0);
    return 0;
}

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

int main () {
  long long X;
  cin >> X;


  long long A, B;
  for (long long i=-1000; i<=1000; i++) {
    for (long long j=-1000; j<=1000; j++) {
      if ((pow(i, 5) - pow(j, 5)) == X) {
        A = i;
        B = j;
      }
    }
  }
  cout << A << " " << B << endl;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
 		
 		
 		ll gcd(ll n,ll m){
 			
 			if(n%m==0){
 				return m;
 			}else{
 				return gcd(m,n%m);
 			}
 			
 		}
 		
int main() {

int N;
cin>>N;
ll a;
cin>>a;
fx(N-1){
	ll k;
	cin>>k;
	ll d;
	if(a>k){
		d=gcd(a,k);
	}else{
		d=gcd(k,a);
	}
	
	a=a/d*k;
	
}

ce(a)

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll get_sum(ll n,vector<ll> que){
  ll sum=0;
  for(int i=0;i<n;i++){
    if(i==que.size()){
      break;
    }
    sum+=que[i];
  }
  return sum;
}
int main(){
  ll N,W,sum,we,ans=-1;
  cin >> N >> W;
  ll w[N],v[N];
  vector<ll> que[4];
  for(ll i=0;i<N;i++){
    cin >> w[i]>>v[i];
    que[w[i]-w[0]].push_back(v[i]);
  }
  for(int i=0;i<4;i++){
    sort(que[i].begin(),que[i].end(),greater<ll>());
  }
  for(int i=0;i<=N;i++){
    for(int j=0;i+j<=N;j++){
      for(int k=0;i+j+k<=N;k++){
        for(int l=0;i+j+k+l<=N;l++){
          we = i*(w[0])+j*(w[0]+1)+k*(w[0]+2)+l*(w[0]+3);
          if(we>W)break;
          sum = get_sum(i,que[0])+get_sum(j,que[1])+
            get_sum(k,que[2])+get_sum(l,que[3]);
          ans = max(ans,sum);
        }
      }
    }
  }
  cout << ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int a,b,x;
    cin >> x >> a >> b;
    if (-a+b<=0){
        cout << "delicious" << endl;
    }else if(-a+b <= x){
        cout << "safe" << endl;
    }else{
        cout << "dangerous" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const ll MOD = 1e9+7;


#define REP(i, N) for (ll i = 0; i < (N); i++)
#define REPP(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((ll)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<ll>>

using namespace std;


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

    ll n;
    string s;
    cin >> n >> s;
    vector<int> r,g,b;

    for(ll i = 0; i < n;i++){
        if(s[i] == 'R'){
            r.push_back(i+1);
        }else if(s[i] == 'G'){
            g.push_back(i+1);
        }else{
            b.push_back(i+1);
        }
    }
    ll ans = 0;
    for(ll i = 0; i < n;i++){
        for(ll l = 1; i+l+l < n;l++){
            if(s[i] != s[i+l] && s[i+l+l] != s[i+l] && s[i+l+l] != s[i]){
                ans++;
            }
        }
    }
    cout <<  r.size()*g.size()*b.size()- ans << endl;

    return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;
typedef vector<char> vech;


int main() {
    ll N;cin>>N;
    vel H(N);rep0(i,N){cin>>H[i];}
    ll cnt=0,ans=0;
    vel B(N-1);rep0(i,N-1){B[i]=H[i+1]-H[i];}
    rep0(i,N-1){
        if(B[i]<=0){cnt++;}
        else{ans=max(ans,cnt);cnt=0;}
    }
    ans=max(ans,cnt);
    cout<<ans<<endl;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

vector<ll> b;

string solve(ll x, ll y) {
  ll u = x + y;
  ll v = x - y;
  string ret;

  string dir = "LDUR";
  for (int i = 30; i >= 0; i--) {
    int j = 0;
    if (u < 0) {
      j += 0;
      u += b[i];
    } else {
      j += 2;
      u -= b[i];
    }
    if (v < 0) {
      j += 0;
      v += b[i];
    } else {
      j += 1;
      v -= b[i];
    }
    ret.push_back(dir[j]);
  }
  reverse(ret.begin(), ret.end());

  return ret;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  b.resize(31);
  b[0] = 1;
  for (int i = 0; i < 30; i++) b[i + 1] = b[i] * 2;
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    mp[abs(x[i] + y[i]) % 2]++;
  }
  if (mp[0] != n && mp[0] != 0) {
    cout << -1 << endl;
    return 0;
  }
  if (mp[0] > 0) {
    cout << 32 << endl;
    ll m = 1;
    cout << 1;
    for (int i = 0; i < 31; i++) {
      cout << " " << m;
      m <<= 1;
    }
    cout << endl;
    for (int i = 0; i < n; i++) {
      cout << "R";
      cout << solve(x[i] - 1, y[i]) << endl;
    }
  } else {
    cout << 31 << endl;
    ll m = 2;
    cout << 1;
    for (int i = 0; i < 30; i++) {
      cout << " " << m;
      m <<= 1;
    }
    cout << endl;
    for (int i = 0; i < n; i++) {
      cout << solve(x[i], y[i]) << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
 
using namespace std;


int main()
{
	int a,p;
	cin>>a>>p;
	p = p + 3*a;
	cout<< p / 2<<endl;
	return 0;
}

Measured memory_bytes: 256
S=input()
T=input()
kaesk=[i for i in range(97,97+26)]
ans=1

for i in range(len(S)):
    tmp=kaesk[ord(S[i])-97]
    no=0
    for j in range(26):
        if kaesk[j]==ord(T[i]):
            no=j
    kaesk[ord(S[i])-97]=ord(T[i])
    kaesk[no]=tmp


for i in range(len(S)):
    if kaesk[ord(S[i])-97]!=ord(T[i]):
        ans=0
        break
if ans==1:
    print("Yes")
else:
    print("No")

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

long long mod=998244353;
struct mint{
    long long x;
    mint(long long 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(long long t)const{
        if(!t)return 1;
        mint a=pow(t>>1);
        a*=a;
        if(t&1)a*=*this;
        return a;
    }
    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,mint& a){return is>>a.x;}
ostream& operator<<(ostream& os,const mint& a){return os<<a.x;}

vector<mint> fac(300001);
vector<mint> ifac(300001);

mint comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    mint tmp = ifac[a-b]* ifac[b];
    return tmp * fac[a];
}

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x %mod;
        x = x*x % mod;
        n = n >> 1;
    }
    return ans;
}

int main() {
    ll n,m,k;
    cin>>n>>m>>k;
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1); // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, mod-2); // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    mint ans=0;
    rep(i,k+1){
        ans+=comb(n-1,i)*m*mpow(m-1,n-i-1);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 7868
D=int(input())
C=list(map(int,input().split()))
import numpy as np
L=np.zeros(26,dtype=np.int)
ans=[]
for d in range(D):
  L+=1
  X=L*C
  xi=X.argmax()
  S=list(map(int,input().split()))
  si=np.argmax(S)
  if si==xi:
    ans.append(si+1)
    L[si]=0
  elif S[si]-C[xi]>X[xi]:
    ans.append(si+1)
    L[si]=0
  else:
    ans.append(xi+1)
    L[xi]=0
for a in ans:
  print(a)

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

int main(){
    while(1){
        int n, m;
        cin >> n >> m;
        if(n == 0 && m == 0) break;
        vector<int> sample(n), c(m);
        for(int i = 0; i < m; i++) cin >> c[i];
        for(int i = 0; i < n; i++) cin >> sample[i];
        vector<vector<ll>> dp(n+1, vector<ll>(256, -1));
        dp[0][128] = 0;
        for(int i = 0; i < n; i++){
            for(int j = 0; j <=255; j++){
                if(dp[i][j] != -1){
                    for(int k = 0; k < m; k++){
                        int idx = j+c[k];
                        idx = min(255, idx);
                        idx = max(0, idx);
                        if(dp[i+1][idx] == -1) dp[i+1][idx] = dp[i][j] + (idx-sample[i])*(idx-sample[i]);
                        else dp[i+1][idx] = min(dp[i+1][idx], dp[i][j]+(idx-sample[i])*(idx-sample[i]));
                    }
                }
            }
        }

        ll ans = 1e9;
        for(int i = 0; i <= 255; i++){
            if(dp[n][i] != -1) ans = min(ans, dp[n][i]);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 43740
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int n = Math.min(a,b);
    int n2 = Math.max(a,b);
    for(int i = 0; i < n2; i++){
      System.out.print(n);
    }
  }
}


Measured memory_bytes: 21332
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

using Vect = pair<long double, long double>;

Vect operator+(Vect lhs, Vect rhs){
  Vect ret = make_pair(0, 0);
  ret.first = lhs.first + rhs.first;
  ret.second = lhs.second + rhs.second;
  return ret;
}
Vect operator-(Vect& lhs, Vect& rhs){
  Vect ret;
  ret.first = lhs.first - rhs.first;
  ret.second = lhs.second - rhs.second;
  return ret;
}

Vect operator*(long double lhs, const Vect& rhs){
  return make_pair(lhs * rhs.first, lhs * rhs.second);
}

long double norm(const Vect& v){
  return sqrt(v.first * v.first + v.second * v.second);
}

Vect rotate(Vect v, long double cost, long double sint){
  return make_pair(
                   v.first * cost - v.second * sint,
                   v.first * sint + v.second * cost
                   );
}

const long double EPS = 1e-12;

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

  vector<pair<Vect, long double>> xyc(N);
  for(int i = 0; i < N; i++){
    long double x, y, c;
    cin >> x >> y >> c;
    xyc[i] = make_pair(make_pair(x, y), c);
  }

  long double ur = 1e7, lr = 0;
  for(int _ = 0; _ < 100; _++){
    //cout << lr << ' ' << ur << endl;
    long double mid = (lr + ur) / 2;
    vector<Vect> center_cands;

    for(auto v: xyc){
      center_cands.push_back(v.first);
    }

    for(auto m1: xyc){
      for(auto m2: xyc){
        long double r1 = mid / m1.second, r2 = mid / m2.second;
        long double l = norm(m1.first - m2.first);
        if(l < EPS){
          continue;
        }
        if((l <= r1 + r2) &&
           (l >= abs(r1 - r2))){
          long double cost = (r1 * r1 + l * l - r2 * r2) / (2 * r1 * l);
          long double sint = sqrt(1 - cost * cost);
          //cout << cost << ' ' << sint << endl;
          Vect diff = m2.first - m1.first;
          //          Vect diff_norm = (1 / l) * (m2.first - m1.first);
          Vect v1 = m1.first + (r1 / l) * rotate(diff, cost, sint);
          Vect v2 = m1.first + (r1 / l) * rotate(diff, cost, -sint);
          center_cands.push_back(v1);
          center_cands.push_back(v2);
        }
      }
    }
    /*
    for(auto c: center_cands){
    cout << '(' << c.first << ',' << c.second << ')' << ' ';
    }cout << endl;
    */

    int max_cnt = 0;
    for(auto center: center_cands){
      int cnt = 0;
      for(auto p: xyc){
        long double dist = norm(center - p.first) * p.second;
        if(dist <= mid + EPS){
          cnt++;
        }
      }
      max_cnt = max(max_cnt, cnt);
    }
    //cout << max_cnt << endl;
    if(max_cnt >= K){
      ur = mid;
    }else{
      lr = mid;
    }
  }
  cout << setprecision(20) << (lr + ur) / 2 << endl;
}


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

namespace my {
template <typename T>
void input_vec(vector<T> &a, ll n) {
  if (!a.empty()) {
    cout << "wrong argument in input_vec" << endl;
    exit(1);
  }
  for (ll i = 0; i < n; i++) {
    T tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
}
template <typename T>
void input_set(set<T> &a, ll n) {
  if (!a.empty()) {
    cout << "wrong argument in input_set" << endl;
    exit(1);
  }
  for (ll i = 0; i < n; i++) {
    T tmp;
    cin >> tmp;
    a.insert(tmp);
  }
}

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

ll gcd(ll a, ll b) {  // O( log(a) )
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * (b / my::gcd(a, b)); }  // O( log(a) )

bool isPrime(ll n) {  // O( sqrt(n) )
  bool flag = true;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      flag = false;
      break;
    }
  }
  return flag;
}

vector<pair<ll, ll>> primeFac(ll n) {  // O( sqrt(n) )
  vector<pair<ll, ll>> ret;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll exp = 0;
    while (n % i == 0) {
      n /= i;
      exp++;
    }
    ret.push_back(make_pair(i, exp));
  }
  if (n != 1) ret.push_back(make_pair(n, 1));
  return ret;
}
}  // namespace my
////////////////////////////////////////////////

int main() {
  const ll M = 1e9 + 7;
  int n;
  cin >> n;
  vector<ll> a;
  my::input_vec(a, n);
  ll sum = 0;
  for (auto &ai : a) {
    sum += ai;
  }
  // cout << sum << endl;
  ll ans = 0;
  for (auto &ai : a) {
    ans += (ai % M) * ((sum - ai) % M);
    ans %= M;
  }
  // cout << ans << endl;
  ans *= 500000004;
  ans %= M;
  cout << ans << endl;
}

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

int main()
{
  int N, M;
  cin >> N >> M;
  vector<vector<int>> adj(N);
  for (int i = 0; i < M; i++)
  {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj.at(a).push_back(b);
    adj.at(b).push_back(a);
  }
  vector<int> p(N);
  queue<int> que;
  vector<bool> d(N, false);
  p.at(0) = -1;
  que.push(0);
  d.at(0) = true;
  while (!que.empty())
  {
    int u = que.front();
    que.pop();
    for (int i = 0; i < adj.at(u).size(); i++)
    {
      int v = adj.at(u).at(i);
      if (d.at(v))
      {
        continue;
      }
      d.at(v) = true;
      p.at(v) = u;
      que.push(v);
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < N; i++)
  {
    cout << p.at(i) + 1 << endl;
  }
}

Measured memory_bytes: 10128
import java.util.*;
import static java.lang.System.*;

public class Main{
  public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  int N = sc.nextInt();
	  int M = sc.nextInt();
	  int[] k = new int[M];
	  int[][] s = new int[M][N];
	  for(int i = 0; i<M; i++) {
		  k[i] = sc.nextInt();
		  for(int j=0; j<k[i]; j++) {
			  s[i][j] = sc.nextInt();
		  }
	  }
	  int[] p = new int[M];
	  for(int i=0; i<M; i++) {
		  p[i] = sc.nextInt();
	  }
	  int count = 0;
	  int button = 1;
	  for(int i=0; i<N; i++) {
		  button *=2;
	  }
	  
	  boolean isTrue = true;
	  //ビット全探索。最大1024回
	  for(int bit=0; bit<button; bit++) {
		  isTrue = true;
		  //全ての電球が条件を満たすかチェック。満たさなければアウト
		  for(int i=0; i<M; i++) {
			  //電球に繋がれてるスイッチをチェック
			  int on = 0;//オンになってるスイッチの数
			  //対象のスイッチがオンになってるか判定
			  for(int j=0; j<k[i];j++) {
				  int n = s[i][j] - 1;
				  if ((bit & (1 <<n)) != 0) {
					  on++;
				  }
			  }
			  if(on%2 != p[i]) {
				  isTrue = false;
				  break;
			  }
			  }	  
		  if(isTrue)
			  count++;
	  }
	  out.println(count);
	  }
  }	

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<17,INF=2147483647;
int n,dat[2*MAX-1];

void init(int n_){
    n=1;
    while(n<n_) n*=2;
    for(int i=0;i<2*n-1;i++){
        dat[i]=INF;
    }
}

void update(int k,int a){
    k+=n-1;
    dat[k]=a;
    
    while(k>0){
        k=(k-1)/2;
        dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
}

int query(int a,int b,int k,int l,int r){
    
    if(r<=a||b<=l) return INF;
    if(a<=l&&r<=b) return dat[k];
    else{
        int vl=query(a,b,2*k+1,l,(l+r)/2);
        int vr=query(a,b,2*k+2,(l+r)/2,r);
        return min(vl,vr);
    }
}



int main(){
    
    int N,Q;cin>>N>>Q;

    init(N);

    for(int i=0;i<Q;i++){
        int a,b,c;cin>>a>>b>>c;
        if(a==0) update(b,c);
        else if(a==1) cout<<query(b,c+1,0,0,n)<<endl;
    }
    
}





Measured memory_bytes: 4112