akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] arg) {
		while (true) {
			int T = sc.nextInt();
			int P = sc.nextInt();
			int R = sc.nextInt();
			if (T == 0) break;
			Team[] ts = new Team[T];
			for (int i = 0; i < T; ++i) {
				ts[i] = new Team(i + 1);
			}
			for (int i = 0; i < R; ++i) {
				int tid = sc.nextInt() - 1;
				int pid = sc.nextInt() - 1;
				int time = sc.nextInt();
				if (sc.next().length() == "CORRECT".length()) {
					ts[tid].ac++;
					ts[tid].pena += time + ts[tid].wa[pid] * 1200;
				} else {
					ts[tid].wa[pid]++;
				}
			}
			Arrays.sort(ts);
			for (int i = 0; i < T; ++i) {
				System.out.println(ts[i].tid + " " + ts[i].ac + " " + ts[i].pena);
			}
		}
	}

	static class Team implements Comparable<Team> {
		int ac, pena, tid;
		int[] wa = new int[10];

		Team(int tid) {
			this.tid = tid;
		}

		public int compareTo(Team o) {
			if (this.ac != o.ac) return o.ac - this.ac;
			if (this.pena != o.pena) return this.pena - o.pena;
			return this.tid - o.tid;
		}
	}

}

Measured memory_bytes: 62028
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL A, B;
	in >> A >> B;
	if (A != 1 && B != 1) out << 1 << std::endl;
	if (A != 2 && B != 2) out << 2 << std::endl;
	if (A != 3 && B != 3) out << 3 << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    int M;
    cin >> N; 
    cin >> M;
    vector<int> array(M * 2);
    vector<int> sum(N);
    for(int i = 0;i < M * 2;i++){
        cin >> array.at(i);
        sum.at(array.at(i) - 1)++;    
    }
    for(int j = 0;j < N;j++){
        cout << sum.at(j) << endl;
    }
}
   
   

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <bitset>
using namespace std;

void Main() {
    // input
    int H, W, K;
    cin >> H >> W >> K;
    int field[H+1][W+1];
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            char c;
            cin >> c;
            if (c == '.') {
                field[i][j] = 0; // 0 white
            } else {
                field[i][j] = 1; // 1 black
            }
        }
    }

    // translate
    int count = 0;
    int allH = 1;
    for (int i = 0; i < H; i++) {
        allH *= 2;
    }
    int allW = 1;
    for (int j = 0; j < W; j++) {
        allW *= 2;
    }

    for (int i = 0; i < allH; i++) {
        for (int j = 0; j < allW; j++) {
            bitset<8> bsH(i);
            bitset<8> bsW(j);

            int black_cnt = 0;
            for (int h = 0; h < H; h++) {
                if (bsH[h]) {
                    continue;
                }
                for (int w = 0; w < W; w++) {
                    if (bsW[w]) {
                        continue;
                    }
                    if (field[h+1][w+1] == 1) {
                        black_cnt++;
                    }
                }
            }

            // cout << "H: " << bsH << ", W: " << bsW << " cnt: " << black_cnt << endl; 
            if (black_cnt == K) {
                count++;
            }
        }
    }

    // output
    cout << count << endl;

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>

void trace(int A[], int N){
 int i;
 for (i = 0; i < N; i++) {
  if ( i > 0 ) printf(" ");
  printf("%d", A[i]);
 }
 printf("\n");
}

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

int main() {
 int N, i, j;
 int A[100];

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

 trace(A, N);
 insertionSort(A, N);

 return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<string>
using namespace std;
int n,thn,tmh;
int main(){
	string s;
	cin>>n>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='I')
		    thn++;
		else
		    thn--;
		if(thn>tmh)
		    tmh++;
	}
	cout<<tmh<<endl;
	return 0;
}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int n= sc.nextInt();
			if(n==0)break;
			
			int flag = 0;
			int ans = 0;
			String[] s = new String[n];
			for(int i=0;i<n;i++) {
				s[i] = sc.next();
			}
			
			int[] haiku = {5,7,5,7,7};
			int c = 0;
			for(int i=0;i<n;i++) {
				for(int j=0;j<=4;j++) {
					if(j==0 && haiku[0]==5) {
							c=i;
					}
					if(haiku[j]==0)continue;
					if(haiku[j]-s[i].length() >= 0) {
						haiku[j] -= s[i].length();
						if(j==4 && haiku[4]==0) {
							ans = c+1;
							flag = 1;
						}
						break;
					}
					else if(haiku[j]-s[i].length() < 0) {
						haiku[0]=5;haiku[1]=7;haiku[2]=5;haiku[3]=7;haiku[4]=7;
						i=c;
						break;
					}	
				}
				if(flag==1)break;
			}
			System.out.println(ans);
			
		}
	}

}



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

    private static final int INF = 1_000_000_000;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        char[][] S = new char[H][W];
        for (int i = 0; i < H; i++) {
            String s = sc.next();
            for (int j = 0; j < W; j++) {
                S[i][j]= s.charAt(j);
            }
        }

        int[] ii = new int[H*W];
        int[] jj = new int[H*W];
        int ti = 0;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                ii[ti] = i;
                jj[ti] = j;
                ti++;
            }
        }

        int[][] dist = new int[H*W][H*W];
        for (int p = 0; p < H*W; p++) {
            for (int q = 0; q < H*W; q++) {
                if (p == q)  {
                    dist[p][q] = 0;
                } else {
                    dist[p][q] = INF;
                    dist[q][p] = INF;
                }
            }
        }

        // up, down, left, right
        int[] vi = new int[] { -1, 1, 0, 0 };
        int[] vj = new int[] { 0, 0, -1, 1 };
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (S[i][j] == '#') {
                    continue;
                }
                for (int v = 0; v < 4; v++) {
                    int iii = i+vi[v];
                    int jjj = j+vj[v];
                    if (0 <= iii && iii < H && 0 <= jjj && jjj < W
                        && S[iii][jjj] == '.') {
                        int src = i*W + j;
                        int dst = iii*W + jjj;
                        dist[src][dst] = 1;
                        dist[dst][src] = 1;
                    }
                }
            }
        }

        for (int k = 0; k < H*W; k++) {
            for (int p = 0; p < H*W; p++) {
                for (int q = 0; q < H*W; q++) {
                    if (dist[p][q] != -1 && dist[p][k] != -1 && dist[k][q] != -1) {
                        dist[p][q] = Math.min(dist[p][q], dist[p][k]+dist[k][q]);
                    }
                }
            }
        }

        /*
        for (int i = 0; i < H*W; i++) {
            System.out.print(ii[i]+" ");
        }
            System.out.println();
        for (int i = 0; i < H*W; i++) {
            System.out.print(jj[i]+" ");
        }
            System.out.println();

        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                System.out.print(S[i][j]);
            }
            System.out.println();
        }
        */

        int ans = 0;

        for (int p = 0; p < H*W; p++) {
            for (int q = 0; q < H*W; q++) {
                if (dist[p][q] != INF) {
                    ans = Math.max(ans, dist[p][q]);
                }
            }
        }


        System.out.println(ans);
    }
}


Measured memory_bytes: 24324
def division(n):
    if n < 2:
        return []
    prime_factors = []
    for p in prime_sieve(int(n ** 0.5)):
        if p * p > n: break
        while n % p == 0:
            prime_factors.append(p)
            n //= p
    if n > 1:
        prime_factors.append(n)
    return prime_factors


def prime_sieve(m):
    prime = list(map(int, "2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 "
                          "127 "
                          "131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 "
                          "251 257 "
                          "263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 "
                          "397 401 "
                          "409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 "
                          "557 563 "
                          "569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 "
                          "701 709 "
                          "719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 "
                          "863 877 "
                          "881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997".split()))
    for x in reversed(range(0, len(prime))):
        if prime[x] > m:
            del prime[x]
    return prime


N = int(input())
prime_dict = {}
primea = prime_sieve(1000)
ans = 1
for t in primea:
    prime_dict[t] = 0
for q in range(2, N + 1):
    for r in division(q):
        prime_dict[r] += 1
for r in prime_dict.values():
    ans *= (r + 1)
print(ans % (10 ** 9 + 7))


Measured memory_bytes: 3064
x,y=map(int,input().split())
z=abs(abs(x)-abs(y))
if z==0:print(1)
elif abs(x)>abs(y):
    if x>0 and y>0:print(z+2)
    elif (x==0 and y>0) or (x<0 and y==0) or (x<0 and y<0):print(z)
    else:print(z+1)
else:
    if x<0 and y<0:print(z+2)
    elif (x==0 and y>0) or (x<0 and y==0) or (x>0 and y>0):print(z)
    else:print(z+1)

Measured memory_bytes: 3064
//https://atcoder.jp/contests/abc142/tasks/abc142_b
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	ll h;
	cin>>h;
	vector<ll> lis;
	lis.resize(n);
	ll i;
	for(i=0;i<n;i++)
	{
		cin>>lis[i];
	}
	ll cnt=0;
	for(i=0;i<n;i++)
	{
		if(lis[i]>=h)
		{
			cnt=cnt+1;
		}
		else
		{
			cnt=cnt;
		}
	}
	cout<<cnt<<"\n";
	return 0;
}

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

void Main()
{
  int a,b,c,k; cin >> a >> b >> c;
  cin >> k;
  rep(i,k) {
    if (a < b and b < c) {cout << "Yes" << endl; return;}
    else {
      if (a >= b) b *= 2;
      else if (b >= c) c *= 2;
    }
    //cout << a << b << c << endl;
  }
  if (a < b and b < c) {cout << "Yes" << endl; return;}
  cout << "No" << endl;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<map>
using namespace std;
#define repc(c) for(char c = 'A'; c <= 'Z'; c++)
int main() {
	int n;
	while (cin >> n, n) {
		map<char, int>m;
		repc(c)m[c] = 0;
		char s[1145];
		for (int i = 1; i <= n; i++)cin >> s[i];
		char maxc = 'A';int maxv = 0;
		for (int i = 1; i <= n; i++) {
			m[s[i]]++;
			if (maxv < m[s[i]]) { maxc = s[i]; maxv = m[s[i]]; }
			repc(c)if (c == maxc)continue; else if (m[c] + n - i >= m[maxc])goto conti;
			cout << maxc << ' ' << i << endl;
			goto endl;
		conti:;
		}
		cout << "TIE\n";
		endl:;
	}
}

Measured memory_bytes: 3084
#include <stdio.h>

int main(void){
    int a,b,d,r;
    double f;
    scanf("%d %d",&a,&b);
    d=a/b;
    r=a%b;
    f=(double)a/(double)b;
    printf("%d %d %f\n",d,r,f);
    return 0; /*0?????????*/
}

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

typedef long double ld;
const ld eps = 1.0e-16; // 許容される誤差

ld mysqrtl(ld x)
{
  ld a = sqrt((double)x); // 近似値
  do {
    a = (a + x/a) / 2.0L;
  } while (fabsl(x - a*a) > eps);
  return a;
}

ld	mto2pi(int m)
{
  	return 3.14159265358979323846264338327950L * (long double)m / 30.0L;
}

ld	hto2pi(int h, int m)
{
	return 3.14159265358979323846264338327950L * ((long double)h * 30.0L + (long double)m / 2.0L) / 180.0L;
}

int main(void)
{
  	int a;
  	int b;
  	int h;
  	int m;
  	ld	t;
  	ld	l;
  	ld  aa;
  	ld  bb;
  	    
  	scanf("%d %d %d %d", &a, &b, &h, &m);
  
    aa = (long double)a;
    bb = (long double)b;
    
	t = hto2pi(h, m) - mto2pi(m);
  
    l = sqrtl(aa * aa + bb * bb - 2.0L * aa * bb * cosl(t));
  	printf("%22.20Lf", l);
  
  	return (0);
}



Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
#define fori(i,n) for(int i =0;i<n;i++)
#define pb push_back
#define ll long long
#define int long long
#define F first
#define S second
#define mp make_pair
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout.precision(15);
 
 
int mod = 1e9+7;
 
int pow(int a, int b) {
    int ans = 1;
    a %= mod;
    while(b) {
        if(b%2) {
            ans *= a;
            ans %= mod;
        }
        b /= 2;
        a *= a;
        a %= mod;
    }
    return ans;
}

int inv(int a) {
    return pow(a,mod-2);
}

int mul (int a,int b) {
    return ((a%mod)*(b%mod))% mod;
}

struct cmp {
    bool operator() (pair<int,int> a, pair<int,int> b) const {
        int x = a.F;
        int y = b.F;
        return x>=y;
    }
};


int32_t main() {
    FAST;
    int t;
    // cin>>t;
    t = 1;
    while(t--) {
        int x,n;
        cin>>x>>n;
        int dist = 1e9;
        set<int> s;
        for(int i = -1000;i<=1000;i++) {
            s.insert(i);
        }
        int p;
        fori(i,n) {
            cin>>p;
            s.erase(p);
        }

        int ans = 1e9;
        for(auto q : s) {
            if(abs(q-x) < dist) {
                ans = q;
                dist = abs(q-x);
            }
        }
        cout<<ans;
    }
    
    return 0;
}

Measured memory_bytes: 3744
#include<iostream>
using namespace std;
int x[5000][2],k;
void lookd(int);
int main(){
  int n,q,m;
  int a,lam,fad;
  while(1){
    //
    for(int i=0;i<5000;i++){
      for(int j=0;j<2;j++){
	x[i][j]=0;
      }
    }
    k=0;
    lam=0;
    fad=0;
    //in
    cin >> n >> q;
    if(n==0&&q==0)break;
    for(int i=0;i<n;i++){
      cin >> m;
      if(m==0)continue;
      for(int j=0;j<m;j++){
	cin >> a;
	lookd(a);
      }
    }
    for(int i=0;i<k;i++){
      if(x[i][1]>lam){
	lam=x[i][1];
	fad=x[i][0];
      }
      else if(x[i][1]==lam){
	if(fad>x[i][0])fad=x[i][0];
	}
    }
    if(lam>=q){
      cout << fad << endl;
    }
    else cout << 0 << endl;
  }
return 0;
}
void lookd(int m){
  for(int i=0;i<k;i++){
    if(x[i][0]==m){
      x[i][1]++;
      return;
    }
  }
  x[k][0]=m;
  x[k][1]++;
  k++;
  return;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n,x,m;
    cin >> n >> x >> m;
    vector<ll>roop(m,0);
    ll a=x;
    ll cnt=1;
    ll ans=x;
    bool lim=false;
    for(ll i=0;i<m+10;i++){
        a=(a*a)%m;
        cnt++;
        ans+=a;
        if(cnt==n) {
            lim=true;
            break;
        }
        bool ok=false;
        roop[a]++;
        if(roop[a]>=2) ok=true;
        if(ok) break;
    }
    if(lim){
        cout << ans << endl;
        return 0;
    }
    n-=cnt;
    ans-=a;
    n++;
    vector<ll>num;
    bool judge=true;
    ll b=a;
    num.push_back(a);
    ll sum=a;
    while(judge){
        b=(b*b)%m;
        if(b==a) break;
        num.push_back(b);
        sum+=b;
    }
    ll siz=num.size();
    ll aa=n/siz;
    ans+=sum*aa;
    n-=aa*siz;
    for(ll i=0;i<n;i++){
        ans+=num[i];
    }
    cout << ans << endl;
}
    

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

struct katana_t
{
    bool operator<( const katana_t& right ) const {
        return b>right.b;
    }
    int a;
    int b;
};

int main(void){
    int n,h;
    cin >> n >> h;
    katana_t k[n];
    int aMax=0;
    unsigned long long int ans=0;
    for (size_t i = 0; i < n; i++)
    {
        scanf("%d %d",&(k[i].a),&(k[i].b));
        if (aMax<k[i].a)aMax=k[i].a;
    }
    sort(k,k+n);
    for (size_t i = 0; i < n && aMax < k[i].b; i++)
    {
        h-=k[i].b;
        ans++;
        if(h<=0)break;
    }
    while (h>0)
    {
        h-=aMax;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
class Main{
  static Integer []cache;
  public static void main(String []args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    cache=new Integer[n];
    int []height=new int[n];
    for(int i=0;i<n;i++){
      height[i]=sc.nextInt();
    }
    System.out.println(ans(height,0));
  }
        
    public static int ans(int[] h,int index){
        if(index==h.length-1) return 0;
        if(cache[index]!=null) return cache[index];
        int one=Integer.MAX_VALUE;
        int two=Integer.MAX_VALUE;
        if(index+1<h.length){
            one=ans(h,index+1)+Math.abs(h[index]-h[index+1]);
        }
        if(index+2<h.length){
            two=ans(h,index+2)+Math.abs(h[index]-h[index+2]);
        }
        return cache[index]=Math.min(one,two);
    }
}

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

/* Aho-Corasick (source: Spaghetti Source)*/
#define ALL(v) (v).begin(), (v).end()

// buildPMA: 0 ... m-1 の複数の検索パターンから，パターンマッチング・オートマトンを構築する．
// match: t を PMA に流し込む．result[k] には p[k] が t に何回現れたかが入る．

struct PMA {
  PMA *next[0x100]; // next[0] is for fail
  vector<int> accept;
  PMA() { fill(next, next+0x100, (PMA*)0); }
};
vector<int> set_union(const vector<int> &a,const vector<int> &b) {
  vector<int> res;
  set_union(ALL(a), ALL(b), back_inserter(res));
  return res;
}
PMA *buildPMA(char *p[], int size) {
  PMA *root = new PMA;
  for (int i = 0; i < size; ++i) { // make trie
    PMA *t = root;
    for (int j = 0; p[i][j]; ++j) {
      char c = p[i][j];
      if (t->next[c] == NULL) t->next[c] = new PMA;
      t = t->next[c];
    }
    t->accept.push_back(i);
  }
  queue<PMA*> Q; // make failure link using bfs
  for (int c = 'a'; c <= 'z'; ++c) {
    if (root->next[c]) {
      root->next[c]->next[0] = root;
      Q.push(root->next[c]);
    } else root->next[c] = root;
  }
  while (!Q.empty()) {
    PMA *t = Q.front(); Q.pop();
    for (int c = 'a'; c <= 'z'; ++c) {
      if (t->next[c]) {
        Q.push(t->next[c]);
        PMA *r = t->next[0];
        while (!r->next[c]) r = r->next[0];
        t->next[c]->next[0] = r->next[c];
        t->next[c]->accept = set_union(t->next[c]->accept, r->next[c]->accept);
      }
    }
  }
  return root;
}
int match(char *t, PMA *v, int *result) {
  int n = strlen(t);
  int count = 0;
  for (int i = 0; i < n; ++i) {
    char c = t[i];
    while (!v->next[c]) v = v->next[0];
    v = v->next[c];
    for (int j = 0; j < v->accept.size(); ++j)
      result[v->accept[j]]++;
  }
}

char s[125252];
char t[252521];
char *ts[125252];

int main(){
  scanf("%s",s);
  int head = 0;
  int n;
  scanf("%d",&n);
  REP(i,n){
    scanf("%s",t+head);
    int l = strlen(t+head);
    ts[i] = t+head;
    head += l+1;
  }
  PMA *root = buildPMA(ts, n);
  PMA *cur = root;
  int ans = 0;
  int m = strlen(s);
  REP(i,m){
    char c = s[i];
    while(!cur->next[c]) cur = cur->next[0];
    cur = cur->next[c];
    if(cur->accept.size() > 0){
      ans++;
      cur = root;
    }
  }
  printf("%d\n",ans);
  return 0;
}




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

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)

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; }

const ll INF = 1LL << 60;
ll dp [100100];

int main(){
  int n; cin >> n;
  dp[0] = 0;
  for (int i = 1; i <= n; i++) {
    dp[i] = INF;
    int power = 1;
    while (power <= i) {
      chmin(dp[i],dp[i-power] + 1);
      power *= 6;
    }

    power = 1;
    while (power <= i) {
      chmin(dp[i], dp[i-power] + 1);
      power *= 9;
    }
  }

  std::cout << dp[n] << '\n';
}


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

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

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a-1)
#define trav(x, a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

ll dp[1<<22],arr[22][22];

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int N; cin >> N;

    F0R(i,N) F0R(j,N) {
        cin >> arr[i][j];
    }

    dp[0] = 1;
    FOR(mask,1,1<<N) {
        int K = __builtin_popcount(mask);
        F0R(i,N) {
            if (mask&(1<<i) && arr[K-1][i]) {
                dp[mask] = (dp[mask]+dp[mask^(1<<i)])%MOD;
            }
        }
    }

    cout << dp[(1<<N)-1] << "\n";

}


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

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

    ld A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    ld max_d = -1;
    ld res_w = -1;
    ld res_s = 0;

    for(int a = 0; a * A * 100 < F; ++a){
        ld A_water = a * A * 100;

        for(int b = 0; b * B * 100 < F - A_water; ++b){
            ld B_water = b * B * 100;

            for(int c = 0; c * C < F - A_water - B_water; ++c){
                ld C_sugar = c * C;

                for(int d = 0; d < F - A_water - B_water - C_sugar; ++d){
                    ld D_sugar = d * D;
                    if(A_water + B_water == 0) break;

                    ld den = 100 * (C_sugar + D_sugar) / (A_water + B_water);
                    if(A_water + B_water + C_sugar + D_sugar > F) break;

                    if((a * A + b * B) * E < C_sugar + D_sugar) break;
                    
                    if(max_d < den) {
                        res_w = A_water + B_water + C_sugar + D_sugar;
                        res_s = C_sugar + D_sugar;
                        max_d = den;

                        if(den == E){
                            cout << res_w << " " << res_s << endl;
                            return 0;
                        }
                    }

                }
            }
        }
    }

    cout << res_w << " " << res_s << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
using namespace std;
int _P=1000000007;
int main(){
	long long a;
	double b;
	int c;
	cin >> a >> b;
	c = 100 * (b-int(b)+0.001);
	cout << a*int(b) + a*c/100 << endl;
	return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
using namespace std;
 
int main(){
  int a,b,c;
  double d,s,l,h;
  cin>>a>>b>>c;
  d=(acos(-1.0)*c)/180.0;
  s=a*b*sin(d)/2.0;
  l=a+b+sqrt(a*a+b*b-2*a*b*cos(d));
  h=b*sin(d);
  printf("%lf\n%lf\n%lf\n",s,l,h);
}



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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

template <class Key, class T>
using gp_hash_table = __gnu_pbds::gp_hash_table<Key, T>;

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

// auto mod int

i64 MOD = 1'000'000'007;

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;
  }

  // for prime MOD
  mint inv() const { return pow(MOD - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 K;
  cin >> K;
  MOD = K;
  int i = 1;
  mint m = 1;
  gp_hash_table<int, bool> seen;
  for (;; ++i) {
    if ((m * 7).x == 0) {
      cout << i << endl;
      return 0;
    }
    if (seen[m.x]) {
      break;
    }
    seen[m.x] = true;
    m = m * 10 + 1;
  }
  cout << -1 << endl;
}


Measured memory_bytes: 40320
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val K = sc.nextInt()
  var i = 1
  var x = 7 % K
  while(x != 0 && i <= K) {
    x = (x * 10 + 7) % K
    i += 1
  }
  if (i > K) {
    println(-1)
  } else {
    println(i)
  }
}


Measured memory_bytes: 55376
import java.util.Arrays;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int c = scanner.nextInt();
		int k = scanner.nextInt();
		int ans = 1;
		int[] t = new int[n];
		for (int i = 0; i < n; i++) {
			t[i] = scanner.nextInt();
		}
		Arrays.sort(t);

		for (int i = 1,b=1,r=t[0]; i < n; i++) {
			while (r + k >= t[i]) {
				if (b < c) {
					b++;
					i++;
					if(i==n){
						break;
					}
				} else {
					break;
				}
			}
			if(i<n){
				ans++;
				r=t[i];
				b=1;
			}
		}
		System.out.println(ans);
	}
}

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

using namespace std;
using pii = pair<int, int>;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W;
  cin >> H >> W;
  int c = H * W;
  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
    for (auto s : S[i])
      if (s == '#') c--;
  }
  vector<vector<int>> grid(H, vector<int>(W, 0));
  grid[0][0] = 1;
  queue<pii> q;
  q.push(make_pair(0, 0));
  while (!q.empty()) {
    pii now = q.front();
    q.pop();
    if (now.first == H - 1 && now.second == W - 1) break;
    for (int i = 0; i < 4; i++) {
      int nx = now.second + dx[i], ny = now.first + dy[i];
      if (0 <= nx && nx < W && 0 <= ny && ny < H && S[ny][nx] == '.' &&
          !grid[ny][nx]) {
        grid[ny][nx] = grid[now.first][now.second] + 1;
        q.push(make_pair(ny, nx));
      }
    }
  }
  cout << (grid[H - 1][W - 1] ? c - grid[H - 1][W - 1] : -1) << '\n';
  return 0;
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

const int mod = 1e9 + 7;

signed main() {
  string s = readString();
  int redCount = 0, blueCount = 0, ans = 0;
  REP(i, s.size()) {
    if (s[i] == '0')
      redCount++;
    else
      blueCount++;
    while (redCount > 0 && blueCount > 0) {
      redCount--;
      blueCount--;
      ans += 2;
    }
  }
  print(ans);
}


Measured memory_bytes: 2432
N,M = map(int, input().split())
xy = [tuple(map(int, input().split())) for _ in range(M)]

prob = [False] * N
prob[0] = True
cnts = [1] * N

for x,y in xy:
    cnts[x-1] -= 1
    cnts[y-1] += 1
    if prob[x-1] == True:
        prob[y-1] = True
    if cnts[x-1] == 0:
        prob[x-1] = False

ans = 0
for i in range(N):
    if prob[i]:
        ans += 1

print(ans) 


Measured memory_bytes: 18180
package main

import (
	"fmt"
)

func main() {
	var a int
	var b int
	var count int
	t := 1
	fmt.Scan(&a, &b)

	for {
		if b == 1 {
			break
		}
		count++
		t = t + a - 1
		if t >= b {
			break
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors


def solve():
    N, K = map(int, rl().split())
    A = list(map(int, rl().split()))
    
    divs = make_divisors(sum(A))
    divs.sort(reverse=True)
    
    ans = 1
    for div in divs:
        if div == 1:
            break
        a_mods = [ai % div for ai in A]
        a_mods.sort(reverse=True)
        sum_mods = sum(a_mods)
        c = sum_mods // div
        d = sum_mods - sum(a_mods[:c])
        if d <= K:
            ans = div
            break
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 42332
#include<stdio.h>
#include<stdlib.h>
 
int main(void){
 int N, M;
 int i, j, k, l;
 int flag;
 char **A, **B;
 scanf("%d%d\n", &N, &M);
 A = (char **)malloc(sizeof(char *)*N);
 for(i = 0; i < N; i++) A[i] = (char *)malloc(N);
 B = (char **)malloc(sizeof(char *)*M);
 for(i = 0; i < M; i++) B[i] = (char *)malloc(M);
 for(i = 0; i < N; i++){
  for(j = 0; j < N; j++) A[i][j] = getchar();
  getchar();
 }
 for(i = 0; i < M; i++){
  for(j = 0; j < M; j++) B[i][j] = getchar();
  getchar();
 }
 
 for(i = 0; i <= N - M; i++){
  for(j = 0; j <= N - M; j++){
   flag = 1;
   for(k = 0; k < M; k++){
    for(l = 0; l < M; l++){
     if(A[k + i][l + j] != B[k][l]) flag = 0;
    }
   }
   if(flag){
    printf("Yes\n");
    return 0;
   }
  }
 }
 printf("No\n");
 return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod =  1000000007;
const ll inf = 1e18;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
template<typename T> ll sum(T begin, T end) {return accumulate(begin, end, 0ll);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int bsearch(const vector<ll>& a, ll x){
  int lft = 0;
  int rgt = a.size();
  while (rgt - lft > 1) {
    int mid = (lft + rgt) / 2;
    if(a[mid] < x) {
      lft = mid;
    }
    else {
      rgt = mid;
    }
  }
  return lft;
}


signed main() {
  ios::sync_with_stdio(false);
  ll n, m, s, t;
  cin >> n >> m >> s >> t;
  s--;
  t--;
  using Pair = pair<ll, int>;
  vector<map<int, ll>> toY(n);
  vector<map<int, ll>> toS(n);
  REP(i, m) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;b--;
    toY[a][b] = c;
    toY[b][a] = c;
    toS[a][b] = d;
    toS[b][a] = d;
  }
  vector<ll> yen(n, -1);
  vector<ll> snuke(n, -1);
  priority_queue<Pair, vector<Pair>, greater<Pair>> q;
  q.emplace(0, s);
  while(q.size()) {
    Pair c = q.top();q.pop();
    if(yen[c.second] != -1) continue;
    yen[c.second] = c.first;
    // cout << c.first << ":" << c.second << endl;
    for(const auto next: toY[c.second]) {
      q.emplace(c.first + next.second, next.first);
    }
  }
  q.emplace(0, t);
  while(q.size()) {
    Pair c = q.top();q.pop();
    if(snuke[c.second] != -1) continue;
    snuke[c.second] = c.first;
    // cout << c.first << ":" << c.second << endl;
    for(const auto next: toS[c.second]) {
      q.emplace(c.first + next.second, next.first);
    }
  }
  vector<ll> ans(n);
  ll tmp = yen[n-1] + snuke[n-1];
  ans[n-1] = tmp;
  REP(i, n) {
    tmp = min(yen[n-1-i] + snuke[n-1-i], tmp);
    ans[n-1-i]  = tmp;
  }
  ll init = 1e15;
  REP(i, n) {
    cout << init - ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 39156
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int N,K,C;
vector<int> sub(string str) {
    vector<int> dp(N+1,0);
    int last = -C-1;
    int cur = 0;
    for(int i = 0;i < N;i++) {
        if(i-last > C && str[i] != 'x')
            cur++,last = i;
        dp[i+1] = cur;
    }

    return dp;
}

int main(void) {
    cin>>N>>K>>C;
    string S;
    cin>>S;
    string T = S;
    reverse(T.begin(),T.end());

    auto L = sub(S);
    auto R = sub(T);
    for(int i = 0;i < N;i++) {
        if(S[i] == 'x')
            continue;
        if(L[i]+R[N-i-1] < K) {
            cout<<i+1<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n;
  cin>>n;

  Int ans=0;
  for(Int w=1;w<=n;w++)
    ans+=w*(n-w+1);

  for(Int i=1;i<n;i++){
    Int u,v;
    cin>>u>>v;
    u--;v--;
    if(!(u<v)) swap(u,v);
    ans-=(u+1)*(n-v);
  }

  cout<<ans<<newl;
  return 0;
}


Measured memory_bytes: 3648
# -*- coding: utf-8 -*-

from collections import Counter 

N, K = map(int, input().split())
num_list = list(map(int, input().split()))

# 各数値ごとに数を集計
num_dict = Counter(num_list)
# 数の少ない順でソート
num_tpl = num_dict.most_common()[::-1]

ans = 0
for i in range(len(num_tpl)):
    # 種類数がK以下なら終了
    if len(num_tpl) - i <= K:
        print(ans)
        exit()
    # 数が少ない要素から、答えに追加していく
    ans += num_tpl[i][1]

Measured memory_bytes: 39344
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;

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

	cin >> N >> M >> K;
	vector<vector<int>>num(N + 1, vector<int>(M + 1, 0));
	vector < string >s(N + 2);
	for (int i = 1; i <= N; i++) {
		cin >> s[i];
		s[i] = '0' + s[i] + '0';
		for (int j = 1; j <= M; j++) {
			if (s[i][j] == '1') {
				num[i][j] = 1;
			}
		}
	}
	vector<vector<int>>tate(N + 2, vector<int>(M + 2, 0));
	vector<vector<int>>yoko(N + 2, vector<int>(M + 2, 0));

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			if (s[i][j] == '1'&&s[i][j + 1] == '1') {
				yoko[i][j]++;
			}
			if (i!=N&&s[i][j] == '1'&&s[i + 1][j] == '1') {
				tate[i][j]++;
			}
		}
	}

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			num[i][j] += num[i][j - 1];
			yoko[i][j] += yoko[i][j - 1];
			tate[i][j] += tate[i][j - 1];
		}
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			num[i][j] += num[i - 1][j];
			yoko[i][j] += yoko[i - 1][j];
			tate[i][j] += tate[i - 1][j];
		}
	}
	//cout << yoko[N][M] << endl;
	//cout << tate[N][M] << endl;
	for (int i = 0; i < K; i++) {
		int sx, sy, gx, gy;
		cin >> sy >> sx >> gy >> gx;
		long long int ans = 0;
		ans = num[gy][gx] + num[sy - 1][sx - 1] - num[gy][sx - 1] - num[sy - 1][gx];
		//cout << ans << endl;
		ans -= yoko[gy][gx - 1] + yoko[sy - 1][sx - 1] - yoko[gy][sx - 1] - yoko[sy - 1][gx - 1];
		//cout << ans << endl;
		ans -= tate[gy - 1][gx] + tate[sy - 1][sx - 1] - tate[gy - 1][sx - 1] - tate[sy - 1][gx];
		cout << ans << endl;
	}
	return 0;
}


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

public class Main
{
  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    String s;
    String sl[];

    s = r.readLine();
    sl = s.split(" ");

    int n = Integer.parseInt(sl[0]);
    long a[] = new long[n];
    long b[] = new long[n];

    s = r.readLine();
    sl = s.split(" ");
    for(int i = 0; i < n; i++)
    {
      a[i] = Long.parseLong(sl[i]);
      b[i] = a[i];
      a[i] = i + 1 + a[i];
      b[i] = i + 1 - b[i];
    }

    Arrays.sort(a);
    Arrays.sort(b);

//    for(int i = 0; i < n; i++)
//    {
//      System.out.println(a[i]);
//    }
//    for(int i = 0; i < n; i++)
//    {
//      System.out.println(b[i]);
//    }

    int k = 0;
    int l = 0;
    long v = 0;
    while(k < n && l < n)
    {
      //System.out.println(k);
      //System.out.println(l);
      if(a[k] < b[l])
      {
        while(k < n && a[k] < b[l]) k++;
      }
      else if(a[k] > b[l])
      {
        while(l < n && a[k] > b[l]) l++;
      }
      else
      {
        long t = a[k];
        long kk = 0;
        long ll = 0;
        while(k < n && a[k] == t)
        {
          k++;
          kk++;
        }
        while(l < n && b[l] == t)
        {
          l++;
          ll++;
        }
        v += kk * ll;
      }
    }

    System.out.println(v);

  }

}

class RemRing
{
  long module;

  public RemRing(long module)
  {
    this.module = module;
  }

  public long sum(long a, long b)
  {
    return (a + b + module) % module;
  }

  public long sub(long a, long b)
  {
    return (a - b + module) % module;
  }

  public long prod(long a, long b)
  {
    return (a * b) % module;
  }

  public long div(long a, long b)
  {
    return (a * inv(b)) % module;
  }

  public long inv(long a)
  {
    long b = this.module;
    long u = 1;
    long v = 0;
    while (b > 0)
    {
      long t = a / b;
      a -= t * b;
      u -= t * v;
      long z = a;
      a = b;
      b = z;
      z = u;
      u = v;
      v = z;
    }
    u %= this.module;
    if (u < 0)
      u += this.module;
    return u;
  }
}

Measured memory_bytes: 76100
n, m, k = map(int, input().split())
mod = 998244353

ans = 0
comb = 1
for i in range(k+1):
  ans += (((m*pow(m-1,n-i-1,mod))%mod)*comb)%mod
  ans %= mod
  comb = (comb*(n-1-i)*pow(i+1, mod-2, mod))%mod

print(ans)

Measured memory_bytes: 9204
#include<stdio.h>
#include<string.h>

int N,M[9][9],f[9][9],m[9][9],i,j,k;

void ch(int y,int x)
{
	int i,j,mv[9][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,0},{0,1},{1,-1},{1,0},{1,1}};
	for(i=0;i<9;i++)
		for(j=0;j<9;j++)
			if(i!=j&&M[y+mv[i][0]][x+mv[i][1]]==M[y+mv[j][0]][x+mv[j][1]])
				f[y+mv[i][0]][x+mv[i][1]]=f[y+mv[j][0]][x+mv[j][1]]=1;
}


int main()
{
	scanf("%d",&N);
	for(;N--;)
	{
		memset(f,0,sizeof(f));
		for(i=0;i<9;i++)
			for(j=0;j<9;j++)
				scanf("%d",&M[i][j]);
		for(i=0;i<9;i++)
			for(j=0;j<9;j++)
				for(k=0;k<9;k++)
				{
					if(k!=i&&M[i][j]==M[k][j])f[i][j]=f[k][j]=1;
					if(k!=j&&M[i][j]==M[i][k])f[i][j]=f[i][k]=1;
				}
		for(i=1;i<9;i+=3)
			for(j=1;j<9;j+=3)
				ch(i,j);
		for(i=0;i<9;i++,puts(""))
			for(j=0;j<9;j++)
				printf("%c%d",f[i][j]?'*':' ',M[i][j]);
		if(N>0)
			puts("");
	}
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n, l;
    cin >> n >> l;
    int m = INF;
    int s;
    int sum = 0;
    for (int i = 1; i <= n; ++i) {
        sum += l + i - 1;
        if (chmin(m, abs(l+i-1))) {
            s = l + i - 1;
        }
    }
    cout << sum - s << endl;
}

Measured memory_bytes: 3596
char buf[10000000],out[11];
sz;
cnt[60];
main()
{
	read(0,buf,10000000);
	long N=0;
	for(;;)
	{
		char k=buf[sz++];
		if(k<'0')break;
		N=N*10+k-'0';
	}
	for(;buf[sz]>='0';)
	{
		long A=0;
		for(;;)
		{
			char k=buf[sz++];
			if(k<'0')break;
			A=A*10+k-'0';
		}
		for(int i=0;i<60;i++)
		{
			cnt[i]+=A&1;
			A>>=1;
		}
	}
	int ans=0;
	for(int i=59;i>=0;i--)
	{
		ans=(ans*2+(N-cnt[i])*cnt[i])%1000000007;
	}
	int outsz=10;
	do{
		out[--outsz]=ans%10+'0';
	}while(ans/=10);
	write(1,out+outsz,10-outsz);
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N; cin >> N;
    vec a;
    ll sum=0;
    a.push_back(0);
    rep(i, N){
        int x; cin >> x;
        a.push_back(x);
    }
    a.push_back(0);
    vec b, c;
    rep(i, N+1){
        ll tmp = abs(a[i]-a[i+1]);
        b.push_back(tmp);
        sum += tmp;
    }
    rep(i, N){
        c.push_back(abs(a[i]-a[i+2]));
    }

    rep(i, N){
        cout << sum - b[i] - b[i+1] + c[i] << endl;
    }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 6648
#include<cstdio>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

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

typedef long long ll;

const int N = 100010;

class BIT{
	static const int N = 100010;
	public:
	ll t[N];
	void init(){rep(i,N)t[i]=0;}
	ll calc(ll a,ll b){return max(a,b);}
	
	void setval(int pos, ll val){
		pos++;
		for(int i=0;;i++){
			if(pos>=N)break;
			if(pos&(1<<i)){
				t[pos] = calc(t[pos],val);
				pos += (1<<i);
			}
		}
	}
	
	ll getval(int pos){
		pos++;
		ll ret = 0;
		for(int i=0;;i++){
			if(pos==0)break;
			if(pos&(1<<i)){
				ret = calc(ret, t[pos]);
				pos -= (1<<i);
			}
		}
		return ret;
	}
	
	void print(){
		printf("t : ");
		rep(i,10)printf("%d ",t[i]);puts("");
	}
};

int main(){
	int n;
	cin>>n;
	
	int p[N];
	ll sum = 0;
	rep(i,n){
		cin>>p[i];
		sum += p[i];
	}
	
	BIT bit;
	bit.init();
	
	rep(i,n){
		bit.setval( p[i], bit.getval(p[i])+p[i] );
		//bit.print();
	}
	
	cout<<sum - bit.getval(n)<<endl;
}

/*
5
1 5 3 2 4

*/

Measured memory_bytes: 2328