akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
using namespace std;
  

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

   int k;
   cin >>k;
   int d[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
   int ans = d[k-1];
   
   cout << ans << endl;
}



Measured memory_bytes: 256
from operator import itemgetter

n, h = map(int, input().split())
ab = sorted([list(map(int, input().split())) for i in range(n)], key=itemgetter(0), reverse=True)

max_a = ab[0][0]
ab_s2 = sorted(ab, key=itemgetter(1), reverse=True)
ans = 0
for a, b in ab_s2:
    if b > max_a:
        h -= b
        ans += 1
        if h <= 0:
            break

if h > 0:
    ans += -(-h // max_a)

print(ans)

Measured memory_bytes: 29792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define mp(a, b) make_pair(a, b)
const int maxn = 2e3 + 10; 
const ll mod = 1e9 + 7;
ll f[maxn][maxn], g[maxn][maxn], ans;
int main()
{
	int m;
	scanf("%d", &m);
	f[0][0] = 1;
	for(int j = 0; j <= m; ++j) g[0][j] = 1;
	for(int i = 1; i <= m; ++i)
	{
		for(int j = 3 * i; j <= m; ++j)
		{
			f[i][j] = g[i - 1][j - 3];
			g[i][j] = (g[i][j - 1] + f[i][j]) % mod;
		}
		ans = (ans + f[i][m]) % mod;
	}
	cout << ans << endl;		
	return 0;
}

Measured memory_bytes: 18684
#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: 3092
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

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

    int n, m;
    string s, t;
    cin >> n >> m >> s >> t;
    bool f = true;
    rep(i, n)
    {
        if ((m * i) % n == 0)
        {
            int p = (m * i) / n;
            if (s[i] != t[p])
            {
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << n * m / gcd(n, m) << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
using namespace std;
int main(){
    int dice,face[6]={},l;
    string command;
    for(int i=0;i<6;i++){
        cin>>face[i];
    }
    cin>>command;
    l=command.size();
    for(int i=0;i<l;i++){
        if(command[i]=='N'){
            int tmpa=face[0];
            int tmpb=face[4];
            face[0]=face[1];
            face[1]=face[5];
            face[4]=tmpa;
            face[5]=tmpb;
        }
        if(command[i]=='S'){
            int tmpc=face[0];
            int tmpd=face[1];
            face[0]=face[4];
            face[1]=tmpc;
            face[4]=face[5];
            face[5]=tmpd;
        }
        if(command[i]=='E'){
            int tmpe=face[0];
            int tmpf=face[2];
            face[0]=face[3];
            face[2]=tmpe;
            face[3]=face[5];
            face[5]=tmpf;
        }
        if(command[i]=='W'){
            int tmpg=face[0];
            int tmph=face[3];
            face[0]=face[2];
            face[2]=face[5];
            face[3]=tmpg;
            face[5]=tmph;
        }
    }
    cout<<face[0]<<endl;
    return 0;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  for (int i = 0; i < N; i++){
    cin >> p[i];
  }
  
  int sum = 0;
  sort(p.begin(), p.end());
  for (int i = 0; i < K; i++){
    sum += p[i];
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 3552
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
#include <utility>
#include <bitset>

using namespace std;

using ll = long long;

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

	ll ans;

	for (int x = 0; x <= min(k, s); x++)
	{
		for (int y = 0; y <= min(k, s - x); y++)
		{
			int z = s - (x + y);
			if (z >= 0 && z <= k)
				ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
class UF():
  def __init__(self, N):
    self.parents = [-1] * (N+1)
    self.weight = [0] * (N+1)

  def union(self, f, t, w):
    w += self.weight[f]
    w -= self.weight[t]

    p1 = self.find(f)
    p2 = self.find(t)
    if p1 == p2:
      return

    if self.parents[p1] > self.parents[p2]:
      p1,p2 = p2,p1
      w = -w
    self.parents[p1] += self.parents[p2]
    self.weight[p2] = w
    self.parents[p2] = p1

  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      y = self.find(self.parents[x])
      self.weight[x] += self.weight[self.parents[x]]
      self.parents[x] = y
      return y

  def compare_weight(self, x, y):
    self.find(x); self.find(y)
    return abs(self.weight[y] - self.weight[x])

  def same(self, n1, n2):
    # import pdb; pdb.set_trace()
    return self.find(n1) == self.find(n2)

N,M = map(int, input().split())
uf = UF(N)
flg = True
for _ in range(M):
  l,r,d = map(int, input().split())
  if uf.same(l, r):
    if uf.compare_weight(l,r) != d:
      flg = False
      break
  else:
    uf.union(l,r,d)

print('Yes') if flg else print('No')



Measured memory_bytes: 106712
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a,b) (abs((a)-(b))<EPS)
int main()
{
	while(1)
	{
		int num;
		cin >> num;
		if(num==0)break;
		for(int i=0;i<9;i++)
		{
			int n;
			cin >> n;
			num-=n;
		}
		cout << num << endl;
	}
	return 0;
}

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

int main(){
	int N,M,X,Y;
	cin >> N >> M >> X >> Y;
	vector<int> x(N);
	vector<int> y(M);
	for(int i=0;i<N;i++){
		cin >> x.at(i);
	}
	for(int i=0;i<M;i++){
		cin >> y.at(i);
	}
	sort(x.begin(),x.end());
	sort(y.begin(),y.end());
	if(X<Y && y.at(0) > X && x.at(N-1) < Y && x.at(N-1)<y.at(0)){
		cout << "No ";
	}



//2...AC
/*	for(int Z=x.at(N-1)+1;Z<y.at(0)+1;Z++){
		if(Z>X&&Z<=Y){
			cout << "No ";
			break;
		}
	}
*/

//1...WA
/*	if(X+1<Y && y.at(0) > X && x.at(N-1)+1<=Y){
		cout << "No ";
	}
*/
	cout << "War" << endl;
}

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

using namespace std;

#define LL long long
#define N 300
#define INF 0x3f3f3f3f3f3f3f3fLL

LL n,tot,dep,ans1,ans2,head[N],x[N],y[N],f[N],g[N],d[N];
struct edge{LL v,nxt;}e[N];

void add(LL x,LL y){e[++tot].v=y; e[tot].nxt=head[x]; head[x]=tot;}

void dfs(LL u,LL fa){
	LL num=0; dep=max(dep,d[u]);
	for (LL i=head[u],v;i;i=e[i].nxt)
		if ((v=e[i].v)!=fa){d[v]=d[u]+1; dfs(v,u); ++num;}
	++f[d[u]]; g[d[u]]=max(g[d[u]],num);
}

int main(){
	scanf("%lld",&n);
	if (n==2){puts("1 2"); return 0;}
	for (LL i=1;i<n;++i){
		scanf("%lld%lld",&x[i],&y[i]);
		add(x[i],y[i]); add(y[i],x[i]);
	}
	ans1=ans2=INF;
	for (LL i=1;i<=n;++i){
		memset(f,0,sizeof f); memset(g,0,sizeof g);
		dep=0; d[i]=1; dfs(i,0);
		if (dep>n/2+2) continue;
		for (LL j=n;j;--j)
			if (g[j]&&g[j+1]) g[j]=g[j]*g[j+1];
		if (dep<ans1){ans1=dep; ans2=g[1];}
		else if (dep==ans1) ans2=min(ans2,g[1]);
	}
	for (LL i=1;i<n;++i){
		memset(f,0,sizeof f); memset(g,0,sizeof g);
		dep=0; d[x[i]]=d[y[i]]=1; dfs(x[i],y[i]); dfs(y[i],x[i]);
		if (dep>n/2+2) continue;
		for (LL j=n;j;--j)
			if (g[j]&&g[j+1]) g[j]=g[j]*g[j+1];
		if (dep<ans1){ans1=dep; ans2=g[1]*2;}
		else if (dep==ans1) ans2=min(ans2,g[1]*2);
	}
	printf("%lld %lld\n",ans1,ans2);
	
	return 0;
}
			

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(long long i=0;i<int(N);++i)
using ll = long long;
// const int INF = 2147483647;
const ll MOD = 1e9+7;
const ll INF = 1000000000000000000LL;
 
 
 int main() {
	 string s;
	 cin >> s;
	 ll ans=0;
	 rep(i,s.size()){
		 ans+=s[i]-'0';
	 }
	 if(ans%9==0)
	 	cout << "Yes" << endl;
	 else
		 cout << "No" << endl;
	 
	 return 0;
 }

Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265
int main()
{
      double a,b,x;
     cin>>a>>b>>x;

  double y = (x-((b*a*a)/2));
    y=y*2;
      y=y/(a*a);
      double alpha;
      double inverse;
      double value;

      if(y < 0)
      {
         y=(2*x)/(b*a);
            alpha= b/y;
      }
      else
         alpha=(b-y)/a;

      inverse=atan(alpha);
        value=(inverse *180)/PI;
       cout<<std::setprecision(14)<<value;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for (int i=(n)-1;i>=0;i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define REPS(i,f,n) for (int i=(f)-1;i>=(n);i--)
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};

int s[101010];
int n, q;
ll sum = 0;

bool binarysearch(ll key){
	int left = 0;
	int right = n;
	int mid;
	while(left < right){
		mid = (left + right) / 2;
		if(key == s[mid])
			return true;
		else if(key > s[mid])
			left = mid + 1;
		else
			right = mid;
	}
	return false;
}

int main(void){
	cin >> n;

	rep(i, n)
		cin >> s[i];	
	//sort(all(s));
	cin >> q;

	rep(i, q){
		ll k;
		cin >> k;
		if (binarysearch(k))
			sum++;
	}

	printf("%lld\n", sum);
	return 0;

}

Measured memory_bytes: 3456
#include<iostream>
#include<string>
#include<cmath>

using namespace std;

int main(){

	string inp;
	string chinp;

	int si, bo;

	while (1){

		cin >> inp;
		if (inp == "#") break;

		chinp = "";
		for (int i = 0; i < inp.size();){
			if (inp[i] == 'n')chinp += 'n', i += 5;
			else chinp += 'w', i += 4;
		}

		si = 0, bo = 1;
		if (chinp[chinp.size() - 1] == 'n') si = 0;
		else si = 90;
		for (int i = chinp.size() - 2; i >= 0; i--){
			int a = chinp.size() - i + 1;
			bo *= 2;
			si *= 2;
			if (chinp[i] == 'n') si -= 90;
			else si += 90;
		}

		while (si % 2 == 0 && bo != 1){
			si /= 2;
			bo /= 2;
		}

		cout << si;
		if (bo != 1) cout << "/" << bo;
		cout << endl;

	}
	return 0;
}

Measured memory_bytes: 1192
N = int(input())
H = list(map(int, input().split()))

ans = 1
for i in reversed(range(1, N, 1)):
    if (H[i-1] - H[i]) == 1:
        H[i-1] -= 1
    if (H[i-1] - H[i]) > 1:
        print('No')
        ans = -1
        break
if ans == 1: print('Yes')

Measured memory_bytes: 14396
#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) { cout << #a << " = " << a << endl; }
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); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int N, M; cin >> N >> M;
  int a[N][M];
  int cnt[22] = {};
  int ans = 0;
  rep(i, N) rep(j, M) {
    cin >> a[i][j];
    cnt[i] += a[i][j];
    maximize(ans, cnt[i]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3104
#include<stdio.h>

int main() {
	//??\???
	char N[1002];
	scanf("%s", N);
	int i = 0;

	while (N[i] != '\0') {
		if (N[i] == 'A')
			N[i] = 'X';
		else if (N[i] == 'B')
			N[i] = 'Y';
		else if (N[i] == 'C')
			N[i] = 'Z';
		else
			N[i] = N[i] - 3;

		i++;
	}
	printf("%s\n", N);
	return 0;
}

Measured memory_bytes: 524
#include <algorithm>
#include <iostream>
#include <tuple>
#include <vector>

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

struct RUP {
  int n;
  vector<int64_t> dat, laz;
  const int64_t def = 1LL << 62;
  RUP() {}
  RUP(int n_) { init(n_); }
  void init(int n_) {
    n = 1;
    while (n < n_)
      n *= 2;
    dat.clear();
    dat.resize(2 * n - 1, def);
    laz.clear();
    laz.resize(2 * n - 1, -1);
  }
  inline void eval(int len, int k) {
    if (laz[k] < 0) return;
    if (k * 2 + 1 < n * 2 - 1) {
      laz[k * 2 + 1] = laz[k];
      laz[k * 2 + 2] = laz[k];
    }
    dat[k] = laz[k];
    laz[k] = -1;
  }
  int64_t update(int a, int b, int64_t x, int k, int l, int r) {
    eval(r - l, k);
    if (r <= a || b <= l) return dat[k];
    if (a <= l && r <= b) return laz[k] = x;
    eval(r - l, k);
    dat[k] = min(update(a, b, x, k * 2 + 1, l, (l + r) / 2),
                 update(a, b, x, k * 2 + 2, (l + r) / 2, r));
    return dat[k];
  }
  int64_t query(int a, int b, int k, int l, int r) {
    eval(r - l, k);
    if (r <= a || b <= l) return def;
    if (a <= l && r <= b) return dat[k];
    auto vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    auto vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
  void update(int a, int b, int64_t x) { update(a, b, x, 0, 0, n); }
  int64_t query(int a, int b) { return query(a, b, 0, 0, n); }
};

int main() {

  int n, m;
  cin >> n >> m;
  vector<tuple<int, int, int>> v;
  rep(i, m) {
    int l, r, c;
    cin >> l >> r >> c;
    v.emplace_back(l - 1, r - 1, c);
  }
  sort(v.begin(), v.end(),
       [](auto &lhs, auto &rhs) { return get<1>(lhs) < get<1>(rhs); });
  RUP t(n);
  const int64_t inf = 1LL << 62;
  t.update(0, 1, 0);
  for (auto p : v) {
    int l, r, c;
    tie(l, r, c) = p;
    auto mn = t.query(l, r);
    // cout << l << " " << r << " " << c << " " << mn << endl;
    auto cur = t.query(r, r + 1);
    if (mn + c < cur) t.update(r, r + 1, mn + c);
  }
  auto ans = t.query(n - 1, n);
  if (ans == inf) ans = -1;
  cout << ans << endl;

  return 0;
}


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

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

int main(){
  int N,M;
  cin>>N>>M;
  int L[M],R[M];
  rep(i,M)
    cin>>L[i]>>R[i];
  int count=0,Lmax=0,Rmin=10000000;
  rep(i,M){
    Lmax=max(Lmax,L[i]);
    Rmin=min(Rmin,R[i]);
  }
  rep(i,N){
    if(Lmax<=i&&i<=Rmin)
      count++;
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 1024
from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    a,b,n = mi()
    tmp = min(b-1,n)
    print((a*tmp)//b)



main()




Measured memory_bytes: 9964
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
dic = {c: alphabet[(i + 26) % 52] for i, c in enumerate(alphabet)}

s = input()
for c in s:
    if c in alphabet:
        print(dic[c], end='')
    else:
        print(c, end='')

print()



Measured memory_bytes: 5716
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.immutable._
import scala.io.StdIn.readLine

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}

object Main {
  val m = (1 << 9) - 1

  def solve(sc: => Scanner): Unit = {
    println(getPrimeList.filter(_ % 5 == 4).drop(500).take(sc.nextInt).force.mkString(" "))
  }

  def recursive(now: Int, A: Array[List[Int]]): Int = {
    if (A(now).size == 0) (now) else {
      val next = A(now).head
      A(now) = A(now).filter(_ != next)
      A(next) = A(next).filter(_ != now)
      recursive(next, A)
    }
  }

  def getPermutation(now: Long = 0): Stream[Long] =
    Stream.cons(now, getPermutation(now + 1))


  def getPrimeList(): Stream[Long] =
    getPrimeListRecursive(getPermutation(2))


  def getPrimeListRecursive(A: Stream[Long]): Stream[Long] =
    Stream.cons(A.head, getPrimeListRecursive(A.tail.filter(_ % A.head != 0)))


  def check(A: Array[List[Int]]): Boolean = {
    A.map(_.size == 0).fold(true)((a, b) => a & b)
  }

  def shift(n: Long): Long = {
    if (n == 0) (0) else if (n == 1) (1) else (shift(n - 1) << 1)
  }

  def unShift(n: Long): Long = {
    if (n == 0) (0) else (unShift(n >> 1) + 1)
  }

  def calc(v: Long): Long = (v + 1) * v / 2

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

Measured memory_bytes: 141252
N = int(input())
xyh = [(0,0,0)]*N
for i in range(N):
    x,y,h = map(int, input().split())
    xyh[i] = (x,y,h)
                 
for Cx in range(101):
    for Cy in range(101):
        for i in xyh:
            if i[2] != 0:
                H = i[2] + abs(i[1]-Cy) + abs(Cx- i[0])
                break
        for i in xyh:
            if i[2] != max(H-(abs(i[1]-Cy) + abs(Cx- i[0])), 0):
                break
        else:
            print(Cx,Cy,H)
            break

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

typedef long long ll;

int main() {
    ll n, k;   cin >> n >> k;
    ll *cnt = new ll[100010];
    ll a, b;
    for (ll i = 0; i < n; i++) {
        cin >> a >> b;
        cnt[a] += b;
    }

    ll c = 0;
    for (ll i = 0; i <= 100000; i++) {
        if (c+cnt[i] >= k) {
            cout << i << endl;
            return 0;
        }
        c += cnt[i];
    }
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int md=1000000007;
int n,m;
int main()
{
	long long ans=0;
	scanf("%d%d",&n,&m);
	if(n+1==m||m+1==n||n==m)
	{
		ans=1;
		for(int i=1;i<=n;i++)ans=ans*i%md;
		for(int i=1;i<=m;i++)ans=ans*i%md;
		if(n==m)ans=ans*2%md;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 500000;
const int inf = 1000000007;
const ll mod = 1000000007;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

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


int k, n, ans;
int p[1005];

int main() {

	cin >> n >> k;
	rep(i, n)cin >> p[i];
	sort(p, p + n);

	rep(i, k)ans += p[i];

	cout << ans << endl;

	return 0;
}


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

int less(const void* a, const void* b){
  return *(int*)a - *(int*)b;
}

int is_no_need(int i, const int* a, int K, int N){
  int dp[K];
  for(int k = 0; k < K; k++) dp[k] = 0;
  
  for(int j = 1; j <= N; j++){
    if(j == i) continue;
    
    for(int k = K - 1; k >= a[j]; k--){
      if(dp[k - a[j]] + a[j] > dp[k])
        dp[k] = dp[k - a[j]] + a[j];
    }
  }
  
  return dp[K - 1] + a[i] < K;
}

int count_no_need(const int* a, int K, int N){
  //不必要でないカードのうち, 書かれた数が最小であるもの
  int need = N + 1;
  //不必要であるカードのうち, 書かれた数が最大であるもの
  int no_need = 0;
  
  while(need - no_need > 1){
    int i = (need + no_need) / 2;
    
    if(is_no_need(i, a, K, N)) no_need = i;
    else need = i;
  }
  
  return no_need;
}

int main(){
  int N, K;
  scanf(" %d %d ", &N, &K);
  
  int a[N + 1];
  a[0] = 0;
  for(int i = 1; i <= N; i++) scanf(" %d ", a + i);
  qsort(a, N + 1, sizeof(int), less);
  
  printf("%d\n", count_no_need(a, K, N));
  
  return 0;
}


Measured memory_bytes: 252
/*
      author : nishi5451
      created: 11.08.2020 22:50:52
*/

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

int main(){
    int n,m;
    cin >> n >> m;
    cout << n*(n-1)/2 + m*(m-1)/2 << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> shortest_path(int N, int src, vector<vector<int> >& G) {
	vector<int> dist(N, -1);
	dist[src] = 0;
	queue<int> que;
	que.push(src);
	while (!que.empty()) {
		int u = que.front(); que.pop();
		for (int i : G[u]) {
			if (dist[i] == -1) {
				dist[i] = dist[u] + 1;
				que.push(i);
			}
		}
	}
	return dist;
}
int main() {
	int N;
	cin >> N;
	vector<vector<int> > G(N);
	for (int i = 0; i < N - 1; ++i) {
		int a, b;
		cin >> a >> b; --a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> d1 = shortest_path(N, 0, G);
	vector<int> d2 = shortest_path(N, max_element(d1.begin(), d1.end()) - d1.begin(), G);
	cout << (*max_element(d2.begin(), d2.end()) % 3 == 1 ? "Second" : "First") << endl;
	return 0;
}

Measured memory_bytes: 14324
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;

int c[8][8], N;

class DP{
public:
	int cost;
	string data;
	
	DP(){}
	DP(int c, string d){
		cost=c;data=d;
	}
	
	bool operator< (const DP &opp) const {
		return cost>opp.cost;
	}
};

main(){
	int i,j,k;
	cin >> N;
	for(i=0;i<N;i++)
		for(j=0;j<N;j++)
			cin >> c[i][j];
	string data = string("12345678").substr(0,N);
	map<string, int> list;
	
	priority_queue<DP> dp;
	dp.push(DP(0,data));
	list[data] = 0;
	DP S;
	while(!dp.empty()){
		S = dp.top();
		dp.pop();
		for(i=0;i<N;i++)
			for(j=i+1;j<N;j++){
				DP T = S;
				T.cost += c[i][j];
				swap(T.data[i], T.data[j]);
				if(list.end() == list.find(T.data) || T.cost < list[T.data]){
					list[T.data] = T.cost;
					dp.push(T);
				//	cout << T.data << ":" << T.cost << endl;
				}
			}
	}
	int max = 0;
	data = string("12345678").substr(0,N);
	do{
		int ret = list[data];
		if(max < ret) max = ret;
	
	}while(next_permutation(data.begin(), data.end()));
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 9044
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int a[n+1],sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<k;i++)
    {
        sum+=a[i];
    }
    cout<<sum<<endl;

}


Measured memory_bytes: 3560
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(H: int, N: int, A: "List[int]"):
    if H <= sum(A):
        print(YES)
    else:
        print(NO)
    return



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

if __name__ == '__main__':
    main()


Measured memory_bytes: 14068
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll INF = 1e17;
const int MOD = 1e9 + 7;

int A,B,C;

int main(void) {
	
	cin >> A>>B>>C;
	cout << min(B / A, C)<<endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>

#define DIV 1000000007
using namespace std;


unsigned long long mypow(unsigned long long k, unsigned long long n) {
	unsigned long long temp = 1;

	k = k % DIV;
	while (n) {
		if (n % 2) temp = temp * k % DIV;
		k = k * k % DIV;
		n = n / 2;
	}
	return temp % DIV;
}

int main() {

	unsigned long long N, K;
	cin >> N >> K;


	unsigned long long temp = (N - 1) * N%DIV;
	unsigned long long ans = (1 + temp) % DIV;

	//cout << 0 << "  ans= " << ans << endl;
	for (unsigned long long i = 1; i <= min(N - 2, K - 1); i++) {
		unsigned long long nume = (N - i) * (N - i - 1) % DIV;
		unsigned long long deno = mypow((i + 1) * (i + 1) % DIV, DIV - 2) % DIV;
		//cout << i << "  ";
		//cout << "nume= " << nume << "   deno=" << deno<<"  ";
		unsigned long long shit = nume * deno % DIV;
		//cout << "  shit=" << shit;
		temp *= shit;
		temp %= DIV;
		ans += temp;
		ans %= DIV;

		//cout << "  temp=" << temp ;
		//cout << "  ans=" << ans << endl;
		if (ans <= 0 || temp <= 0 || shit <= 0) {

			break;
		}
	}


	cout << ans << endl;
}


Measured memory_bytes: 256
p = 10**9+7
S = input().strip()
A = [[0 for k in range(13)] for j in range(13)]
for j in range(13):
    for k in range(13):
        for m in range(10):
            if (10*k+m)%13==j:
                A[j][k] = 1
                break
B = [[0 for _ in range(10)] for _ in range(13)]
for j in range(13):
    for m in range(10):
        for k in range(13):
            if (10*k+m)%13==j:
                B[j][m] = k
                break
N = len(S)
dp = [[0 for _ in range(13)] for _ in range(N+1)]
for j in range(13):
    if S[0]!="?":
        dp[1][j] = int(int(S[0])==j)
    else:
        if j<10:
            dp[1][j] = 1
for i in range(2,N+1):
    for j in range(13):
        if S[i-1]!="?":
            dp[i][j] = (dp[i][j]+dp[i-1][B[j][int(S[i-1])]])%p
        else:
            for k in range(13):
                dp[i][j] = (dp[i][j]+dp[i-1][k]*A[j][k])%p
print(dp[N][5])

Measured memory_bytes: 65884
N = int(input())
A = list(map(int,input().split()))
C = {}
for i in range(N):
    a = A[i]
    if a not in C:
        C[a] = 0
    C[a] += 1
C = sorted(list(C.items()),key=lambda x:x[0])
cmax = 0
for i in range(len(C)):
    if i==0:
        c1 = C[0][0]
        cnt = C[0][1]
        if len(C)>1 and C[1][0]==c1+1:
            cnt += C[1][1]
        cmax = max(cmax,cnt)
    elif i==len(C)-1:
        c1 = C[-1][0]
        cnt = C[-1][1]
        if len(C)>1 and C[-2][0]==c1-1:
            cnt += C[-2][1]
        cmax = max(cmax,cnt)
    else:
        c1 = C[i][0]
        cnt = C[i][1]
        if C[i-1][0]==c1-1:
            cnt += C[i-1][1]
        if C[i+1][0]==c1+1:
            cnt += C[i+1][1]
        cmax = max(cmax,cnt)
print(cmax)

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



int main()
{
    int n,a[200000];
    int bucket[200000] = {0};
    int i,j;
    long long ans = 0;

    scanf("%d",&n);

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

    for (i = 1; i <= n; i++)
    {
        ans += (long long)bucket[i] * (bucket[i] - 1) / 2;
    }
    for (i = 0; i < n; i++)
    {
        printf("%lld\n", ans - bucket[a[i]] + 1);
    }
    
}


Measured memory_bytes: 4096
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>

using namespace std;


int main()
{
	int n;
	double x[101];
	double y[101];
	cin >> n;
	for (int i = 0; i < n; i++)cin >> x[i];
	for (int i = 0; i < n; i++)cin >> y[i];
	double m=0;
	for (int i = 0; i < n; i++)
	{
		m += abs(x[i] - y[i]);
	}
	cout <<fixed<< m << endl;
	m = 0;
	for (int i = 0; i < n; i++)
	{
		m += abs(x[i] - y[i])*abs(x[i] - y[i]);
	}
	m = sqrt(m);
	cout << m<<endl;
	//3次元
	m = 0;
	for (int i = 0; i < n; i++)
	{
		m += abs(x[i] - y[i])*abs(x[i] - y[i])*abs(x[i] - y[i]);
	}
	m = cbrt(m);
	cout << m << endl;

	m = 0;
	for (int i = 0; i < n; i++)
	{
		m = max(m, abs(x[i] - y[i]));
	}
	cout << m;
}

Measured memory_bytes: 1312
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n;
    cin>>n;
    string s[100010];
    for(int i=0;i<n;++i) cin>>s[i];
    cout<<"AC x "<<count(s,s+n,"AC")<<endl;
    cout<<"WA x "<<count(s,s+n,"WA")<<endl;
    cout<<"TLE x "<<count(s,s+n,"TLE")<<endl;
    cout<<"RE x "<<count(s,s+n,"RE")<<endl;
}



Measured memory_bytes: 6732
import sys
N,M,X = map(int,input().split())
array_gate = list(map(int,input().split()))
array_base = [0] * (N+1)

if not ( 1 <= N,M <= 100):
    sys.exit()
if not ( 1 <= X <= N -1 ):
    sys.exit()
if not ( 1 <= min(array_gate) <= max(array_gate) <= N - 1):
    sys.exit()

for I in range(len(array_base)):
    if I in array_gate:
        array_base[I] = 1

left = array_base[0:X]
right = array_base[X:-1]
if left.count(1) <= right.count(1):
    result = left.count(1)
else:
    result = right.count(1)

print(result)


Measured memory_bytes: 9064
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}
ll mpower(ll a,ll b,ll c){
  int z;
  if(b==0){
    z=1;
    z%=c;
    return z;
  }
  if(b==1){
    z=a;
    z%=c;
    return z;
  }
  else{
    return (((mpower(a,b/2,c))*(mpower(a,b/2,c))%c)*mpower(a,b%2,c)%c);
  }
}
bool IsPrime(int num){
  if(num<2) return false;
  else if(num==2) return true;
  else if(num%2==0) return false;
  double sqrtNum=sqrt(num);
  for(int i=3;i<=sqrtNum;i+=2){
    if(num%i==0){
      return false;
    }
  }
  return true;
}

int main(){
  int n;
  cin>>n;
  ll ans=1,mod=1000000007,a=0,b;
  for(int i=1;i<1001;i++){
    if(IsPrime(i)==true){
      b=n;
      while(b>=i){
        a+=b/i;
        b/=i;
      }
    }
    ans*=a+1;
    ans%=mod;
    a=0;
  }
  cout<<ans<<endl;
}

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

int main() {
	long long int x;
	long long int a, b;
	cin >> x;

	a = x / 11;
	b = x % 11;

	if (b > 6)cout << 2 * a + 2 << "\n";
	else if (b == 0)cout << 2 * a << "\n";
	else cout << 2 * a + 1 << "\n";
	return 0;
}

Measured memory_bytes: 256
#import<iostream>
#import<map>
#import<queue>
#import<cstdlib>
#import<cstring>
using namespace std;struct B{int z[2];char s[14];bool operator<(const B&r)const{return strcmp(s,r.s)<0;}};main(){int a[13][5]={{2,-1},{2,5,-1},{0,1,3,6,-1},{2,7,-1},{5,-1},{1,4,6,9,-1},{2,5,7,10,-1},{3,6,8,11,-1},{7,-1},{5,10,-1},{6,9,11,12,-1},{7,10,-1},{10,-1}},X[]={2,1,2,3,0,1,2,3,4,1,2,3,2},Y[]={0,1,1,1,2,2,2,2,2,3,3,3,4},v,d,s,i,j,t,u;B g={0,0,"0123456789:;0"};for(;;){map<B,int>m;deque<B>q;B b={i=-1,-1};for(;++i<13;!v?b.z[*b.z>=0]=i:0){cin>>v;if(v<0)return 0;b.s[i]=48+v;}b.s[13]=0;m[b]=1;for(q.push_back(b);!q.empty();q.pop_front()){B&b=q.front();if(!strcmp(b.s,g.s))break;d=0;for(i=13;i--;v?d+=abs(X[v]-X[i])+abs(Y[v]-Y[i]):0)v=b.s[i]-48;s=m[b];if(s+d<22)for(j=2;j--;)for(i=0;~a[u=b.z[j]][i];i++){B n=b;t=n.z[j]=a[u][i];if(t-n.z[1-j]){swap(n.s[u],n.s[t]);int&r=m[n];if(!r)r=s+1,q.push_back(n);}}}printf(m[g]?"%d\n":"NA\n",m[g]-1);}}

Measured memory_bytes: 1480
#include<iostream>
using namespace std;
char a;
int main()
{
	cin >> a;
	if(a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u') cout << "vowel" << endl;
	else cout << "consonant" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n,a,b,c,d;
  string s;
  cin >> n >> a >> b >> c >> d >> s;
  a--; b--; c--; d--;
  auto yes = [&]() {
    cout << "Yes\n";
  };
  auto no = [&]() {
    cout << "No\n";
  };
  for (int i = a; i <= max(c,d)-1; ++i) {
    if (s[i] == '#' && s[i+1] == '#') { //途中に岩が並んでたらNG
      debug(s[i], s[i+1], i);
      no();
      return 0;
    }
  }
  if (c < d) { //後ろにいる人が前にいる人を超えないように移動できる
    yes();
    return 0;
  }
  bool ok = false;
  for (int i = b; i <= d; ++i) { 
    if (i == 0 || i == n-1) continue;
    if (s[i-1] == '.' && s[i] == '.' && s[i+1] == '.') {
      ok = true; break;
    }
  }
  if (ok) yes(); //aの目的値までにマスあれば超えられる
  else no();
  return 0;
}

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  vector<ll> v(N);
  for (int i = 0; i < N; i++) cin >> v[i];
  sort(v.begin(), v.end(), greater<ll>());
  double ans = 0;
  for (int i = 0; i < A; i++) ans += v[i];
  cout << setprecision(30) << (double)ans / A << endl;

  ll comb[51][51] = {};
  for (int i = 1; i <= 50; i++) {
    comb[i][0] = comb[i][i] = 1;
    for (int j = 1; j <= i - 1; j++) {
      comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
    }
  }

  int cnt = 0, x = -1;
  for (int i = 0; i < N; i++) {
    if (v[i] == v[A - 1]) {
      cnt++;
      if (x == -1) x = i;
    }
  }
  ll ans2 = comb[cnt][A - x];
  if (v[0] == v[A - 1]) {
    for (int i = A; i < B; i++) {
      if (v[i] != v[A - 1]) continue;
      ans2 += comb[cnt][i - x + 1];
    }
  }
  cout << ans2 << endl;
}

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

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 long long INF = 1LL << 60;
char s[60][60];
int bomb[60][60];
int main()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	int res = min(B, D) - max(A, C);
	if (res <= 0) {
		res = 0;
	}
	cout << res << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {

	Scanner sc = new Scanner(System.in);

	int A = sc.nextInt();
	int B = sc.nextInt();
	int C = sc.nextInt();
	int D = sc.nextInt();

		if (A <= B && C <= D) {
			System.out.println(A + C);
		}else if (A <= B && C > D) {
			System.out.println(A + D);
		}else if (A >= B && C <= D) {
			System.out.println(B + C);
		}else if (A >= B && C >= D) {
			System.out.println(B + D);
		}

	}
}

Measured memory_bytes: 21844
/** ２つの整数 a, b と１つの演算子 op を読み込んで、a op b を計算するプログラムを作成して下さい。
 * ただし、演算子 op は、"+"(和)、"-"(差)、"*"(積)、"/"(商)、のみとし、
 * 割り算で割り切れない場合は、小数点以下を切り捨てたものを計算結果とします。
 */

/*sucannerクラス使うためにインポート*/
import java.util.Scanner;

class Main {
	// プログラムのエントリポイント
	public static void main(String[] args) {
		// 入力ストリームの生成
		Scanner sc = new Scanner(System.in);
		int intmax = -1000000;
		int intmin = 1000000;
		long lonsum = 0;
		int inthakosuu = sc.nextInt();
		int[] hako;
		hako = new int[inthakosuu];


		for (int i = 0; i < inthakosuu; i++) {
			hako[i] = sc.nextInt();
			if (intmin > hako[i]) {
				intmin = hako[i];
			} if (intmax < hako[i]) {

				intmax = hako[i];
			}

			lonsum += hako[i];
		}
		System.out.println(intmin + " " + intmax + " " + lonsum);

	}
}

Measured memory_bytes: 31744
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <functional>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int H,W,K;
  cin >> H >> W >> K;

  vector<string> s(H);
  for(int i = 0;i < H;i++)cin >> s[i];

  vector<P> st;

  for(int i = 0;i < H;i++){
    for(int j = 0;j < W;j++){
      if(s[i][j] == '#')st.push_back(P(i,j)); 
    }
  } 
 
  vector<vector<int>> ans(H,vector<int>(W,0)); 

  for(int i = 0;i < K;i++){
    P now_st = st[i];

    int start_x = now_st.second;
    int start_y = now_st.first;

    ans[start_y][start_x] = i + 1;
    for(int j = start_x-1;j >= 0;j--){//左側
      if(s[start_y][j] != '#'){
        ans[start_y][j] = i+1;	
      }
      else break;
    }

    for(int j = start_x + 1;j <= W-1;j++){//右側
      if(s[start_y][j] != '#'){
	ans[start_y][j] = i+1;
      }
      else break;
    }

  }

  for(int i = 0;i < H;i++){
    for(int j = 0;j < W;j++){
      if(ans[i][j] != 0){
	for(int k = i-1;k >= 0;k--){
	  if(ans[k][j] == 0)ans[k][j] = ans[i][j];
	  else break;
	}
	for(int k = i+1;k < H;k++){
	  if(ans[k][j] == 0)ans[k][j] = ans[i][j];
	  else break;
	}
      }
    }
  }

  for(int i = 0;i < H;i++){
    for(int j = 0;j < W;j++){
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }

}

Measured memory_bytes: 2040
#include<stdio.h>

void partition(int,int);

int A[100001],i,l;
int main(){
  int n,j;
  scanf("%d",&n);
  for(j=0;j<n;j++){
    scanf("%d",&A[j]);
  }
  partition(0,n-1);
  for(j=0;j<n;j++){
    if(j==i)printf("[%d]",A[j]);
    else printf("%d",A[j]);
    if(j<n-1)printf(" ");
    if(j==n-1)printf("\n");
  }
  return 0;
}





  void partition(int p,int r){
    int x,j,k;
    x=A[r];
    i=p-1;
    for(j=p;j<r;j++){
      if(A[j]<=x){
	i=i+1;
	k=A[i];
	A[i]=A[j];
	A[j]=k;
      }
    }
    k=A[i+1];
    A[i+1]=A[r];
    A[r]=k;
    i+=1;
  }
  



Measured memory_bytes: 2116
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n;
	while (cin >> n, n){
		int w, h;
		cin >> w >> h;
		vector<vector<bool>> cell(w, vector<bool>(h));
		REP(i, n){
			int x, y;
			cin >> x >> y;
			cell[x - 1][y - 1] = true;
		}
		int s, t;
		int ans = 0;
		cin >> s >> t;
		REP(i,w-s+1)
			REP(j, h - t + 1){
			int cnt = 0;
			REP(k, s)
				REP(l, t)
				if (cell[i + k][j + l])
					cnt++;
			ans = max(ans, cnt);
		}
		cout << ans<< endl;
	}

}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n,q,x;
    cin>>n;
    vector<int>v(n);
    vector<int>::iterator it;
    for(int i=0; i<n; i++)
        cin>>v[i];
    cin>>q;
    while(q--) {
        cin>>x;
        it=lower_bound(v.begin(),v.end(),x);
        if(it != v.end())
            cout<<it-v.begin()<<' ';
        else
            cout<<n<<' ';
        it=upper_bound(v.begin(),v.end(),x);
        if(it != v.end())
            cout<<it-v.begin()<<endl;
        else
            cout<<n<<endl;
    }
    return 0;
}





Measured memory_bytes: 3108
// C - Tax Increase
#include <bits/stdc++.h>
using namespace std;
int A,B;

int solve(){
	int a = (A*100+8-1)/8;
	int b = (B*100+10-1)/10;

	int aa = a*0.08;
	int ab = a*0.10;
	int ba = b*0.08;
	int bb = b*0.10;

	if(aa==A && ab==B) return ba==A && bb==B? min(a,b): a;
	else return ba==A && bb==B? b: -1;
	return -1;
}

int main(){
	cin>>A>>B;
	cout<< solve() <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int e[111][111],d[111],used[111];
signed main(){
  int n;
  cin>>n;
  int INF=1LL<<55LL;
  fill((int*)e,(int*)(e+111),INF);
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v,c;
      cin>>v>>c;
      e[u][v]=min(e[u][v],c);
    }
  }
  memset(used,0,sizeof(used));
  for(int i=0;i<n;i++)d[i]=INF;
  d[0]=0;
  while(1){
    int u=-1;
    for(int i=0;i<n;i++){
      if(used[i])continue;
      if(d[i]==INF)continue;
      if(u<0||d[i]<d[u])u=i;
    }
    if(u<0)break;
    used[u]=1;
    for(int i=0;i<n;i++)d[i]=min(d[i],d[u]+e[u][i]);
  }
  for(int i=0;i<n;i++)cout<<i<<" "<<d[i]<<endl;
  return 0;
}



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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
  int dp[1001][1001] {0};
  char a[1001][1001];
 
 
int main()
 { 
    int t;
  
   t=1;
   
   
   while(t--)
   { 
       
       
   int n,i,j,k,l,m;
   cin>>n>>m;
   
   
 
 
 
   for(i=0;i<n;i++)
   {
   	 for(j=0;j<m;j++)
   	 cin>>a[i][j];
   	
   }
 
   if(a[0][0]=='.')
   dp[i][j]=1;
   
   for(i=1;i<m;i++)
   {
   	  if(a[0][i]=='.'&&a[0][i-1]=='.')
   	  dp[0][i]=1;
   	  
   	  else
   	  break;
   	
   }
   
   
   for(i=1;i<n;i++)
   {
   	  if(a[i][0]=='.'&&a[i-1][0]=='.')
   	  dp[i][0]=1;
   	  
   	  else
   	  break;
   	
   }
   
   
   for(i=1;i<n;i++)
   {
   	
   	 for(j=1;j<m;j++)
   	 { 
   	    if(a[i][j]=='#')
   	    dp[i][j]=0;
   	 	
   	 	
          else
   	 	  dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007;
   	 	  
   	 	
		}
   	
   }
   
//    for(i=0;i<n;i++)
//   {
//   	
//   	 for(j=0;j<n;j++)
//   	 {
//   	 	// cout<<dp[i][j]<<" ";
//   	 	  
//   	 	
//		}
//   	
//   	//cout<<endl;
//   }
  
 cout<<dp[n-1][m-1];
  
  
   
}
	return 0;
}


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

int main()
{  ll n;
cin>>n;
ll * A = new ll[n];
for(ll i=0;i<n;i++)
{
    cin>>A[i];
}
   ll yo = 0;
for (ll i = 0; i < n; i++)
  {    yo ^= A[i];}

for (ll i = 0; i < n; i++)
       { A[i] = yo ^ A[i];
           cout<<A[i]<<" ";
       }



return 0;
}

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

#define ll long long



void solve(){
    ll l,r; cin>>l>>r;
    ll mod=2019;
    ll mini=1LL<<60;
    int cnt=0;
    for(ll i=l; i<r; i++){
        for(ll j=i+1; j<=r; j++){
            ll x=i%mod;
            ll y=j%mod;
            ll e=x*y%mod;
            mini=min(mini, e);
            cnt++;
            if(cnt>2019*2019){
                cout<<mini<<endl;
                return;
            }
        }
    }
    cout<<mini<<endl;
}

signed main(){
    //while(1)
    solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,r[3],i=0,ans=0;
  cin >> n;
  int nn = n;
  while(nn%10 != 0){
    r[i] = nn%10;
    nn/=10;
    i++;  
  }
  ans = r[0]*100+r[1]*10+r[2];
  if(ans == n) cout << "Yes" << endl;
  else cout << "No" << endl;
}    
  
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long LL;
LL a[110000];
vector<LL> p1, p2;

pair<LL,LL> neg(pair<LL,LL> b){
	return make_pair(b.second,b.first);
}
int main(){
	srand(150);
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	map<pair<LL,LL>,int> d;
	int n1 = 0;
	vector<int> q;
	for(int j = 2; j < 2200; j++){
		int ok = 1;
		for(int z = 2; z*z <= j; z++){
			if(j % z == 0){
				ok = 0;
				break;
			}
		}
		if(ok) q.push_back(j);
	}
	for(int z = 0; z < n; z++){
		p1.clear();
		p2.clear();
		for(int i = 0; i < q.size(); i++){
			LL j = q[i];
			LL p = j*j*j;
			while(a[z] % p == 0){
				a[z] /= p;
			}
			p = j;
			if(a[z] % (p*p) == 0){
				p2.push_back(p);
				a[z] /= (p*p);
			}
			if(a[z] % (p) == 0){
				p1.push_back(p);
				a[z] /= (p);
			}
		}
		if(a[z] > 1){
			LL c = sqrt(a[z]);
			if(c*c == a[z]){
				p2.push_back(c);
			} else {
				p1.push_back(a[z]);
			}
		}
		if(p1.empty() && p2.empty()){
			n1 = 1;
			continue;
		}
		LL r, s;
		r = s = 1;
		for(int i = 0; i < p1.size(); i++){
			r *= p1[i];
		}
		for(int i = 0; i < p2.size(); i++){
			s *= p2[i];
		}
		d[make_pair(r,s)]++;
		d[make_pair(s,r)]+=0;
	}
	LL ans = 0;
	for(map<pair<LL,LL>,int>::iterator it = d.begin(); it != d.end(); it++){
		ans += max(d[it->first],d[neg(it->first)]);
	}
	ans /= 2;
	ans += n1;
	cout << ans << endl;
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    ll X,Y;
    cin >> X >> Y;
    ll res = X;
    int i = 0;
    while(res <= Y) {
        res *= 2;
        i++; 
    }
    cout << i << endl;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    string s;
    cin >> s;
    OP(count(ALL(s), '1'));
    return 0;
}

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

constexpr int MAX_N = 100;

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

	int csum[2][MAX_N] = {};

	for(int i = 0; i < 2; ++i){
		for(int j = 0; j < N; ++j){
			int input;
			std::cin >> input;

			if(j > 0){
				csum[i][j] = csum[i][j - 1] + input;
			}
			else{
				csum[i][j] = input;
			}
		}
	}

	int ans = csum[0][0] + csum[1][N - 1];
	for(int i = 0; i < N; ++i){
		ans = std::max(ans,  csum[0][i] + csum[1][N - 1] - csum[1][i - 1]);
	}

	std::cout << ans << std::endl;

	return 0;
}


Measured memory_bytes: 256