akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> pii;
using namespace std;
using ll = long long;
#define PI 3.14159265358979323846264338327950L
const int mod =  998244353;





void solve(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    map<int,int> memo;
    rep(i,n) memo[a[i]]++;
    ll sum = 0;
    rep(i,n) sum += a[i];
    int q;
    cin >> q;
    rep(i,q){
        ll b,c;
        cin >> b >> c;
        ll count = memo[b];
        
        memo[c] += memo[b];
        memo[b] = 0;
        sum += count*(c-b);
        cout << sum << endl;
    }
}



int main(){
    solve();
}




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

int main(){
  string L;
  cin >> L;
  int ans=0,ans1=0;
  for(int i=0;i<L.size();i++){
    if(L[i]=='R'){
      ans1++;
    }
    if(L[i]=='S' || i==L.size()-1){
      ans=max(ans,ans1);
      ans1=0;
      
    }
  }
 cout << ans <<endl;
}

  

Measured memory_bytes: 3616
#include <stdio.h>
#include <stdlib.h>

int main (void)
{
    int n, a[(int)10e5], i, sum = 0;

    scanf("%d", &n);
    a[0] = 0;
    for(i = 1; i < (n + 1); ++i) {
        scanf("%d", &a[i]);
        sum += abs(a[i] - a[i - 1]);
    }
    a[n + 1] = 0;
    sum += abs(a[n + 1] - a[n]);

    for(i = 1; i < (n + 1); ++i) {
        printf("%d\n", sum - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]));
    }
}


Measured memory_bytes: 2944
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n").map(Number);
while(true){
   var n=arr.shift();
   if(n==0)break;
   var coin=[""];
   for(var i=1;i<=17;i++)coin.push(i*i);
   var dp=[];
   for(var i=0;i<=17;i++){
      dp[i]=[];
      for(var j=0;j<=n;j++){
         dp[i][j]=0;
      }
   }
   dp[0][0]=1;
   for(var i=1;i<=17;i++){
      for(var j=0;j<=n;j++){
        var k=0;
         while(coin[i]*k+j<=n){
            dp[i][coin[i]*k+j]+=dp[i-1][j];
            k++;
         }
      }
   }
   console.log(dp[17][n]);
}

Measured memory_bytes: 16732
#include <algorithm>
#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()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    int N, K;
    cin >> N >> K;
    vector<ll> A(N), sum(N + 1), B, can;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        sum[i + 1] = A[i];
    }

    rep(i, N) { sum[i + 1] += sum[i]; }

    for (int i = 0; i < N + 1; i++) {
        for (int j = i + 1; j < N + 1; j++) {
            B.push_back(sum[j] - sum[i]);
        }
    }

    sort(all(B));
    vector<ll> now = B;
    for (int i = 63; i > -1; i--) {
        vector<ll> next;
        for (auto n : now) {
            if (n & (1LL << i))
                next.push_back(n);
        }
        if (next.size() >= K)
            now = next;
    }

    ll ans = now[0];
    rep(i, K) { ans &= now[i]; }

    cout << ans << endl;
}

Measured memory_bytes: 12932
#!/usr/bin/env python3
import sys
# from math import gcd

def gcd(a, b):
    while b: a, b = b, a % b
    return abs(a)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# print(factorization(14)) 

def solve(A: int, B: int):
    a = gcd(A,B)
    ap = a
    ct = 0
    x = 2
    if a % x == 0:
        ct+=1
        while a % x == 0:
            a = a // x
    x = 3
    while x*x < ap+1: 
        if a % x == 0:
            ct+=1
            while a % x == 0:
                a = a // x
        x+=2
    # print(pa)
    if a != 1:
        ct +=1
    print(ct+1)
    
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
n = int(input())
h = list(map(int, input().split()))
h.append(0)
count = 0

while True:
  if h.count(0) == n+1:
    break
  else:
    for i in range(n):
      if h[i] == 0:
        continue
      else:
        h[i] -= 1
        if h[i+1] == 0:
          count += 1
print(count)

Measured memory_bytes: 3060
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(W: int, H: int, N: int, a: "List[int]", b: "List[int]"):
    ret = [0] * 10
    ret[0] = (H - 2) * (W - 2)
    reduces = []
    for i in range(N):
        lx = max(0, a[i] - 3)
        rx = min(W - 2, a[i])
        ly = max(0, b[i] - 3)
        ry = min(H - 2, b[i])
        for bx in range(lx, rx):
            for by in range(ly, ry):
                reduces.append((bx, by))
    reduces.sort()
    cnt = 1
    for i in range(1, len(reduces)):
        if reduces[i] == reduces[i - 1]:
            cnt += 1
        else:
            ret[0] -= 1
            ret[cnt] += 1
            cnt = 1
    if len(reduces):
        ret[0] -= 1
        ret[cnt] += 1
    for r in ret:
        print(r)
    return


def _solve(W: int, H: int, N: int, a: "List[int]", b: "List[int]"):
    ret = [0] * 10
    ret[0] = (H - 2) * (W - 2)
    reduces = []
    for i in range(N):
        lx = max(0, a[i] - 3)
        rx = min(W - 2, a[i])
        ly = max(0, b[i] - 3)
        ry = min(H - 2, b[i])
        for bx in range(lx, rx):
            for by in range(ly, ry):
                cnt = 0
                for x in range(0, 3):
                    for y in range(0, 3):
                        #print(a[i] - 1, b[i] - 1, bx + x, by + y)
                        if grid[by + y][bx + x]:
                            cnt += 1
                ret[cnt] -= 1
                ret[cnt + 1] += 1
        #print(b[i] - 1, a[i] - 1, H, W)
        grid[b[i] - 1][a[i] - 1] = True
    for r in ret:
        print(r)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]" 
    b = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(H, W, N, a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 116976
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

int main(void)
{
    std::string S;
    std::cin >> S;

    std::map<std::string, int64_t> dow = {
        {"SUN", 7},
        {"MON", 6},
        {"TUE", 5},
        {"WED", 4},
        {"THU", 3},
        {"FRI", 2},
        {"SAT", 1},
    };

    std::cout << dow[S] << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int n, k, w[100000];
bool sim(int p)
{
	int count = 1, tmp = 0;
	for(int i = 0; i != n; i++) {
		if((tmp += w[i]) > p) {
			if(w[i] > p) {
				return false;
			}
			tmp = w[i];
			count++;
		}
	}
	if(count <= k) {
		return true;
	} else {
		return false;
	}
}
int main(void)
{
	scanf("%d%d", &n, &k);
	for(int i = 0; i != n; i++) {
		scanf("%d", w + i);
	}
	int ok = 1000000000, ng = -1;
	while(ok - ng > 1) {
		int med = (ok + ng) / 2;
		if(sim(med)) {
			ok = med;
		} else {
			ng = med;
		}
	}
	printf("%d\n", ok);
	return 0;
}


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

int main() {
	int n;
	cin >> n;
	int x[101][101];
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < n;j++) {
			x[i][j] = 0;
		}
	}
	int u, k, v;
	for (int i = 0;i < n;i++) {
		cin >> u >> k;
		u = u - 1;
		for (int j = 0;j < k;j++) {
			cin >> v;
			v = v - 1;
			x[u][v] = 1;
		}
	}

	for (int i = 0;i < n;i++) {
		for (int j = 0;j < n;j++) {
			if (j == 0) { cout << x[i][j]; }
			else{cout <<" "<< x[i][j];}
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3136
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define pr(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;


int main(void) {
    string N;
    cin >> N;
    ll dp[11][8][2]={};
    ll i, j, l;
    
    dp[0][0][1]=1;
    for(i=0; i<N.size(); i++) {
        for(j=0; j<8; j++) {
            
            for(l=3; l<=7; l+=2) {
                dp[i+1][j | 1<<(l/2-1)][0]+=dp[i][j][0];
            }
            
            ll max=N[i]-'0';
            for(l=3; l<max; l+=2) {
                dp[i+1][j | 1<<(l/2-1)][0]+=dp[i][j][1];
            }
            
            if(max==3 || max==5 || max==7) {
                dp[i+1][j | 1<<(max/2-1)][1]+=dp[i][j][1];
            }
            
        }
        
    }
    
    ll ans=dp[N.size()][7][0]+dp[N.size()][7][1];
    for(i=3; i<N.size(); i++) {
        ans+=pow(3, i)-3*(pow(2, i)-2)-3;
    }
    
    pr(ans);
    
}















Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N, M; cin >> N >> M;
  vector<pair<pair<int,int>, ll>> LRC(M);
  rep(i,M){
    cin >> LRC[i].first.first >> LRC[i].first.second >> LRC[i].second;
    LRC[i].first.first--;
    LRC[i].first.second--;
  }
  vector<vector<int>> G(N);
  vector<vector<ll>> CO(N);
  rep(i,M){
    G[LRC[i].first.first].pb(LRC[i].first.second);
    CO[LRC[i].first.first].pb(LRC[i].second);
  }
  rep(i,N-1){
    G[i+1].pb(i);
    CO[i+1].pb(0);
  }

  // ここからダイクストラ
  vector<ll> D(N, -1);
  vector<bool> used(N, false);
  priority_queue<pair<ll,int>,
                 vector<pair<ll,int>>,
                 greater<pair<ll,int>>> q;

  q.push({0,0});
  int cnt = 0;
  while(!q.empty()){
    pair<ll,int> nowNode = q.top(); q.pop();
    if(used[nowNode.second]) continue;
    used[nowNode.second] = true;
    D[nowNode.second] = nowNode.first;
    rep(i, (int)G[nowNode.second].size()){
      // if(D[G[nowNode.second][i]] != -1 && D[G[nowNode.second][i]] <= D[nowNode.second] + nowNode.first) continue;
      q.push({D[nowNode.second] + CO[nowNode.second][i], G[nowNode.second][i]});
      cnt++;
    }
  }
  // rep(i,N) cout << D[i] << endl;
  // cout << cnt << endl;
  cout << D[N-1] << endl;
  return 0;
}


Measured memory_bytes: 15348
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int s;
	cin >> s;
	
	int front = s / 100;
	int back = s % 100;
	
	if( front > 0 && front <= 12 ) {
		if( back > 0 && back <= 12 ) cout << "AMBIGUOUS" << endl;
		else cout << "MMYY" << endl;
	}
	
	else {
		if( back > 0 && back <= 12 ) cout << "YYMM" << endl;
		else cout << "NA" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long N;
    long sum;
    cin >> N;
    sum = 0;
    for(int i = 1; i <= N; i++){
        if(i % 3 != 0 && i % 5 != 0){
            sum += i; 
        }
    }
    cout << sum << endl;
}

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

const int INF = 1e8;

int main(){
  int N;
  string S;
  cin >> N >> S;
  int r[N],l[N];
  for(int i = 0 ; i < N ; i++){
    r[i] = l[i] = 0;
  }

  for(int i = 0 ; i < N ; i++){
    if(S[i] == 'W')l[i]++;
    if(S[N-1-i] == 'E')r[N-1-i]++;
    if(i+1 < N)l[i+1] += l[i];
    if(N-1-i-1 >= 0)r[N-1-i-1] += r[N-1-i];
  }

  int res = INF;
  for(int i = 0 ; i < N ; i++){
    res = min(res,l[i] + r[i] - 1);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3076
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 
 using namespace std;
 
 const int MAX_V=100+5;
 const int INF=100000000;

 int main()
 {
   int graph[2][MAX_V][MAX_V];
   int path,V;
   while(cin>>path>>V&&(path||V))
   {
     for(int m=0;m<2;m++)
     {
       for(int i=0;i<V;i++)
       {
         for(int j=0;j<V;j++)
         {
           if(i==j) graph[m][i][j]=0;
           else graph[m][i][j]=INF;        
         }       
       }        
     }  
     while(path--)
     {
       int p,q;
       int cost,time;
       cin>>p>>q>>cost>>time;
       graph[0][p-1][q-1]=cost;
       graph[1][p-1][q-1]=time;     
       graph[0][q-1][p-1]=cost;
       graph[1][q-1][p-1]=time;         
     }                       
     for(int m=0;m<2;m++)
     {
       for(int k=0;k<V;k++)
       {
         for(int i=0;i<V;i++)
         {
           for(int j=0;j<V;j++)
           {
             graph[m][i][j]=min(graph[m][i][j],graph[m][i][k]+graph[m][k][j]);        
           }        
         }          
       }        
     }     
     int que;
     cin>>que;
     while(que--)
     {
       int start,end,type;
       cin>>start>>end>>type;
       cout<<graph[type][start-1][end-1]<<endl;           
     }
   }
   //while(1);
   return 0;
 }

 

Measured memory_bytes: 3136
let n = Scanf.scanf " %d" (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let ans = ref min_int
let _ = Array.iteri (fun i a -> for j = i + 1 to n - 1 do ans := max !ans @@ abs @@ a - a_s.(j) done) a_s; Printf.printf "%d\n" !ans

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;

long long cnt = 0;
int l;
int n;
int A[1000000];
vector<int> G;

void insertionSort(int A[], int n, int g) {
    for (int i = g; i < n; i++) {
        int v = A[i];
        int j = i-g;
        while (j >= 0 && A[j] > v) {
            A[j+g] = A[j];
            j -= g;
            cnt++;
        }
        A[j+g] = v;
    }
}

void shellSort(int A[], int n) {

    for (int h = 1; ;) {
        if (h > n)
            break;
        G.push_back(h);
        h = 3*h + 1;
    }

    for (int i = G.size()-1; i >= 0; i--)
        insertionSort(A, n, G[i]);
}

int main() {
    cin >> n;

    for (int i = 0; i < n; i++)
        scanf("%d", &A[i]);

    cnt = 0;

    shellSort(A, n);

    cout << G.size() << endl;

    for (int i = G.size()-1; i >= 0; i--) {
        printf("%d", G[i]);
        if (i != 0)
            printf(" ");
        else
            printf("\n");
    }

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

    for(int i = 0; i < n; i++)
        printf("%d\n", A[i]);

    return 0;
}

Measured memory_bytes: 7208
#include <iostream>
#include <vector>
using namespace std;
int N,M,H[100001],A,B,cnt;
int main() {
    cin>>N>>M;
    for (int i=1; i<=N; i++) cin>>H[i];
    vector<vector<int>> data(N+1);
    for (int i=1; i<=M; i++) {
        cin>>A>>B;
        data.at(A).push_back(B);
        data.at(B).push_back(A);
    }

    for (int i=1; i<=N; i++) {
        bool f=true;
        for (int j=0; j<data.at(i).size(); j++) {
            if ( H[i] <= H[data.at(i).at(j)] ) {
                f=false;break;
            }
        }
        if (f) cnt++;
    }

    cout<<cnt<<endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 1; i <= n; i++){
        cin >> a[n-i];
    }
    for (int i = 0; i < n; i++){
        cout << a[i];
        if (i < n-1) cout << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

#define sp ' '
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define forn(YY, yy) for(long long int yy = 0; yy < YY; ++yy)
#define prn(XX) cout << XX << endl
#define prs(XX) cout << XX << " "

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

const int MOD = 1e9 + 7;
const int INF = 2e9 + 13;
const int mINF = -2e9 - 13;
const double PI = 3.14159265358979;
const double EPS = 1e-9;

vll dp;
ll N;
vvll mw;

ll dn(ll n, ll w){
    if(w == (1 << N)-1) return 1;
    if(n >= N) return 0;

    if(dp[w] != -1) return dp[w];
    ll toplam = 0;
    for(ll i = 0; i < mw[n].size(); ++i){
        ll wn = mw[n][i];
        if(!((1 << wn)&w)){
            toplam += dn(n+1, w|(1<<wn))%MOD;
            toplam %= MOD;
        }
    }
    return dp[w] = toplam%MOD;
}

int main(int argc, char **argv){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    cin >> N;
    dp.resize((1 << N), -1);
    mw.resize(N);

    for(ll i = 0; i < N; ++i){
        for(ll j = 0; j < N; ++j){
            bool b; cin >> b;
            if(b) mw[i].pb(j);
        }
    }
    cout << dn(0, 0) << endl;

    return 0;
}

//cikisir



Measured memory_bytes: 16640
import Control.Applicative
import Data.Bool (bool)

main :: IO ()
main = solve <$> getLine >>= putStrLn

solve :: String -> String
solve = bool "Rabbit" "Cat" . catcheck

catcheck :: String -> Bool
catcheck "" = True
catcheck ('m' : xs) = f 1 [0] [] xs
  where
    f _ [] [] [] = True
    f _ [] [] _ = False
    f i ms es ('m':xs) = f (i+1) (i:ms) es xs
    f i ms es ('e':xs) = f (i+1) ms (i:es) xs
    f i (m:ms) (e:es) ('w':xs)
      | m < e && e < i = f (i+1) ms es xs
      | otherwise = False
    f _ _ _ _ = False                
catcheck _ = False



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

int main()
{
	ios::sync_with_stdio(false);
	ll n,h,w,ans=0;
	cin>>n>>h>>w;
	for(int i=1;i<=n;i++) 
	{
		ll a,b;
		cin>>a>>b;
		if(a>=h&&b>=w) ans++;
	}
	cout<<ans<<endl;
}

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

int main(){
  int n,array[1000],ans=1e9;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>array[i];
  }
  for(int i=-100;i<=100;i++){
    int sum=0;
    for(int j=0;j<n;j++){
      sum+=(array[j]-i)*(array[j]-i);
    }
    ans=min(sum,ans);
  }
  cout<<ans<<endl;
}

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

using namespace std;

int main()
{
  int a[2];
  cin>>a[0];
  cin>>a[1];
  int b[2];
  cin>>b[0];
  cin>>b[1];
  int flag=0;
  for(int i = 0 ; i<101;i++){
    b[0]-=a[1];
    if(b[0]<=0){ flag=0; break;}
    a[0]-=b[1];
    if(a[0]<=0){ flag=1; break;}
  }
  if(flag)cout<<"No";
  else cout<<"Yes";

}


Measured memory_bytes: 3624
<?php
list($n, $k) = fscanf(STDIN, '%d %d');
$p = trim(fgets(STDIN));
$p = explode(' ', $p);

$max = 0;
$current = 0;
$queue = new ArrayObject();
foreach ($p as $i => $v) {
    $v = (int)$v;

    $current += $v;
    $queue->offsetSet($i, $v);

    if ($i >= $k) {
        $removeIndex = $i - $k;
        $current -= $queue->offsetGet($removeIndex);
        $queue->offsetUnset($removeIndex);
    }

    $max = max($max, $current);
}

echo ($max + $k) / 2;


Measured memory_bytes: 29168
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

L = [(10-a%10)%10, (10-b%10)%10, (10-c%10)%10, (10-d%10)%10, (10-e%10)%10]
print(a+b+c+d+e+sum(L)- max(L))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pr printf
#define sc scanf

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef long double ld;

struct pt {
	int x, y, q1 = 0, q2 = 0, q3 = 0, q4 = 0;
};
bool comp1(pt p, pt q) {return p.x < q.x;}
bool comp2(pt p, pt q) {return p.x > q.x;}
int n;
vector<pt> li;
struct Node{
	int v = 0;
	Node *L = NULL, *R = NULL;
};
typedef Node *pNode;
int query(pNode &node, int l, int r, int i) {
	if(!node) return 0;
	if (l == r) return node->v;
	int m = (l+r)>>1;
	if(i <= m) return query(node->L, l, m, i);
	return ((node->L) ? node->L->v : 0) + query(node->R, m+1, r, i);
}

void update(pNode &node, int l, int r, int i) {
	if (l == r) {node->v = node->v + 1;return;}
	int m = (l+r)>>1;
	if(!node->L) node->L = new Node;
	if(!node->R) node->R = new Node;
	if(i <= m) update(node->L, l, m, i);
	else update(node->R, m+1, r, i);
	node->v = node->L->v + node->R->v;
}
pNode root;
int query(int i) {
	return query(root, -1000000000, 1000000000, i);
}

void update(int i) {
	update(root, -1000000000, 1000000000, i);
}

int powMod[200010];


int main () {
	root = new Node;
	sc("%d\n", &n);
	powMod[0] = 1;
	for(int i = 1; i <= n; i++) {
		powMod[i] = (powMod[i-1]+powMod[i-1]);
		if(powMod[i] >= 998244353) powMod[i] -= 998244353;
	}
	for(int i = 0; i <= n; i++) {
		powMod[i]--;
		if(powMod[i] < 0) powMod[i] += 998244353;
	}
    for(int i = 0; i < n; i++) {
		int x, y;
		sc("%d %d", &x, &y);
		li.push_back({x, y});
	}
	
	sort(li.begin(), li.end(), comp1);
	for(pt &p : li) {
		int q1 = query(p.y);
		int q2 = query(1000000000) - q1;
		p.q2 = q2;
		p.q3 = q1;
		update(p.y);
	}
	
	root = new Node;
	sort(li.begin(), li.end(), comp2);
	for(pt &p : li) {
		int q1 = query(p.y);
		int q2 = query(1000000000) - q1;
		p.q1 = q2;
		p.q4 = q1;
		update(p.y);
	}
	ll r = 0;
	for(pt p : li) {
		r = r + powMod[n] - powMod[p.q1 + p.q2] - powMod[p.q2 + p.q3] - powMod[p.q3 + p.q4] - powMod[p.q4 + p.q1] + powMod[p.q1] + powMod[p.q2] + powMod[p.q3] + powMod[p.q4];
	}
	pr("%lld\n", (((r)% 998244353LL) + 998244353LL) % 998244353LL);
    return 0;
}


Measured memory_bytes: 342380
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int k,n,diff1,diff2,mn=INT_MAX;
    cin>>k>>n;

    long long int a[n];

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

    for(long long int i=0;i<n;i++)
    {
        int nxt= (i+1)%n;
        int prv= (i-1+n)%n;

        if(a[i]<a[nxt])
            diff1= k- (a[nxt]-a[i]);
        else
            diff1= a[i]-a[nxt];

        if(a[i]>a[prv])
            diff2=k-(a[i]-a[prv]);
        else
            diff2=a[prv]-a[i];

        mn=min(diff1,mn);
        mn=min(diff2,mn);
    }
    cout<<mn<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <numeric>
#include <string>

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl

using namespace std;
using i64 = long long;

// m > n >= 0
template <class T>
T gcd(T m, T n)
{
    if (n == 0)
        return m;
    return gcd(n, m % n);
}

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

    // GCD(A,B) を割り切れる素数の個数 +1
    if (A < B)
        swap(A, B);
    i64 g; // GCD
    g = gcd(A, B);

    int gsq = sqrt(g);
    vector<int> primelist{2};
    vector<bool> seen(gsq + 10, false);
    // エラトステネスの篩
    // gsq以上の素数は高々一つ
    // なのでgsq以下の素数で順々に割っていけばよい
    for (int num = 3; num <= gsq; num++)
    {
        if (seen[num])
            continue;
        for (int i = 2; i * num <= gsq; i++)
            seen[i * num] = true;
        primelist.push_back(num);
    }

    int counter = 1;
    for (auto &&p : primelist)
    {
        if (g % p != 0)
            continue;
        counter++;
        while (g % p == 0)
        {
            g /= p;
        }
    }
    if (g != 1)
        counter++;

    /*
    debug(g);
    for (auto &&p : primelist)
    {
        debug(p);
    }
    */

    cout << counter << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
	#ifdef LOCAL
	freopen("input.txt","r", stdin);
	#endif
	string s;
	cin >> s;
	int count  = 0;
	int ans = 0;
	for(int i=0;i<3;i++){
		if(s[i]=='R')count++;
		else count = 0;
		ans = max(ans, count);
	}
	cout << ans;
}

Measured memory_bytes: 3624
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Deque<Integer> deq = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            if(n % 2 != 0) {
                if(i % 2 == 0) {
                    deq.addFirst(sc.nextInt());
                } else {
                    deq.addLast(sc.nextInt());
                }
            } else {
                if(i % 2 == 0) {
                    deq.addLast(sc.nextInt());
                } else {
                    deq.addFirst(sc.nextInt());
                }
            }

        }
        for (int i : deq) {
            System.out.print(i + " ");
        }
    }
}

Measured memory_bytes: 66524
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int j,k;long long l,r,ans=0;
int main()
{
	cin>>l>>r;
	if(l==r) return 0*puts("1");
	for(j=60;~j;--j) 
		if((l&(1LL<<j))!=(r&(1LL<<j))) break; 
		else l=min(l,l^(1LL<<j)),r=min(r,r^(1LL<<j));
	ans+=(1LL<<j)-l;
	for(k=j-1;~k;--k) if(r&(1LL<<k)) break;
	ans+=(1LL<<k+1)+(1LL<<j)-l-max(0LL,(1LL<<k+1)-l);
	cout<<ans;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool is_pal(string s){
	 int i=0;
	 int j=s.size()-1;
	 while(i<=j){
        if(s[i]!=s[j])
        	return false;
        i++;
        j--;
	 }
	 return true;
}
int main(){
FASTIO	
string s;
cin>>s;
int n=s.size();
string s1;
for(int i=1;i<=((n-1)/2);i++){
	s1+=s[i-1];
}
string s2;
for(int i=((n+3)/2);i<=n;i++){
	s2+=s[i-1];
}
if((is_pal(s))&&(is_pal(s1))&&(is_pal(s2))){
	cout<<"Yes";
}
else{
	cout<<"No";
}
return 0;
}

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

int main() {
    int R;
    cin >> R;
    cout << 2 * R * M_PI << endl;
    return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	long long ans=0;
	for(int i=0;i<(1<<(s.size()-1));i++)
	{
		int last=-1;
		long long res=0;
		for(int j=0;j+1<s.size();j++)
		{
			if((i&(1<<j))!=0)
			{
				long long cur=0;
				for(int k=last+1;k<=j;k++)
				{
					cur=cur*10+s[k]-'0';
				}
				res+=cur;
				last=j;
			}
		}
		long long cur=0;
		for(int j=last+1;j<s.size();j++)
		{
			cur=cur*10+s[j]-'0';
		}
		res+=cur;
		ans+=res;
	}
	cout<<ans<<"\n";
 	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<utility>
using namespace std;

int d[6][2]={{1,1},{0,1},{-1,0},{-1,-1},{0,-1},{1,0}};

int main(){
  int t,n;
  while(cin>>t>>n,t){
    bool map[200][200]={false};
    int x=0,y=0;
    for(int i=0;i<n;i++){
      cin>>x>>y;
      map[y+100][x+100]=true;
    }
    cin>>x>>y;
    //  cout<<" t = "<<t<<" , n = "<<n<<endl;
    x+=100;
    y+=100;
    int cnt=0;
    queue<pair<int,int> > q;
    q.push(make_pair(y*1000+x,0));
    map[y][x]=true;
    while(!q.empty()){
      pair<int,int> p=q.front();
      if(p.second>t) break;
      //  cout<<" t = "<<t<<" p.second="<<p.second<<endl;
      y=p.first/1000;
      x=p.first%1000;
      cnt++;
      q.pop();
      //      cout<<" x = "<<x<<" y = "<<y<<" p.first ="<<p.first<<" p.second = "<<p.second<<endl;
      for(int i=0;i<6;i++){
	int xx=x+d[i][0];
	int yy=y+d[i][1];
	if(!map[yy][xx]){
	  map[yy][xx]=true;
	  q.push(make_pair(yy*1000+xx,p.second+1));
	}
      }
    }
    cout<<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 1260
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string s;
  cin >> s;
  ll ans = 0;
  for (auto c : s) {
    if (c == '1') ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    map<ll, ll> mp;
    rep(i, n) {
        cin >> a[i];
        mp[a[i]]++;
    }

    ll ans = 0;
    for (auto &p : mp) {
        ans += p.second * (p.second - 1) / 2;
    }

    rep(i, n) {
        int now = mp[a[i]];
        cout << ans - now + 1 << "\n";
    }

    return 0;
}

Measured memory_bytes: 11952
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

vector<ll> divisor(ll n){
	vector<ll> res;
	for(ll i = 1; i*i <= n; i++){
		if(n%i == 0){
			res.push_back(i);
			if(i != n/i) res.push_back(n/i);
		}
	}
	return res;
}

int digits(ll n){
	int res = 0;
	while(n > 0){
		n /= 10;
		res++;
	}
	return res;
}

int f(ll a, ll b){
    int ret = digits(a);
    chmax(ret, digits(b));
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> div = divisor(n);
    int ans = 10;
    for(auto p : div){
        ll a = p, b = n/p;
        chmin(ans, f(a, b));
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
  int x,y;
  cin>>x>>y;
  string ans="No";
  int s[]={ 0,1,3,1,2,1,2,1,1,2,1,2,1};
  if(s[x]==s[y]) ans="Yes";
  cout<< ans <<endl;
}



Measured memory_bytes: 256
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

A = [a for a, b in AB]
B = [b for a, b in AB]

A.sort()
B.sort()

if N % 2:
    ma = B[N // 2]
    mi = A[N // 2]
else:
    ma = B[N // 2 - 1] + B[N // 2]
    mi = A[N // 2 - 1] + A[N // 2]

print(ma - mi + 1)

Measured memory_bytes: 117356
#include<iostream>
#include<queue>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<map>

using namespace std;

int main(){
    int a;
    string s;
    cin >> a;
    cin >> s;
    if(a>=3200){
        cout << s << endl;
    }
    else{
        cout << "red" << endl;
    }
}

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

int main(){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    
    rep(i, tx-sx){
        cout << "R";
    }
    rep(i, ty-sy){
        cout << "U";
    }

    rep(i, tx-sx){
        cout << "L";
    }
    rep(i, ty-sy){
        cout << "D";
    }
    
    cout << "D";
    rep(i, tx-sx+1){
        cout << "R";
    }
    rep(i, ty-sy+1){
        cout << "U";
    }
    cout << "L";

    cout << "U";
    rep(i, tx-sx+1){
        cout << "L";
    }
    rep(i, ty-sy+1){
        cout << "D";
    }
    cout << "R" << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int num[] = new int[n];
            for(int i = 0 ; i < n ; i++)
                num[i] = sc.nextInt();
            for(int i = n - 1 ; i > 0 ; i--)
                System.out.print(num[i] + " ");
            System.out.println(num[0]);
    }
}


Measured memory_bytes: 26204
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<cmath>
#include<string>
#include<cstring>
using namespace std;
long long num[200005], sum[200005];
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &num[i]);
		sum[num[i]]++;
	}
	long long ans = 0;
	for (int i = 1; i <= n; i++)
	{
		ans += (sum[i] - 1) * sum[i] / 2;
	}
	for (int i = 0; i < n; i++)
	{
		printf("%lld\n", ans - (sum[num[i]] - 1));
	}
	return 0;
}

Measured memory_bytes: 4736
#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;
  sort(a.begin(), a.end());
  
  int r=a[0], num=1;
  for(int i=1; i<n; ++i){
    if(a[i]==r)++num;
    else{
      if(num-r>=0)ans+=min(num-r, num);
      else ans+=num;
      r=a[i]; num=1;
    }
  }
  if(num-r>=0)ans+=min(num-r, num);
  else ans+=num;
  
  cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<ll>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool a)
{
    if (a == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

ll gcd(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

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

    vector<bool> a(100000000, false);
    a[s] = true;
    int ans = 1;
    while (1)
    {
        ans++;
        if (s % 2 == 0)
        {
            s /= 2;
            if (a[s])
                break;
            a[s] = true;
        }
        else
        {
            s = s * 3 + 1;
            if (a[s])
                break;
            a[s] = true;
        }
    }
    cout << ans << endl;
}


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


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

    if(N >= B-1) {
      cout << floor(A*(B-1)/B) << endl;
      return 0;
    } else {
      cout << floor(N*A/B) << endl;
      return 0;
    }
    
  
    
}

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

int main(){
  int A, B;
  cin >> A >> B;
  if(A==1){
    if(B==2){
      cout << 3 << endl;
    }
    else{
      cout << 2 << endl;
    }
  }
  else if(A==2){
    if(B==1){
      cout << 3 << endl;
    }
    else{
      cout << 1 << endl;
    }
  }
  else{
    if(B==1){
      cout << 2 << endl;
    }
    else{
      cout << 1 << endl;
    }
  }   
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <time.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 2020000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll a,b,c,k; cin >> a >> b >> c >> k;
	while(a >= b){
		b *= 2;
		k--;
	}
	while(b >= c){
		c *= 2;
		k--;
	}
	if(k < 0) puts("No");
	else puts("Yes");
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int[] L=new int[N];
		int max=0;int mi=0;
		for(int i=0;i<N;i++) {
			L[i]=sc.nextInt();
			if(L[i]>max) {max=L[i];mi=i;}
		}
		int S=0;
		for(int i=0;i<N;i++) {
			if(i!=mi)S+=L[i];
		}
		String str="No";
		if(S>max)str="Yes";
		
		
		System.out.println(str);
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 998244353
#define fcout cout << fixed << setprecision(15)
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

int mod_pow(int x, int pow) {
    if(pow == 0) return 1;
    int a = mod_pow(x, pow / 2);
    a = a * a % MOD;
    if(pow % 2 == 1) a *= x;
    return a % MOD;
}

int mod_div(int a, int b) {
    return a * mod_pow(b, MOD - 2) % MOD;
}

vector<int> fact;

void init_fact(int n) {
    fact = vector<int>(n);
    fact[0] = 1;
    for(int i = 1; i < n; i++) fact[i] = fact[i - 1] * i % MOD;
}

int calc_comb(int n, int r) {
    if(n < r) return 0;
    return mod_div(fact[n], fact[r] * fact[n - r] % MOD);
}

signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    init_fact(200020);
    int n, m, k;
    cin >> n >> m >> k;
    int ans = 0;
    rep(i, k+1) {
        int cur = calc_comb(n - 1, i) * mod_pow(m - 1, n - 1 - i);
        ans += cur % MOD, ans %= MOD;
    }
    cout << ans * m % MOD << endl;
    return 0;
}

Measured memory_bytes: 4764
package main

import (
	"bufio"
	"fmt"
	"math/rand"
	"os"
	"strconv"
	"time"
)

const (
	limitSecs = 2.0
)

// D
var (
	D         int
	c         [26]int
	s         [][26]int
	startTime time.Time
)

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func calcScore(t []int) int {
	var last [26]int
	score := 0
	S := 0
	for i := 0; i < 26; i++ {
		last[i] = -1
	}
	for d := 0; d < len(t); d++ {
		S += s[d][t[d]]
		last[t[d]] = d
		for i := 0; i < 26; i++ {
			S -= c[i] * (d - last[i])
		}
		score += max(1000000+S, 0)
	}
	return score
}

func solution3() []int {
	var t []int
	for d := 0; d < D; d++ {
		score := -1
		best := -1
		t = append(t, 0)
		for i := 0; i < 26; i++ {
			t[len(t)-1] = i
			newScore := calcScore(t)
			if newScore > score {
				best = i
				score = newScore
			}
		}
		t[len(t)-1] = best
	}
	return t
}

func optimize1(t []int) []int {
	var (
		d   [3]int
		old [3]int
	)
	rand.Seed(time.Now().UnixNano())
	score := calcScore(t)
	for time.Now().Sub(startTime).Seconds()+0.011 < limitSecs {
		n := rand.Intn(3) + 1
		for i := 0; i < n; i++ {
			d[i] = rand.Intn(D)
			old[i] = t[d[i]]
			t[d[i]] = rand.Intn(26)
		}
		newScore := calcScore(t)
		if newScore < score {
			for i := n - 1; i > -1; i-- {
				t[d[i]] = old[i]
			}
		} else {
			score = newScore
		}
	}
	return t
}

func main() {
	defer flush()

	startTime = time.Now()

	D = readInt()
	for i := 0; i < 26; i++ {
		c[i] = readInt()
	}
	s = make([][26]int, D)
	for i := 0; i < D; i++ {
		for j := 0; j < 26; j++ {
			s[i][j] = readInt()
		}
	}

	t := solution3()
	t = optimize1(t)
	for d := 0; d < D; d++ {
		println(t[d] + 1)
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


Measured memory_bytes: 2196
#include <stdio.h>
int c[] = { 0,31,60,91,121,152,182,213,244,274,305,335 };
char n[7][10] = { "Wednesday", "Thursday", "Friday", "Saturday",
		  "Sunday", "Monday", "Tuesday"};
int main()
{
  int m,d;
  for(;;){
    scanf("%d%d",&m,&d);
    if(m==0)break;
    printf("%s\n",n[(c[m-1]+d)%7]);
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int read() {
	int x; scanf("%d", &x); return x;	
}
const int maxn = 3e5 + 10;
const int INF = 1e9;
int mod = 1e9 + 7;
using namespace std;

int S(int K) {
	if (K == 7 || K == 1) return 1;
	vector<bool> r(K, false);
	int c = 7, len = 1;
	r[c] = true;
	while (1) {
	    c = (c * 10 + 7) % K;
	    len++;
	    if (c == 0) return len;
	    else if (r[c]) {
	        break;
	    }
	    r[c] = true;
	}
	return -1;
}
int main() {
	cout << S(read()) << endl;
	return 0;
}


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

using ll = long long;

const int N = 100005;

char s[N];
int n;

void F(){ puts("-1"); exit(0); }

int main(){
    scanf("%s", s + 1);
    n = strlen(s + 1);
    for(int i = 1; i <= n; i++) s[i] -= '0';
    if(!s[1] || s[n]) F();
    for(int i = 1; i <= n / 2; i++) if(s[i] != s[n - i]) F();
    puts("1 2");
    for(int i = 2, c = 1; i < n; i++){
        printf("%d %d\n", c, i + 1);
        if(s[i]) c = i + 1;
    }
}

Measured memory_bytes: 1536
#include <iostream>
        #include <vector>
        #include <algorithm>
        #include <cmath>
         
        using namespace std;
         
        int main() {
          int A,B,Q;
          cin >> A >> B >> Q;
          
          vector<long long> jin(A+2);
          vector<long long> tera(B+2);
          
          long long INF = std::pow(10, 18);
          
          jin[0] = -INF;
          jin[A+1] = INF;
            
          tera[0] = -INF;
          tera[B+1] = INF;
          
          for (int i=1; i<A+1;i++){
            cin >> jin[i];
          }
          for (int i=1; i<B+1;i++){
            cin >> tera[i];
          }
          
          long long qu;
          
          for (int i; i<Q;i++){
            //cin >> qu[i];
            cin >> qu;
            long long b = upper_bound(jin.begin(), jin.end(), qu) - jin.begin();
            long long d = upper_bound(tera.begin(), tera.end(), qu) - tera.begin();
            
            long long res = INF;
            vector<long long> jinv{jin[b-1],jin[b]};
            vector<long long> terav{tera[d-1],tera[d]};
            vector<long long> dv(3);
     
            for (auto j: jinv) {
              for (auto t: terav){
                dv[0] = std::abs(j-qu)+std::abs(t-j);
                dv[1] = std::abs(t-qu)+std::abs(j-t);
                dv[2] = res;
                res = *std::min_element(dv.begin(), dv.end());
              }
            }
            cout << res << endl;
            
          }
        return 0;
        }

Measured memory_bytes: 2944
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

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

        int N = sc.nextInt();
        String[] S = new String[N];
        int[] P = new int[N];
        for (int i = 0; i < N; ++i) {
            S[i] = sc.next();
            P[i] = sc.nextInt();
        }

        System.out.println(solve(S, P));

        sc.close();
    }

    static String solve(String[] S, int[] P) {
        return IntStream.range(0, S.length).boxed()
                .sorted((i1, i2) -> !S[i1].equals(S[i2]) ? S[i1].compareTo(S[i2]) : -Integer.compare(P[i1], P[i2]))
                .map(i -> String.valueOf(i + 1)).collect(Collectors.joining("\n"));
    }
}

Measured memory_bytes: 36596
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ln "\n"
#define pb push_back
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define vll vector<ll>
#define vpll vector<pll>
#define vvll vector<vector<ll>>
#define sll stack<ll>
#define qll queue<ll>
#define mp make_pair
#define f first
#define s second
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define Test ll t;cin>>t; while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define init(x,n,v) for(ll i=0;i<=n;i++) x[i]=v;
#define all(x) x.begin(),x.end()
ll MOD = 1e9+7 , MAX = 1e18;
int main() 
{
	fast_io;
	ll n,i,w,j,s=0,ans;
	cin>>n>>w;
	vpll k(n);
	for(auto &i: k) cin>>i.f>>i.s , s+=i.s;
	ll dp[s+1];
	init(dp,s,MAX);
	dp[0]=0;
	for(auto i: k)
	 for(j=s-i.s;j>=0;j--)
	  dp[j+i.s]=min(dp[j+i.s],dp[j]+i.f);
	for(i=0;i<=s;i++) if(dp[i]<=w) ans=i;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int n,t,t1,h=0;
	 int *g;
	 scanf("%d",&n);
	g = (int*)malloc(sizeof(int)*n);
	 for(t=0;t<n;t++)
	{
		scanf("%d",&g[t]);
		h += g[t];
	}
	 for(t=0;t<n;t++)
	{
		for(t1=t+1;t1<n;t1++)
		{
			if(g[t]>g[t1])
			{
				int a;
				a = g[t];
				g[t] = g[t1];
				g[t1] = a;
			}
		}
	}
	 if(h%10 != 0) goto z;
	 for(t=0;t<n;t++)
	{
		for(t1=t;t1<n;t1++)
		{
			h -= g[t1];
			if(h%10 != 0) goto z;
			else		h+=g[t1];
		}
		h -= g[t];
	}
z:	printf("%d\n",h);
	 return 0;
}

Measured memory_bytes: 128