akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

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

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class ATakahashiIsMissing {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int x; cin >> x;
      double p; cin >> p;
      ll r = (x+1)/2;
      cout << setprecision(8) << fixed << r*100/p << endl;
    }
};

signed main() {
  ATakahashiIsMissing solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

int main(int argc, char *argv[]) {
  int q;
  std::cin >> q;
  std::multimap<std::string, long> m;
  for (int i = 0; i < q; ++i) {
    int c;
    std::string key;
    std::cin >> c >> key;
    switch (c) {
    case 0:
      int x;
      std::cin >> x;
      m.insert({key, x});
      break;
    case 1:
      if (m.find(key) != m.end()) {
        auto r = m.equal_range(key);
        for (auto i = r.first; i != r.second; ++i) {
          std::cout << i->second << std::endl;
        }
      }
      break;
    case 2:
      m.erase(key);
      break;
    case 3:
      std::string r;
      std::cin >> r;
      auto begin = m.lower_bound(key), end = m.upper_bound(r);
      for (auto i = begin; i != end; ++i) {
        std::cout << i->first << " " << i->second << std::endl;
      }
      break;
    }
  }
}



Measured memory_bytes: 24940
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
    public static void main(String []args){
        Scanner in = new Scanner (System.in);
        int n;
        long k;
        n = in.nextInt();
        k = in.nextLong();
        int []arr = new int[n+5];
        arr[0] = 0;
        for(int i=1;i<=n;i++)
            arr[i] = in.nextInt();
        long []dp = new long[n+5];
        for(int i=0;i<n+5;i++)
            dp[i] = 1000000007;
        dp[0] = 0;
        dp[1] = 0;
        dp[2] = Math.abs(arr[2] - arr[1]);
        for(int i=3;i<=n;i++){
            for(int j=1;j<=k;j++){
                if(i-j >= 1)
                dp[i] = Math.min(dp[i-j]+Math.abs(arr[i] - arr[i-j]), dp[i]);
            }

            //System.out.println("Final value --> " + dp[i] + " ");
        }
        //System.out.println();
        System.out.println(dp[n]);
    }
}

Measured memory_bytes: 52572
#include<iostream>
#include<stdio.h>
using namespace std;

int main() {
        double r,S,L;
        scanf("%lf",&r);
        S=3.141592653589*r*r;
        L=2*3.141592653589*r;
        printf("%.6lf %.6lf\n",S,L);
}



Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

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

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    ll A = in<ll>(),B = in<ll>();
    int amix = sqrt(A);
    int bmix = sqrt(B);
    vector<ll> As(0);
    vector<ll> Bs(0);
    for(int i = 2;i < amix+2;){
        if(i == amix+1 && A != 1)As.pb(A);
        if(A % i == 0){
            As.pb(i);
            A/=(i);
        }else{
            i++;
        }
    }
    for(int i = 2;i < bmix+2;){
        if(i == bmix+1 && B != 1)Bs.pb(B);
        if(B % i == 0){
            Bs.pb(i);
            B/=(i);
        }else{
            i++;
        }
    }
    sort(ALL(As));
    sort(ALL(Bs));
    UNIQUE(As);
    UNIQUE(Bs);
    vector<ll> list(0);
    set_intersection(ALL(As),ALL(Bs),back_inserter(list));
    cout << list.size() +1  << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#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; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
bool dp[100100];
 
 
int main () {
    int N, M;
    cin >> N >> M;

    vector<int>A(N);
    int sou =0;
    rep(i,N){
        cin >> A[i];
        sou += A[i];
    }

    sort(A.begin(),A.end(),greater<>());

    if(A[M-1] >= (float)sou/(4*M)){
        cout << "Yes" << endl;
    }else cout <<"No" << endl;

}

Measured memory_bytes: 3616
#include<stdio.h>
int main(void)
{
  int a,b;
  scanf("%d",&a);
  scanf("%d",&b);
  if(a==1 && b==2){
    printf("3");
  }
  else if(a==2 && b==1){
    printf("3");
  }
  else if(a==1 && b==3){
    printf("2");
  }
  else if(a==2 && b==3){
    printf("1");
  }
  else if(a==3 && b==1){
    printf("2");
  }
  else if(a==3 && b==2){
    printf("1");
  }
  return 0;
}
  

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
struct edge{
	int a,b,c;
	edge(int x,int y,int z) : a(x),b(y),c(z) {}
};
bool comp(const edge& x,const edge& y){
	return x.c<y.c;
}

typedef vector<int> vi;
typedef pair<int,int> P;
const int MAX_V=500;
vector<int> G[MAX_V];
map<P,int> mp;
int ord[MAX_V];
bool inS[MAX_V];
stack<int> roots,S;
vector<vi> cc;
vector<P> bs;
int cnt;
int N,M;
vector<int> cans;

void init(){
	rep(i,N) G[i].clear(),ord[i]=0,inS[i]=0;
	mp.clear();
	cc.clear();
	bs.clear();
	cans.clear();
	cnt=0;
}
void add_edge(int a,int b){
	if(a>b) swap(a,b);
	G[a].pb(b);
	G[b].pb(a);
	mp[P(a,b)]++;
}
void vis(int v,int p){
	ord[v]=++cnt;
	S.push(v);
	inS[v]=true;
	roots.push(v);
	for(int u:G[v]){
		if(ord[u]==0){
			vis(u,v);
		}else if( (u!=p&&inS[u]) || (u==p&&mp[P(min(v,p),max(v,p))]>=2) ){
			while(ord[roots.top()]>ord[u]) roots.pop();
		}
	}
	if(v==roots.top()){
		bs.pb(P(p,v));
		vector<int> vc;
		while(true){
			int w=S.top();S.pop();
			inS[w]=false;
			vc.pb(w);
			if(v==w) break;
		}
		roots.pop();
		cc.pb(vc);
	}
}
void bridge(){
	rep(i,N) if(ord[i]==0){
		vis(i,-1);
		bs.pop_back();	//P(-1,hoge)
	}
}

int par[500];
int find(int x){
	if(x==par[x]) return x;
	return par[x]=find(par[x]);
}
bool same(int x,int y){
	return find(x)==find(y);
}
void unite(int x,int y){
	par[find(x)]=find(y);
}
int main(){
	cin>>N>>M;
	vector<edge> es;
	rep(i,M){
		int a,b,c;
		cin>>a>>b>>c;
		a--,b--;
		es.pb(edge(a,b,c));
	}
	sort(all(es),comp);
	int n=0,c=0;
	int now=es[0].c;
	rep(i,N) par[i]=i;
	es.pb(edge(0,0,-1));
	rep(i,M+1){
		if(es[i].c!=now){
			bridge();
			n+=bs.size(),c+=bs.size()*now;
			for(int j:cans) unite(es[j].a,es[j].b);
			now=es[i].c;
			init();
		}
		if(i==M) continue;
		if(es[i].c==now){
			if(!same(es[i].a,es[i].b)){
				int a=find(es[i].a),b=find(es[i].b);
				cans.pb(i);
				add_edge(a,b);
			}
		}
	}
	cout<<n<<" "<<c<<endl;
}

Measured memory_bytes: 5628
import sys
sys.setrecursionlimit(10**8)
N = int(input())
H = list(map(int, input().split()))
dp = [float('inf')] * N
dp[0] = 0
dp[1] = abs(H[1] - H[0])


def rec(i):
    if dp[i] != float('inf'):
        return dp[i]
    else:
        dp[i] = min(rec(i-1) + abs(H[i]-H[i-1]), rec(i-2) + abs(H[i]-H[i-2]))
        return dp[i]


# print(*dp)
print(rec(N-1))


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

using namespace std;

#define int long long

using ll = long long;
using pii =  pair<int, int>;

const int IINF =  0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const ll MOD = 1e9+7;

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)

#define rep(i,n) for_(i,0,n)
#define rrep(i,n) rfor_(i,0,n)

#define pb push_back
//#define eb emplace_back
#define mp make_pair
#define ft first
#define sd second

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))

#define endl '\n'

const int limit = 100007;

int N, K;
int A[limit], B[limit];

int m, s;

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

	cin>>N>>K;
	rep(i, N)cin>>A[i]>>B[i];

	rep(i, N) {
		if((K&A[i])==A[i])m += B[i];
	}


	rep(i, 31) {
		if(!K)break;

		s = 0;
		rep(j, N) {
			if(A[j]&1) {
				A[j] = A[j]>>1;
				continue;
			}
			if((K&A[j]) == A[j])s += B[j];
			A[j] = A[j]>>1;
		}

		if(1&K)m = m>s?m:s;

		K = K>>1;

	}

	cout<<m<<endl;

	return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

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

    double r = sin.nextDouble();
    System.out.printf("%.6f %.6f",r*r*Math.PI,2*Math.PI*r);

    sin.close();
  }
}


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

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

    if(k%2==0){
        cout << "-1" << endl;
        return 0;
    }
    int ans = 1, mod = 7%k;
    while(true){
        if(mod==0){
            cout << ans << endl;
            return 0;
        }
        mod = (mod*10+7)%k;
        ans++;
        if(ans>k){
            cout << "-1" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3600
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/pending/disjoint_sets.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/numeric/ublas/vector.hpp>
// ↓これいる？
#include <boost/graph/strong_components.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;
using namespace boost::numeric;
using ll = long long;
namespace bst = boost;
template<class T> void fill(T& v) { for (auto&& i : v) cin >> i; }

//#include "atcoder.hpp"

ll pow(ll a, ll b) {
  ll tmp = 1;
  
  while (b > 0) {
    if (b%2) tmp = (tmp * a) % 998244353LL;
    a = (a * a) % 998244353LL;
    b /= 2;
  }
  
  return tmp;
}

int main() {
    int N, mx = 0;
    
    cin >> N;
  
    vector<int> D(N),cnt(N, 0);
  
    fill(D);
  
  REP(i, N) {
    cnt[D[i]]++;
    mx = max(mx, D[i]);
  }
  
  if (D[0] != 0 || cnt[0] != 1){
    cout << 0 << endl;
    return 0;
  }
  
  ll ret = 1LL;
  for (int i = 2; i <= mx;i++) {
    auto mul = pow((ll)cnt[i-1], (ll)cnt[i]);
    ret = (ret * mul) % 998244353LL;
  }
    
    cout << ret << endl;
    
    return 0;
}








Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int NMAX = 110;
const int WMAX = 100010;

int N, W;
int v[NMAX + 1];
int w[NMAX + 1];
long dp[NMAX + 1][WMAX + 1];

int main()
{
    cin >> N >> W;

    for (size_t i = 1; i <= N; i++) {
        cin >> w[i] >> v[i];
    }

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= W; j++) {

            dp[i][j] = dp[i - 1][j];
            if (j - w[i] < 0) {
                continue;
            }

            dp[i][j] = max(dp[i - 1][j], v[i] + dp[i - 1][j - w[i]]);
        }
    }

    cout << dp[N][W] << '\n';

    return 0;
}


Measured memory_bytes: 79360
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;


void solve(){
    int n;
    cin >> n;
    int a[100500];
    for(int i = 0; i < n; i++){
        cin >> a[i + 1];
    }
    int but = 1;
    int cnt = 0;
    while(but != 2 && cnt <= 1e8){
        but = a[but];
        cnt++;
    }
    if(cnt > 1e8){
        cout << -1;
    }
    else cout << cnt;
}
int main(){
    int q = 1;
    //cin >> q;}
    while(q--) solve();
}


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

typedef long long int ll;
typedef long double ld;

#define Pb push_back
#define Mp make_pair

#define ff first
#define ss second

#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))

#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN

#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define db1(x) cout<<#x<<" : "<<x<<endl;
#define db2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define db3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;

#define PI 3.14159265358979323846264338327950L

void solve()
{
  cout << setprecision(16) << fixed;
  int a,b,h,m;
  cin >> a >> b >> h >> m;
  ld rad = PI * 2 * ((ld)h/12.0+((ld)m/60.0)/12.0 - (ld)m/60.0);
  ld ans = (ld)(a*a + b*b) - (ld)(2*a*b)*cos(rad);
  ans = sqrt(ans);
  cout << ans << endl;
}

signed main()
{
  IOS;
  //freopen("input.txt", "rt", stdin);
  //freopen("output.txt", "wt", stdout);
  int t=1;
  //cin >> t;
  while(t--)
  {
    solve();
  }
  return 0;
}
/*==============================================================================================================================================================*/


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

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

using vi = vector<int>;
using mvi = map<int,vi>;

int main()
{
  int n,m;
  while(cin >> n >> m,n+m){
    mvi mv;
    int r;
    cin >> r;
    REP(i,r){
      int t,_n,_m,s;
      cin >> t >> _n >> _m >> s;
      if(s){
        if(mv.find(_m) == mv.end()){
          mv[_m].resize(1300,0);
        }
        mv[_m][t]++;
      }else{
        mv[_m][t]--;
      }
  }
    for(auto it = mv.begin();it != mv.end();++it){
      REP(i,1300-1){
        it->second[i+1] += it->second[i];
      }
    }
    int q;
    cin >>q;
    REP(i,q){
      int t1,t2,_m;
      cin >> t1 >> t2 >> _m;
      int ans = 0;
      if(mv.find(_m)!=mv.end()){
        auto mc = mv[_m];
        for(int i = t1;i < t2;++i){
          if(mc[i]>0){
            ans++;
          }
        }
      }
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 3732
N = int(input())
a_list = list(map(int, input().split()))
MOD = 10**9 + 7 

cnts = [0,0,0]
sames = 0
ind = -1
res = 1
for a in a_list:
    for i, cnt in enumerate(cnts):
        if cnt == a: 
            sames += 1
            ind = i
    res *= sames
    res %= MOD
    cnts[ind] += 1
    sames = 0

print(res)

Measured memory_bytes: 20656
function main(input) {
  const N = parseInt(input, 10);
  
  if (N <= 111) {
    console.log(111);
  } else if (N > 111 && N <= 222) {
    console.log(222);
  } else if (N > 222 && N <= 333) {
    console.log(333);
  } else if (N > 333 && N <= 444) {
    console.log(444);
  } else if (N > 444 && N <= 555) {
    console.log(555);
  } else if (N > 555 && N <= 666) {
    console.log(666);
  } else if (N > 666 && N <= 777) {
    console.log(777);
  } else if (N > 777 && N <= 888) {
    console.log(888);
  } else if (N > 888 && N <= 999) {
    console.log(999);
  }
}

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

Measured memory_bytes: 29488
#include<stdio.h>
int main(){
  int unused __attribute__((unused));
  int A, B, C, D;
  unused = scanf("%d %d %d %d", &A ,&B, &C, &D);

  while(A>0 && C>0){
    C = C-B;
    A = A-D;
  }
  if(C<=0) printf("Yes");
  else if(A<=0) printf("No");
  else if(C<=0 && A<=0) printf("Yes"); 
  return 0;
}

Measured memory_bytes: 1712
import sys
from collections import deque


fin = sys.stdin.readline
N = int(fin())
adj = [[] for _ in range(N)]
w = {}
for _ in range(N - 1):
    u, v, w_ = [int(elem) for elem in fin().split()]
    u -= 1
    v -= 1
    w[u, v] = w_
    w[v, u] = w_
    adj[u].append(v)
    adj[v].append(u)

que = deque()
que.append([0, 0])
color_of_node = [-1] * N

while que:
    node, dist = que.popleft()
    if dist % 2 == 0:
        color_of_node[node] = 0
    else:
        color_of_node[node] = 1
    for neighbor in adj[node]:
        if color_of_node[neighbor] == -1:
            que.append([neighbor, dist + w[node, neighbor]])

print(*color_of_node, sep="\n")

Measured memory_bytes: 91936
#include<bits/stdc++.h>
using namespace std;
#define ll long long int;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
	fastio;
	int n;
	cin>>n;
	int arr1[n],arr2[n];
	for(int i=0;i<n;i++){
		cin>>arr1[i]>>arr2[i];
	}
	int count=0;
	for(int i=0;i<n-2;i++){
		if(arr1[i]==arr2[i] && arr1[i+1]==arr2[i+1] && arr1[i+2]==arr2[i+2]){
			cout<<"Yes";
			count=1;
			break;
		}
	}
	if(count==0) cout<<"No";
	
}

Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<complex>
#include<cstdlib>
#include<cctype>

#define REP(i,n) for(int i = 0;i < (n);i++)
#define PB push_back
#define MP make_pair
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cout << v[i] << ' ';cout << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cout << v[a][b] << ' ';cout << endl;}cout << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;

int main()
{
	int n,m;
	
	cin >> n >> m;
	
	iiv v1;
	
	REP(i,n)
	{
		iv v_tmp;
		REP(j,m)
		{
			int tt;
			cin >> tt;
			v_tmp.PB(tt);
		}
		v1.PB(v_tmp);
		
	}
	
	//SHOW2d(v1,n,m);
	int ans = n,count = n;
	
	while(v1[0].size()-1)
	{
		int _max = 0,place = 0;
		int check[m+1] = {};
		REP(i,n)check[v1[i][0]]++;
		//SHOW1d(check,m+1);
		for(int i = 1;i <= m;i++)
		{
			if(_max < check[i])
			{
				_max = check[i];
				place = i;
			}
		}
		
		//cout << place << endl << endl;

					
		REP(i,n)
		{
			REP(j,v1[i].size())
			{
				if(v1[i][j] == place)
				{
					v1[i].erase(v1[i].begin()+j);
					break;
				}
			}
		}
		//SHOW2d(v1,n,v1[a].size());
		ans = min(ans,_max);
		
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 998244353
#define INF 98765431219876543
#define bitcnt(a) (ll) __builtin_popcount((a))
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

int main() {
  ll l, bs;
  cin >> l;
  vector<string> v;
  REP(i, 21) {
    if (pow(2, i) > l) {
      bs = i;
      break;
    }
  }
  cout << bs;
  REP(i, bs - 1) {
    v.pb(to_string((i + 1)) + " " + to_string((i + 2)) + " " + to_string(int(pow(2, bs - 2 - i))));

    v.pb(to_string((i + 1)) + " " + to_string((i + 2)) + " " + to_string(0));
  }
  int x = 1 << (bs - 1);
  for (int i = bs - 2; i >= 0; i--) {
    if ((l >> i) & 1) {
      v.pb(to_string(1) + " " + to_string(bs - i) + " " + to_string(x));
      x += 1 << i;
    }
  }
  cout << " " << v.size() << endl;

  for (auto &a : v) {
    cout << a << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

int keta(int x){
	int i=0;
	while (x/pow(10,i)>=1){
		i++;
	}
	if (x==0){
		return 1;
	}
	else
	return i;
	}
int main(){
	 int a1,b1;
	while(cin>>a1>>b1){
cout<<keta(a1+b1)<<endl;
	}
	return 0;
}

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

int main(){
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    for(int i = 0; i < b; i++){
        for(int j = 0; j < a; j++){
            cout << 1;
        }
        for(int j = a; j < w; j++){
            cout << 0;
        }
        cout << endl;
    }

    for(int i = b; i < h; i++){
        for(int j = 0; j < a; j++){
            cout << 0;
        }
        for(int j = a; j < w; j++){
            cout << 1;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
def check_palindrome(s):
    n = len(s)
    n_half = int(n/2)
    for i in range(n_half):
        if s[i] != s[n - 1 - i]:
            return False
    return True
S = input()
N = len(S)
N_half_end = int((N - 1)/2)
S_half_1 = S[:N_half_end]
S_half_2 = S[N_half_end + 1:]
if S_half_1 == S_half_2[::-1]:
    strong_check = True
else:
    strong_check = False
if strong_check:
    strong_check = check_palindrome(S_half_1) and check_palindrome(S_half_2)
if strong_check:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
	int n;
	while (cin >> n, n) {
		int sum = 0, j[67890];
		for (int i = 0; i < n; i++) {
			int p; cin >> p; sum += p;
		}
		for (int i = 0; i < n - 1; i++) {
			cin >> j[i]; sum += j[i];
		}
		int ans = sum;
		sort(j, j + n - 1);
		for (int i = 0; i < n - 1; i++) {
			sum -= j[i];
			ans = max(ans, sum*(i + 2));
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3556
// Author: 23forever
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
typedef long long LL;
const int MAXN = 100;
using namespace std;

inline void enableFileIO() {
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
}

inline int read() {
  int x = 0, w = 1;
  char c = ' ';

  while (c < '0' || c > '9') {
    c = getchar();
    if (c == '-') w = -1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }

  return x * w;
}

int n, x, a[MAXN + 5];

void init() {
  //enableFileIO();
  
  n = read();
  x = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
}

int ans;

int main() {
  init();
  
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; ++i) {
    if (x >= a[i]) {
      x -= a[i];
      ++ans;
    }
  }
  
  if (ans == n && x) --ans;
  
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A_odd = A[1::2]
A_even = A[::2]
if N%2 !=0:
 A_even = A_even[::-1]
 ans = A_even + A_odd
 for s in ans:
  print(s, end =" ")
else:
 A_odd = A_odd[::-1]
 ans = A_odd + A_even
 for s in ans:
  print(s, end =" ")

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

int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  for (int i=0; i <N ; i++)
    cin>> X.at(i);
  sort(X.begin(),X.end());
  int a=0;
  vector<int>Y(1,X.at(0));
  for (int i=0; i<N-1;i++){
    if (X.at(i) < X.at(i+1))
      Y.push_back( X.at(i+1) );
  }
  cout<< Y.size()<<endl;
}

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

int main() {
  std::string S;
  std::cin >> S;

  int t = S.size(), N = S.size();

  for (int i = 1; i < N; i++) {
    if (S[i] != S[i-1]) {
      t = std::min(t, std::max(i, N - i));
    }
  }

  std::cout << t << std::endl;
}


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

#define boost ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define lld long double
#define f(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define pii pair<long long, long long >
#define INF 10000000000000009 //1e16+9
#define F first
#define S second
//#define MAX
using namespace std;
ll dp[101][100001];
ll knap(ll wt[],ll v[],ll w,ll n)
{
    if(w==0 || n==0)
        return 0;
        if(dp[n][w]!=-1) return dp[n][w];
    if(wt[n-1]<=w)
        return dp[n][w]=max(v[n-1]+knap(wt,v,w-wt[n-1],n-1),knap(wt,v,w,n-1));
    else return dp[n][w]=knap(wt,v,w,n-1);

}

void solve()
{
ll n,w;
cin>>n>>w;
ll wt[n],v[n];
f(i,0,n)
cin>>wt[i]>>v[i];
memset(dp,-1,sizeof(dp));
ll ans=knap(wt,v,w,n);
cout<<ans;
}






int main()
{
	boost;
	//int t;
	//cin>>t;
	//while(t--)
	//{

		solve();
		//cout<<endl;
	//}
	return 0;
}


Measured memory_bytes: 82496
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

typedef struct rect_tbl
{
	double x1, y1;
	double x2, y2;
} rect_t;

bool
isoverlap(rect_t a, rect_t b)
{
	if (a.x1 > b.x2 || a.x2 < b.x1)
		return false;

	if (a.y1 > b.y2 || a.y2 < b.y1)
		return false;

	return true;
}

int
main(int argc, char **argv)
{
	rect_t a, b;

	while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &a.x1, &a.y1, &a.x2, &a.y2, &b.x1, &b.y1, &b.x2, &b.y2) != EOF)
		printf("%s\n", isoverlap(a, b) ? "YES" : "NO");

	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;



int main(){
    ll n;cin>>n;
    ll a[200010];
    rep(i,0,n)cin>>a[i];
    ll ng=0,an=a[n-1];
    if(a[0]!=0)ng=1;
    rep(i,0,n-1){
        if(a[i]<a[i+1]&&a[i+1]-a[i]!=1)ng=1;
        if(a[i]>=a[i+1])an+=a[i];
    }
    if(ng)cout<<-1<<endl;
    else cout<<an<<endl;
}
    









Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define vi vector<int>
#define rep_(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) rep_(i, 0, n)
#define rev_(i, m, n) for(int i=(int)(m-1);i>=(int)(n);i--)
#define rev(i, n) rev_(i, n, 0)
#define each(i, n) for(auto&& i: n)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size()) 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define dump(x) cerr << #x << "=" << x <<endl
#define gcd __gcd
int lcm(int a, int b){return a / gcd(a, b) * b;}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-15;
const double PI = acos(-1);

void solve()
{
	/*--------------------------*/

	vi A(9); rep(i, 9) cin >> A[i];
	int N; cin >> N;
	rep(i, N) {
		int b; cin >> b;
		rep(j, 9) {
			if (A[j] == b) A[j] = -1;
		}
	}
	bool ans = false;
	vector<vi> bingo = {
		{0, 1, 2}, {3, 4, 5}, {6, 7, 8},
		{0, 3, 6}, {1, 4, 7}, {2, 5, 8},
		{0, 4, 8}, {2, 4, 6}
	};
	each(bi, bingo) {
		bool f = true;
		each(i, bi) {
			if (A[i] != -1) f = false;
		}
		if (f == true) ans = true;
	}
	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	/*--------------------------*/
}

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	solve();
}

Measured memory_bytes: 256
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()

sum_time=0
query = []
for i in range(N-1):
    query.append(many_int())

for i in range(N-1):
    C,S,F=query[i]
    sum_time = C+S

    for j in range(i+1,N-1):
        
        C, S, F =query[j]
        sum_time = max(S, sum_time)
        temp = (sum_time-S)/F
        if temp.is_integer():
            pass
        else:
            temp = int((sum_time-S)//F + 1)
            sum_time = S +temp * F
        sum_time += C
    print(int(sum_time))
print(0)

Measured memory_bytes: 42604
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int a[n],dp[n+2]={0};
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=1;i<n;i++)
    {
        int ex,e1=INT_MAX;
        if(i-k<0)
        ex=0;
        else
        ex=i-k;
        for(int j=i-1;j>=ex;j--)
        {
            e1=min(dp[j]+abs(a[j]-a[i]),e1);
        }
        dp[i]=e1;
    }
    cout<<dp[n-1]<<endl;
}

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

int main(){
  ll N;
  cin >> N;
  vector<ll> a(100);
  
  int cnt=0;
  while(N!=0){
    a[cnt]=(N-1)%26;
    N=(N-1-a[cnt])/26;
    cnt++;
  }
  vector<char> alpha={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  
  for(int i=cnt-1;i>=0;i--){
    cout << alpha[a[i]];
  }
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
ll cnt = 0;

int main(){
  int n;    cin >> n;
  vector<ll>a(n),b(n);
  for(int i=0;i<n;i++){
     cin >> a.at(i) >> b.at(i);
  }
  for(int i=n-1;i>=0;i--){
      a[i]+=cnt;
      if(a[i] % b[i] != 0){
          ll m;
          m=a[i] / b[i];
          cnt+=(m+1)*b[i]-a[i];
      }
  }
  cout << cnt << endl;
}

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

int main() {
  // Input
  int A, B;
  cin >> A >> B;
    
  // Compute
  if (A >= 13) {
    cout << B << endl;
  }
  else if (A >=6) {
    cout << B / 2 << endl;
  }
  else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

from collections import Counter
N = ii()
S = input()
l = Counter(S)
mod = 10**9+7

if len(l) == 1:
    print(N)
    exit()

ans = 1
for v in l.values():
    ans *= (v + 1)
    ans %= mod

print((ans-1) % mod)

Measured memory_bytes: 3572
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


typedef pair <int, int> PII;
typedef vector <PII> VP;

const int SIZE = 100001;
const int Y_SIZE = 10000;
int a, b, r;
VI A[Y_SIZE];
int X[SIZE], Y[SIZE];

double sq( double x ) {
    return x * x;
}

bool input() {
    if ( ! ( cin >> a >> b >> r && a ) ) return false;
    for ( int i = 0; i < Y_SIZE; ++ i ) {
        A[i].clear();
    }
    for ( int i = 0; i < a; ++ i ) {
        int x, y;
        cin >> x >> y;
        A[y].push_back(x);
    }
    for ( int i = 0; i < Y_SIZE; ++ i ) {
        sort( A[i].begin(), A[i].end() );
    }
    for ( int i = 0; i < b; ++ i ) {
        cin >> X[i] >> Y[i];
    }
    return true;
}

int solve() {
    int res = 0;
    for ( int i = 0; i < b; ++ i ) {
        int x = X[i], y = Y[i];
        for ( int j = y - 4 * r; j <= y + 4 * r; ++ j ) {
            if ( j < 0 || j >= Y_SIZE ) continue;
            if ( A[j].empty() ) continue;
            int range = (int)sqrt( sq( 4.0 * r ) - sq( y - j ) );
            res +=
                upper_bound( A[j].begin(), A[j].end(), x + range ) -
                lower_bound( A[j].begin(), A[j].end(), x - range );
        }
    }
    return res;
}
 
int main() {
    while ( input() ) {
        cout << solve() << endl;
    }
    return 0;
}

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

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

	long long r, d, x;
	cin >> r >> d >> x;

	for (int i = 0; i < 10; i++) {
		long long t = r * x - d;
		cout << t << "\n";
		x = t;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define es cout<<" "
#define dump(x) cout<<" "<<#x<<"="<<x
#define pdump(p) cout<<" "<<#p<<"=("<<p.fst<<","<<p.snd<<")"
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std; using lint = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<lint, lint>;
template<class T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<class T, class... Ts> 
auto make_vec(size_t a, Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));}

int main(void) {
    lint r, d, a;
    cin >> r >> d >> a;
    rep (10) {
        a = a * r - d;
        cout << a << endl;
    }
}

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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int N, K;
    cin>>N>>K;

    vec_int A(N);
    rep(i,N)cin>>A.at(i);
    //これは二分探索だ
    int large_num = pow(10,9)*2;
    int small_num = 1;

    while(large_num>small_num+1){
        int medium_num = ( small_num + large_num)/2;

        int count = 0;
        for(int i=0;i<N;i++){
            //A.at(i)をmedium_numよりも短くするのに必要な回数
            count += A.at(i)/medium_num;
            if(A.at(i)%medium_num==0){
                count = count-1;
            }
        }
        if(count<=K){
            //丸太をもっと短くできる
            large_num = medium_num;
        }else{
            //丸太はもっと長い
            small_num = medium_num;
        }
    }

        int count = 0;
        for(int i=0;i<N;i++){
            count += A.at(i)/small_num;
            if(A.at(i)%small_num==0){
                count = count-1;
            }
        }
        if(count<=K){
            cout<<small_num<<endl;
        }else{


    cout<<large_num<<endl;
        }

    return 0;
}

Measured memory_bytes: 4708
n, m = gets.split.map(&:to_i)
products_vote = (gets.split.map(&:to_i)).sort
#puts products_vote
# if <= products.sum / (4 * m)
products_vote_sum = products_vote.sum


count = 0
#puts n, m
border =  products_vote_sum * (1.0 / (4.0 * m))
#puts  border
puts products_vote[-m] < border ? :No : :Yes

# (0..n-1).each { |product|
#   if border < products_vote[product]
#     count += 1
#   end
#   print border, " ",products_vote[product],"\n"
# }

# if count >= m
#   puts "Yes"
# else
#   puts "No"
# end  


Measured memory_bytes: 14252
(defun count-RGB (s c)
  (let ((counter 0))
    (loop :for i :across s
          :do (if (string= i c) (incf counter)))
    counter))

(defun RGB-Triplets (n s)
    (let ((ans 0))
        (incf ans (* (count-RGB s "R") (count-RGB s "G") (count-RGB s "B")))
        (loop
            :for i :from 0 :to (- n 3)
            :do (loop
                    :for j :from (+ i 2) :to (- n 1) :by 2
                    :do (cond
                            ((string= (char s i) (char s j)) ())
                            ((string= (char s i) (char s (/ (+ i j) 2))) ())
                            ((string= (char s j) (char s (/ (+ i j) 2))) ())
                            (t (decf ans)))))
        ans))

(princ (RGB-Triplets (read) (read-line)))

Measured memory_bytes: 77260
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> v;
  for (int i = 1; i * i <= m; i++) {
    if (m % i == 0) {
      v.push_back(i);
      if (i * i != m) {
        v.push_back(m / i);
      }
    }
  }
  std::sort(v.begin(), v.end());
  int ans = -1;
  for (auto x : v) {
    if (x >= n) {
      ans = x;
      break;
    }
  }
  std::cout << m / ans << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }
  else{
        return a.first < b.first;
    }
}
int main() {
  int n,h;
  cin>>n>>h;
  vector<pair<int,int>>katana(n);
  for(int i=0;i<n;i++) cin>>katana[i].first>>katana[i].second;
  sort(katana.begin(),katana.end());
  int use=katana[n-1].first;
  int ultimate=katana[n-1].second;
  katana[n-1].first=0;
  katana[n-1].second=0;
  sort(katana.begin(),katana.end(), compare_by_b);
  int ans=0;
  int best=n-1;
  while(h>0){
    if(ultimate>=h){
      ans++;
      break;
    }
    else{
      if(katana[best].second>use){
        h-=katana[best].second;
        best--;
        ans++;
      }
      else{
        h-=use;
        ans++;
      }
    }
  }
  cout<<ans<<endl;      
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
  
int main()
{
    string u,s,t;
    int a,b;
    cin >> s >> t;
    scanf("%d%d",&a,&b);
    
    cin >> u;
    if(u == s) a--;
    else b--;
	 
	cout << a << " " << b << endl;
    return 0;
}

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

int main()
{
	int x=600, d;

	while(cin>>d){
		int n=x/d;
		//cout<<"n="<<n<<endl;
		long sum=0; //d^2+(2d)^2+(3d)^2+...
		for(int i=0;i<n;++i){
			sum+=((i*d)*(i*d));
			//cout<<sum<<endl;
		}
		cout<<sum*d<<endl;
	}
	return 0;
}

Measured memory_bytes: 2980
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i)
#define rep(i,n) REP(i, 0, n)
typedef tuple<int, int, int> tup;
int N, M, L;
int solve(const vector<vector<tup>>& edges) {
    const int S = 0, G = N - 1;
    vector<vector<int>> dist(N, vector<int>(L + 1, INF));
    priority_queue<tup, vector<tup>, greater<tup>> que;
    que.push(tup(0, S, L)); dist[S][L] = 0;
    while(!que.empty()) {
        int cos, ver, money;
        tie(cos, ver, money) = que.top(); que.pop();
        if(dist[ver][money] < cos) continue;
        for(const auto& e : edges[ver]) {
            int to, dis, ene; tie(to, dis, ene) = e;
            //not hire
            if(dist[to][money] > cos + ene) {
                dist[to][money] = cos + ene;
                que.push(tup(dist[to][money], to, money));
            }
            //hire
            int nm = money - dis;
            if(nm < 0) continue;
            if(dist[to][nm] > cos) {
                dist[to][nm] = cos;
                que.push(tup(dist[to][nm], to, nm));
            }
        }
    }
    int ans = INF;
    rep(i, L + 1) ans = min(ans, dist[G][i]);
    return ans;
}
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    vector<vector<tup>> edges;
    while(cin >> N >> M >> L && N) {
        int a, b, d, e;
        edges.assign(N, vector<tup>());
        rep(___, M) {
            cin >> a >> b >> d >> e;
            --a; --b;
            edges[a].push_back(tup(b, d, e));
            edges[b].push_back(tup(a, d, e));
        }
        cout << solve(edges) << endl;;
    }
    return 0;
}

Measured memory_bytes: 3424
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	while(cin>>s){
    	int joi=0,ioi=0;
    	for(int i=0;i<s.size()-2;i++){
    		if(s.substr(i,3)=="JOI")
    			joi++;
    		if(s.substr(i,3)=="IOI")
    			ioi++;
    	}
    	cout<<joi<<endl<<ioi<<endl;
	}
}



Measured memory_bytes: 3072
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	s, t := []byte(ReadString()), []byte(ReadString())
	sort.Slice(s, func(i, j int) bool {
		return s[i] < s[j]
	})
	sort.Slice(t, func(i, j int) bool {
		return t[i] > t[j]
	})
	a, b := string(s), string(t)
	if a < b {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

void Main()
{
	string s; cin >> s;
	int res = 0;
	rep(i, s.size() - 1) {
		if (s[i] == s[i + 1]) {
			s[i + 1] = s[i] == '0' ? '1' : '0';
			++res;
		}
	}
	cout << res << endl;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=2147483647;
const ll LLMAX=9223372036854775807;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll A,B,C,K;
    cin>>A>>B>>C>>K;
    if(A>=K){
        cout<<K<<endl;
    }else if(A+B>=K){
        cout<<A<<endl;
    }else{
        cout<<A-(K-A-B)<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n, m;

llong num[1024][1024];
pair<llong, llong> dp[1024][1024];
bool is_prime[1000005];

void sieve(llong n) {
    for (int i = 0; i <= n; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;

    for (int i = 2; i <= n; i++) {
        if (is_prime[i]) {
            for (int j = 2 * i; j <= n; j += i) is_prime[j] = false;
        }
    }
    return;
}

pair<llong, llong> rec(int i, int j) {
    if (i >= 1024 || j < 0 || j >= 1024) return {0, 0};
    if (num[i][j] > m) return {0, 0};

    if (dp[i][j] != make_pair(-1ll, -1ll)) return dp[i][j];

    pair<llong, llong> ret = max({rec(i + 1, j - 1),
                                  rec(i + 1, j),
                                  rec(i + 1, j + 1)});

    if (ret == make_pair(0ll, 0ll) && is_prime[num[i][j]]) {
        ret.first = 1;
        ret.second = num[i][j];
    }
    else if (is_prime[num[i][j]]){
        ret.first++;
    }
    
    return dp[i][j] = ret;
}

int main() {
    {
        sieve(1000000);
        llong x, y;
        llong c = 3;
        llong w = 3;
        num[512][512] = 1;
        num[512][513] = 2;
        x = 513;
        y = 512;

        while (c <= 1000000) {
            for (int i = 0; i < w - 2; i++) {
                y--;
                num[y][x] = c;
                c++;
            }

            for (int i = 0; i < w - 1; i++) {
                x--;
                num[y][x] = c;
                c++;
            }

            for (int i = 0; i < w - 1; i++) {
                y++;
                num[y][x] = c;
                c++;
            }

            for (int i = 0; i < w; i++) {
                x++;
                num[y][x] = c;
                c++;
            }
            w += 2;
        }
    }
    
    while (1) {
        cin >> m >> n;
        if (n == 0) break;

        llong x, y;
        for (int i = 0; i < 1024; i++) {
            for (int j = 0; j < 1024; j++) {
                if (num[i][j] == n) {
                    y = i;
                    x = j;
                }
                dp[i][j] = make_pair(-1ll, -1ll);
            }
        }

        auto p = rec(y, x);

        cout << p.first << ' ' << p.second << '\n';
    }

    return 0;
}



Measured memory_bytes: 28552
#include<bits/stdc++.h>
using namespace std;
int res=-10000000;
int cnt=10000000;
int main()
{
	int a,b,x,y;
	cin>>a>>b>>x>>y;
	int c[10000],d[10000];
	for(int i=0;i<a;i++)
	{
		cin>>c[i];
		res=max(res,c[i]);
	}
	for(int j=0;j<b;j++)
	{
		cin>>d[j];
		cnt=min(cnt,d[j]);
	}
	for(int k=res+1;k<=cnt;k++)
	{
		if(k>x&&k<y)
		{
			cout<<"No War"<<endl;
			return 0;
		}
	}
	cout<<"War"<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
x = a[-1]/2
ans = 0
dis = float("Inf")
for i in range(n-1):
    if dis > abs(x-a[i]):
        ans = a[i]
        dis = abs(x-a[i])
print(a[-1],ans)

Measured memory_bytes: 14428
n = int(input())
a = list(map(int, input().split()))
s = set()
free = 0
for ai in a:
    rank = ai // 400
    if rank > 7:
        free += 1
    else:
        s.add(rank)

if len(s) == 0:
    ans = (1, free)
else:
    ans = (len(s), len(s) + free)

print(*ans)



Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
N = int(input())
def m5(N):
    count = 0
    while True :
        k = N // 5
        if k == 0 :
            break
        else :
            N = k
            count += k // 2
    return count
if N % 2 == 1 :
    print(0)
else :
    s = str(N)
    o = int(s[-1])
    N -= o
    print(m5(N))

Measured memory_bytes: 3060
# import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq # priolity-queue
# import time
# import itertools
# import collections # queue
# from operator import itemgetter
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def main():
    s = input()
    l = len(s) - 2
    ans = [s[0],str(l),s[-1]]
    print(''.join(ans))
    return

if __name__=='__main__':
    main()

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int s[] = new int[n];

		String str[] = br.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			s[i] = Integer.parseInt(str[i]);
		}

		Arrays.sort(s);

		int q = Integer.parseInt(br.readLine());

		str = br.readLine().split(" ");

		int ans = 0;
		for (int i = 0; i < q; i++) {
			int t = Integer.parseInt(str[i]);

			int left = 0;
			int right = n;
			int mid = 0;

			while (right - left > 1) {
				mid = (right + left) / 2;

				if (t == s[mid]) {
					ans++;
					break;
				}
				if (t > s[mid]) {
					left = mid;
				} else {
					right = mid;
				}
			}
		}

		System.out.println(ans);
	}
}



Measured memory_bytes: 51416