akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const ll mod=1000000007;
int main(void){
    string s,t;
    cin>>s>>t;
    bool ok=true;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i]) ok=false;
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <algorithm>
using namespace std;


int main() {
    int Q, c, a, n, minv, sum;
    scanf("%d", &Q);
    for (int i = 0; i < Q; i++) {
        scanf("%d %d %d", &c, &a, &n);
        sum = 0;
        minv = min(c, min(a, n));
        sum += minv; c -= minv, a -= minv, n -= minv;
        minv = min(c/2, a);
        sum += minv;
        a -= minv, c -= minv*2;
        sum += c/3;
        printf("%d\n", sum);
    }
    return 0;
}



Measured memory_bytes: 2696
n = int(input())
s = list(input())
cnt = 0
ans = []
for i in s[1:]:
    if i == "E":
        cnt += 1
ans.append(cnt)
for i in range(1,n):
    if s[i] == "E":
        cnt -= 1
    if s[i - 1] == "W":
        cnt += 1
    ans.append(cnt)

print(min(ans))

Measured memory_bytes: 22932
S = input()
N = len(S)
flag = True
for i in range(N//2+1):
    if S[i] != S[-i-1]:
        flag = False
        break
if flag:
    s2 = S[:N//2]
    n2 = len(s2)
    ans = 'Yes'
    for i in range(n2):
        if s2[i] != s2[-i-1]:
            ans = 'No'
            break
    print(ans)
    
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
  int x;
  cin>>x;
  if(x/100==7 || x/10%10==7 || x%10==7) {
    cout<<"Yes";
  }else {
    cout<<"No";
  }
  return 0;
}

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

struct Card{
  char suit;
  char value;
};

typedef struct {
  char value;
  char suit[4]; // suit order
} same_t;

void swap(struct Card*, struct Card*);
void pr(struct Card*, int);
int a2n(char);
void chkSt( struct Card*, struct Card*, int);

int main(){
  struct Card C1[101], C2[101];
  int n, i, j;
  int mini;
  char ch; // spacer

  scanf("%d%c", &n, &ch);

  for ( i = 0; i <= n; i++ ){
    scanf("%c%c%c", &C1[i].suit, &C1[i].value, &ch);
  }

  // bubble sort
  memcpy( C2, C1, sizeof(C1));
  for( i = 0 ; i < n ; i++){
    for(j = n-1 ; j > i ; j--){
      if( a2n(C2[j].value) < a2n(C2[j-1].value) ){
	swap(&C2[j] ,&C2[j-1]);
      }
    }
  }
  pr(C2,n);
  chkSt(C1,C2,n);

  // slection sort
  memcpy( C2, C1, sizeof(C1));
  for( i = 0 ; i < n ; i++){
    mini = i;
    for(j = i ; j < n ; j++){
      if( a2n(C2[j].value) < a2n(C2[mini].value) ){
	mini = j;
      }
    }
    if( i != mini){
      swap(&C2[i] ,&C2[mini]);
    }
  }
  pr(C2,n);  
  chkSt(C1,C2,n);

  return 0;
}

void chkSt( struct Card* c1_p, struct Card* c2_p, int n){
  same_t chk[101]={0}; // 0 is teminater
  int i, j, k;

  j = -1;
  for(i=0 ; i<n ; i++){
    k = 0;
    if(a2n(c2_p[i].value)==a2n(c2_p[i+1].value)){
      j++;
      chk[j].value   = c2_p[i].value;
      chk[j].suit[0] = c2_p[i].suit;
      chk[j].suit[1] = c2_p[i+1].suit;
      k++;
    }
    if(a2n(c2_p[i].value)==a2n(c2_p[i+2].value)){
      chk[j].suit[2] = c2_p[i+2].suit;
      k++;
    }
    if(a2n(c2_p[i].value)==a2n(c2_p[i+3].value)){
      chk[j].suit[3] = c2_p[i+3].suit;
      k++;
    }
    i += k;
  }  

  for(i=0 ; chk[i].value != 0 ; i++){
    k =0;
    for(j=0 ; j < n ; j++){
      if(chk[i].value == c1_p[j].value ){
	if( chk[i].suit[k] == c1_p[j].suit){
	  k++;
	  if( k==4){
	    break;
	  }
	}else{
	  printf("Not stable\n");
	  return;
	}
      }
    }
  }
 
  printf("Stable\n");
  return;
}

int a2n(char a){
  return a - '0';
}

void swap(struct Card *a_p, struct Card *b_p){
  struct Card k;
  memcpy( &k,  a_p, sizeof(*a_p));
  memcpy( a_p, b_p, sizeof(*a_p));
  memcpy( b_p, &k, sizeof(*a_p));
}

void pr(struct Card *a_p, int n){
  int i;
  for( i = 0 ; i < n ; i++ ){
    printf("%c%c" ,a_p[i].suit ,a_p[i].value );
    if( i != (n-1)){
      printf(" ");
    }
  }
  printf("\n");
}

Measured memory_bytes: 1040
from itertools import product

N, M, X = map(int, input().split())
inp = [list(map(int, input().split())) for _ in range(N)]

C, A = [], []
for i in range(N):
    C.append(inp[i][0])
    A.append(inp[i][1:])

#判定
z_A = list(zip(*A))
for i in range(M):
    if sum(z_A[i]) < X:
        print(-1)
        exit()

ans = sum(C)

for buy_bit in product(range(2), repeat=N):
    buy = 0
    tmp = 0
    skill = [0] * M
    for i in range(N):
        if buy_bit[i]:
            for j in range(M):
                skill[j] += A[i][j]
            buy += C[i]
    
    f = True
    for s in skill:
        if s < X:
            f = False
            break
    if f:
        ans = min(ans, buy)

print(ans)

Measured memory_bytes: 9168
// finish date: 2018/09/24
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>>
        vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int N, x;
    cin >> N >> x;
    ll sum = 0;
    vi a(N);
    rep(i, N) {
        cin >> a[i];
        sum += a[i];
    }
    sort(a.begin(), a.end());
    int cnt = 0;
    rep(i, N) {
        if (x - a[i] < 0) {
            break;
        }
        cnt++;
        x -= a[i];
        if (i == N - 1 && x != 0) cnt--;
    }
    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main (void) {
    int N;

    scanf("%d", &N);

    int A[N];
    int B[N];

    for (int i = 0; i < N; i++) {
        B[i] = 0;
    }
    A[0] = 0;

    for (int i = 1; i < N; i++) {
        int j = 1;
        scanf("%d", &A[i]);
        
        while (j != A[i]) {
            j++;
        }
        B[j - 1]++;
    }

    for (int i = 0; i < N; i++){
        printf ("%d\n", B[i]);
    }
    
    return 0;
}

Measured memory_bytes: 3288
#include<stdio.h>
int main()
{
	int a,b,h,s;
	1<=a<=100;
	1<=b<=100;
	1<=h<=100;
	scanf("%d%d%d",&a,&b,&h);
	s=(a+b)*h/2;
	printf("%d",s);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.io.*;
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}

        // int n=sc.nextInt();
        char s[]=sc.nextString().toCharArray();
        int n=s.length;
        int a[] = new int[n];
        int c[] = new int[n];
        int da[] = new int[n];
        int dc[] = new int[n];

        if(s[0]=='A')a[0]++;
        if(s[0]=='?')da[0]++;
        for(int i=1; i<n; i++) {
            a[i]=a[i-1]+ (s[i]=='A' ? 1:0);
            da[i]=da[i-1]+ (s[i]=='?' ? 1:0);
        }
        
        if(s[n-1]=='C')c[n-1]++;
        if(s[n-1]=='?')dc[n-1]++;
        for(int i=n-2; 0<=i; i--) {
            c[i]=c[i+1]+ (s[i]=='C' ? 1:0);
            dc[i]=dc[i+1]+ (s[i]=='?' ? 1:0);
        }
        long ans=0;
        long t[]= new long[n+1];
        t[0]++;
        for(int i=1; i<=n; i++) {
            t[i]=t[i-1]*3;
            t[i]%=mod;
        }
        for(int i=1; i<n-1; i++) {
            long e=0,f=0;
            if(s[i]=='B' || s[i]=='?'){
                e=a[i]*t[da[i-1]]%mod;
                if(da[i-1]>=1)e+=t[da[i-1]-1]*da[i-1];
                e%=mod;
                f=c[i]*t[dc[i+1]]%mod;
                if(dc[i+1]>=1)f+=t[dc[i+1]-1]*dc[i+1];
                f%=mod;
                e=(e*f)%mod;
                ans+=e;
                ans%=mod;
            }
        }

        out.println(ans);
        out.flush();
    }


    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

class P implements Comparable<P>{
    int id, d;
    P(int  id, int d) {
        this.id=id;
        this.d=d;
    }
    public int compareTo(P p){
        return Integer.compare(d,p.d); //des
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Measured memory_bytes: 25300
#include<iostream>
using namespace std;
#define ll long long
int main()
{
	int n;
	cin>>n;
	int count1=0;
	int count2=0;
	int count4=0;
	int a;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		if(a%4==0)
		{
			count4++;
		}
		else if(a%2==0)
		{
			count2++;
		}
		else
		{
			count1++;
		}
	}
	if(count2!=0)
	{
		count1++;
	}
	if(count1-1<=count4)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

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


int main() {
    ll N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;
    
    ll mini = min(A, min(B, min(C, min(D, E))));
    
    cout << (N-1) / mini + 5 << endl;
    
}

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

int main(){
  int a,b,x;
  cin >> a >> b >> x;
  if(a+b >= x && x >= a) cout << "YES" << endl;
  else cout << "NO" << endl;
  
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    int H, W;
    cin >> H >> W;
    int a[H][W];
    REP(i, H)
    {
        REP(j, W)
        {
            cin >> a[i][j];
        }
    }
    vector<int> beforeX, beforeY;
    vector<int> afterX, afterY;
    int count = 0;
    REP(i, H)
    {
        REP(j, W)
        {
            if (a[i][j] % 2 == 1)
            {
                if (i != H - 1 || j != W - 1)
                {
                    count++;
                    beforeY.push_back(i + 1);
                    beforeX.push_back(j + 1);
                    a[i][j]--;
                    if (i + 1 < H && j + 1 < W)
                    {
                        if (a[i][j + 1] % 2 == 1)
                        {
                            a[i][j + 1]++;
                            afterY.push_back(i + 1);
                            afterX.push_back(j + 2);
                        }
                        else if (a[i + 1][j] % 2 == 1)
                        {
                            a[i + 1][j]++;
                            afterY.push_back(i + 2);
                            afterX.push_back(j + 1);
                        }
                        else
                        {
                            a[i][j + 1]++;
                            afterY.push_back(i + 1);
                            afterX.push_back(j + 2);
                        }
                    }
                    else if (i + 1 < H)
                    {
                        a[i + 1][j]++;
                        afterY.push_back(i + 2);
                        afterX.push_back(j + 1);
                    }
                    else if (j + 1 < W)
                    {
                        a[i][j + 1]++;
                        afterY.push_back(i + 1);
                        afterX.push_back(j + 2);
                    }
                }
            }
        }
    }

    cout << count << endl;
    REP(i, count)
    {
        cout << beforeY[i] << " " << beforeX[i] << " " << afterY[i] << " " << afterX[i] << endl;
    }
}


Measured memory_bytes: 5220
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>
#define maxn 105
using namespace std;
typedef long long ll;
int n,r,b;
char s[maxn];
int main(){
  scanf("%d",&n);
  scanf("%s",s);
  for(int i = 0;i < n;i++){
    if(s[i] == 'R') r++;
    else b++;
  }
  if(r > b) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
static const int MAX_SIZE=3000;
string dp[2][MAX_SIZE+10];
int main(void){
	string s,t,ans;
		cin >> s >> t;
	int ss=s.size(),ts=t.size();
	
	for(int i=ss-1,k=0;i>=0;i--,k^=1){
		for(int j=ts-1;j>=0;j--){
			if(s[i]==t[j])
				dp[k][j]=dp[k^1][j+1]+s[i];
			else
				dp[k][j]=(dp[k][j+1].size()>dp[k^1][j].size()?dp[k][j+1]:dp[k^1][j]);
		}
	}
	
	for(int i=dp[ss%2^1][0].size()-1;i>=0;i--)
		cout << dp[ss%2^1][0][i];
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 18900
n,m=map(int, input().split())
alist=[]
for i in range(m):
  p,y=map(int, input().split())
  alist.append([i+1,p,y])
alist.sort(key=lambda x: x[2])
blist=[0]*(n+1)
ans=[0]*m
for i in range(m):
  blist[alist[i][1]]+=1
  ans1='0'*(6-len(str(alist[i][1])))
  ans2=str(alist[i][1])
  ans3='0'*(6-len(str(blist[alist[i][1]])))
  ans4=str(blist[alist[i][1]])
  ans[alist[i][0]-1]=ans1+ans2+ans3+ans4
for i in range(m):
  print(ans[i])

Measured memory_bytes: 36656
#include <bits/stdc++.h>
#define rep(i, ns, ne) for (int i = ns; i < ne; ++i)
#define rep2(i, ns, ne) for (int i = ns; i <= ne; ++i)
using namespace std;

int H, W, N;
vector<vector<bool>> v;

void func(int y, int x, int a) {
  int sx, ex, sy, ey;
  if (a == 1) {
    sy = 1;
    ey = H;
    sx = 1;
    ex = x;
  } else if (a == 2) {
    sy = 1;
    ey = H;
    sx = x + 1;
    ex = W;
  } else if (a == 3) {
    sy = 1;
    ey = y;
    sx = 1;
    ex = W;
  } else if (a == 4) {
    sy = y + 1;
    ey = H;
    sx = 1;
    ex = W;
  }
  rep2(i, sy, ey) {
    rep2(j, sx, ex) {
      v[i][j] = false;
    }
  }
}

void prtALl() {
  for (auto h : v) {
    for (bool w : h) {
      if (w) {
        cout << "@";
      } else {
        cout << ".";
      }
    }
    cout << endl;
  }
}

int main() {
  cin >> W >> H >> N;
  v.resize(H + 1, vector<bool>(W + 1, true));
  rep(i, 0, H + 1) { v[i][0] = false; }
  rep(i, 0, W + 1) { v[0][i] = false; }

  int x, y, a;
  rep(i, 0, N) {
    cin >> x >> y >> a;
    func(y, x, a);
  }

  int ans = 0;
  for (auto h : v) {
    for (bool w : h) {
      if (w) {
        ans++;
      }
    }
  }

  cout << ans << endl;
  getchar();
}

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

#define MOD 1000000007
typedef unsigned long long ull;

ull gcd(ull a, ull b) {
  ull s = a % b;
  if (s != 0) {
    gcd(b, a % b);
  } else {
    return b;
  }
}

ull a, b;
int main() {
  cin >> a >> b;
  cout << a * b / gcd(a, b);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;

int N,M;
vector<vector<int>> G;
int res = 0;

void dfs(int i,vector<int> &used){
   if(used[i] == 1) return;

   used[i] = 1;

   rep(j,N){
      if(G[i][j] == 1){
         if(used[j] == -1){
            dfs(j,used);
         }
      }
   }
}

int main(){
   cin >> N >> M;
   G.resize(N,vector<int>(N,-1));
   rep(i,M){
      int a,b;
      cin >> a >> b;
      a--; b--;
      G[a][b] = 1;
      G[b][a] = 1;
   }
   
   rep(i,N){
      repr(j,i+1,N){
         if(G[i][j] == 1){
            G[i][j] = -1;
            G[j][i] = -1;
            vector<int> used(N,-1);
            dfs(0,used);
            bool ok = false;
            rep(k,N){
               if(used[k] == -1) ok = true;
            }
            if(ok) res++;
            G[i][j] = 1;
            G[j][i] = 1;
         }
      }
   }
   cout << res << endl;
}



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

int main(){
  int N, K, i;
  int a=1;
  cin >> N >> K;
  
  for(i=0;i<N;i++){
    if((2*a) < (a+K)){
      a*=2;
    }
    else{
      a+=K;
    }
  }
  cout << a << endl;
}


Measured memory_bytes: 384
import sys
input = lambda : sys.stdin.readline().rstrip()

def segfun(x, y):
    return min(x, y)
ide_ele = 10**9 + 1


class SegmentTree:
    def __init__(self, n, ele, segfun):
        self.ide_ele = ele
        self.segfun = segfun
        self.n = n
        self.N0 = 1 << n.bit_length()
        self.data = [self.ide_ele] * (self.N0 * 2)
 
    def update(self, l, r, val):
        l += self.N0
        r += self.N0
        while l < r:
            if l & 1:
                self.data[l] = self.segfun(self.data[l], val)
                l += 1
            if r & 1:
                self.data[r - 1] = self.segfun(self.data[r - 1], val)
                r -= 1
            l //= 2
            r //= 2
 
    def query(self, i):
        i += len(self.data) // 2
        ret = self.data[i]
        while i > 0:
            i //= 2
            ret = self.segfun(ret, self.data[i])
        return ret


n, q = map(int, input().split())
stx = []
for _ in range(n):
    s, t, x = map(int, input().split())
    stx.append([x, s - x, t - x])
# stx.sort(reverse=True)
d = [int(input()) for _ in range(q)]

import bisect

seg = SegmentTree(q, ide_ele, segfun)

for x, start, last in stx:
    l = bisect.bisect_left(d, start)
    r = bisect.bisect_left(d, last)
    seg.update(l, r, x)

for i, j in enumerate(d):
    res = seg.query(i)
    if res == ide_ele:
        print(-1)
    else:
        print(res)
    



Measured memory_bytes: 112348
import java.util.Scanner;

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

      while(true){

        int h = sc.nextInt();
        int w = sc.nextInt();

        if(h==0&&w==0){
          break;
        }

        for(int i = 0; i<h; i++){

            for(int j =0; j<w; j++){

                System.out.print("#");

            }

            System.out.println("");
        }

      System.out.println("");

      }

    } 
}


Measured memory_bytes: 35388
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
using namespace std;
int main()
{
	int n,h,w;
	cin>>n>>h>>w;
	int a[n];
	int b[n];
	int ans=0;
	rep(i,n)
	{
		cin>>a[i];
		cin>>b[i];
		if(a[i]>=h&&b[i]>=w)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int N, K, x, l=0;
  cin >> N >> K;
     
  for (int i=1; i<=N; i++){
    cin >> x;
    int A=x*2;
    int B=(K-x)*2;
    if(A<=B)
      l+=A;
    else
      l+=B;
  }
    cout << l << endl;
}


Measured memory_bytes: 256
import re
chars = {'10':'D', '11':'J', '12':'Q', '13':'K'}
while True:
    try:
        f = sorted(map(int, input().strip().split(',')))
        g = list(map(str,f.copy()))
        for i in chars.keys():
            while i in g:
                g[g.index(i)] = chars[i]
        h = ''.join(g)
        if re.search(r'(.)\1\1\1', h):
            print('four card')
        elif re.search(r'(.)\1\1(.)\2', h) or re.search(r'(.)\1(.)\2\2', h):
            print('full house')
        elif (f[1]==f[0]+1 and f[2]==f[0]+2 and f[3]==f[0]+3 and f[4]==f[0]+4) or h=='1DJQK':
            print('straight')
        elif re.search(r'(.)\1\1', h):
            print('three card')
        elif  re.search(r'(.)\1.?(.)\2', h):
            print('two pair')
        elif  re.search(r'(.)\1', h):
            print('one pair')
        else:
            print('null')

    except EOFError:
        break

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

#define rep(i, l, r) for(int i = l, i##end = r; i <= i##end; ++i)
#define per(i, l, r) for(int i = l, i##end = r; i >= i##end; --i)
#define repo(i, l, r) for(int i = l, i##end = r; i < i##end; ++i)
#define pero(i, l, r) for(int i = l, i##end = r; i > i##end; --i)
#define debug(x) cerr << "debug(" << #x << ')' << ": " << x << " " << endl
typedef long long ll;
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int MAXN = 2 * 1e5 + 5;
const int mod = 998244353;
const double PI = acos(-1);
inline int read() {
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {
		if(ch=='-')w=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}
//int cmpfunc (const void * a, const void * b){return ( *(int*)a - *(int*)b );}
//rise; qsort (a, n, sizeof(int), cmpfunc);

/*struct cmp{bool operator( ) (int x, int y) const {return a[x] + b[x] > a[y] + b[y];}};*/

ll inv[MAXN];
ll f[MAXN];

ll ksm(ll ans, ll p) {
	ll res = 1;
	while(p) {
		if(p & 1) res = res * ans % mod;
		p >>= 1;
		ans = ans * ans % mod;
	}
	return res;
}
ll c(ll a, ll b) {
	return f[a] * inv[a-b] % mod * inv[b] % mod;
}

void solve() {
	ll n, m, k;
	cin >> n >> m >> k;

	int maxn = max(n,m);
	f[0] = 1;
	for(ll i = 1; i<=maxn; i++) f[i] = f[i-1] * i % mod;//求i!
	inv[maxn] = ksm(f[maxn], mod-2);
	for(ll i = maxn-1; i>=0; i--) inv[i] = inv[i+1] * (i+1) % mod;//求逆元

	ll ans = 0;//C(n-1,n-1-i)*m*(m-1)^(n-1-i) //n-1-i为隔板数
	ll tem = ksm(m-1,n-1-k);
	for(int i=n-1-k; i<=n-1; i++) {
		ans = ans + c(n-1, i) % mod * m % mod * tem % mod;
		ans = ans % mod;
		tem = tem * (m-1) % mod;
	}
	cout<<ans;
}

int main() {
#ifdef ACM_LOCAL
	freopen("in.txt", "r", stdin);
#endif
//	int T; cin >> T;
//	while(T--)
	solve();
	return 0;
}

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

int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    for(int i=k; i<n; i++){
        if(a[i-k] < a[i]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 4816
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator > (long&& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};

template<typename a>
struct S001 {
  int n;
  std::vector<a> xs;
  S001(const std::vector<a>& ys) : xs(ys.size() + 1) {
    int n = (int)ys.size();
    a t = 0;
    xs[0] = 0;
    for(int i = 0; i < n; ++i) {
      t += ys[i];
      xs[i+1] = t;
    }
  }
  a operator [] (int i) {
    return xs[i];
  }
  a f(int x, int y) {
    return xs[y] - xs[x];
  }
  typename std::vector<a>::iterator begin() { return xs.begin(); }
  typename std::vector<a>::iterator end() { return xs.end(); }
};

struct Solver {
  std::string s, t;
  long q;
  std::vector<std::array<long, 4>> qs;
  Solver() {
    S002 reader;
    reader >= s >= t >= q >q>= qs;
  }
  void solve() {
    std::vector<long> xs, ys;
    for(long i = 0; i < (long)s.size(); ++i) {
      xs.push_back(s[i] == 'A' ? 1 : 2);
    }
    for(long i = 0; i < (long)t.size(); ++i) {
      ys.push_back(t[i] == 'A' ? 1 : 2);
    }
    S001<long> xs2(xs);
    S001<long> ys2(ys);
    for(auto x : qs) {
      long a = xs2.f(x[0] - 1, x[1]);
      long b = ys2.f(x[2] - 1, x[3]);
      puts(a % 3 == b % 3 ? "YES" : "NO");
    }
  }
  ~Solver() { fprintf(stderr, "--end--\n"); }
};
 

int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}

Measured memory_bytes: 7288
N = int(input())
*A ,=map(int,input().split())
count =0
for i in range(N):
    mini = i
    for j in range(i+1,N):
        if A[j] <A[mini]:
            mini = j
    A[mini],A[i] = A[i],A[mini]
    if (mini != i):count +=1
print(' '.join(list(map(str,A))))
print(count)


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

using namespace std;

int main() {
    string s1, s2, s3, res;
    cin >> s1 >> s2 >> s3;
    res += s1[0];
    res += s2[0];
    res += s3[0];
    for (int i = 0; i < res.length(); i++) {
        res[i] = static_cast<char>(toupper(res[i]));
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	string s;
	cin >> s;
	if (s[0] == s[1] && s[1] == s[2]) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
H,W = list(map(int,input().split()))   
a = [input().split() for l in range(H)]

for j in range(H+2):
    if j == 0 or j == H+1:
        print("#"*(W+2))
    else:
        tmp = "#" + a[j-1][0] + "#"
        print(tmp)


Measured memory_bytes: 3060
import numpy as np
import sys
import math
read = sys.stdin.readline

N = int(read().rstrip())
A = list(map(int,read().rstrip().split()))
da = []
for i , a in enumerate(A):
    da.append([i,a])

dR = {}
dL = {}

ans = 0
for d in reversed(da):
    r = d[0] + d[1] + 1
    l = d[0] - d[1] + 1 
    if r in dR:
        dR[r] += 1
    else:
        dR[r] = 1

    if r in dL:
        ans += dL[r]

    if l in dL :
        dL[l] += 1
    else:
        dL[l] = 1  

print(ans)


Measured memory_bytes: 95452
#include <stdio.h>
int n, v, a[25][2], r, f[25];
void p1(int u) { if(!~u) return; printf(" %d", u), p1(a[u][0]), p1(a[u][1]); }
void p2(int u) { if(!~u) return; p2(a[u][0]), printf(" %d", u), p2(a[u][1]); }
void p3(int u) { if(!~u) return; p3(a[u][0]), p3(a[u][1]), printf(" %d", u); }
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", &v), scanf("%d%d", a[v], a[v] + 1), f[a[v][0]] = f[a[v][1]] = 1;
	for(int i = 0; i < n; i++) if(!f[i]) r = i;
	puts("Preorder"); p1(r); puts("");
	puts("Inorder"); p2(r); puts("");
	puts("Postorder"); p3(r); puts("");
}

Measured memory_bytes: 2748
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

class Prog
{
    public Prog() { }
    public static int Main()
    {
        new Prog().calc();
        return 0;
    }

    Scanner cin;

    public void calc()
    {
        cin = new Scanner();
        long a = cin.nextLong();
        long b = cin.nextLong();
        long x = cin.nextLong();

        if (a == 0) Console.WriteLine(ret(b, x));
        else Console.WriteLine(ret(b, x) - ret(a - 1, x));

    }

    private static long ret(long a,long x)
    {
        return a / x + 1;
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))

using namespace std;

typedef long long ll;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n; cin>>n;
  
  rep(i, 11) {
    int a = 1000*i;
    
    if(n-a <= 0) {
      cout<<abs(n-a);
      return 0;
    }
  }
  
  return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>
int main(void){
    
    int x,i=0;
    do {
     i++; 
        scanf("%d\n", &x);
        
        if(x ==0){
            break;
        }
        printf("Case %d: %d\n",i,x);
    } while(x != 0);
        
    return 0;
}



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

long long GCD(long long x, long long y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

int main() {
    int K;
    cin >> K;
    long long res = 0;
    for (int a = 1; a <= K; ++a) {
        for (int b = 1; b <= K; ++b) {
            for (int c = 1; c <= K; ++c) {
                res += GCD(GCD(a, b), c);
            }
        }
    }
    cout << res << endl;
}

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


using namespace std;



const int MAXN = 100 * 1000 + 123;




int n, a[MAXN];


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

Measured memory_bytes: 640
'use strict'
function Main(input){
  input=input.trim().split(/\s+/);
  var N=input.shift()-0;
  var rightA=input.reduce((acc,str)=>acc+(str[str.length-1]==='A'?1:0), 0);
  var leftB=input.reduce((acc,str)=>acc+(str[0]==='B'?1:0), 0);
  var both=input.reduce((acc,str)=>acc+((str[0]==='B'&&str[str.length-1]==='A')?1:0),0);
  var AB=input.reduce((acc,str)=>acc+str.split('AB').length-1, 0);
  var m=Math.min(rightA,leftB);
  if(both===rightA&&rightA===leftB)m--;
  console.log(AB+Math.max(m,0));
}

Main(require('fs').readFileSync('/dev/stdin','utf8'));


Measured memory_bytes: 8724
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const string YES = "Yes";
const string NO = "No";

void solve(std::string S, std::string T){
    bool ans = false;
    REP(i, S.size()) {
        string s1 = S.substr(0, i);
        string s2 = S.substr(i);
        if (s2 + s1 == T) {
            ans = true;
            break ;
        }
    }
    if (ans) cout << YES << '\n';
    else cout << NO << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int n,a,e4=0,e2=0,odd=0,re=0;
	cin >> n;
	while(n--){
		cin >> a;
		if(a%4==0){
			e4++;
		}
		else if(a%2==0){
			e2++;
		}
		else{ 
			odd++;	
		}
	}
	if(e2==0){
		if(odd<=e4+1){
			re=1;	
		}
	}
	else {
		if(odd<=e4){
			re=1;
		}
	}
	if(re==1)cout << "Yes" << endl;	
	else cout << "No" << endl;

	return 0;
}	

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (;;) {
            int n = sc.nextInt(), m = sc.nextInt();
            if ((n | m) == 0) {
                break;
            }
            int[] l = new int[n];
            for (int i = 0; i < n; i++) {
                l[i] = sc.nextInt();
            }
            Arrays.sort(l);
            int sum = 0;
            for (int i = n - 1, j = 1; i >= 0; i--, j++) {
                if (j % m != 0) {
                    sum += l[i];
                }
            }
            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 59612
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;

#define ARRAY_MAX 101
#define MOD 1000000007

int main(){

   int sx,sy,tx,ty;
   cin >> sx >> sy >> tx >> ty;
   string s;

    for(int i = 0;i < ty-sy;i++){
        s.push_back('U');
    }
    for(int i = 0;i < tx-sx;i++){
        s.push_back('R');
    }
    for(int i = 0;i < ty-sy;i++){
        s.push_back('D');
    }
    for(int i = 0;i < tx-sx;i++){
        s.push_back('L');
    }
    //1往復
    //cout << s << endl;
    s.push_back('L');
    for(int i = 0;i < (ty-sy+1);i++){
        s.push_back('U');
    }
    for(int i = 0;i < tx-sx+1;i++){
        s.push_back('R');
    }
    //cout << s << endl;
    s.push_back('D');
    s.push_back('R');
    for(int i = 0;i < ty-sy+1;i++){
        s.push_back('D');
    }
    for(int i = 0;i < tx-sx+1;i++){
        s.push_back('L');
    }
    s.push_back('U');
    cout << s << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    s64 n, k;
    cin >> n >> k;
    vs64 s(n + 1);
    s[0] = 0;
    s64 a;
    rep (i, n)
    {
        cin >> a;
        s[i + 1] = s[i] + a;
    }

    map<s64, s64> m;
    s64 maxA = 0;
    rep (l, n)
    {
        for (int r = l + 1; r <= n; ++r)
        {
            ++m[s[r] - s[l]];
            maxA = MAX(maxA, s[r] - s[l]);
        }
    }

    s64 t = 0;
    while (((s64)1 << t) <= maxA) ++t;
    --t;
    s64 x = 0;
    while (t >= 0)
    {
        s64 y = (s64)1 << t;
        int cnt = 0;
        for (auto item : m)
        {
            if ((item.first & (x + y)) == x + y)
            {
                cnt += item.second;
            }
        }
        if (cnt >= k) x = x + y;
        --t;
    }

    cout << x << "\n";
    return 0;
}



Measured memory_bytes: 33536
N,W = map(int,input().split())
dp = [[0 for j in range(W+1)] for i in range(N+1)]
for i in range(1,N+1):
    w,v = map(int,input().split())
    for j in range(W+1):
        if j >= w:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]+v)
        else:
            dp[i][j] = dp[i-1][j]
print(dp[N][W])

Measured memory_bytes: 173448
def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n // i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


A, B, K = map(int, input().split())
A_yaku = make_divisors(A)
B_yaku = make_divisors(B)
A_B_yaku = sorted(list(set(A_yaku) & set(B_yaku)))
print(A_B_yaku[len(A_B_yaku) - K])


Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MOD=1e9+7;

int main(){
	int N;
	cin>>N;
	string S,T;
	cin>>S>>T;
	
	//縦か横*2かの情報を読み込む.pop_backで後ろから
	vector<int> d(1,0);
	while(!S.empty()){
		char x=S.back();
		S.pop_back();
		if(x==S.back()){
			d.push_back(2);
			S.pop_back();
		}
		else d.push_back(1);
	}
	int l=(int)d.size();
	
	lli ans=1;
	rep1(i,l-1){
		if(d[i]==1){
			if(d[i-1]==0){
				ans=(ans*3)%MOD;
			}
			else if(d[i-1]==1){
				ans=(ans*2)%MOD;
			}
			else{
				ans=(ans*1)%MOD;
			}
		}
		else{
				if(d[i-1]==0){
				ans=(ans*6)%MOD;
			}
			else if(d[i-1]==1){
				ans=(ans*2)%MOD;
			}
			else{
				ans=(ans*3)%MOD;
			}
		}
	}
	cout<<ans;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

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

    int ew = 0, ow = 0;
    for (int i=0; i<s.size(); i++) {
        if (i%2 == 0 and s[i] == '0') ew++;
        else if (i%2 and s[i] == '0') ow++;
    }
    int n = s.size();
    if (n%2 == 0) {
        cout << min(n/2 - ew + ow, ew + n/2 - ow) << endl;
    }
    else {
        cout << min((n/2+1) - ew + ow, ew + n/2 - ow) << endl;
    }
}


Measured memory_bytes: 512
<?php
     
    while ($line = fgets(STDIN)) {
        $inputs = array();
        $inputs[] = explode(' ', trim($line));
         
        $result = (int) $inputs[0][0] + (int) $inputs[0][1];
         
        $length = strlen($result);
        print_r("$length\n");
    }

Measured memory_bytes: 15272
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

int n;
int a[111111];
int b[111111];
int c[111111];

/*
 */
int binary_search_a(int num);
/*
 */
int binary_search_c(int num);

int main(){
  ios_base::sync_with_stdio(false);

  long long ans = 0;

  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    cin >> b[i];
  }
  for(int i=0;i<n;i++){
    cin >> c[i];
  }
  
  sort(a, a+n);
  sort(c, c+n);

  for(int i=0;i<n;i++){
    long long aa = binary_search_a(b[i]);
    long long cc = binary_search_c(b[i]);
    ans += aa * cc;
  }    

  cout << ans << endl;

  return 0;
}

int binary_search_a(int num){
  int ng = -1;
  int ok = n;
  int mid = abs(ok - ng);

  while(abs(ok - ng) > 1){
    mid = (ok + ng) / 2;
    if(num <= a[mid]){
      ok = mid;   
    } else {
      ng = mid;
    }
  }
  
  return ok;
}

int binary_search_c(int num){
  int ng = -1;
  int ok = n;
  int mid = abs(ok - ng);

  while(abs(ok - ng) > 1){
    mid = (ok + ng) / 2;
    if(num < c[mid]){
      ok = mid; 
    } else {
      ng = mid;
    }
  }

  return (n - ok);
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
const int MOD = 1000000007;


int main(){
    int H, W; cin >> H >> W;
    int N; cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];

    int color = 0;
    vector<vector<int>> ans(H, vector<int>(W,0));

    rep(i,(H+1)/2){
        a[color-1];

        for(int j = 0; j < W; j++){

            ans[2*i][j] = color+1;

            a[color]--;
            if (a[color] == 0){
                color++;
            }
        }

        if (2*i+1 == H) break;

        for(int j = W-1; j >= 0; j--){

            ans[2*i+1][j] = color+1;

            a[color]--;
            if (a[color] == 0){
                color++;
            }
        }
    }
    rep(i,H){
        rep(j,W){
            cout << ans[i][j];
            if (j < W-1){
                cout << " ";
            }
        }
        cout << endl;
    }
}

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

int main(void) {
  int N;
  cin >> N;
  vector<int> X(N);
  vector<int> X_copy(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    X_copy[i] = X[i];
  }
  sort(X_copy.begin(), X_copy.end());
  for (int i = 0; i < N; i++) {
    if (X[i] <= X_copy[N / 2 - 1]) {
      cout << X_copy[N / 2] << endl;
    } else {
      cout << X_copy[N / 2 - 1] << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int maxPrice;
		int n;
		int maxnow = 0;
		do {
			int tmp;
			n = sc.nextInt();
			maxPrice = sc.nextInt();
			if(n == 0 && maxPrice == 0) {
				break;
			}
			maxnow = 0;
			int[] priceArray = new int[n];
			for (int i = 0; i < n; i++) {
				priceArray[i] = sc.nextInt();
			}

			for (int i = 0; i < n - 1; i++) {
				for (int i2 = i + 1; i2 < n; i2++) {
					if ((tmp = priceArray[i] + priceArray[i2]) > maxnow && maxPrice >= tmp)
						maxnow = tmp;
				}
			}

			if (maxnow != 0)
				System.out.println(maxnow);
			else
				System.out.println("NONE");

		} while (true);
	}
}



Measured memory_bytes: 51396
def my_match s,t
  
  sl = s.length
  sl.times do |i|
    return false if s[i] != ?? and s[i] != t[i]
  end
  return true
end

def solve sp,t
  
  s = sp
  sl = s.length
  tl = t.length
  
  no = "UNRESTORABLE"
  return no if sl < tl
  
  if sp.include?(t)
    k = sp.index(t)
    s[k, tl] = t
    return s.gsub(??, ?a)
  end
  
  k = sl - tl
  k.downto(0) do |i|
    if my_match(sp[i,tl],t)
      s[i,tl] = t
      return s.gsub(??, ?a)
    end
  end
  
  return no
end

sp = gets.chomp
t = gets.chomp

puts solve sp,t

Measured memory_bytes: 1916
#include<iostream>
using namespace std;
int main()
{
	int C,N,M,ba=1;
	int move[1001],d[1001];
	
	while(1){
		ba = 1;
		cin >> N >> M;
		if(N == 0 && M == 0)
			break;
		for(int i=1;i<=N;i++)
			cin >> move[i];
		for(int i=1;i<=M;i++)
			cin >> d[i];
		for(C=1;C<=M;C++){
			ba += d[C];
			ba += move[ba];
			if(ba >= N)
				break;
		}
		cout << C << endl;
	}
	return 0;
}

Measured memory_bytes: 3016
#include <stdio.h>

int isprime(int n){
	for(int i = 2; i * i <= n; i++){
        	if(n % i == 0) return 0;
    	}
    return 1;
}

int main(){
    int i,n;
    while(scanf("%d", &n) != EOF){
        for(i = n; i >= 5; i--){
            if(isprime(i) && isprime(i-2)) {
                printf("%d %d\n", i-2, i);
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1816
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define dmp(x) cerr<<#x<<":"<<x<<endl
typedef pair<int,int> P;
typedef pair<int,P> PP; 
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;}
const int MOD = 1e9+7;

signed main(){
  string s;
  cin>>s;
  if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3])cout<<"Bad"<<endl;
  else cout<<"Good"<<endl;
  return 0;
}


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

using namespace std;

int main(){

    int N, L;
    cin >> N >> L;
   
    if (1 <= (1-L) && (1-L) <= N) {
        cout << (L-1)*N + N*(N+1)/2 << endl;
    }else if(L*L <= (L+N-1)*(L+N-1)){
        cout << (L-1)*N + N*(N+1)/2 - L << endl;
        
        
    }else{
        
        cout << (L-1)*N + N*(N+1)/2 - (L+N-1) << endl;
        
        
    }
    
    
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> F(H, vector<char>(W));
  rep(i, H) rep(j, W) cin >> F[i][j];
  vector<vector<int>> dp(H, vector<int>(W, inf));
  dp[0][0] = F[0][0] == '#';
  rep(i, H) rep(j, W) {
    if (i + 1 < H) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (F[i][j] == '.' && F[i + 1][j] == '#'));
    if (j + 1 < W) dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + (F[i][j] == '.' && F[i][j + 1] == '#'));
  }
  cout << dp[H - 1][W - 1] << "\n";
}


Measured memory_bytes: 256