akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>

#define INF 100000000

using namespace std;

int V,match[2001];
bool used[2001];
vector<int>G[2001];

void add_edge(int u,int v){
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs(int v){
  used[v]=true;
  for(int i=0;i<G[v].size();i++){
    int u=G[v][i],w=match[u];
    if(w<0 || !used[w] && dfs(w)){
      match[v]=u;
      match[u]=v;
      return true;
    }
  }
  return false;
}

int bipartite_matching(){
  int res=0;
  fill(match,match+2001,-1);
  for(int v=0;v<V;v++){
    if(match[v]<0){
      fill(used,used+2001,false);
      if(dfs(v))res++;
    }
  }
  return res;
}
int main(void){
 
  int n,m,l,u,v,d,dist[101][101],graph[1001][1001],p[1001],t[1001];
 
  while(cin >> n >> m >> l,n|m|l){  
 
    for(int i=0;i<2001;i++)G[i].clear();
 
    fill(dist[0],dist[101],INF);
    fill(graph[0],graph[1001],0);

    for(int i=0;i<101;i++)dist[i][i]=0;
    for(int i=0;i<m;i++){
      cin >> u >> v >> d;
      dist[u][v]=dist[v][u]=d;
    }
     
    for(int i=0;i<l;i++){
      cin >> p[i] >> t[i];
    }
    
    for(int k=0;k<n;k++)
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	  dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
    
    for(int i=0;i<l;i++)
      for(int j=0;j<l;j++)
	if(i!=j && dist[p[i]][p[j]]+t[i]<=t[j])
	  graph[i][j]=1;

    for(int i=0;i<l;i++){
      for(int j=0;j<l;j++){
	if(i!=j && graph[i][j])add_edge(i,j+l);
      }
    }
    V=2*l;
    cout << l-bipartite_matching() << endl;
  }
  return 0;
}

Measured memory_bytes: 13648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1000000000
#define rep(i,a,b) for(int i =(a);i<(b);i++)
#define fs first
#define ss second
inline int Scan() {
    int x=0;int f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

template<typename T, typename U>
static inline void amin(T &x, U y)
{
    if (y < x)
        x = y;
}

// call by reference is used in x
template<typename T, typename U>
static inline void amax(T &x, U y)
{
    if (x < y)
        x = y;
}
//////////////////////////////////////end of template//////////////////////////////////////

int main(){

 int n;
 cin >> n;
 
 int a,b,c;
 int aa=0,ab=0,ac=0;
 int na=0,nb=0,nc =0;
 for(int i = 0;i<n;i++){
  	 cin >> a >> b >> c;
	 na = max( ab+a,ac+a);
	 nb = max( ac+b,aa+b);
	 nc = max( ab+c,aa+c);
	 aa = na;
	 ab = nb;
	 ac = nc;
	 
 }
 
 cout << max(max(aa,ab),ac) <<endl;  
   
	   
} 





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

int main(){
  int n, m;
  cin >> n >> m;
  long long x[n], y[n], z[n], a[n], b[n], c[n], d[n];
  long long amax = 0;
  long long bmax = 0;
  long long cmax = 0;
  long long dmax = 0;
  long long amin = 0;
  long long bmin = 0;
  long long cmin = 0;
  long long dmin = 0; 
  
  for(int i=0; i<n; ++i){
    cin >> x[i] >> y[i] >> z[i];
    a[i] = x[i] + y[i] + z[i];
    b[i] = x[i] + y[i] - z[i];
    c[i] = x[i] - y[i] + z[i];
    d[i] = x[i] - y[i] - z[i];
  }
  
  sort(a,a+n);
  sort(b,b+n);
  sort(c,c+n);
  sort(d,d+n);
  
  for(int i=0; i<m; ++i){
    amax += a[n-1-i];
    bmax += b[n-1-i];
    cmax += c[n-1-i];
    dmax += d[n-1-i];
    amin -= a[i];
    bmin -= b[i];
    cmin -= c[i];
    dmin -= d[i];
  }
  cout << max({amax,bmax,cmax,dmax,amin,bmin,cmin,dmin}) << endl;
}

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

const ll INF = 1LL << 60;

ll dp[100005];

// セグメントツリー
//  範囲内の最小値を返す
template <typename T = int>
struct SegmentTree {
  int N;
  vector<T> node;
  T ival;
  SegmentTree( int size, T iv = 0 ) {
    init(size, iv);
  }
  void init( int size, T iv = 0 ) {
    N = 1; while( N < size ) N<<=1;
    node.resize( 2*N-1 );
    ival = iv;
    for(int i=0; i<2*N-1; ++i ) node[i] = ival;
  }
  void update( int pos, T dat ) {
    pos = N + pos - 1;
    node[pos] = dat;
    while ( pos > 0 ) {
      pos = (pos-1)/2;
      node[pos] = min( node[pos*2+1], node[pos*2+2] );
    }
  }
  // [a,b) 区間から取得。現在位置 k, 現在位置の範囲[l,r)
  T get( int a, int b, int k, int l, int r ) {
    if (a>=r || b<=l) return ival;
    if (a<=l && b>=r) return node[k];
    T vl = get( a, b, 2*k+1, l, (l+r)/2 );
//    cout << " vl : " << a << " " <<  b  << " " << 2*k+1 << " " << l << " " << (l+r)/2<< " -> " << vl << endl;
    T vr = get( a, b, 2*k+2, (l+r)/2, r );
//    cout << " vr : " << a << " " <<  b  << " " << 2*k+2 << " " << (l+r)/2 << " " << r << " -> " << vr << endl;
    return min(vl,vr);
  }
  void print() {
    cout << "---- node " << endl;
    for ( int i=0; i<2*N-1; ++i ) {
      cout << " " << i << " : " << node[i] << endl;
    }
  }
  int getRMax() { return N; }
};

int main() {
  int N,M;
  cin >> N >> M;
  vector< tuple<int,int,int> > q;
  SegmentTree<ll> st(N,INF);
  REP(i,M) {
    int l,r,c;
    cin >> l >> r >> c;
    l--; r--;
    q.emplace_back( r, l, c );
  }
  sort( q.begin(), q.end() );
  
  REP(i,N) dp[i] = INF;
  dp[0] = 0;
  
  st.update( 0, dp[0] );
//  st.print();
  REP(i,M) {
    int l,r,c;
    tie(r,l,c) = q[i];
    ll val = st.get(l,r+1,0,0,st.getRMax()) + c;
//    printf("%d %d %d : %lld %lld\n",r,l,c,val,dp[r]);
    if ( dp[r] > val ) {
      dp[r] = val;
      st.update( r, val );
//      st.print();
    }
  }
//  REP(i,N) cout << dp[i] << endl;

  cout << ((dp[N-1]==INF) ? -1 : dp[N-1]) << endl;
}


Measured memory_bytes: 4340
public partial class IntroductionToProgramming{
	public static void Main(){
		string[] line = System.Console.ReadLine().Split(' ');

		int h = int.Parse(line[0]);
		int w = int.Parse(line[1]);

		string es = string.Empty;
		string os = string.Empty;
		for (int i = 0; i < 300; i++)
		{
			es += i % 2 == 0 ? "#" : ".";
			os += i % 2 == 0 ? "." : "#";
		}

		while (!(h == 0 && w == 0))
		{
			for (int i = 0; i < h; i++ )
			{
				System.Console.WriteLine(i % 2 == 0 ? es.Substring(0, w) : os.Substring(0, w));
			}
			System.Console.WriteLine(string.Empty);

			string[] line2 = System.Console.ReadLine().Split(' ');

			h = int.Parse(line2[0]);
			w = int.Parse(line2[1]);
		}
	}
}

Measured memory_bytes: 5460
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int>vi;
#define pb push_back
#define sc(n) scanf("%d",&n)
#define lsc(n) scanf("%lld",&n)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define rev1(i,n) for(i=n;i>0;i--)
#define in insert
#define IT ::iterator
#define pr(n) printf("%d\n",n)
#define lpr(n) printf("%lld\n",n);


int main()
{
	ll n,m,i,j,k;
	cin >> n >> m >> k;
	ll a[n],b[m];
	rep(i,n)
	{
		cin >> a[i];
	}
	rep(i,m)
	{
		cin >> b[i];
	}
	ll pa[n+1],pb[m+1];
	pa[0]=0LL,pb[0]=0LL;
	rep(i,n)
	{
		pa[i+1]=pa[i]+a[i];
	}
	rep(i,m)
	{
		pb[i+1]=pb[i]+b[i];
	}
	j=m;
	ll ans=0LL;
	rep(i,n+1)
	{
		if(pa[i]>k)
		{
			break;
		}
		while(pb[j]>k-pa[i])
		{
			j--;
		}
		ans=max(ans,i+j);
		//cout << ans << endl;
	}
	cout << ans;
    return 0;
}


Measured memory_bytes: 9884
#include <iostream>
using namespace std;
int digitsum(long a){
  int p = 0;
  while(a>0){
    p+=a%10;
    a/=10;
  }
  return p;
}
int main(){
  long a;
  cin >> a;
  if(a%digitsum(a) == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
n, m = map(int, input().split())

k = []
a = []

for i in range(n):
    kk = list(map(int, input().split()))
    k.append(kk[0])
    a.append(kk[1:])

#print(k)
#print(a)

ans = [0 for _ in range(m)]

for i in range(n):
    for j in range(len(a[i])):
#        print(i, j)
        if a[i][j] != 0:
            ans[a[i][j]-1] += 1

#print(ans)

num = 0

for i in range(len(ans)):
    if ans[i] == n:
        num += 1

print(num)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ffor for(;;)
#define ub upper_bound
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout << "Case #" <<qqq+1<<": "
 
typedef long long ll;
//typedef long long T;
const int INF = 100000000;
const ll INF64 = 922337203685477580ll;
//const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
int main(){
    int n;
    std::cin >>n;
    string s;
    std::cin >> s;
    std::vector<std::vector<int> > p(10);
    rep(i,n){
        p[s[i]-'0'].pb(i);
    }
    rep(i,10)p[i].pb(INF);
    rep(i,10)p[i].pb(INF*2);
    rep(i,10)p[i].pb(INF*3);
    int ans=0;
    rep(i,10){
        rep(j,10){
        //std::cout << po << std::endl;
            rep(k,10){
                int po=p[i][0];
                po=*ub(all(p[j]),po);
                po=*ub(all(p[k]),po);
                if(po<INF)ans++;
            }
        }
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>
#include <regex>
#include <random>

#define ll long long
#define ld long double
#define ull unsigned ll
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pii pair<int,int> 
#define vi vector<int>
#define vpii vector<pii>
#define vvi vector<vector<int>>
#define forn(it,from,to) for(int (it)=from; (it)<to; (it)++)
const int  Inf = 2 * 1000 * 1000 * 1000;
ll LINF = (ll)4e18;
using namespace std;
#define M_PI       3.14159265358979323846   // pi


int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("sum.in", "r", stdin);
	//freopen("sum.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	if (a > b) swap(a, b);

	if (c >= a && c <= b) cout << "Yes\n";
	else cout << "No\n";
 	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    // cout << setprecision(8) << setiosflags(ios::fixed);

    int x, y;
    cin >> x >> y;

    if (x % y == 0) cout << "-1\n";
    else cout << x << endl;

    return 0;
}


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

int keta(int64_t x){
  int count=1;
  while(x/10!=0){
    x/=10;
    count++;
  }
  return count;
}

int main() {
  int N,K; cin>>N>>K;
  vector<bool> S(10,false);
  rep(i,K) {
    int s;
    cin>>s;
    S.at(s)=true;
  }
  for(int i=N;i<1000000;i++){
    int a=keta(i),b=i;
    bool ans=true;
    rep(j,a){
      int c=b%10;
      if(S.at(c)) ans=false;
      b/=10;
    }
    if(ans){
      cout<<i;
      break;
    }
  }
}


Measured memory_bytes: 3544
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
// #include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
#include <cassert>
#include<unordered_set>
using namespace std;

 
int main(){
    int a, b;
    cin >> a >> b;
    int mina, minb;
    if(a*100%8 == 0) mina = a*100/8;
    else mina = (a*100)/8+1;
    if(b*100%10 == 0) minb = b*100/10;
    else minb = (b*100)/10+1;
    int minN = max(mina, minb);

    a++; b++;
    if(a*100%8 == 0) mina = a*100/8 - 1;
    else mina = (a*100)/8;
    if(b*100%10 == 0) minb = b*100/10 - 1;
    else minb = (b*100)/10;
    int maxN = min(mina, minb);

    // cout << minN << maxN << endl;

    if(maxN >= minN) cout << minN << endl;
    else cout << -1 << endl;
    


}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] args){

        try{
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

                String str = reader.readLine();
                String[] arr = str.split(" ");

                int a = Integer.parseInt(arr[0]);
                int b = Integer.parseInt(arr[1]);
                int c = Integer.parseInt(arr[2]);

                if(a < b && b < c){
                    System.out.println("Yes");
                }
                else{
                    System.out.println("No");
                }
        }catch(IOException e){
            e.printStackTrace();
        }

    }
}

Measured memory_bytes: 24232
#include<bits/stdc++.h>
#include<queue>
using namespace std;
int main () {
  int H, W;
  cin >> H >> W;
  char maze[1010][1010];
  int ans[1010][1010];
  queue<int>qx;
  queue<int>qy;
  for (int i = 1; i <= H; i ++) {
    for (int j = 1; j <= W; j ++) {
      ans[i][j] = -1;
    }
  }
  for (int i = 1; i <= H; i ++) {
    for (int j = 1; j <= W; j ++) {
      cin >> maze[i][j];
      if (maze[i][j] == '#') {
        qx.push(i);
        qy.push(j);
        ans[i][j] = 0;
      }
    }
  }
  for (int i = 1; i <= H; i ++) {
    maze[i][0] = maze[i][W + 1] = '#';
  }
  for (int i = 1; i <= W; i ++) {
    maze[0][i] = maze[H + 1][i] = '#';
  }
  int x[] = {1, 0, -1, 0};
  int y[] = {0, 1, 0, -1};
  while(!qx.empty()) {
    int ux = qx.front();
    int uy = qy.front();
    for (int i = 0; i < 4; i ++) {
      int vx = ux + x[i];
      int vy = uy + y[i];
      if (maze[vx][vy] == '.' && ans[vx][vy] == -1) {
        qx.push(vx);
        qy.push(vy);
        ans[vx][vy] = ans[ux][uy] + 1;
      }
    }
    qx.pop();
    qy.pop();
  }
  int answer = 0;
  for (int i = 1; i <= H; i ++) {
    for (int j = 1; j <= W; j ++) {
      if (ans[i][j] > answer) answer = ans[i][j];
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 13440
#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h> 

using namespace std;

vector<signed int> countSame(vector<signed int> arr){
  sort(arr.begin(),arr.end());
  vector<signed int> ans(arr.size(), 1);
  int ind = 0; 
  for(int i = 0; i < arr.size() - 1; i++){
    if(arr[i] == arr[i + 1]) ans[ind]++;
    else ind++;
  }
  for (int i = ind + 1; i < ans.size(); i++) ans[i] = -1;

  sort(ans.begin(), ans.end(), greater<signed int>());
  return ans;
}

int main(){
  int N, K;
  cin >> N >> K;
  vector<signed int> A(N, 0);
  int ans = 0;
  for(int i = 0; i < N; i++) cin >> A[i];  
  A = countSame(A);

  for (int i = K; i < A.size() && A[i] > 0; i++){
    ans += A[i];
  }
  
  cout << ans;
}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

vector<pair<int, int>>cards(9);

bool check(vector<pair<int, int>>cards3) {
	sort(cards3.begin(), cards3.end());
	bool ok = all_of(cards3.begin(), cards3.end(), [=](const pair<int, int>&p) {
		return p.first == cards3[0].first;

	}) && ((cards3[0].second==cards3[1].second&&cards3[1].second==cards3[2].second)||(cards3[0].second + 1 == cards3[1].second&&cards3[1].second + 1 == cards3[2].second));
	return ok;
}
bool check(const vector<int>&v) {
	vector<pair<int, int>>c;
	for (int i = 0; i < v.size(); ++i)c.push_back(cards[v[i]]);
	return check(c);
}

int main() {
	int T; cin >> T;
	map<char, int>mp{ {'R',0},{'B',1},{'G',2} };
	while (T--) {
		for (int i = 0; i < 9; ++i) {
			int a; cin >> a;
			cards[i].second = a;
		}
		for (int j = 0; j < 9; ++j) {
			char c; cin >> c;
			cards[j].first = mp[c];
		}
		vector<int>v(6);
		int ans = false;
		for (v[0] = 0; v[0] < 9; ++v[0]) {
			for (v[1] = v[0] + 1; v[1] < 9; ++v[1]) {
				for (v[2] = v[1] + 1; v[2] < 9; ++v[2]) {
					for (v[3] = 0; v[3] < 9; ++v[3]) {
						for (v[4] = v[3] + 1; v[4] < 9; ++v[4]) {
							for (v[5] = v[4] + 1; v[5] < 9; ++v[5]) {
								bool ok = true;
								for (int i = 0; i < 3; ++i) {
									for (int j = 0; j < 3; ++j) {
										if (v[i] == v[j + 3])ok = false;
									}
								}
								if (ok) {
									vector<int>used(9);
									for (int i = 0; i < 6; ++i) {
										used[v[i]] = true;
									}
									vector<int>as(v.begin(), v.begin() + 3);
									vector<int>bs(v.begin() + 3, v.begin() + 6);
									vector<int>cs;
									for (int i = 0; i < 9; ++i) {
										if (!used[i])cs.push_back(i);
									}
									if (check(as) && check(bs) && check(cs)) {
										ans = true;
									}
								}
							}
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    int N; cin >> N;
    while (N % 111 != 0) {
    	N++;
    }
    cout << N << endl;
    
    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 256
import itertools
H,W,K = map(int,input().split())
c = [input() for _ in range(H)]
res = 0
for ls1 in itertools.product([0,1], repeat=H):
    for ls2 in itertools.product([0,1], repeat=W):
        tmp = 0
        for h in range(H):
            for w in range(W):
                if c[h][w] == '#' and ls1[h] == 0 and ls2[w] == 0:
                    tmp += 1
        if tmp==K:
            res += 1
print(res)

Measured memory_bytes: 68332
import sys
from heapq import heapify, heapreplace


def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    As = list(map(int, input().split()))
    heapify(As)
    BCs = [None] * M
    for i in range(M):
        BCs[i] = list(map(int, input().split()))
    BCs = reversed(sorted(BCs, key=lambda x: x[1]))
    for B, C in BCs:
        for _ in range(B):
            if As[0] >= C:
                print(sum(As))
                sys.exit()
            heapreplace(As, C)
    print(sum(As))


if __name__ == '__main__':
    main()


Measured memory_bytes: 33688
import math
N,M=map(int,input().split())

if(N%2==1):
  for i in range(M):
    print(i+1,N-i)
else:
  for i in range(min(M,N//4)):
    print(i+1,N//2-i)
  for i in range(max(M-N//4,0)):
    print(N//2+1+i,N-1-i)

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

int main(){
	int n,w,h; cin >> n >> w >> h;
	vl tate(h+1,0),yoko(w+1,0);
	rep(i,n){
		int x,y,W; cin >> x >> y >> W;
		tate[max(0,y-W)]++; tate[min(h,y+W)]--;
		yoko[max(0,x-W)]++; yoko[min(w,x+W)]--; 
	}
	bool flag = true;
	rep(i,h){
		tate[i+1] += tate[i];
		if(tate[i] <= 0) flag = false;
	}
	if(flag){
		puts("Yes");
		return 0;
	}
	flag = true;
	rep(i,w){
		yoko[i+1] += yoko[i];
		if(yoko[i] <= 0) flag = false; 
	}
	if(flag) puts("Yes");
	else puts("No");
}


Measured memory_bytes: 4428
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll N;
  cin >> N;
  vector<ll> ss(N);
  ll sum = 0;
  for (auto i = 0; i < N; i++) {
    cin >> ss[i];
    sum += ss[i];
  }
  sort(ss.begin(), ss.end());
  for (ll i = 0; i < N && sum % 10 == 0; i++) {
    if (ss[i] % 10 == 0) continue;
    sum -= ss[i];
  }

  cout << (sum % 10 == 0 ? 0 : sum) << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        int a = in.ni();
        long b = in.nl(), n = in.nl();
        long x = Math.min(b-1, n);
        out.println(Math.round(Math.floor((a*x)/(double)b)-a*Math.floor((double)x/(double)b)));
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 32764
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int main(){
    fast;
    ll n, m;
    cin >> n >> m;
    ll a[m], ans = 0;
    for(int i = 0; i < m; ++i){
        cin >> a[i];
        ans += a[i];
    }
    if((n - ans) >= 0)
        cout << n-ans;
    else
        cout << -1;
    return 0;
}
//                                     #!!{*[$um1t_Kum@r]*}!!#


Measured memory_bytes: 3684
#include<bits/stdc++.h>
#pragma GCC optimize ("-O3")
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
using namespace std;

int32_t main()
{
    IOS;
    int n;
    cin >> n;
    int a[n];
    int ans = 0,mx = 1;
    for(int i = 0;i < n; i++){
        cin >> a[i];
        mx = max(a[i],mx);
        ans += (mx-a[i]);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 5200
#include<cstdio>
#include<vector>

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

using namespace std;

class union_find{
	int n;
	vector<int> a;
public:
	union_find(int N):a(N,-1),n(N){}
	int find(int x){
		if(a[x]<0) return x;
		return a[x]=find(a[x]);
	}
	void unite(int x,int y){
		x=find(x),y=find(y);
		if(x!=y){ a[x]+=a[y]; a[y]=x; n--; }
	}
	int size(){ return n; }
};

struct slime{ int x,y,id; };

int main(){
	int n,w,h; scanf("%d%d%d",&n,&w,&h);
	static slime s[40000];
	rep(i,n) scanf("%d%d",&s[i].x,&s[i].y), s[i].x--, s[i].y--, s[i].id=i;

	static vector<slime> X[100000],Y[100000];
	rep(i,n){
		X[s[i].x].push_back(s[i]);
		Y[s[i].y].push_back(s[i]);
	}

	union_find U(n);
	rep(j,w) rep(k,(int)X[j].size()-1) U.unite(X[j][k].id,X[j][k+1].id);
	rep(i,h) rep(k,(int)Y[i].size()-1) U.unite(Y[i][k].id,Y[i][k+1].id);

	bool corner=false;
	rep(i,n) if(s[i].x==0 || s[i].x==w-1 || s[i].y==0 || s[i].y==h-1) corner=true;

	int ans=0;
	ans+=n-U.size(); // 1 回の移動で合体できるスライムたちをまとめる
	if(U.size()>=2){
		ans+=2*U.size()-1; // どこかの外壁に並べる
		if(corner) ans--;
	}
	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 8328
#include <iostream>

int main(int argc, const char * argv[]) {
    int a, b, c;
    std::cin >> a >> b >> c;
    
    int nokori = a-b;
    if(c-nokori >= 0)
        std::cout << c-nokori << std::endl;
    else
        std::cout << 0 << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdint>
#include <unordered_map>
#include <sstream>
#include<boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P& element1, const P& element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{ //second降順
	return element1.second > element2.second;
}
int digits(int n)
{
	int count = 0;
	while (n > 0)
	{
		n /= 10;
		count++;
	}
	return count;
}
ll combination(ll n, ll r)
{
	if (r * 2 > n)
		r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i)
	{
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
int GCD(int x, int y)
{
	return x ? GCD(y % x, x) : y;
}
vector<int> divisor(int n)
{
	vector<int> value;
	FOR(i, 1, pow(n, 0.5) + 1)
	{
		if (i <= sqrt(n))
		{
			if (n % i == 0)
			{
				value.push_back(i);
				if (i * i != n)
				{
					value.push_back(n / i);
				}
			}
		}
	}
	return value;
}

int main()
{
	int n;
	cin >> n;
	vector<cpp_int>alpha(n);
	rep(i, n) {
		string s;
		cin >> s;
		cpp_int tmp = 0;
		rep(j, s.size()) {
			int t = s[j] - 97;
			//cout << t << endl;
			cpp_int m = mp::pow(cpp_int(10),t);
			/*rep(k, t) {
				m *= 10;
			}*/
			tmp += m;
		}
		alpha[i] = tmp;
	}
	ll ans = 0;
	sort(all(alpha));
	ll cnt = 0;
	rep(i, n-1) {
		if (alpha[i] == alpha[i + 1]) {
			cnt++;
		}
		else {
			ans += cnt * (cnt + 1) / 2;
			cnt = 0;
		}
	}
	ans += cnt * (cnt + 1) / 2;
	cout << ans << endl;
}

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

int main() {
  int h,w,bc = 0;
  cin >> h >> w;
  vector<string>data(h);
  rep(i,0,h){
    cin >> data[i];
    rep(j,0,w) if(data[i][j] == '#') bc++;
  }
  vector<vector<int>>dist(h,vector<int>(w,-1));
  dist[0][0] = 0;
  queue<P>que;
  que.push(P(0,0));
  while(!que.empty()){
    int x = que.front().first,y = que.front().second;
    que.pop();
    if(x > 0){
      if(data[x-1][y] == '.' && dist[x-1][y] == -1){
        que.push(P(x-1,y));
        dist[x-1][y] = dist[x][y]+1;
      }
    }
    if(x < h-1){
      if(data[x+1][y] == '.' && dist[x+1][y] == -1){
        que.push(P(x+1,y));
        dist[x+1][y] = dist[x][y]+1;
      }
    }
    if(y > 0){
      if(data[x][y-1] == '.' && dist[x][y-1] == -1){
        que.push(P(x,y-1));
        dist[x][y-1] = dist[x][y]+1;
      }
    }
    if(y < w-1){
      if(data[x][y+1] == '.' && dist[x][y+1] == -1){
        que.push(P(x,y+1));
        dist[x][y+1] = dist[x][y]+1;
      }
    }
  }
  if(dist[h-1][w-1] == -1) cout << -1 << endl;
  else cout << h*w-dist[h-1][w-1]-1-bc << endl;
}

Measured memory_bytes: 3644
import Data.List
import qualified Data.ByteString.Char8 as B
import Control.Monad
import Data.Bits

main :: IO ()
main = breads >>= main'
    where
        main' [n, k] = replicateM n breads >>= print . solve k

solve :: Int -> [[Int]] -> Int
solve k xs = foldl' ff 0 ks
    where
        ks = k : [ shift (shift k (-i - 1)) (i + 1) + shift 1 i - 1 | i <- [0..30], shift 1 i .&. k /= 0]
        ff acc n = max acc $ foldl' ff2 0 xs
            where
                ff2 acc2 [a, b]
                    | m .&. complement a == m = acc2 + b
                    | otherwise = acc2
                    where
                        m = complement n

breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)


Measured memory_bytes: 35708
#include<iostream>
#include<vector>

using namespace std;

int main(){
	int h,w,k;
	cin >>h>>w>>k;
	int m[h][w];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			char temp;
			cin >>temp;
			if(temp=='.') m[i][j]=0;
			else m[i][j]=1;
		}
	}
	
	int num=1;
	for(int i=0;i<h+w;i++){
		num*=2;
	}
	
	bool check[h+w];
	int ans=0;
	for(int i=0;i<num;i++){
		int q=i;
		for(int j=0;j<h+w;j++){
			if(q%2==0){
				check[j]=false;
				q=q/2;
			}else{
				check[j]=true;
				q=(q-1)/2;
			}
		}
		int sum=0;
		for(int c=0;c<h;c++){
			if(check[c]==true) continue;
			for(int r=0;r<w;r++){
				if(check[h+r]==true) continue;
				sum+=m[c][r];
			}
		}
		if(sum==k) ans++;
	}
	
	cout <<ans<<endl;
	return 0;
}

Measured memory_bytes: 3636
require 'prime'
x = 10**9+7
n = gets.to_i
def f(a)
  return 1 if a.zero?
  a * f(a-1)
end
d = f(n)
c = 1
pr = d.prime_division
pr.each do |i|
  c *= i[1] + 1
end
p c%x

Measured memory_bytes: 4604
#include<stdio.h>
int main(void) {
    int MM[100][100];
    int n, u, k, v, i, j;
    scanf("%d", &n);
    for ( i = 0; i < n; i++ ) {
        for ( j = 0; j < n; j++ ) MM[i][j] = 0;
    }
    for ( i = 0; i < n; i++ ) {
        scanf("%d %d", &u, &k);
        u--;
        for ( j = 0; j < k; j++ ) {
            scanf("%d", &v);
            v--;
            MM[u][v] = 1;
        }
    }

    for ( i = 0; i < n; i++ ) {
        for ( j = 0; j < n; j++ ) {
            if ( j ) printf(" ");
            printf("%d", MM[i][j]);
        }
        printf("\n");
    }
    return 0;
}

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

#define rep(i,n)  for(int i=0;i<n;++i)
#define per(i,n)  for(int i=n-1;i>=0;--i)
#define sc1(a)  scanf("%d",&a)
#define sc2(a,b)  scanf("%d %d",&a,&b)
#define sc3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define sl1(a)  scanf("%lld",&a)
#define sl2(a,b)  scanf("%lld %lld",&a,&b)
#define sl3(a,b,c)  scanf("%lld %lld %lld",&a,&b,&c)
#define PI 3.1415926535897932

int main(){
    int n,m,ans;
    char s[100];
    vector <int> d(6);
    for(auto&e:d) sc1(e);
    scanf("%s",s);
    n=strlen(s);
    rep(i,n) {
        int tmp;
        if (s[i]=='N') {
            tmp=d[0];
            d[0]=d[1];
            d[1]=d[5];
            d[5]=d[4];
            d[4]=tmp;
        } else if (s[i]=='W') {
            tmp=d[0];
            d[0]=d[2];
            d[2]=d[5];
            d[5]=d[3];
            d[3]=tmp;
        } else if (s[i]=='E') {
            tmp=d[0];
            d[0]=d[3];
            d[3]=d[5];
            d[5]=d[2];
            d[2]=tmp;
        } else {
            tmp=d[0];
            d[0]=d[4];
            d[4]=d[5];
            d[5]=d[1];
            d[1]=tmp;
        }
    }
    printf("%d\n",d[0]);
    return 0;
}


Measured memory_bytes: 3212
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000000
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int N, Q;

std::string s;

char t[222222], d[222222];


int compute(int x)
{
  for (int i = 0; i < Q; i ++)
    if (s[x] == t[i]) {
      x += d[i] == 'L' ? -1 : 1;

      if (x < 0)
        return -1;

      if (x >= N)
        return 1;
    }

  return 0;
}


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::cin >> N >> Q >> s;

  for (int i = 0; i < Q; i ++)
    std::cin >> t[i] >> d[i];

  int l = -1, r = N;

  while (r - l > 1) {
    int m = (l + r) / 2;

    int x = compute(m);

    (x == -1 ? l : r) = m;
  }

  int m = r;

  l = -1, r = N;

  while (r - l > 1) {
    int m = (l + r) / 2;

    int x = compute(m);

    (x == 1 ? r : l) = m;
  }

  int p = l;
  
  std::cout << p - m + 1 << std::endl;

  return 0;
}


Measured memory_bytes: 1020
#include<iostream>
using namespace std;
  
#define mod 1000000007
  
long rec(int a[], int n, long **mem, int id, int k)
{
  if(k<0)
	return 0;
  if(k==0)
  	return 1;
  if(id==n&&k>0)
	return 0;
  if(id==n&&k==0)
    return 1;
  if(mem[id][k]!=-1)
    return mem[id][k];
  
  long ans=(rec(a,n,mem,id+1,k)+rec(a,n,mem,id,k-1)-rec(a,n,mem,id+1,k-1-a[id])+mod)%mod;
  mem[id][k]=ans;
  return ans;
}
  
int main(){
  int n,k;
  cin>>n>>k;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  long **mem=new long*[n+1];
  for(int i=0;i<=n;i++)
  {
    mem[i]=new long[k+1];
    for(int j=0;j<=k;j++)
      mem[i][j]=-1;
  }
  
  cout<<rec(a,n,mem,0,k);
  
  /*long dp[n+1][k+1];
  for(int j=0;j<=k;j++)
    dp[0][j]=0;
  for(int i=0;i<=n;i++)
    dp[i][0]=1;
  for(int i=1;i<=n;i++)
  {
    int sum[k+1];
    sum[0]=dp[i-1][0];
    for(int j=1;j<=k;j++)
      sum[j]=(sum[j-1]+dp[i-1][j])%mod;
    for(int j=0;j<=k;j++)
    {
      int tr=sum[j];
      if(j-a[i-1]-1>=0)
        tr=(tr-sum[j-a[i-1]-1]+mod)%mod;
      dp[i][j]=tr;
    }
  }
  
  cout<<dp[n][k];*/
  

}

Measured memory_bytes: 88832
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    int ans = 0;
    rep(i, N) {
        int a;
        cin >> a;
        if (i % 2 == 0) {
            if (a % 2 == 1) ans++;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,k; cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    auto c = [&](ll x) {
        ll s = 0;
        rep(i,0,n){
            if(a[i] % x == 0)
                s += (a[i] / x) - 1;
            else{
                s += a[i] / x;
            }
        }
        debug(x, s);
        if(s <= k) return true;
        return false;
    };
    ll ok = 1e9, ng = 0;
    while(abs(ok - ng) > 1){
        ll x = (ok + ng) / 2;
        if(c(x)) ok = x;
        else
            ng = x;
    }

    cout << ok << "\n";
}

Measured memory_bytes: 4776
inpl = lambda: list(map(int,input().split()))
X, K, D = inpl()
X = abs(X)
if X + D >= K * D:
    print(abs(X-K*D))
else:
    if K % 2:
        K += 1
        X += D
    E = D*2
    R = X % E
    print(min(R, E-R))


Measured memory_bytes: 61856
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#include<numeric>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}
//nCr mod m
#define MOD 1000000007
#define M 1000000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 1;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return out;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

    int x,y;
    cin>>x>>y;
    if((x+y)%3){
        cout<<0<<endl;
        return 0;
    }
    int a=(x+y)/3,b=x-a;
    if(b<0||b>a){
        cout<<0<<endl;
        return 0;
    }
    cout<<nCr(a,b)<<endl;
}


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

struct mp{
	int to,dis;
	mp(int x,int y):to(x),dis(y){}
};

void trip(int nw,int f,int64_t dist,vector<vector<mp>>&v,vector<int64_t>&d){
	d.at(nw)=dist;
	for(int i=0;i<v.at(nw).size();++i){
		if(v.at(nw).at(i).to!=f){
			trip(v.at(nw).at(i).to,nw,dist+v.at(nw).at(i).dis,v,d);
		}
	}
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<vector<mp>>v(n+1);
	for(int i=1;i<n;++i){
		int a,b,c; cin>>a>>b>>c;
		mp x(a,c),y(b,c);
		v.at(a).emplace_back(y);
		v.at(b).emplace_back(x);
	}
	int q,k; cin>>q>>k;
	vector<int64_t>d(n+1);
	trip(k,-1,0,v,d);
	for(int i=0;i<q;++i){
		int x,y; cin>>x>>y;
		cout<<d.at(x)+d.at(y)<<"\n"s;
	}
}

Measured memory_bytes: 17408
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000
int MOD=1000000007;
int modpow(int a,int x){
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}
int gyaku(int n){
    return modpow(n,MOD-2);
}
signed main() {
  int n;
  int ans=0;
  cin>>n;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  sort(a.begin(),a.end());
  rep(i,n-1){
    if(i==0)ans+=a[n-1-i];
    else{
      ans+=a[n-1-(i+1)/2];
    }
  }
  cout<<ans;
}


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

int main() {
    int n;
    double ans = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        double buf;
        cin >> buf;
        ans += 1/buf;
    }
    cout << 1/ans << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
 
  int A;
  int B;
  int M;
  cin>>A>>B>>M;
  vector<int>A1(A);
  vector<int>B1(B);
  vector<int>MX(M);
  vector<int>MY(M);
  vector<int>MC(M);
  for(int i=0;i<=A-1;i++){
  
    cin>>A1[i];
  }
  for(int i=0;i<=B-1;i++){
  
    cin>>B1[i];
  }
  for(int i=0;i<=M-1;i++){
  
    cin>>MX[i];
    cin>>MY[i];
    cin>>MC[i];
  }
  int minvalue=99999999;
  for(int i=0;i<=M-1;i++){
  
    if(minvalue>A1[MX[i]-1]+B1[MY[i]-1]-MC[i])
    minvalue=A1[MX[i]-1]+B1[MY[i]-1]-MC[i];
  }
  sort(A1.begin(),A1.end());
  sort(B1.begin(),B1.end());
  if(A1[0]+B1[0]<minvalue){
  
    minvalue=A1[0]+B1[0];
  }
  cout<<minvalue;
  return 0;
}

Measured memory_bytes: 5096
import sys
sys.setrecursionlimit(10000000)
input=lambda : sys.stdin.readline().rstrip()

while True:
    n=int(input())
    if n==0:
        break
    books=[]
    read_t=0
    write_t=0
    for i in range(n):
        r,w=map(int,input().split())
        read_t+=r
        write_t+=w
        books.append((r,w))
    books=sorted(books)
    if books[-1][0]<=read_t//2:
        print(read_t+write_t)
        continue
    sukima=books[-1][0]-(read_t-books[-1][0])
    dp=[[0 for i in range(sukima+1)] for i in range(n)]
    for i in range(1,n):
        for j in range(1,sukima+1):
            dp[i][j]=max(dp[i-1][j],
            dp[i-1][j-books[i-1][1]]
            +books[i-1][1] if j-books[i-1][1]>=0 else 0)

    print(read_t+write_t+sukima-dp[-1][-1])

    


Measured memory_bytes: 7612