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

using namespace std;

int main(){
    int H,W;
    int N;
    int a[10000];
    cin>>H>>W;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    int ans[100][100];
    int color=0;
    int color_num=0;
    for(int i=0;i<H;i++){
        if(i%2==0){
            for(int j=0;j<W;j++){
                if(color_num < a[color]){
                    ans[i][j]=color+1;
                    color_num++;
                }else{
                    color++;
                    ans[i][j]=color+1;
                    color_num=1;
                }
            }
        }else{
            for(int j=W-1;j>=0;j--){
                if(color_num < a[color]){
                    ans[i][j]=color+1;
                    color_num++;
                }else{
                    color++;
                    ans[i][j]=color+1;
                    color_num=1;
                }
            }
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cout<<ans[i][j]<<' ';
        }
        cout<<endl;
    }
    
    return 0;
}


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

int main(){
	int n,l ;
	cin >> n >> l ;
	int mn = 10000000 ;
    int m ;
	for(int i=1;i<=n;i++){
		int sub = l+i-1 ;
		if(sub<0) sub *= -1 ;
		if(mn>sub){
            mn = sub ;
            m = i ;
        }
	}
	cout << n*l+n*(n-1)/2-(l+m-1) << endl ;
}


Measured memory_bytes: 256
// tokiomarine2020_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    string S;
    cin >> S;
    print(S.substr(0, 3));

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}


int main(void) {
  ll N;
  cin >> N;
  string s[11111];
  ll i, j;
  
  ll ans=0;
  for(i=0; i<N; i++) {
    cin >> s[i];
  }
  
  for(i=0; i<N; i++) {
    
    for(j=0; j<(ll)s[i].size()-1; j++) {
      if(s[i][j]=='A'&&s[i][j+1]=='B') ans++;
    }
    
  }
  
  ll cba=0, ca=0, cb=0;
  for(i=0; i<N; i++) {
    ll len=s[i].size();
    string t=s[i];
    if(t[0]=='B' && t[len-1]=='A') cba++;
    else if(t[0]=='B') cb++;
    else if(t[len-1]=='A') ca++;
  }
  
  //pt(ca<<" "<<cba<<" "<<cb);
  
  if(cba>0) {
    if(ca>0 && cb>0) {
      ca--; cb--;
      ans+=cba+1+min(ca, cb);
    }else if(ca==0 && cb>0) {
      ans+=cba;
    }else if(ca>0 && cb==0) {
      ans+=cba;
    }else if(ca==0 && cb==0) {
      ans+=cba-1;
    }
  }else {
    ans+=min(ca, cb);
  }
  
  
  pt(ans);
}









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

int main()
{
    int n, t, a;
    cin >> n >> t >> a;
    int h[n];
    int ans = 0;
    double sub = 10000000.0;
    for(int i=0;i<n;i++){cin >> h[i];}
    for(int j=0;j<n;j++){
        if(fabs(t-h[j]*0.006-a)<sub){
            sub = fabs(t-h[j]*0.006-a);
            ans = j+1;
            }
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){

    std::ios_base::sync_with_stdio(0),cin.tie(0),cin.tie(0);

    string str;
    int ln;

    cin >> str;
    ln = str.size();
    if(ln==2)
        cout << str;
    else{
        reverse(str.begin(),str.end());
        cout << str;
    }
    cout << endl;
    return 0;
}


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

int main(){
  int i,j,k,cnt=0;
  ll n;
  cin>>n;
  ll p=(ll)round(sqrt(n));
  ll sum=0;
  for(i=1;i<p;i++){
    if(n%i==0)sum+=n/i-1;
  }
  cout<<sum;
}


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

#define int long long

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf long double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define data asd09123jdf02i3h

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

int n,a[maxn],b[maxn],t[maxn],c[maxn],sta[maxn],top;

signed main() {
    read(n);int mx=0,p=1;
    for(int i=1;i<=n;i++) {
        read(a[i]);
        if(a[i]>mx) mx=a[i],p=i;
    }
    for(int i=1;i<=n;i++) read(b[i]);
    
    for(int i=p;i<=n;i++) t[i-p]=a[i];
    for(int i=1;i<=p;i++) t[i+n-p]=a[i];
    for(int i=0;i<=n;i++) a[i]=t[i];
    for(int i=p;i<=n;i++) t[i-p]=b[i];
    for(int i=1;i<=p;i++) t[i+n-p]=b[i];
    for(int i=0;i<=n;i++) b[i]=t[i];

    // for(int i=0;i<=n;i++) printf("%lld ",a[i]);puts("");
    for(int i=2;i<=n;i++) c[i]=2*(c[i-1]+b[i-1])-c[i-2],a[i]-=c[i];
    // for(int i=0;i<=n;i++) printf("%lld ",c[i]);puts("");
    // for(int i=0;i<=n;i++) printf("%lld ",a[i]);puts("");
    lf ans=0;
    for(int i=0;i<=n;i++) {
        while(top>1&&1.0*(a[i]-a[sta[top]])/(i-sta[top])>=1.0*(a[sta[top]]-a[sta[top-1]])/(sta[top]-sta[top-1])) top--;
        sta[++top]=i;
    }
    // for(int i=1;i<=top;i++) write(sta[i]);
    for(int i=2;i<=top;i++) 
        for(int j=sta[i-1];j<sta[i];j++)
            ans+=a[sta[i-1]]+1.0*(a[sta[i]]-a[sta[i-1]])/(sta[i]-sta[i-1])*(j-sta[i-1]);
    for(int i=0;i<n;i++) ans+=c[i];
    ans/=n;
    printf("%.12Lf\n",ans);
    return 0;
}


Measured memory_bytes: 11464
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static io;
public class CompetitiveProgramming
{
  public void Solve()
  {
    var N = Int1;
    long min = 1 << 62;
    long ans = -(1 << 62);
    for (int i = 0; i < N; ++i)
    {
      var x = Long1;
      if (i != 0)
        ans = Max(ans, x - min);
      if (min > x) min = x;

    }
    Write(ans);
  }


}



class Program
{
  static void Main(string[] args)
  {
    var CompetitiveProgramming = new CompetitiveProgramming();
    CompetitiveProgramming.Solve();
  }
}
public static class io
{
  public static string Str => Console.ReadLine();
  public static string[] Strs => Str.Split(' ');
  public static long[] Longs => Strs.Select(long.Parse).ToArray();
  public static int[] Ints => Strs.Select(int.Parse).ToArray();
  public static char[] Chars => Str.ToArray();
  public static double[] Doubles => Strs.Select(double.Parse).ToArray();
  public static long Long1 => Longs[0];
  public static int Int1 => Ints[0];
  public static char Char1 => Chars[0];
  public static double Double1 => Doubles[0];
  public static long[] VerticalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; }
  public static void Write(string a) => Console.WriteLine(a);
  public static void Write(params object[] i) => Write(string.Join(" ", i));
  public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a));
  public static void Verticalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); }
  public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); }
}



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

int main(void)
{
    int c[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> c[i][j];
        }
    }
    for (int i = 0; i <= 1; i++) {
        if (c[0][i+1]-c[0][i] == c[1][i+1]-c[1][i] && c[1][i+1]-c[1][i] == c[2][i+1]-c[2][i]) {
            continue;
        }
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    for (int i = 0; i <= 1; i++) {
        if (c[i+1][0]-c[i][0] == c[i+1][1]-c[i][1] && c[i+1][1]-c[i][1] == c[i+1][2]-c[i][2]) {
            continue;
        }
        else {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}


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

int main() {
  int n,h,cnt=0,max=-1;
  cin >> n;
  vector<int> height(n);
  for(int i=0 ;i<n ;i++){
    cin >> h;
    height[i] = h;
  }
  for(int i : height){
    if(i >= max){
      cnt++;
      max = i;
    }
  }
  cout << cnt << endl; 
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
 
public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;
 
    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);
 
    private void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
 
        int ans;
        if (a <= d && c <= b) {
            ans = Math.min(b, d) - Math.max(a, c);
        } else {
            ans = 0;
        }
        _out.println(ans);
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();
 
        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();
 
        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

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

using ll = long long;
const ll MOD = 1000000007;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int k = (int)s.length();
    vector<vector<ll>> dp(n+1,vector<ll>(n+1,0ll));
    dp[0][0] = 1ll;
    for (int i = 0; i < n; i++) {
        ( dp[i+1][0] += dp[i][0] ) %= MOD;
        ( dp[i+1][1] += dp[i][0] ) %= MOD;
        for (int j = 1; j <= i; j++) {
            ( dp[i+1][j-1] += dp[i][j] * 2 ) %= MOD;
            ( dp[i+1][j+1] += dp[i][j] ) %= MOD;
        }
    }
    cout << dp[n][k] << endl;
    return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

const ull B = 100000007;
bool contain(string a, string b){
  ll al = a.size(), bl = b.size();
  if(al > bl)
    return false;

  ull t = 1;
  REP(i, al)
    t *= B;
  ull ah = 0, bh = 0;
  REP(i, al)
    ah = ah*B + a[i];
  REP(i, al)
    bh = ah*B + b[i];

  for(ll i = 0; i + al <= bl; i++){
    if(ah == bh)
      return true;
    if(i+al < bl)
      bh = bh*B + b[i+al]-b[i]*t;
  }
}

struct RollingHash{
  static const ll base1 = 1007, base2 = 1009;
  static const ll mod1 = 1e9+7, mod2 = 1e9+9;
  vll hash1, hash2, power1, power2;
  RollingHash(string s){
    ll n = s.size();
    hash1.assign(n+1, 0);
    hash2.assign(n+1, 0);
    power1.assign(n+1, 1);
    power2.assign(n+1, 1);
    for(int i = 0; i<n; i++){
      hash1[i+1] = (hash1[i]*base1+s[i])%mod1;
      hash2[i+1] = (hash2[i]*base2+s[i])%mod2;
      power1[i+1] = (power1[i]*base1)%mod1;
      power2[i+1] = (power2[i]*base2)%mod2;
    }
  }

  inline pair<ll, ll> get(ll l, ll r){
    ll res1 = hash1[r] - hash1[l]*power1[r-l]%mod1;
    if(res1<0)
      res1 += mod1;
    ll res2 = hash2[r] - hash2[l]*power2[r-l]%mod2;
    if(res2<0)
      res2 += mod2;
    return {res1, res2};
  }
};

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

  ll n;
  cin >> n;
  string s;
  cin >> s;

  RollingHash rh(s);


  auto check = [&](ll d){
    map<pll, ll> ma;

    REP(i, n){
      pll p = rh.get(i, i+d);
      if(ma.count(p)){
        if(i-ma[p]>=d)
          return true;
      }
      else
        ma[p] = i;
    }

    return false;
  };


  //binary search for m
  ll ans = 0;
  ll ok = 0;
  ll ng = n/2+1;
  while(ng-ok>1){
    ll mid = (ok+ng)/2;
    if(check(mid))
      ok = mid;
    else
      ng = mid;
  }
  ans = ok;
  cout << ans << endl;
}


Measured memory_bytes: 768
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <vector>
using namespace std;

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

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

struct state {
	int x, y, level;
	state(int x, int y, int level):x(x), y(y), level(level){}
	bool operator>(const state& s) const {
		return level > s.level;
	}
};

map<int, int> nextOffice() {
	int w, h, x, y;
	cin >> w >> h >> x >> y;
	--x;
	--y;

	vector<vector<int> > field(h, vector<int>(w));
	for(int i = 0; i < h; ++i)
		for(int j = 0; j < w; ++j)
			cin >> field[i][j];

	vector<vector<bool> > visited(h, vector<bool>(w, false));
	priority_queue<state, vector<state>, greater<state> > que;
	que.push(state(x, y, field[y][x]));

	while(!que.empty()) {
		state s = que.top();
		que.pop();

		visited[s.y][s.x] = true;

		for(int i = 0; i < 4; ++i) {
			int nx = s.x + dx[i], ny = s.y + dy[i];
			if(nx < 0 || ny < 0 || nx >= w || ny >= h || visited[ny][nx])
				continue;

			chmax(field[ny][nx], field[s.y][s.x]);
			que.push(state(nx, ny, field[ny][nx]));
		}
	}

	map<int, int> res;
	res.insert(make_pair(0, 0));
	for(int i = 0; i < h; ++i)
		for(int j = 0; j < w; ++j)
			res[field[i][j]] += 1;

	for(map<int, int>::iterator it = res.begin(); it != res.end(); ++it) {
		map<int, int>::iterator next = it;
		++next;

		if(next != res.end())
			next->second += it->second;
	}

	return res;
}

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

	for(int r; cin >> r, r;) {
		map<int, int> office1 = nextOffice();
		map<int, int> office2 = nextOffice();

		int ans = MAX * 2;
		map<int, int>::const_iterator it = office1.begin();
		map<int, int>::const_reverse_iterator it2 = office2.rbegin();
		for(; it != office1.end(); ++it) {
			while(it->second + it2->second >= r) {
				chmin(ans, it->first + it2->first);
				if(++it2 == office2.rend())
					goto finish;
			}
		}

	finish:;
		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 15776
import java.util.*;
import java.io.*;
class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // StringTokenizer st = new StringTokenizer(br.readLine());
        String s = br.readLine();
        String[] sarr = s.split(" ");
        Long a = Long.parseLong(sarr[0]);
        Character op = sarr[1].charAt(0);
        Long b = Long.parseLong(sarr[2]);
        if(op=='+')
            System.out.println(a+b);
        else
            System.out.println(a-b);

    }

}


Measured memory_bytes: 20820
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;

bool G[2000][2000];
int match[2000];
bool used[2000];

int V;

void add_edge(int v, int u) {
	G[v][u] = G[u][v] = true;
}

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

int calc() {
	int res = 0;
	fill(match, match + V, -1);
	for(int v = 0; v < V; v++) {
		if(match[v] < 0) {
			fill(used, used + V, false);
			if(dfs(v)) {
				res++;
			}
		}
	}
	return res;
}

typedef long long ll;
const ll INF = 1LL << 50;
ll wf[100][100];
int p[1000];
ll t[1000];

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

	int N, M, L;
	while(cin >> N >> M >> L, N) {
		for(int i = 0; i < N; i++)
			for(int j = 0; j < N; j++)
				wf[i][j] = i == j ? 0 : INF;

		for(int i = 0; i < M; i++) {
			int u, v, d;
			cin >> u >> v >> d;
			wf[u][v] = wf[v][u] = d;
		}

		for(int k = 0; k < N; k++)
			for(int i = 0; i < N; i++)
				for(int j = 0; j < N; j++)
					wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j]);

		V = 2 * L;
		for(int i = 0; i < L; i++) {
			cin >> p[i] >> t[i];
		}
		for(int i = 0; i < V; i++) {
			for(int j = 0; j < V; j++) {
				G[i][j] = false;
			}
		}
		for(int i = 0; i < L; i++) {
			for(int j = 0; j < L; j++) {
				if(i == j) continue;
				int u = p[i], v = p[j];
				if(t[i] + wf[u][v] <= t[j]) {
					add_edge(i, j + L);
				}
			}
		}

		cout << L - calc() << endl;
	}

}

Measured memory_bytes: 7132
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  N = int(readline())
  H = list(map(int, readline().split()))
  max_h = 0
  ans = 0
  for i in range(N):
    h = H[i]
    if max(h,max_h) == h:
      max_h = h
      ans += 1
  print(ans)
  
  
  
if __name__ == '__main__':
  main()

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

//Coding below.
int main (){
    int N,K;
    cin >> N >> K;
    int h;
    int ans=0;
    for(int i=0;i<N;i++){
        cin >> h;
        if(h>=K){
            ans++;
        }
    }
    cout << ans;
}

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

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

			String in = br.readLine();
			String chr[] = in.split(" ");

			System.out.println(chr[0].equals("H")?chr[1]
							   :chr[0].equals("D")&&chr[1].equals("D")?"H"
							   :"D");

		}
	}
}


Measured memory_bytes: 25280
def main():
    n = int(input())
    a = list(map(int,input().split()))
    import collections
    c =collections.Counter(a)
    ans = 0
    for k in c.keys():
        ans += c[k]*(c[k]-1)//2
    for i in range(n):
        draw = c[a[i]]*(c[a[i]]-1)//2-(c[a[i]]-1)*(c[a[i]]-2)//2
        print(ans-draw)

if __name__ == "__main__":
    main()

Measured memory_bytes: 24748
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      string s = "0000";
      cin >> s.at(0) >> s.at(1) >> s.at(2) >> s.at(3);
      sort(s.begin(),s.end());
      if(s=="1479") cout << "YES" << endl;
      else cout << "NO" << endl;
      return 0;
    }

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

int main(){
  long long A,B,K,a,b;
  cin>>A>>B>>K;
  a=A-K;
  a=max((long long)0,a);
  
  if(A-K<0) b=B-(K-A);
  else b=B;
  b=max((long long)0,b);
  
  cout<<a<<" "<<b<<endl;
  
}

Measured memory_bytes: 256
N = gets.to_i
A = gets.chomp.split.map(&:to_i).sort.reverse
ans = A[0]

(1..(N-2)/2).each do |i|
  ans += A[i]*2
end
if (N-2)%2 == 1
  ans += A[(N-2)/2+1]
end

puts ans

Measured memory_bytes: 33328
#include <iostream>
#include<vector>
using namespace std;
int main(void){
    int n,m,x;
    cin >> n >> m >> x;
    vector<vector<int>> a(n,vector<int>(m));
    vector<int> c(n);
    
    for(int i = 0;i < n;i++){
          cin >> c[i];
          for(int j = 0;j < m;j++){
                cin >> a[i][j];
          }
    }
    
    int ans = 1234567878;
    
    for(int i = 0;i < 1 << n;i++){
          int t = 0;
          bool ok = true;
          vector<int> level(n);
          for(int j = 0;j < n;j++){
                if(i >> j & 1){
                      for(int k = 0;k < m;k++){
                            level[k] += a[j][k];
                      }
                      t += c[j];
                }
          }
          for(int j = 0;j < m;j++){
                if(level[j] < x)ok = false;
          }
          if(ok){
                ans = min(ans,t);
          }
          
          
    }
    if(ans == 1234567878){
          cout << -1 << endl;
    }else{
          cout << ans << endl;
    }
}


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

#define ll long long
#define rep(i,N) for(ll i=0; i<N; i++)
const int mx = 2e5;

int main(void){
  ll N;
  cin >> N;
  ll A[N];
  ll bitnum1[61], bitnum0[61];
  rep(i,61){
    bitnum1[i]=0;
    bitnum0[i]=0;
  }
  rep(i,N){
    cin >> A[i];
    rep(j,61){
      if((A[i] >> j)&1 == 1) bitnum1[j]++;
      else bitnum0[j]++;
    }
  }
  ll ans = 0;
  rep(i,61){
    ll point = pow(2,i);
    point %= 1000000007;
    point *= bitnum1[i];
    point %= 1000000007;
    point *= bitnum0[i];
    ans += point;
    ans %= 1000000007;
  }
  
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 100100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << min(a,b)+min(c,d) << endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(S: str):
    if S[-1] == 's':
        S += "es"
    else:
        S += "s"
    print(S)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61724
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}

vi lose,back;
vector<double> p,y;
int n,t;

void solve(){
	if(t==0)return;
	auto next=p;
	fill(all(next),0.0);
	auto ny=y;
	fill(all(ny),0.0);
	rep(i,n){
		if(i==n-1){
			next[i]+=p[i];
			continue;
		}
		rep(j,6){
			int pos=i+j+1;
			if(pos>=n)pos=n-1-(pos-n+1);
			if(find(all(lose),pos)!=lose.end()){
				ny[pos]+=p[i]/6;
			}else if(find(all(back),pos)!=back.end()){
				next[0]+=p[i]/6;
			}else{
				next[pos]+=p[i]/6;
			}
		}
	}
	rep(i,n) next[i]+=y[i];
	y=ny;
	p=next;
	t--;
	solve();
}



int main(){
	int l,b;
	while(cin>>n>>t>>l>>b,n){
		n++;
		p.resize(n);
		fill(all(p),0.0);
		y.resize(n);
		fill(all(y),0.0);
		p[0]=1.0;
		lose.resize(l);
		back.resize(b);
		for(auto&i:lose)cin>>i;
		for(auto&i:back)cin>>i;
		solve();
		cout.precision(6);
		cout<<fixed<<p[n-1]<<endl;
	}
	return 0;
}



Measured memory_bytes: 3364
n=int(input())
a=list(map(int,input().split()))
switch=0
for i in range(n-1):
    minj=i
    for j in range(i+1,n):
        if a[j]<a[minj]:
            minj=j
    if a[i]!=a[minj]:
        switch+=1
    a[i],a[minj]=a[minj],a[i]

for i in range(n-1):
    print(a[i],end=" ")
print(a[n-1])
print(switch)



Measured memory_bytes: 5608
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	var Input = input.split("\n")
    
    var a = Number (Input[0].split(" ")[1])
    var cnt = 0
    
    var z = Input[1].split(" ")
    
    for(var i in z){
    	var b = Number(z[i])
       
        if(b >= a){
          cnt ++
        }
    }
    
  console.log(cnt)
  
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 18892
n = int(input())
A = [int(x) for x in input().split()]
B = [0] * n

for i in reversed(range(n)):
    if i + 1 > n // 2:
        B[i] = A[i]
        # iの倍数が書かれた箱に入っているボールの個数はOK
    else:
        # iの倍数が書かれた箱に入っているボールの個数
        c = n // (i+1)
        s = 0
        for j in range(c):
            s += B[(i+1)*(j+1)-1]
        if s % 2 == A[i]:
            continue
        else:
            B[i] = 1

ans = sum(B)
print(ans)
count = 0
for i in range(len(B)):
    if B[i] == 1:
        count += 1
        if count == sum:
            print(i + 1)
        else:
            print(i + 1, end=' ')


Measured memory_bytes: 7276
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Map<String,Integer> map = new HashMap<>();
		for(; N > 0; N--) {
			String a = sc.next();
			if(map.containsKey(a)) {
				map.put(a, (map.get(a)+1));
			}else {
				map.put(a, 1);
			}
		}

		List<Entry<String, Integer>> list_entries = new ArrayList<Entry<String, Integer>>(map.entrySet());
		Collections.sort(list_entries, new Comparator<Entry<String, Integer>>() {
			public int compare(Entry<String, Integer> obj1, Entry<String, Integer> obj2){
				return obj2.getValue().compareTo(obj1.getValue());
            }
        });

		ArrayList<String> list = new ArrayList<>();
		int ch = 0;
		for(Entry<String, Integer> entry : list_entries) {
			String key = entry.getKey();
			if((entry.getValue() != ch)&&(ch != 0)) {
				break;
			}else {
				list.add(key);
				ch = entry.getValue();
			}
		}
		Collections.sort(list);
		for(int i = 0; i < list.size(); i++) {
			System.out.println(list.get(i));
		}
	}
}

Measured memory_bytes: 83604
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>

// author:Swastik Banerjee

using namespace std;

typedef long long ll;
#define MOD 1000000007

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



  ll N, K;
  cin >> N >> K;

  ll arr[N];
  for (ll i = 0; i < N; i++) {
    cin >> arr[i];
  }

  ll dp[N];
  for (int i = 0; i < N; i++) {
    dp[i] = LLONG_MAX;
  }
  dp[0] = 0;

  for (int i = 0; i < N; i++) {
    ll curr = LLONG_MAX;
    for (int j = 1; j <= K; j++) {
      if (i - j < 0) break;
      curr = dp[i - j] + abs(arr[i] - arr[i - j]);
      if (curr < dp[i]) dp[i] = curr;
    }
  }

  cout << dp[N - 1];
}

Measured memory_bytes: 1792
sx, sy, tx, ty = gets.chomp.split.map(&:to_i)

ans = []
ans << 'U' * (ty - sy)
ans << 'R' * (tx - sx)
ans << 'D' * (ty - sy)
ans << 'L' * (tx - sx)
ans << 'L'
ans << 'U' * (ty - sy + 1)
ans << 'R' * (tx - sx + 1)
ans << 'D'
ans << 'R'
ans << 'D' * (ty - sy + 1)
ans << 'L' * (tx - sx + 1)
ans << 'U'

puts ans.join

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

int main()
{
	ll S,lim=(ll)(1e9);
	cin>>S;
	if (S<=lim){printf ("0 0 0 1 %lld 1",S);return 0;}
	ll x=(S-1)/lim+1;
	if (x*lim==S){printf ("0 0 0 %lld %lld 0",x,lim);return 0;}
	ll res=x*lim-S;
	printf ("0 0 %lld 1 %lld %lld",x,res,lim);
	return 0;
}


Measured memory_bytes: 256
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

import scala.annotation.tailrec

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(h, w) = in.readLine().split("\\s+").map(_.toInt)
    val n = in.readLine().toInt
    val as = in.readLine().split("\\s+").map(_.toInt)
    val grid = Array.ofDim[Int](h, w)

    @tailrec
    def coloring(totalCount: Int, as: List[(Int, Int)]): Unit = {
      val x = if (totalCount % (2 * w) < w) {
        totalCount % (2 * w)
      } else {
        w - 1 - totalCount % w
      }
      val y = totalCount / w

      as match {
        case (color, count) :: rest =>
          System.err.println(s"(${y})(${x}) = ${color}")
          grid(y)(x) = color
          if (count > 1) {
            coloring(totalCount + 1, (color, count - 1) :: rest)
          } else {
            coloring(totalCount + 1, rest)
          }
        case Nil =>
      }
    }

    coloring(0, as.zipWithIndex.map { case (a, index) =>
      (index + 1, a)
    }.toList)

    for (y <- 0 until h) {
      out.println(grid(y).mkString(" "))
    }

    out.flush()
  }
}

Measured memory_bytes: 40604
<?php

[$N, $M, $K ] = fscanf(STDIN, "%d%d%d");

$A =  fscanf(STDIN, str_repeat("%d", $N));
$B =  fscanf(STDIN, str_repeat("%d", $M));

$ans = 0;
$time = 0;
for($i=0;$i<$N;$i++){
    if($time + $A[$i] <= $K){
        $ans++;
        $time += $A[$i];
    }else{
        break;
    }
}
$i--;
$max = $i;
$j=0;
while($time <= $K){
    if($time + $B[$j] <= $K){
        $time+=$B[$j];
        $ans++;
        $j++;
        if($j == $M){
            break;
        }
    }else{
        break;
    }
}
$maxans = $ans;
if($N+$M === $ans){
    echo $ans;
    exit;
}
for($i=$max; $i>=0; $i--){
    $time -= $A[$i];
    $ans--;
    while($time <= $K){
        if($time + $B[$j] <= $K){
            $time+=$B[$j];
            $ans++;
            $j++;
            if($j == $M){
                break;
            }
        }else{
            break;
        }
    }
    $maxans = max($ans, $maxans);
    if($j===$M){
        break;
    }
}
echo $maxans;

Measured memory_bytes: 33732
import math, itertools, copy
 
# 入力受け取り
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
rewrite = [] 
for i in range(M):
	rewrite.append(list(map(int, input().split())))


#N, M = 10, 3
#A = [1, 8, 5, 7, 100, 4, 52, 33, 13, 5]
#rewrite = [[3, 10], [4, 30], [1, 4]]

rewrite = sorted(rewrite, key = lambda x : x[1], reverse = True)
A = sorted(A)
# print(A)

cur_M = 0
trg_A = 0

while trg_A < N and cur_M < M:
	# 書き換える必要性がそれ以上ない場合
	if rewrite[cur_M][1] <= A[trg_A]:
		break
	# 書き換えられる場合
	elif rewrite[cur_M][0] > 0:
		# 数字を書き換える
		A[trg_A] = rewrite[cur_M][1]
		# 残りの書き換え回数を更新
		rewrite[cur_M][0] -= 1
		# 対象カードをずらす
		trg_A += 1
	#　残りが0になった場合
	else:
		cur_M += 1
		
print(sum(A))
# print(A)

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

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

  vector<string> res;
  res.emplace_back("a");
  auto dfs = [&](auto& f, int d)->void {
    if (d == n) return ;
    int m = sz(res);
    vector<string> nres;
    for (int i = 0; i < m; i++) {
      int k = 0;
      for (int j = 0; j < d; j++) {
        k = max(k, res[i][j] - 'a');
      }
      for (int j = 0; j <= k + 1; j++) {
        nres.emplace_back(res[i] + (char)('a' + j));
      }
    }
    swap(res, nres);
    f(f, d + 1);
  };
  dfs(dfs, 1); 
  /*
  sort(res.begin(), res.end());
  res.erase(unique(res.begin(), res.end()), res.end());
  */
  for (auto e : res) cout << e << endl;
  return 0;
}

Measured memory_bytes: 11212
int main()
{
  int n;
  scanf("%d", &n);
  int i, digit = 1, tmp = n;
  for (i = 0; tmp / 10 != 0; i++)
  {
    tmp /= 10;
    digit++;
  }
  int ans = 0;
  if (digit % 2 == 0)
    for (i = 0; digit > 0 ; i++)
    {
      digit -= 2;
      ans += 9 * pow(10, i * 2);
    }
  else if (digit % 2 == 1)
  {
    for (i = pow(10, digit - 1); i <= n; i++)
      ans++;
    for (i = 0; digit > 1; i++)
    {
      digit -= 2;
      ans += 9 * pow(10, i * 2);
    }
  }
  printf("%d", ans);
}

Measured memory_bytes: 2520
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int n=0;
    char s[max], t[max];
    
    scanf("%s", s);
    scanf("%s", t);
    
    rep(i, strlen(s)){
        if (s[i]!=t[i]) {
            n++;
        }
    }
    
    printf("%d", n);
    
    return 0;
}



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

using namespace std;

#define INF int(1e9)

struct Point {
	int idx, x, y;

	Point() { idx = x = y = -1; }

	Point(int idx, int x, int y) :
			idx(idx), x(x), y(y) {
	}
};

struct Edge {
	int u, v, c;
	Edge(int u, int v, int c) :
			u(u), v(v), c(c) {
	}
};

struct DSU {   //Zero-based
	int size;
	int* p;
	int* rank;

	DSU(int n) {
		size = n;
		p = new int[n];
		rank = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = i;
			rank[i] = 0;
		}
	}

	int findSet(int i) {
		return i == p[i] ? i : p[i] = findSet(p[i]);
	}

	bool isSameSet(int i, int j) {
		return findSet(i) == findSet(j);
	}

	void merge(int i, int j) {
		i = findSet(i);
		j = findSet(j);
		if (i == j)
			return;
		if (rank[i] < rank[j]) {
			p[i] = j;
		} else {
			p[j] = i;
			if (rank[i] == rank[j])
				rank[i]++;
		}
		size--;
	}
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, x, y;
	cin >> n;
	Point points[n];
	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		points[i] = Point(i, x, y);
	}
	vector<Edge> edges;
	edges.reserve(2 * (n - 1));

	sort(points, points + n, [](Point& a, Point& b) {
		return a.x < b.x;
	});
	for (int i = 0; i < n - 1; i++) {
		edges.push_back(
				{ points[i].idx, points[i + 1].idx, min(
						abs(points[i].x - points[i + 1].x),
						abs(points[i].y - points[i + 1].y)) });
	}

	sort(points, points + n, [](Point& a, Point& b) {
		return a.y < b.y;
	});
	for (int i = 0; i < n - 1; i++) {
		edges.push_back(
				{ points[i].idx, points[i + 1].idx, min(
						abs(points[i].x - points[i + 1].x),
						abs(points[i].y - points[i + 1].y)) });
	}

	sort(edges.begin(), edges.end(), [](Edge& a, Edge& b) {
		return a.c < b.c;
	});

	DSU unionFind(n);
	long long ans = 0;
	for (Edge e : edges) {
		if (!unionFind.isSameSet(e.u, e.v)) {
			unionFind.merge(e.u, e.v);
			ans += e.c;
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 4608
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())

c = 0
c += a1*t1-b1*t1
c += a2*t2-b2*t2

#print(c)
if c == 0:
    print('infinity')
    exit()

if c > 0:
    if b1*t1-a1*t1 < 0:
        ans = 0
    else:
        q, r = divmod(b1*t1-a1*t1, c)
        if r == 0:
            ans = 2*q
        else:
            ans = 2*q+1
else:
    c *= (-1)
    if -b1*t1+a1*t1 < 0:
        ans = 0
    else:
        q, r = divmod(-b1*t1+a1*t1, c)
        if r == 0:
            ans = 2*q
        else:
            ans = 2*q+1
print(ans)


Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int h, a;
    cin >> h >> a;
    cout << (h + a - 1) / a << endl;
    return 0;
}

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

int main()
{
	int n, x, t;
	int jyozan, amari;
	
	cin >> n >> x >> t;
	
	jyozan = n / x;
	amari  = n % x;
	
	if(amari > 0)
	{
		cout << (jyozan + 1) * t;
	}
	else
	{
		cout << jyozan * t;
	}
	
	return 0;
}


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

int main(){
  char S[100];
  long long int K;
  cin >> S;
  cin >> K;
  int a[100];
  for(int i=0;i<100;i++){
    a[i]=S[i]-0x30;
    //cout << a[i]<<'\n';
  }
  int i=0;
  while(a[i]==1){
    i++;
  }
  if(K>i){
  cout << a[i];
}
  else{
    cout <<1;
  }
  return 0;
}


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

int main(){
        int n,i,a,b,node,used,cnt,chi,cn=0;
        cin >> n;
        vector<vector<int>> g(n);
        vector<pair<int,int>> o(n-1);
        vector<int> p(n); p.at(0)=-1;
        map<pair<int,int>, int> c; c[(make_pair(-1,0))]=0;
        for(i=0;i<n-1;++i){
                cin >> a >> b;
                --a; --b;
                o.at(i) = make_pair(a,b);
                g.at(a).push_back(b);
                g.at(b).push_back(a);
        }
        queue<int> q;
        q.push(0);
        while(!q.empty()){
                node = q.front(); q.pop();
                used = c.at(make_pair(min(node,p.at(node)),max(node,p.at(node))));
                cnt = 1;
                for(i=0;i<g.at(node).size();++i){
                        chi = g.at(node).at(i);
                        if(chi==p.at(node)) continue;
                        p.at(chi) = node;
                        q.push(chi);
                        if(cnt==used) ++cnt;
                        c[make_pair(min(node,chi),max(node,chi))] = cnt;
                        ++cnt;
                        cn = max(cn, c.at(make_pair(min(node,chi),max(node,chi))));
                }
        }
        cout << cn << endl;
        for(i=0;i<n-1;++i) cout << c[o.at(i)] << endl;
        return 0;
}

Measured memory_bytes: 16104
from sys import stdin
from collections import deque
def main():
  _map, _input, _int = map, stdin.readline, int
  n, q = _map(_int, _input().split())
  values = [0] * n
  links = [[] for _ in range(n)]
  for _ in range(n - 1):
    a, b = _map(_int, _input().split())
    if a >= b:
      return
    links[a - 1].append(b - 1)
    links[b - 1].append(a - 1)
  for _ in range(q):
    p, x = _map(_int, _input().split())
    values[p - 1] += x
  d = deque()
  d.append((0, -1))
  while len(d) != 0:
    i, p = d.popleft()
    for j in links[i]:
      if j == p:
        continue
      values[j] += values[i]
      d.append((j, i))
  print(*values)
main()

Measured memory_bytes: 62232
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
int main(){
  int N ;
  int t[100100], x[100100], y[100100];
  cin >> N;
  t[0] = x[0] = y[0] = 0;
  for(int i = 0; i < N; i++){
    cin >> t[i+1] >> x[i+1] >> y[i+1];
  }
  bool b = true;
  for(int i = 0; i< N; i++){
    int d_lim = t[i+1] - t[i];
    int dxdy = abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
    if(d_lim < dxdy){
      b = false;
    }
    if(d_lim %2 != dxdy%2){
      b = false;
    }
  }
  
  if(b ==true) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ret = 0;
  for (int i = 0; i < s.size() && (i = s.find("ABC", i)) != string::npos; i += 3) { ++ret; }
  cout << ret << "\n";
  return 0;
}

  


Measured memory_bytes: 888
use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let q: usize = sc.read();
    for _ in 0..q {
        let a: usize = sc.read();
        let b: usize = sc.read();
        let (a, b) = if a > b { (b, a) } else { (a, b) };

        let mut ok = a - 1;
        let mut ng = 1e10 as usize;
        while ng - ok > 1 {
            let x = (ok + ng) / 2;
            let mut max = 0;
            if x >= b - 1 {
                // 1 ... a-1    a+1   ... x-b+1 x-b+2 ... x
                // x ... x-a+2  x-a+1 ... b+1   b-1   ... 1
                max = get_max(1, a - 1, x, x + 2 - a);
                max = cmp::max(max, get_max(a + 1, x - (b - 1), x - (a - 1), b + 1));
                max = cmp::max(max, get_max(x + 2 - b, x, b - 1, 1));
            } else {
                // 1 ... a-1      a+1 ... x
                // x-1 ... x-a+1  x-a ... 1
                max = get_max(1, a - 1, x - 1, x - (a - 1));
                max = cmp::max(max, get_max(a + 1, x, x - a, 1));
            }

            if max < a * b {
                ok = x;
            } else {
                ng = x;
            }
        }
        println!("{}", if a <= ok { ok - 1 } else { ok });
    }
}

fn get_max(from_a: usize, to_a: usize, from_b: usize, to_b: usize) -> usize {
    if from_a > to_a {
        return 0;
    }
    assert_eq!(to_a + 1 - from_a, from_b + 1 - to_b);
    let mut m = (from_a + from_b) / 2;
    let mut max = cmp::max(from_a * from_b, to_a * to_b);
    if from_a <= m && m <= to_a {
        let da = m - from_a;
        let b = from_b - da;
        max = cmp::max(max, m * b);
    }
    m += 1;
    if from_a <= m && m <= to_a {
        let da = m - from_a;
        let b = from_b - da;
        max = cmp::max(max, m * b);
    }
    max
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main() {
        int sum , m;
        cin >> sum >> m;
        int cs = 0;
        for(int i = 0 ; i < m ; i++){
            int y;
            cin >> y;
            cs+= y;
        }
        cout << max(sum - cs , -1) << endl;
}


Measured memory_bytes: 3636