akhauriyash/Code-Regression huggingface dataset:
import heapq
n, m = map(int, input().split())
day = [[] for _ in range(10**5+1)]
for _ in range(n):
    a, b = map(int, input().split())
    day[a].append(b)
benefit = []
heapq.heapify(benefit)
ans = 0
for i in range(1, m+1):
    for j in day[i]:
        heapq.heappush(benefit, -j)
    if benefit:
        ans -= heapq.heappop(benefit)  # 最大値を加算
print(ans)


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

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;

int main() {
#ifdef LOCAL
  assert(freopen("c.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

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

  ll ans = 0;

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

  cout << ans << endl;
}



Measured memory_bytes: 1024
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<ll, ll>
const ll  MOD = 1000000007;

int main() {
	ll n, m;
	cin >> n >> m;
	vector<ll> v(m, 0);
	rep(i, n) {
		ll k;
		cin >> k;
		rep(j, k) {
			ll a;
			cin >> a;
			a--;
			v.at(a)++;
		}
	}
	ll ans = 0;
	rep(i, m) {
		if (v.at(i) == n) ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
from fractions import gcd
A,B=map(int,input().split())
C=gcd(A,B)

count=1
C_copy=C
n=2
while n**2<=C:  #C==1になるまでCを割る方針では、Cに大きい素因数が含まれている場合にTLEする
   if C_copy==1:
      break

   flag=False
   while C_copy%n==0:
      C_copy//=n
      flag=True
   if flag:
      count+=1
      n=n+1 if n==2 else n+2
   else:
      n=n+1 if n==2 else n+2

if C_copy!=1:
   count+=1

print(count)

Measured memory_bytes: 5048
#include <iostream>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a < b) {
        cout << "a < b" << endl;
    } else if (a == b){
        cout << "a == b" << endl;
    } else {
        cout << "a > b" << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    string s;
    cin>>s;
    int k;
    cin>>k;
    rep(i,s.size()){
        int a=(26-(s[i]-'a'))%26;
        if(a<=k) k-=a,s[i]='a';
        if(i==s.size()-1) s[i]+=k%26;
    }
    cout<<s;
}

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


int main()
{
    int n; cin>>n;
  
    int x[n];
    rep(i,n)  cin>>x[i];
 
    int ans =100001000;
   for(int i=0;i<=100;i++)
   {
       int now =0;
   
       for(int j=0;j<n;j++)
       {
          int z = abs(x[j]-i);
         
           now += z*z;
       }
     
      ans = min(now,ans);
   
   }
   

    cout<<ans<<endl;
  
}


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

using namespace std;

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

template<typename T>
class tRMQ {
  vector<T> data;
  T unit;

public:
  static const long long INF = 100000000000;
  int n;
  function<T(const T &, const T &)> f;

  tRMQ(int _, T u, function<T(T, T)> bi) {
    unit = u;
    f = bi;
    n = 1;
    while (n < _) {
      n <<= 1;
    }
    data.resize(n * 4);
    for (int i = 0; i < n * 4; i++)
      data[i] = unit;
  }

  void update(int index, T val) {
    int i = index + n - 1;
    data[i] = val;
    while (i > 0) {
      i = (i - 1) / 2;
      data[i] = f(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }

  // [a, b)
  T query(int a, int b, int k, int l, int r) {
    if (a < 0 || r <= a || b <= l)
      return unit;
    if (a <= l && r <= b)
      return data[k];
    else
      return f(query(a, b, k * 2 + 1, l, (l + r) / 2),
               query(a, b, k * 2 + 2, (r + l) / 2, r));
  }

  T query(int a, int b) { return query(a, b, 0, 0, n); }
};

tRMQ<ll> minrmq(int n) {
  return tRMQ<ll>(n, 10000000000000000LL, [](ll r, ll l) { return min(l, r); });
}

tRMQ<ll> maxrmq(int n) {
  return tRMQ<ll>(n, -10000000000000000LL,
                  [](ll r, ll l) { return max(l, r); });
}

tRMQ<ll> sumrmq(int n) {
  return tRMQ<ll>(n, 0, [](ll l, ll r) { return l + r; });
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) a[i] -= k;
  map<ll, int> f;
  ll sum = 0;
  f[0] = 0;
  vector<ll> s(n + 1);
  for (int i = 0; i < n; i++) {
    sum += a[i];
    f[sum] = 0;
    s[i + 1] = sum;
  }
  int c = 0;
  for (auto &v : f) v.second = c++;
  vector<ll> v(c);
  for (int i = 0; i <= n; i++) v[f[s[i]]]++;
  auto r = sumrmq(c);
  for (int i = 0; i < c; i++) {
    r.update(i, v[i]);
  }
  
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    r.update(f[s[i]], r.query(f[s[i]], f[s[i]] + 1) - 1);
    auto it = f.lower_bound(s[i]);
    if (it == f.end()) continue;
    int id = it->second;
    ans += r.query(id, c);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 25600
def main(A: int, B: int, C: int, D: int):
    train, bus = 0, 0
    if A <= B:
        train += A
    else:
        train += B

    if C <= D:
        bus += C
    else:
        bus += D

    return train + bus


if __name__ == '__main__':
    A = int(input())
    B = int(input())
    C = int(input())
    D = int(input())
    print(main(A, B, C, D))


Measured memory_bytes: 3064
from collections import defaultdict
def main():
  n,k=map(int,input().split())
  xy=[list(map(int,input().split())) for _ in range(n)]
  x=[p[0] for p in xy]
  y=[p[1] for p in xy]
  x.sort()
  y.sort()
  
  s1=[[0]*n for _ in range(n)]
  s2=[[0]*n for _ in range(n)]
  s3=[[0]*n for _ in range(n)]
  s4=[[0]*n for _ in range(n)]
  for i in range(n):
    for j in range(n):
        for p in xy:
            if p[0]<=x[i] and p[1]<=y[j]:
              s1[i][j]+=1
              s2[i][j]+=(p[0]<x[i])
              s3[i][j]+=(p[1]<y[j])
              s4[i][j]+=(p[0]<x[i])*(p[1]<y[j])
  ans=float('inf')
  for s in range(n):
    for t in range(s+1,n):
      for u in range(n):
        for v in range(u+1,n):
          if s1[t][v]-s3[t][u]-s2[s][v]+s4[s][u]>=k:
            ans=min(ans,(x[t]-x[s])*(y[v]-y[u]))
  print(ans)

if __name__=='__main__':
  main()


Measured memory_bytes: 9572
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <deque>
#define pb push_back
#define mod 1000000007
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

int main(void){
  vector<int> a(3);
  cin>>a[0]>>a[1]>>a[2];
  sort(a.begin(),a.end());
  if(a[0]+a[1]==a[2]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)
#define REPIT(i,x) for(auto i{(x).begin()}; i != (x).end(); i++) 

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int MOD = 1000000007;

int n, m;
Vi va;
vector<pii> vm;
priority_queue<int, Vi, greater<int>> que;

void init()
{
	cin >> n >> m;
	va.resize(n);
	REP(i, n) cin >> va[i];
	vm.reserve(m);
	REP(i, m)
	{
		int b, c; cin >> b >> c;
		vm.emplace_back(pii(c, b));
	}
	sort(ALL(vm), greater<pii>());
}


int main()
{
	init();

	int i = 0;
	while (que.size() < n && i < m)
	{
		int x = vm[i].first;
		int t = vm[i].second;
		REP(_i, t)
			que.push(x);
		++i;
	}

	REP(i, n)
		que.push(va[i]);

	while (que.size() > n)
		que.pop();
	
	ll ans = 0;
	REP(i, n)
	{
		ans += (ll)que.top();
		que.pop();
	}

	cout << ans << endl;
	
}

//// done A-D in 15min on Sep 27, 2019 ////


Measured memory_bytes: 2552
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
  
int main(){
  long long N,K;
  long long i,j;
  int bit_length=60;
  cin >> N >> K;
  K++;
  vector<long long> A(N);
  for(i=0;i<N;i++){
    cin >> A[i];
  }
  vector<long long> total(bit_length,0);
  long long t=1;
  for(i=0;i<bit_length;i++){
    for(j=0;j<N;j++){
      if((A[j]&t)>0){
        total[i]++;
      }
    }
    //cout << total[i];
    t = t << 1;
  }
  //cout << "\n";
  long long f=0;
  long long fmax = 0;
  t=1;
  for(i=0;i<bit_length;i++){
    f=0;
    if((K&t)>0){
      //cerr << i << "\n";
      long long t2 =1;
      for(j=0;j<i;j++){
    	if(total[j]<=N/2){
     	  f += (N-total[j])*t2;
  		}else{
          f += total[j]*t2;
    	}
        t2 = t2 << 1;
        //cerr << f << "\n";
      }
      //cerr << f << "\n";
      f+=total[j]*t2;
      //cerr << f << "\n";
      t2 = t2 << 1;
      for(j=i+1;j<bit_length;j++){
        if((K&t2)>0){
          f += (N-total[j])*t2;
        }else{
          f+=total[j]*t2;
        }
        t2 = t2 << 1;
      }
      //cerr << f << "\n";
      if(f>fmax)fmax=f;
    }
    t = t << 1;
  }
      
  //for(i=0;i<K_bit_length;i++){
  //  if(total[i]<=N/2){
  //    f += (N-total[i])*t;
  //  }else{
  //    f += total[i]*t;
  //  }
  //  t = t << 1;
  //}
      
  cout << fmax << "\n";
    
  //for(i=0;i<bit_length;i++){
  //  cout << total[i] << "\n";
  //}
}


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

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    string s;
    cin>>s;
    int n = s.size();
    bool check = true;
    for(int i=0;i< (n-1)/2;++i)
    {
        if(s[i]!=s[(n-1)/2-1-i]) check = false;
    }
    for(int i=(n+3)/2;i<n;++i)
    {
        if(s[i]!=s[n-i-1]) check=false;
    }
    if(check) cout<<"Yes";
    else cout<<"No";
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

int main() {
	long long int N = 0;
	std::cin >> N;
	std::vector<long long int> count(4, 0);
	for (long long int i = 0; i < N; ++i) {
		std::string result = "";
		std::cin >> result;
		if (result == "AC") {
			count[0] += 1;
		} else if (result == "WA") {
			count[1] += 1;
		} else if (result == "TLE") {
			count[2] += 1;
		} else if (result == "RE") {
			count[3] += 1;
		}
	}
	std::cout << "AC x " << count[0] << std::endl;
	std::cout << "WA x " << count[1] << std::endl;
	std::cout << "TLE x " << count[2] << std::endl;
	std::cout << "RE x " << count[3] << std::endl;
}


Measured memory_bytes: 3200
import java.util.Scanner;

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

   int C=0;
   if(N>=10){
     C=R;
   }
  else if(N<10){
     C=R+(100*(10-N));
   }
 System.out.println(C);
 }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
 
const int mod = 1e9+7;
 
int dp[110][10];
 
int main(){
  int h, w, k;
  cin >> h >> w >> k;
  dp[0][0] = 1;
  rep(i,h) {
    rep(j,w) {
      rep(bit,1<<(w-1)) {
        bool ok = true;
        rep(k,w-2) {
          if ((bit & 1 << k) && (bit & 1 << (k+1))) ok = false;
        }
        if (ok) {
          if (j >= 1 && (bit & 1<<(j-1))) {
            (dp[i+1][j-1] += dp[i][j]) %= mod;
          } else if (j <= w-2 && (bit & 1<<j)) {
            (dp[i+1][j+1] += dp[i][j])%= mod;
          } else {
            (dp[i+1][j] += dp[i][j]) %= mod;
          }
        }
      }
    }
  }
  cout << dp[h][k-1] << endl;
  return 0;
} 

Measured memory_bytes: 256
N = gets.to_i
A = gets.chomp.split(' ').map(&:to_i)

hash = {}
A.each do |a|
  if hash[a]
    hash[a] += 1
  else
    hash[a] = 1
  end
end
puts hash.max { |a, b| a[1] <=> b[1] }[1] == 1 ? 'YES' : 'NO' 


Measured memory_bytes: 34820
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{
   
    class Program
    {
        
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            long N = long.Parse(str[0]);
            long M = long.Parse(str[1]);

            if (N == 1 && M == 1) Console.WriteLine(1);
            else if (N == 1) Console.WriteLine(M - 2);
            else if (M == 1) Console.WriteLine(N - 2);
            else Console.WriteLine((N - 2) * (M - 2));
            
        }
    }
}

Measured memory_bytes: 13140
l = int(input())

n = 20
e = []
for i in range(n - 2):
    e.append([i + 1, i + 2, 0])
    e.append([i + 1, i + 2, 2 ** i])
i = 0
while l:
    if (l >> i) & 1 == 1:
        l -= 1 << i
        e.append([i + 1, n, l])
    i += 1
if e[-1][0] == n:
    e.pop()
    e.append([n - 1, n, 0])
    e.append([n - 1, n, 2 ** (n - 2)])

print(n, len(e))
for a, b, c in e:
    print(a, b, c)


Measured memory_bytes: 3064
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args){
		FastScanner sc = new FastScanner();
		int count = sc.nextInt();
		long pattern = sc.nextInt();
		long result = pattern;
		for(int i=1;i<count;i++){
			result *= (pattern-1);
		}
		System.out.println(result);
	}
}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
}

Measured memory_bytes: 19796
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void){
  cout << std::fixed << std::setprecision(16);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  
  int n;
  cin>>n;
  int a=0;
  for(int i=1;i<=n;i++){
    if(i%2==1) a++;
  }
  cout<<(double)a/n<<endl;



  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int x,y;
int group(int k) {
	if (k==2)
		return 3;
	if (k==4||k==6||k==9||k==11)
		return 2;
	return 1;
}
int main() {
	scanf("%d %d",&x,&y);
	if (group(x)==group(y))
		printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

int main()
{
  int n,m,i,num,maxl=0,minr=100000;
  int l[100010],r[100010];

  cin>>n>>m;
  for(i=0;i<m;i++) cin>>l[i]>>r[i];

  for(i=0;i<m;i++){
    if(maxl<l[i]) maxl = l[i];
    if(minr>r[i]) minr = r[i];
  }

  if(maxl>minr){
    num=0;
  }else{
    num = minr - maxl +1;
  }

  cout<<num<<endl;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr <<__LINE__<< ": " << #x << " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
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;


void solve() {
    int n;
    string s;
    cin >> n >> s;
    map<char, int> mp;
    rep(i, n) mp[s[i]]++;
    ll ans = 1LL * mp['R'] * mp['G'] * mp['B'];
    rep(i, n) REP(j, i + 1, n) {
        int k = 2 * j - i;
        if (k >= n) continue;
        if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) ans--;
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a,a+n);
    for(int i=1;i<n;i++){
        if(a[i] == a[i-1]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


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

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

typedef pair<int,int> pii;
int main() {
  int n,m;
  while(cin>>n>>m,n+m) {
    vector<int> v(m);
    REP(i,n) {
      REP(j,m) {
        bool f;
        cin >> f;
        if (f)
          v[j]++;
      }
    }
    vector<pii> vv(m);
    REP(i,m) {
      vv[i] = pii(v[i], 10000-i-1);
    }
    sort(ALL(vv),greater<pii>());
    REP(i,vv.size()) {
      if (i)cout << " ";
      cout << 10000-vv[i].second;
    }
    cout << endl;
  }
}

Measured memory_bytes: 912
import java.util.*;

class Main{
    void solve(){
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int R = sc.nextInt();
        if ( H*(-1) == R ) System.out.println("0");
        else if ( H*(-1) > R ) System.out.println("-1");
        else if ( H*(-1) < R ) System.out.println("1");
    }

    public static void main(String[] args){ new Main().solve(); }
}




Measured memory_bytes: 26316
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 500;

int a[N][N], ch[N], used[N] = {0};
bool del[N] = {0};

int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			cin >> a[i][j];

	int cur = 0;
	for (int i = 1; i <= n; ++i)
	{
		ch[i] = 1;
		++used[a[i][ch[i]]];
		cur = max(cur, used[a[i][ch[i]]]);
	}

	int ans = cur;
	for (int k = 0; k < m - 1; ++k)
	{
		int most = 1;
		for (int j = 1; j <= m; ++j)
			if (used[j] > used[most])
				most = j;

		del[most] = true;
		for (int i = 1; i <= n; ++i)
		{
			if (a[i][ch[i]] == most)
			{
				--used[most];
				while (del[a[i][ch[i]]])
					++ch[i];

				++used[a[i][ch[i]]];
			}
		}

		cur = 0;
		for (int j = 1; j <= m; ++j)
			cur = max(cur, used[j]);

		ans = min(ans, cur);
	}

	cout << ans << endl;

}

Measured memory_bytes: 896
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
struct edge {
	int to, cost;
};
int n, a, b, c, sub[100009], par[100009]; vector<edge> g[100009];
long long calc(int pos, int pre) {
	sub[pos] = 1;
	par[pos] = pre;
	long long ret = 0;
	for (edge e : g[pos]) {
		if (e.to == pre) continue;
		ret += calc(e.to, pos);
		ret += 1LL * e.cost * min(sub[e.to], n - sub[e.to]);
		sub[pos] += sub[e.to];
	}
	return ret;
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n - 1; ++i) {
		cin >> a >> b >> c; --a, --b;
		g[a].push_back(edge{ b, c });
		g[b].push_back(edge{ a, c });
	}
	long long ret = calc(0, -1);
	int mx = 1 << 30;
	bool halving = false;
	for (int i = 0; i < n; i++) {
		if (sub[i] * 2 == n) {
			halving = true;
			for (edge e : g[i]) {
				if (e.to == par[i]) mx = e.cost;
			}
		}
	}
	if (!halving) {
		for (int i = 0; i < n; i++) {
			bool gravity = (sub[i] * 2 >= n);
			for (edge e : g[i]) {
				if (e.to != par[i]) {
					gravity = gravity && (sub[e.to] * 2 <= n);
				}
			}
			if (gravity) {
				for (edge e : g[i]) {
					mx = min(mx, e.cost);
				}
			}
		}
	}
	cout << ret * 2 - mx << "\n";
	return 0;
}

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


bool check(int x, vector<int> const& s, const int M) {
    int lv = 1;
    int i = 0;
    int cnt = 0;
    while(lv + x <= s.back()) {
        if(s[i] >= lv + x) {
            if(i == 0) {
                return false;
            }
            lv += max(1, x - abs(lv - s[i-1]));
        } else {
            int cand = max(1, x - abs(lv - s[i]));
            if(i > 0) {
                cand = max(cand, x - abs(lv - s[i - 1]));
            }
            lv += cand;
        }
        i = lower_bound(s.begin(), s.end(), lv) - s.begin();
        cnt++;
    }
    cnt++; // for boss
    return cnt >= M;
}

int main() {
    int N, M;
    while(cin >> N >> M, N) {
        vector<int> s(N);
        for(int i = 0; i < N; ++i) {
            cin >> s[i];
        }

        int lb = -1, ub = 1e9;
        while(ub - lb > 1) {
            int m = (lb + ub) / 2;
            if(1 + m <= s[0]) {
                lb = m;
                continue;
            }
            if(check(m, s, M)) {
                lb = m;
            } else {
                ub = m;
            }
        }
        int res = -1;
        if(check(lb, s, M)) {
            res = lb;
        }
        if(check(ub, s, M)) {
            res = ub;
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX=60;

template<int char_size>
struct Trie{
    struct TrieNode{
        char c; int dep;
        vector<int> nxt,idxs;
        TrieNode(char c,int dep):c(c),dep(dep),nxt(char_size,-1){}
    };
    vector<TrieNode> Nodes;
    function<int(char)> ctoi;
    Trie(function<int(char)> ctoi):ctoi(ctoi){
        Nodes.emplace_back('$',0);
    }
    inline int &next(int node,int c){
        return Nodes[node].nxt[c];
    }
    inline int &next(int node,char c){
        return next(node,ctoi(c));
    }
    void add(const string &s,int x){
        int node=0;
        for (int i=0;i<s.size();++i){
            int k=ctoi(s[i]);
            if (next(node,k)<0){
                next(node,k)=Nodes.size();
                Nodes.emplace_back(s[i],i+1);
            }
            node=next(node,k);
        }
        Nodes[node].idxs.emplace_back(x);
    }
    int find(const string &s){
        int node=0;
        for (int i=0;i<s.size();++i){
            int k=ctoi(s[i]);
            if (next(node,k)<0) return -1;
            node=next(node,k);
        }
        return node;
    }
    template<typename F>
    void query(const string &s,const F &f,int l){
        int node=0;
        for (int i=l;i<s.size();++i){
            node=next(node,s[i]);
            if (node<0) return;
            for (auto &idx:Nodes[node].idxs) f(idx);
        }
    }
    int size(){return Nodes.size();};
    vector<int> idxs(int node){return Nodes[node].idxs;}
    int ch(int node){
        int res=0;
        if (~next(node,0)) res|=1<<0;
        if (~next(node,1)) res|=1<<1;
        return (res==1||res==2);
    }
    int dep(int node){return Nodes[node].dep;}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; ll L; cin >> N >> L;
    vector<string> S(N);
    for (int i=0;i<N;++i) cin >> S[i];
    Trie<2> trie([](char c){return c-'0';});
    for (int i=0;i<N;++i) trie.add(S[i],i);
    ll G=0,s=trie.size();
    for (int i=0;i<s;++i) if (trie.ch(i)){
        ll d=L-trie.dep(i),grundy;
        for (int i=MAX;i>=0;--i)
            if (d&1LL<<i) grundy=1LL<<i;
        G^=grundy;
    }
    cout << (G?"Alice":"Bob") << '\n';
}

Measured memory_bytes: 11048
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// ALDS1_4_D - Allocation
// https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/4/ALDS1_4_D

// 最大値の最小値を求める問題。
// 確か最大積載量Pを決め打ちして二分探索するんだった気がする。
// 最大積載量Pは、1 (=重さ1x1個)から、10^9(=重さ10,000 x 100,000個)の範囲の可能性がある。
// 最大積載量Pを1~10^9の間で決め打ちすると、その積載量Pxk台のトラックでn個の荷物を積み切れるか判定するにはO(N)かかる
// 最大積載量Pは2分探索できるので、O(NlogN)で間に合う
func isOK(w []int, p, k int) bool {
	// w: 荷物
	// p: トラック一台あたりの最大積載量
	// k: トラックの台数
	current, tracks := 0, 1
	for i := 0; i < len(w); i++ {
		if current+w[i] <= p {
			current += w[i]
		} else if tracks < k && w[i] <= p {
			current = w[i]
			tracks++
		} else {
			return false
		}
	}
	return true
}
func lbound(w []int, k int) int {
	left, right := 0, 10000*100000
	for right-left > 1 {
		// fmt.Printf("right %d, left %d\n", right, left)
		mid := (left + right) / 2
		if isOK(w, mid, k) {
			right = mid
		} else {
			left = mid
		}
	}
	return right
}
func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	k := nextInt(sc)
	w := make([]int, n)
	for i := range w {
		w[i] = nextInt(sc)
	}
	fmt.Println(lbound(w, k))
}
func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}



Measured memory_bytes: 2344
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

enum MAX = 1_000_100;
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias Pass = Tuple!(long, "x", long, "y");

long[MAX] fac;
long[MAX] inv;
long[MAX] finv;

void combinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    foreach (i; iota(2, MAX))
    {
        fac[i] = i * fac[i - 1] % MOD;
        inv[i] = MOD - (inv[MOD % i] * (MOD / i)) % MOD;
        finv[i] = inv[i] * finv[i - 1] % MOD;
    }
}

auto comb(long n, long k)
{
    if (n < k || n < 0 || k < 0)
        return 0;
    else
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void main()
{
    long x, y;
    scan(x, y);
    long fst, snd;
    fst = 2 * x - y;
    snd = 2 * y - x;
    if (fst < 0 || snd < 0)
        writeln(0);
    else if (fst % 3 || snd % 3)
        writeln(0);
    else
    {
        fst /= 3;
        snd /= 3;
        combinit();
        (fst + snd).comb(fst).writeln();
    }
}

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 23680
#include<iostream>

#include<cmath>
#include<string>
#include <algorithm> 

using namespace std;

# define p(s) cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) cout << (j ? "Yes" : "No") << endl;

string lpad(string l,int s,int n){
    string temp = to_string(n);
    string res = "";
    int loop = s - temp.size();
    while(loop--) res+=l;

    return res+temp;
}

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

    string res;
    if(d==25) res = "Christmas";
    if(d==24) res = "Christmas Eve";
    if(d==23) res = "Christmas Eve Eve";
    if(d==22) res = "Christmas Eve Eve Eve";

    p(res)
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector <int> p(n);
  vector <int> q(n);
  REP(i, n) {
	cin >> p[i];
  }
  REP(i, n) {
	cin >> q[i];
  }
  int pc = 0;
  int qc = 0;
  vector <int> a(n);
  REP(i, n) {
	a[i] = i + 1;
  }
  int c = 0;
  do {
	  bool fp = true;
	  bool fq = true;
	  REP(i, n) {
		if (a[i] != p[i]) {
			fp = false;
		  }
		if (a[i] != q[i]) {
			fq = false;
		  }
	  }
	  if (fp) {
		  pc = c;
		}
	  if (fq) {
		  qc = c;
		}
	  c++;
	} while (next_permutation(all(a)));
  cout << abs(pc - qc) << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a,b;
  cin>>a>>b;
  vector<P> c(a);
  rep(i,a)
    cin>>c[i].first>>c[i].second;
  sort(all(c));
  int d=b,e=0;
  rep(i,b){
  if(c[i].second<d){
  d-=c[i].second;
    e+=c[i].first*c[i].second;
  }
    else{
    e+=d*c[i].first;
      break;
    }
  }
  out(e);
}

Measured memory_bytes: 5000
n = int(input())

a = [int(x) for x in input().split()]

mx = 0
ls = -1
cnt = 0
for i in a:
	if i <= ls:
		cnt += 1
	else:
		mx = max(mx, cnt)
		cnt = 0
	ls = i
mx = max(mx, cnt)
print(mx)

Measured memory_bytes: 14252
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Scanner;

public class Main {
    int n, w;
    int[] vs;
    int[] ws;
    int[] ms;
    int[][] dp;
    ArrayList<ArrayDeque<Pos>> ds;

    public static void main(String[] args) {
        Main m = new Main();
        m.read();
        m.solve();
    }

    private void read() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        w = sc.nextInt();
        vs = new int[n];
        ws = new int[n];
        ms = new int[n];
        for (int i = 0; i < n; i++) {
            vs[i] = sc.nextInt();
            ws[i] = sc.nextInt();
            ms[i] = sc.nextInt();
        }
        dp = new int[n+1][w+1];
        ds = new ArrayList<ArrayDeque<Pos>>(1001);
        for (int i = 0; i < 1001; i++)
            ds.add(new ArrayDeque<Pos>());
    }

    private void solve() {

        for (int i = 1; i < n + 1; i++) {
            int v = vs[i-1];
            int m = ms[i-1];
            int w = ws[i-1];
//            for (int j = 0; j < w; j++) {
//                for (int k = 0; k <= m; k++) {
//                    if (j + w * k <= this.w+1)
//                        ds.get(j).add(new Pos(i-1, j+w*k));
//                    if (j >= w)
//                        dp[i][j] = Math.max(dp[i-1][j], dp[i-1][j-w] + v);
//                }
//            }
            for (int j = 0; j < this.w + 1; j++) {
                add(i, j);
                Pos p = ds.get(j % w).getFirst();
                dp[i][j] = dp[p.i][p.j] + v * ((j - p.j) / w);
            }
            for (int j = 0; j < w; j++)
                ds.get(j).clear();
//            for (int j = 0; j < this.w + 1; j++)
//                System.out.printf("%3d ", dp[i][j]);
//            System.out.println();
        }
        int ans = Integer.MIN_VALUE;
        for (int j = 0; j <= w; j++) {
            ans = Math.max(ans, dp[n][j]);
        }
        System.out.println(ans);
    }

    private void add(int i, int j) {
        Pos newP = new Pos(i-1, j);
        ArrayDeque<Pos> deque = ds.get(j%ws[i-1]);
        while (!deque.isEmpty()) {
            Pos p = deque.getLast();
            if (j < ws[i-1] ||
                    dp[p.i][p.j] + vs[i-1] * ((j - p.j) / ws[i-1]) >= dp[i-1][j])
                break;
            deque.removeLast();
        }
        deque.addLast(newP);
        if (j - deque.getFirst().j > ms[i-1] * ws[i-1])
            deque.removeFirst();
    }

    private class Pos {
        int i, j;
        Pos (int i, int j) {
            this.i = i;
            this.j = j;
        }
    }
}

Measured memory_bytes: 56900
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
int n,m,a,b,d[1010][1010];
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(m);
	read(a); read(b);
	for (int i=1;i<=b;i++)
	for (int j=1;j<=a;j++) d[i][j]=1;
	for (int i=b+1;i<=n;i++)
	for (int j=a+1;j<=m;j++) d[i][j]=1;
	for (int i=1;i<=n;i++) {
		for (int j=1;j<=m;j++) printf("%d",d[i][j]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 5120
#include <iostream>

using namespace std;

int f(int x,int y,int a,int b){
	if( x >= 5 && y >= 2 ) return ( a * x + b * y ) * 8 / 10;
	return ( a * x + b * y );
}

int main(){
	int N;
	while(cin >> N&&N){
	int sum = 0,mx=0;
	for(int i = 0 ; i < N ; i++){
		int x;
		cin >> x;
		if(x){
			sum++;
			mx=max(x,mx);
		}
	}
	if(mx>=2){
		cout << sum+1 << endl;
	}else{
		cout << "NA" << endl;
	}
	}
	
}

Measured memory_bytes: 1160
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr double DINF = 100000000000000000.0;
constexpr long long INF = 100000000000000000;
const double PI = acos(-1);

const int MAX_V = 100100;

vector<int> G[MAX_V];
LL V;
int color[MAX_V];
//頂点を1と-1で塗っていく
bool dfs(int v, int c) {
	color[v] = c;//vをcで塗る
	for (int i = 0; i < G[v].size(); i++) {
		//隣接している頂点が同じ色ならfalse
		if (color[G[v][i]] == c)return false;
		//隣接している頂点がまだ塗られてないなら-cで塗る
		if (color[G[v][i]] == 0 && !dfs(G[v][i], -c))return false;
	}
	//全ての頂点が塗れたらtrue
	return true;
}

int main() {
	LL m;
	cin >> V >> m;
	int a, b;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		a--, b--;
		G[a].emplace_back(b);
		G[b].emplace_back(a);
	}
	for (int i = 0; i < V; i++) {
		if (color[i] == 0) {
			//まだ頂点が塗られてなければ1で塗る
			if (!dfs(i, 1)) {
				cout << V*(V - 1) / 2 - m << endl;
				return 0;
			}
		}
	}
	LL B = 0, W = 0;
	for (int i = 0; i < V; i++) {
		if (color[i] == 1)B++;
		else if (color[i] == -1)W++;
	}
	cout << B*W - m << endl;
}

Measured memory_bytes: 6528
#include <cmath>
#include <cstdio>

int main() {
  int a, b, C;
  scanf("%d%d%d", &a, &b, &C);

  const double PI = 3.141592653589;
  double S = a * b * sin(C * PI / 180) / 2;
  double L = a + b + sqrt(a * a + b * b - 2 * a * b * cos(C * PI / 180));
  double h = S * 2 / a;

  printf("%f %f %f\n", S, L, h);

  return 0;
}


Measured memory_bytes: 3004
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var A = sc.nextInt();
        var B = sc.nextInt();
        var ans = Max(A + B, Max(A - B, A * B));
        WriteLine(ans);
    }
    
}

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);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

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

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

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

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 998244353
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

const int mod = 119 << 23 | 1, nax = 2e5 + 44;
ll fac[nax], fin[nax];
ll powe(ll x, ll e) {
	ll r = 1;
	while (e) {
		if (e & 1) r = r * x % mod;
		x = x * x % mod;
		e >>= 1;
	}
	return r;
}
ll inv(ll x) {
	return powe(x, mod - 2);
}
ll choose(int a, int b) {
	if (b < 0 || b > a) return 0;
	return fac[a] * fin[b] % mod * fin[a - b] % mod;
}
void solve() {
	fac[0] = 1;
	for (int i = 1; i < nax; ++i) fac[i] = fac[i - 1] * i % mod;
	fin[nax - 1] = inv(fac[nax - 1]);
	for (int i = nax - 2; i >= 0; --i) fin[i] = fin[i + 1] * (i + 1) % mod;
	int n, m, k;
	cin >> n >> m >> k;
	
	int ans = 0;
	for(int i = n - k - 1; i < n; i++) {
//		cout << choose(n - 1, i) * m % mod * powe(m - 1, i) % mod << endl;
		(ans += (choose(n - 1, i) * m) % mod * powe(m - 1, i) % mod) %= mod;
	}
	
	cout << ans << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

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

int main(){
int N,K,Q;cin >> N >> K >> Q;
vector<int> A(Q);
vector<int> X(N,K);
for(int i = 0; i < Q; i++){
  cin >> A[i];
}
for(int j = 0; j < Q; j++){
  X[A[j]-1] += 1;
}  
for(int k = 0; k < N; k++){
  X[k] -= Q; 
  }

for(int i = 0; i < N; i++){
  if(X[i] > 0){
    cout << "Yes" <<endl;
  }
  else{
    cout << "No" << endl;
  }
}
}


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

int main()
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    std::ifstream in("a.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    string s;
    cin >> s;

    map<string, string> m;

    int pos = 0;

    int ans = 0;

    string s_pre("0");
    while(pos < s.size())
    {

        int len = 1;
        for (len; (pos + len) <= s.size(); len++)
        {
            if (s.substr(pos, len) != s_pre)
            {
                //cout << s.substr(pos, len) << endl;
                ans++;
                s_pre = s.substr(pos, len);
                break;
            }
        }
        pos += len;
    }

    cout << ans;


    return 0;
}


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

int main(){
  int D,G;
  cin >> D >> G;
  int result_num = 0;
  rep(i,D){
   	d[i][0] = (i+1)*100;
    cin >> d[i][1];
    cin >> d[i][2];
    d[i][3] = (i+1)*100*d[i][1] + d[i][2];
    d[i][4] = 0; 
    result_num = result_num + d[i][1];
  }

  int result_point=0;
  rep( i, 1 << D){
    int point=0;
    int num=0;
    
    vector<int> flag(D);
    rep(j,D) if( i>>j & 1 ) {
      flag[j] = 1;
      point = point + d[j][3];
      num = num + d[j][1];
    }
    for (int j = D-1; 0 <= j; j--){
      if(flag[j] == 0) rep(k,d[j][1]){
        if( point + d[j][0] * k >= G && num + k < result_num){
          result_point = k * d[j][0] + point;
          result_num =  num + k;
        }
      }
    }
  }
  cout << result_num << endl;
  return 0;
}

Measured memory_bytes: 256
import sys

n,k= map(int,input().split())
v={}

min = sys.maxsize

if n == 0 :print(0);exit()

if n > k :
    x = n%k
    if x == 0 or x > k: 
        print(x);exit()
    else:
        n=x
        v[x] = True

while True:
    diff = abs(n- k)

    if v.get(diff):
        break
    else:
        # print(diff)
        v[diff] = True
        n = diff

        if diff < min:
            min = diff



print(min)

Measured memory_bytes: 3064
N = int(input())
W = list(map(int, input().split()))

ans = sum(W)
for T in range(N + 1):
    S1 = S2 = 0
    for i, Wi in enumerate(W):
        if i <= T:
            S1 += Wi
        else:
            S2 += Wi
    if ans > abs(S1 - S2):
        ans = abs(S1 - S2)

print(ans)

Measured memory_bytes: 3060
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef pair<ll,ll> p;
#define vv(a) vector< vector<a> >
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll power(ll x, ll y, ll p=mod)
{ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
int main()
{
fast;
ll n,m;
cin>>n>>m;
vector< vector<ll> >adj(n+1);
for(ll i=0;i<m;i++)
{
    ll a,b;
    cin>>a>>b;
    adj[a].pb(b);
    adj[b].pb(a);
}
vector<bool>visited(n+1,false);
vector<ll>parent(n+1,-1);
queue<ll>q;
q.push(1);
visited[1]=true;
while(!q.empty())
{
    ll x=q.front();
    q.pop();
    for(auto y:adj[x])
    {
        if(visited[y]==false)
        {
            visited[y]=true;
            parent[y]=x;
            q.push(y);
        }
    }
}
for(ll i=1;i<=n;i++)
{
    if(visited[i]==false)
    {
        cout<<"No"<<endl;
        return 0;
    }
}
cout<<"Yes"<<endl;
for(ll i=2;i<=n;i++)
{
    cout<<parent[i]<<endl;
}
return 0;
}


Measured memory_bytes: 13116
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define f first
#define s second
using namespace std;
ll n;
ll a[100005][4],dp[100005][4];

ll f(ll day,ll flag)
{
    if(dp[day][flag]!=-1)
        return dp[day][flag];
    if(day==n)
        return 0;
    ll maxi=0;
    if(flag==0)
    {
        maxi=max(maxi,a[day][1]+f(day+1,1));
        maxi=max(maxi,a[day][2]+f(day+1,2));
        maxi=max(maxi,a[day][3]+f(day+1,3));
    }
    else if(flag==1)
    {
        maxi=max(maxi,a[day][2]+f(day+1,2));
        maxi=max(maxi,a[day][3]+f(day+1,3));
    }
    else if(flag==2)
    {
        maxi=max(maxi,a[day][1]+f(day+1,1));
        maxi=max(maxi,a[day][3]+f(day+1,3));
    }
    else
    {
        maxi=max(maxi,a[day][1]+f(day+1,1));
        maxi=max(maxi,a[day][2]+f(day+1,2));
    }
    return dp[day][flag]=maxi;
}

int main() {
    cin>>n;
    for(ll i=0;i<n;i++)
        for(ll j=1;j<=3;j++)
            cin>>a[i][j];
    memset(dp,-1,sizeof(dp));
    cout<<f(0,0);
	return 0;
}


Measured memory_bytes: 17664