akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=20005;
const ll mod=1e9+7;
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {x=x*10+ch-'0',ch=getchar();}
    return x*f;
}
int h,n,a[N],b[N],f[N];
int main()
{
	h=read(); n=read();
	clr(f, 60); f[0]=0;
	for(int i=1; i<=n; i++){
		a[i]=read(); b[i]=read();
		for(int j=0; j<=h; j++){
			f[j+a[i]]=min(f[j+a[i]], f[j]+b[i]);
		}
	}
	int ans=2e9;
	for(int i=h; i<=10000+h; i++) ans=min(ans, f[i]);
	cout<<ans<<endl;
}

Measured memory_bytes: 384
n,m = map(int,input().split())
ACc = [0 for i in range(n)]
WAc = [0 for i in range(n)]

for i in range(m):
    p,s = input().split()
    p = int(p)
    if s == "AC":
        if ACc[p-1] == 0:
            ACc[p-1] += 1
    else:
        if ACc[p-1] != 1:
            WAc[p-1] += 1
for j in range(n):
    if ACc[j] == 0:
        WAc[j] = 0

print(sum(ACc),sum(WAc))

Measured memory_bytes: 4656
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define of(i,l,r) for(int i=l;i>=r;i--)
#define fe(i,u) for(int i=head[u];i;i=e[i].next)
using namespace std;
typedef long long ll;
inline void open(const char *s)
{
	#ifndef ONLINE_JUDGE
	char str[20];
	sprintf(str,"in%s.txt",s);
	freopen(str,"r",stdin);
//	sprintf(str,"out%s.txt",s);
//	freopen(str,"w",stdout);
	#endif
}
inline ll rd()
{
	static ll x,f;
	x=0;f=1;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1ll;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10ll+ch-'0';
	return f>0?x:-x;
}
const int N=100010;
int n,m,tp;ll q[N],f[N],ans[N];

int main()
{
	n=rd();m=rd();
	q[tp=1]=n;
	fo(i,1,m){
		ll x=rd();
		while(tp&&x<=q[tp])tp--;
		q[++tp]=x;
	}
	f[tp]=1;
	of(i,tp-1,0){
		ll len=q[i+1];
		while(len>q[1]){
			int p=upper_bound(q+1,q+i+1,len)-q-1;
			f[p]+=len/q[p]*f[i+1];len%=q[p];
		}
		ans[len]+=f[i+1];
	}
	of(i,q[1],1)ans[i]+=ans[i+1];
	fo(i,1,n)printf("%lld\n",ans[i]);
	return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <math.h>
#include<iomanip>
using namespace std;

int main(){
  int A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,I=0,J=0,K=0,L=0,M=0,N=0,O=0,P=0,Q=0,R=0,S=0;
  int A2=0,A3=0,B2=0,B3=0;
  int X;
  cin >>X;
  A=100,B=101,C=102,D=103,E=104,F=105;
  if(X>=2100){
    cout << "1" << endl;
  }
  else if((100<=X&&X<=105)||(200<=X&&X<=210)||(300<=X&&X<=315)||(400<=X&&X<=420)||
    (500<=X&&X<=525)||(600<=X&&X<=630)||(700<=X&&X<=735)||(800<=X&&X<=840)||
    (900<=X&&X<=945)||(1000<=X&&X<=1050)||(1100<=X&&X<=1155)||(1200<=X&&X<=1260)||
    (1300<=X&&X<=1365)||(1400<=X&&X<=1470)||(1500<=X&&X<=1575)||(1600<=X&&X<=1680)||
    (1700<=X&&X<=1785)||(1800<=X&&X<=1890)||(1900<=X&&X<=1995)||(2000<=X&&X<=2100)){
    cout <<"1"<< endl;    
  }
  else cout <<"0"<<endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0



a, b, c = map(int, input().split())
for i in itertools.permutations([a, b, c], 3):
    if i[0] == sum(i[1:]) or sum(i[:2]) == i[2]:
        print("Yes")
        exit()

print("No")


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds; 
using ll = long long int;
#define INF             1e14
#define dd              double
#define MOD             1000000007
#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
#define nl              cout<<endl
#define fill(a,val)     memset(a,val,sizeof(a))
#define mp              make_pair
#define endl            "\n"
#define pb              push_back
#define ff              first    
#define ss              second
#define SIZE            200005
#define all(v)          v.begin(),v.end()
#define s(ar,n)         sort(ar,ar+n)
#define rs(ar,n)        sort(ar, ar+n, greater<ll>()) 
#define oa(a,n)         for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n)         for(ll i=0;i<n;i++)cin>>a[i];
#define maxa(ar,N)      *max_element(ar,ar+N)
#define mina(ar,N)      *min_element(ar,ar+N)
#define fastio()        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define printclock      cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order() - 0 indexing
// order_of_key() - number of elements strictly smaller
ll power(ll x, ll y){
    ll res=1;x=x;
    while(y>0){
        if(y&1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}  
ll logtwo(ll n){
    if(n==1)
        return 0;
    return logtwo(n/2)+1;
}
//---------------------------------------GL HF------------------------------------------------------
// -------------------------------------ManavJ07----------------------------------------------------
ll seive[1000005],ma[1000005];
bool f[1000005];
signed main()
{
    fastio();   
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll N,a;
        cin>>N;
        ll ar[N];
        for(ll i=0;i<N;i++){
            cin>>a;
            ar[i]=a;
            ma[a]++;
            if(ma[a]>1)
                f[a]=1;
        }
        for(ll i=1;i<1000005;i++){
            if(ma[i]!=0){
                for(ll j=2*i;j<1000005;j+=i){
                    if(ma[j])
                        f[j]=1;
                }
            }
        }
        ll ans=0;
        for(ll i=0;i<N;i++){
            if(f[ar[i]]==0)
                ans++;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 14000
#include<bits/stdc++.h>
using namespace std;
#define lli long long
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lli n,x,k;
  cin>>n>>k;
  vector<lli> h;
  for(lli i=0;i<n;i++)
  {
    cin>>x;
    h.push_back(x);
  }
  vector<lli> dp(n,999999999);
  dp[0]=0;
  for(lli i=0;i<n;i++)
  {
    for(lli j=i+1;j<=i+k;j++)
    {
      if(j<n)
      {
      	dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
      }
    }
  }
  cout<<dp[n-1];
}

Measured memory_bytes: 1908
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	int a;
	cin>>a;
	cout<<(a-1)/2<<endl;
}


Measured memory_bytes: 256
# define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };

int n;
vi h, r;
int memo[2000][2000];
int dp(int H, int R)
{
	if (memo[H][R] != -1)return memo[H][R];
	int ans=0;
	for (int i = 0; i < n; i++)
	{
		if (h[i] > H&&r[i] > R)
		{
			ans = max(ans, dp(h[i], r[i]));
		}
	}
	ans++;
	return memo[H][R] = ans;
}
int main()
{
	while (cin >> n&&n)
	{
		memset(memo, -1, sizeof memo);
		h.clear();
		r.clear();
		FOR(i, n)
		{
			INT(H); INT(R);
			h.push_back(H);
			r.push_back(R);
		}
		INT(m);
		n += m;
		FOR(i, m)
		{
			INT(H); INT(R);
			h.push_back(H);
			r.push_back(R);
		}
		cout << dp(0, 0)-1 << endl;
	}
}

Measured memory_bytes: 18756
#include <bits/stdc++.h>
using namespace std;
int a[100005],b[100005];
int main(){
	int n,i;
	unsigned long long sum=0;
	cin>>n;
	for(i=1;i<=n+1;i++){
		cin>>a[i];
	}
	for(i=1;i<=n;i++){
		cin>>b[i];
	}
	for(i=1;i<=n;i++){
		if(a[i]<=b[i]){
			sum+=a[i];
			b[i]-=a[i];
			a[i]=0;
			if(a[i+1]<b[i]){
				sum+=a[i+1];
				a[i+1]=0;
				b[i]-=a[i+1];
			}
			else{
				sum+=b[i];
				a[i+1]-=b[i];
				b[i]=0;
			}
		}
		else{
			sum+=b[i];
			a[i]-=b[i];
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
 
int main(){
  int i,j,cnt;
  int n,m;
  cin>>n>>m;
  int a[n],b[m],c[m];
  for(i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  for(i=0;i<m;i++)cin>>b[i]>>c[i];
  vector<pair<ll,ll>> v;
  v.push_back(pair<ll,ll>(a[0],1));
  for(i=1;i<n;i++){
    if(a[i-1]!=a[i]){
      v.push_back(pair<ll,ll>(a[i],1));
    }
    else v[v.size()-1].second++;
  }
  for(i=0;i<m;i++){
    v.push_back(pair<ll,ll>(c[i],b[i]));
  }
  sort(v.begin(),v.end(),greater<pair<ll,ll>>());
  ll sum=0;
  for(i=0;i<v.size();i++){
    if(n>v[i].second){
      sum+=v[i].first*v[i].second;
      n-=v[i].second;
    }else{
      sum+=v[i].first*n;
      n=0;
    }
    if(n==0)break;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 7664
#include <cstdio>
#include <algorithm>

#define BIT 380000.0

using namespace std;

int main() {
    int N;
    double x, sum=0;
    char u[4];
    scanf("%d", &N);
    for (int i=0; i<N; i++) {
        scanf("%lf %s", &x, u);
        if (u[0] == 'J') sum += x;
        else sum += BIT*x;
    }
    printf("%lf\n", sum);
    return 0;
}

Measured memory_bytes: 128
/*
ID: jerrywcy
TASK: AtCoder ABC 101 Problem D
LINK: https://abc102.contest.atcoder.jp/tasks/abc102_d
LANG: C++
*/
#include <bits/stdc++.h>

using namespace std;

long long d=1;
int k;
 
int sum(long long x){
	if(!x) return 0;
	return x%10+sum(x/10);
}
 
long long f(long long n){
	if(sum(n+d*10)*(n+d)>(n+d*10)*sum(n+d)) d*=10;
	return n+d;
}
 
int main(){
	cin>>k;
	int i,j;
	int cur=1;
	long long n=1;
	for(i=0;i<k;i++){
		if(i!=0) n=f(n);
		cout<<n<<endl;
	}
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const lint mod = 1e9 + 7, INF = 1e18;
lint dx[8] = { 0, -1, 1, 0, 1, -1, 1, -1 }, dy[8] = { 1, 0, 0, -1, -1, -1, 1, 1 };

lint N, K;
lint arr[200000];
lint dp[200000];
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N >> K;
	REP(i, N) {
		cin >> arr[i];
	}
	set<lint> st;
	REP(i, K) {
		st.insert(arr[i]);
	}
	dp[0] = 1;
	lint depli = 0;
	REP(i, N - 1) {
		if (arr[i] < arr[i + 1]) {
			dp[i + 1] = dp[i] + 1;
			if (dp[i + 1] >= K) depli++;
		}
		else {
			dp[i + 1] = 1;
		}
	}
	lint cnt = 0;
	if (dp[K - 1] < K) cnt++;
	FOR(i, K, N) {
		st.insert(arr[i]);
		lint minv = *st.begin();
		lint maxv = *(--st.end());
		if (dp[i] < K && !(minv == arr[i - K] && maxv == arr[i])) cnt++;
		st.erase(arr[i - K]);
	}
	cout << cnt + min(1ll, depli) << endk;
}

Measured memory_bytes: 16052
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define POW_10_5 100000
#define POW_10_9 1000000000
#define INF (numeric_limits<int>::max()/2)
#define int long long

typedef pair<int, int> Pair;
typedef unordered_map<int, int> Hash;

// ---
const int Nlim = POW_10_5;
int N, K;
Pair dt[Nlim];

int Ans() {
  sort(dt, dt+N);
  // REP(i, N) {
  //   cout << dt[i].first << " " << dt[i].second << endl;
  // }
  int ans = 0;
  Hash kind;
  FOR(i, N-K, N-1) {
    ans += dt[i].first;
    ++kind[dt[i].second];
  }
  ans += (kind.size() * kind.size());
  int ans2 = ans;
  int i = N-K;
  RFOR(j, N-K-1, 0) {
    if (kind.find(dt[j].second) == kind.end()) {
      // cout << i << " " << j << " " << endl;
      while(i < N && kind[dt[i].second] <= 1) { ++i; }
      if (i == N) { return ans; }
      ans2 -= dt[i].first;
      --kind[dt[i].second];
      ++i;
      // cout << kind.size() << endl;
      ans2 -= (kind.size() * kind.size());
      ans2 += dt[j].first;
      ++kind[dt[j].second];
      // cout << kind.size() << endl;
      ans2 += (kind.size() * kind.size());
      ans = MAX(ans, ans2);
    }
  }
  return ans;
}

signed main() {
  cin >> N >> K;
  REP(i, N) { cin >> dt[i].second >> dt[i].first; }

  auto ans = Ans();

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


Measured memory_bytes: 5260
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,M,X,A[110];
    int sum1=0,sum2=0;
    cin >> N >> M >> X;
    for(int i=0; i<M; i++){
        cin >> A[i];
    }
    for(int i=0; i<X; i++){
        for(int j=0; j<M; j++){
            if(i == A[j]){
                sum1++;
            }
        }
    }

    for(int i=X+1; i<N; i++){
        for(int j=0; j<M; j++){
            if(i == A[j]){
                sum2++;
            }
        }
    }
    int  ans = min(sum1,sum2);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<ios>
#include<iomanip>
#include<vector>
#include<list>
#include<queue>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<string>
#include<numeric>
#include<set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

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

  vector<int> ans(N, Q);
  int tmp;
  rep(i, Q){
    cin >> tmp;
    ans[tmp-1]--;
  }

  rep(i, N){
    if(K - ans[i] <= 0)
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  }
  
  return 0;
}

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

int main()
{

    long long m,n,sum;
    while(scanf("%lld%lld",&n,&m)!=EOF)
    {
        sum=0;
        if(m>n*2){
        sum+=n;
        m=m-2*n;
        m=m/4;
        sum+=m;
        }
        else
        {
            if(m%2!=0)
                m=m-1;

            sum+=m/2;
        }

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


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef struct {
	double x, y;
} coor;

void input_coor(coor *rec)
{
	scanf("%lf %lf", &rec->x, &rec->y);
}

int main(void)
{
	coor a, b, c, d;
	int n;
	int i;

	scanf("%d", &n);
	for (i = 0; i < n; i++){
		input_coor(&a);
		input_coor(&b);
		input_coor(&c);
		input_coor(&d);
		if ((a.x - b.x) * (c.y - d.y) - (a.y - b.y) * (c.x - d.x) == 0) puts("YES");
		else puts("NO");
	}

	return (0);
}

Measured memory_bytes: 620
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N, M; cin >> N >> M;
    lint ans;
    ans = min(N, M / 2);
    N -= ans; M -= 2 * ans;
    ans += M / 4;
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int x[30][30],xx,gxx,a,b,cnt,n,s[100],l[100],w,ww,www;
 
int main(){
    for(xx=0;xx<30;xx++){
        for(gxx=0;gxx<30;gxx++){
            x[xx][gxx]=0;
        }
    }
    while(1){
    	cin >> a >> b;
    	if(a==0&&b==0)break;
    	cin >> n;
    	for(int i=1;i<=a;i++){
        	for(int m=1;m<=b;m++){
            	x[i][m]=0;
        	}
    	}
    	for(int xx=0;xx<100;xx++){
        	s[xx]=0;
        	l[xx]=0;
    	}
 
    	for(int i=0;i<n;i++){
        	cin >> s[i] >> l[i];
    	}
    	x[1][1]=1;
    	for(int i=1;i<=a;i++){
        	for(int m=1;m<=b;m++){
                w=x[i][m-1]+x[i-1][m];
               	x[i][m]+=w;
            	for(int r=0;r<n;r++){
                	www=s[r];
            		ww=l[r];
                	x[www][ww]=0;
    			}
			}
		}
  		cout << x[a][b] << endl;
    }
 
    return 0;
}

Measured memory_bytes: 1164
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;

ll dp[2][5000];

int main(){
	int N,L,X[5000],A[5000];
	cin>>N>>L;
	for(int i=0;i<N;i++) cin>>X[i];
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	for(int i=0;i<N;i++){
		for(int j=0;X[i]+A[i]*j<L;j++){
			dp[i&1][X[i]+A[i]*j] = 1;
			if(A[i]==0) break;
		}
		if(i==0) continue;
		ll sum = 0;
		for(int j=0;j<L;j++){
			dp[i&1][j] = (dp[i&1][j]*sum)%MOD;
			sum += dp[(i-1)&1][j]%MOD;
			dp[(i-1)&1][j] = 0;
		}
	}
	ll ans = 0;
	for(int i=0;i<L;i++) ans += dp[(N-1)&1][i]%MOD;
	printf("%lld\n",ans%MOD);
	return 0;
}

Measured memory_bytes: 1264
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <numeric>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;

ll gcd(ll a, ll b){
    if(b == 0)
        return a;
    else
        return gcd(b, a % b);
}
ll lcm(ll a, ll b){
    return (a / gcd(a, b)) * b;
}
int main(){
    int N;
    cin >> N;
    ll T[N];
    REP(i, N) cin >> T[i];
    ll ans = 1LL;
    FOR(i, 0, N){
        ans = (ll)lcm(T[i], ans);
    }
    cout << (ll)ans << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int y, m, d;
    char c;
    cin >> y >> c >> m >> c >> d;

    if(y <= 2019 && m <= 4 && d <= 31){
        cout << "Heisei" << endl;
    }else{
        cout << "TBD" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.io.*;

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

        String[] str1 = br.readLine().split(" ");
        int r = Integer.parseInt(str1[0]);
        int c = Integer.parseInt(str1[1]);
        int[][] data = new int[r][c];
        int[] sumR = new int[r];
        int[] sumC = new int[c];
        int sumX = 0;

        // r x c ????¨??????\????????????????´???????
        for(int i=0; i<r; i++){
            String[] str2 = br.readLine().split(" ");
            for(int k=0; k<c; k++){
                data[i][k] = Integer.parseInt(str2[k]);
            }
        }

        // sumR ??¨ sumX ????¨??????????
        for(int i=0; i<r; i++){
            for(int k=0; k<c; k++){
                sumR[i] += data[i][k];
            }
            sumX += sumR[i];
        }
        // sumC ????¨??????????
        for(int i=0; i<c; i++){
            for(int k=0; k<r; k++){
                sumC[i] += data[k][i];
            }
        }

        // ??????
        for(int i=0; i<r; i++){
            for(int k=0; k<c; k++){
                sb.append(data[i][k]).append(" ");
            }
            sb.append(sumR[i]).append("\n");
        }
        for(int k=0; k<c; k++){
            sb.append(sumC[k]).append(" ");
        }
        sb.append(sumX).append("\n");

        System.out.print(sb);
    }
}

Measured memory_bytes: 27652
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int a, b, c, k;

int main() {
  scanf("%d%d", &a, &b);
  scanf("%d", &c);
  scanf("%d", &k);
  if(a >= b && a >= c) {
    a <<= k;
  } else {
    if(b >= a && b >= c) {
      b <<= k;
    } else {
      c <<= k;
    }
  }
  printf("%d\n", a + b + c);
  return 0;
}


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

int main()
{
	ll L, R;
	cin >> L >> R;

	ll ans = 2019;
	for (ll i = L; i < R; ++i)
	{
		for (ll j = i + 1; j <= R; ++j)
		{
			ans = min(ans, (i * j) % 2019);
			if (ans == 0)
			{
				cout << ans << endl;
				return 0;
			}
		}
	}

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


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;
int main()
{
    int i,n,sum=0;
    char a[1000000];
    gets(a);
    n=strlen(a);
    for(i=0;i<n-1;i++)
    {
        if(a[i]!=a[i+1])sum++;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n, a, b, ans = 0;
    scanf("%lld %lld %lld", &n, &a, &b);
    if(a%2ll != b%2ll){
        if(n-b > a-1ll){
            b -= a;
            ans += a;
            a = 1ll;
        }
        else{
            a += n - b + 1;
            ans += n - b + 1;
            b = n;
        }
    }
    ans += (b-a)/2ll;
    printf("%lld\n", ans);
}

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

b = [0] * (n + 2)
b[0] = 1

for i in range(m):
   b[int(input())] = -1

for i in range(n):
   if (b[i] != -1):
      if (b[i+1] != -1):
         b[i+1] += b[i]
      if (b[i+2] != -1):
         b[i+2] += b[i]

print(b[n] % 1000000007)


Measured memory_bytes: 462708
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <set>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> ii;

int main() {
  ios_base::sync_with_stdio(0);
  unordered_map<ll, ll> cc;
  ll h, w, n;
  cin >> h >> w >> n;
  ll count[10]; memset(count, 0, sizeof count);
  ll sum = 0;
  ll x = 1e9;
  for (int i = 0; i < n; i++) {
    ll a, b;
    cin >> a >> b;
    a--; b--;
    for (int j = -2; j <= 0; j++) {
      for (int k = -2; k <= 0; k++) {
        ll r = a+j;
        ll c = b+k;
        if (r >= 0 && c >= 0 && r+2 < h && c+2 < w) {
          int d = ++cc[r*x+c];
          if (d-1 == 0) {
            sum++;
          } else {
            --count[d-1];
          }
          ++count[d];
        }
      }
    }
  }
  count[0] = (h-3+1)*(w-3+1)-sum;
  for (int i = 0; i < 10; i++) {
    cout << count[i] << '\n';
  }
}


Measured memory_bytes: 36624
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <climits>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
#include <functional>
#include <algorithm>
#include <bitset>

using namespace std;

#define cin_desync()                      \
	do {                                  \
		ios_base::sync_with_stdio(false); \
		cin.tie(0);                       \
	} while (0)                           \

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}

#else
#define trace(...)
#endif // ifndef ONLINE_JUDGE

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

const int max_N = 2e3 + 10;
bitset<max_N * max_N * 2> dp[2];

int main()
{
	const int offset = max_N * max_N;
	dp[0][0 + offset] = true;

	int N;
	cin >> N;

	int all_sum = 0;
	for (int i = 1; i <= N; ++i) {
		int x;
		cin >> x;
		all_sum += x;

		int curr = i % 2, prev = !curr;
		dp[curr] = (dp[prev] >> x) | (dp[prev] << x);
	}

	int min_diff = max_N;
	for (int i = 0; i < 2 * max_N * max_N; ++i) {
		if (dp[N % 2][i]) {
			min_diff = min(min_diff, abs(i - offset));
		}
	}

	cout << (all_sum + min_diff) / 2 << endl;
}


Measured memory_bytes: 6144
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//typedef long long ll;
int main(void)
{
  char str[11],ttr[12],dm;
  scanf("%s",str);
  scanf("%c",&dm);
  scanf("%s",ttr);
  ///printf("%s",ttr);
  int l=strlen(ttr),ss=strlen(str),flag=1;;
  
  for(int i=0;i<ss;i++){
    if(str[i]!=ttr[i]) flag=0; 
  }
  if(ss+1!=l) flag=0;
  if(flag==1) printf("Yes");
  else printf("No");
  
  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll x,y;
	cin >> x >> y;

	vector<ll> v;
	v.push_back(x);

	ll t = 2 * x;
	while(t <= y){
		v.push_back(t);
		t *= 2;
	}

	cout << v.size() << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <functional>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#define SIZE 200005
#define MOD 1000000007
#define BT 256*1024*2

using namespace std;
typedef pair <int,int> P;
typedef long long int ll;

struct BIT
{
	ll bit[SIZE];
	
	void init()
	{
		memset(bit,0,sizeof(bit));
	}
	void add(int k,ll x)
	{
		k++;
		while(k<SIZE)
		{
			bit[k]+=x;
			if(bit[k]>=MOD) bit[k]-=MOD;
			k+=k&-k;
		}
	}
	ll get(int k)
	{
		k++;
		ll ret=0;
		while(k>0)
		{
			ret+=bit[k];
			if(ret>=MOD) ret-=MOD;
			k-=k&-k;
		}
		return ret;
	}
	ll get(int s,int t)
	{
		return (get(t)-get(s-1)+MOD)%MOD;
	}
};
BIT bit;
int X[SIZE],V[SIZE];
vector <int> vec[SIZE];
int pos[SIZE];
ll dp[SIZE];
int back[SIZE];
int to[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	vector <int> vx,vv;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&X[i]);
		scanf("%d",&V[i]);
		vx.push_back(X[i]);
		vv.push_back(V[i]);
	}
	sort(vx.begin(),vx.end());
	sort(vv.begin(),vv.end());
	for(int i=0;i<n;i++)
	{
		X[i]=lower_bound(vx.begin(),vx.end(),X[i])-vx.begin();
		V[i]=lower_bound(vv.begin(),vv.end(),V[i])-vv.begin();
		pos[X[i]]=V[i];
	}
	pos[n]=n;
	n++;
	set <P> st;
	set <P>::iterator it;
	for(int i=0;i<n;i++)
	{
		st.insert(P(pos[i],i));
		it=st.end();it--;
		to[i]=it->first;
	}
	st.clear();
	for(int i=n-1;i>=0;i--)
	{
		st.insert(P(pos[i],i));
		it=st.begin();
		back[i]=it->first;
	}
	//back->toがたくさんできて、それで[0,n-1]を覆う問題になる
	for(int i=0;i<n;i++) vec[to[i]+1].push_back(back[i]);
	dp[0]=1;
	bit.init();
	bit.add(0,1);
	for(int i=1;i<=n;i++)
	{
		sort(vec[i].begin(),vec[i].end());
		dp[i]=0;
		for(int j=0;j<vec[i].size();j++)
		{
			int to=vec[i][j];
			dp[i]=(dp[i]*2LL+bit.get(to,i))%MOD;
		}
		bit.add(i,dp[i]);
	}
	printf("%lld\n",dp[n]);
	return 0;
}


Measured memory_bytes: 29164
#include<stdio.h>
int main(void)
{
	int m,nmin,nmax,a[200],i,gap,gmax,n;
	
	while(scanf("%d %d %d",&m,&nmin,&nmax))
	{
		gmax = 0;
		
		if(m==0 && nmin==0 && nmax==0)
		{
			break;
		}
		
		for(i=0;i<m;i++)
		{
			scanf("%d",&a[i]);
			
			if(i>=nmin && i<=nmax)
			{
				gap = a[i-1] - a[i];
				
				if(gap>=gmax)
				{
					gmax = gap;
					n = i;
				}
					
			}
		}
		
		printf("%d\n",n);
	}
	
	return 0;
}
		
		


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

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0);
#define endl            "\n"
#define NUM             10005
#define MAX             12345678

typedef long long ll;

ll h,n;
ll a[NUM],b[NUM],memo[NUM];

long long solve()
{
    ll sum = 0,mx;
    memo[0] = 0;
    for(ll i=1;i<=h;i++)
    {
        for(ll j=0;j<n;j++)
        {
            mx = max(0LL,i-a[j]);
            memo[i] = min(memo[mx]+b[j],memo[i]);
            //cout<<memo[i]<<mx;
        }
    }

    return memo[h];
}

int main()
{
    FastRead

    memset(memo,MAX,sizeof(memo));

    cin>>h>>n;

    for(ll i=0;i<n;i++)
        cin>>a[i]>>b[i];

    cout<<solve();

}


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

const int INF = 1e9 + 5;

int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for(int i=0; i < n; i++)
	cin >> h[i];
  vector <int> dp(n, INF);
  dp[0] = 0;
  for(int i=0; i < n; i++)
      {
        for(int j = i + 1; j <= i + k; j++)
        {
          if(j < n)
          	dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
        }
      }
   cout << dp[n-1];
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	string s[3];
	cin >> n >> s[0] >> s[1] >> s[2];
	int ans=0;
	for(int i=0; i<n; i++){
		int c=0;
		if(s[0][i]!=s[1][i]) c++;
		if(s[1][i]!=s[2][i]) c++;
		if(s[2][i]!=s[0][i]) c++;
		ans+=max(c-1,0);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,a,b,c = inpl()
l = inpln(n)
x = [a,b,c]
res = INF

for flag in itertools.product(range(4), repeat=n):
    cnt = 0
    xx = [[]for i in range(4)]
    for i,bit in enumerate(flag):
        xx[bit].append(i)
    for i in range(3):
        if xx[i] == []:
            break
        cnt += (len(xx[i]) - 1)*10
        sum = 0
        for j in xx[i]:
            sum += l[j]
        cnt += abs(sum-x[i])
    else:
        res = min(res,cnt)
print(res)

Measured memory_bytes: 71768
#include<iostream>
using namespace std;
int main(){
    int r, c;
    cin >> r >> c;
    int A[r][c];
    int sumR[r];
    int sumC[c+1];
    
    for(int i = 0; i < r; i++){//配列の初期化
        sumR[i] = 0;
        for(int j = 0; j < c+1; j++){
            A[i][j] = 0;
            sumC[j] = 0;
        } 
    }

    
    for(int n1 = 0; n1 < r; n1++){
        for(int m1 = 0; m1 < c; m1++){
            int a;
            cin >> a;
            A[n1][m1] = a;//入力
            
            sumR[n1] += A[n1][m1];//ついでに各行の合計も計算
        }
    }
    
    for(int m2 = 0; m2 < c+1; m2++){//各列の合計を計算
        if(m2 == c){
            for(int n2 = 0; n2 < r; n2++){
                sumC[m2] += sumR[n2];
            }
        } else {
            for(int n22 = 0; n22 < r; n22++){
                sumC[m2] += A[n22][m2];
            }
        }
    }
    
    for(int n3 = 0; n3 < r+1; n3++){
        for(int m3 = 0; m3 < c+1; m3++){
            if(m3 == 0 && n3 != r){
                cout << A[n3][m3];
            } else if(m3 == c && n3 != r){
                cout << " " << sumR[n3] << endl;
            } else if(m3 == 0 && n3 == r){
                cout << sumC[m3];
            } else if (m3 != 0 && n3 == r){
                cout << " " << sumC[m3];
            } else {
                cout << " " << A[n3][m3];
            }
        }
    }
    
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main(){
    LL n;
    string s;
    map<string, LL> st;
    LL m;
    string t;
    cin >> n;
    for(LL i=0; i<n; i++){
        cin >> s;
        st[s]++;
    }
    cin >> m;
    for(LL i=0; i<m; i++){
        cin >> t;
        st[t]--;
    }
    LL kiyu=0;
    for(auto itr=st.begin(); itr!=st.end(); itr++){
        kiyu=max(kiyu, itr->second);
    }

    cout << kiyu << endl;

    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
const ll longinf=1LL<<60;
using namespace std;

int n,m,k;

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



Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string input_string;
    bool flag=true;
    getline(cin,input_string);
  	if(input_string.length()%2){cout<<"No";return 0;}
    for(int i=0;i<input_string.length();i++)
    {
        if(i%2&&input_string[i]!='i'){cout<<"No";flag=false;break;}
        else if(i%2==0&&input_string[i]!='h'){cout<<"No";flag=false;break;}
    }
    if(flag)
    cout<<"Yes";
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>

using namespace std;

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

const int MX = 2e5;

int main() {
  int n;
  cin >> n;
  int a[n];
  rep (i, n) cin >> a[i];
  double dp[2][MX];
  rep (i, 2) rep (j, MX) dp[i][j] = 1e99;
  dp[0][1] = 0;
  rep (i, n) {
    rep (j, MX) if (j > 0) for (int k = j; k < MX; k += j) dp[1][k] = min(dp[1][k], max(dp[0][j], (double)abs(k - a[i]) / a[i]));
    rep (j, MX) dp[0][j] = dp[1][j];
    rep (j, MX) dp[1][j] = 1e99;
  }
  double res = 1e99;
  rep (i, MX) res = min(res, dp[0][i]);
  printf("%.12lf\n", res);
}

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

ll mod=1000000007;

int main(){
    ll N,K;
    cin >> N >> K;
    ll A[N];
    ll B[2*N];
    rep(i,N) cin >> A[i];

    ll ans = 0;
    rep(i,N){
        ll count1 = 0;
        ll count2 = 0;
        for(ll j=i+1;j<N;j++){
            if(A[i]>A[j]){
                count1++;
            }
        }
        rep(j,N){
            if(A[i]>A[j]){
                count2++;
            }
        }
        ans = (ans%mod+count1%mod*K+((K*(K-1))/2)%mod*count2%mod)%mod;
    }

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

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

int main(){
	char ch;
	int tot;
	cin >> ch ;
	if( ch == '1' )
		tot++;
	cin >> ch ;
	if( ch == '1' )
		tot++;
	cin >> ch ;
	if( ch == '1' )
		tot++;
	cout << tot << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long K = sc.nextLong();
        if((A+B) >= K){
            System.out.println(Math.min(K, A));
        }else{
            long ans = A - (K-A-B);
            System.out.println(ans);
        }
    }

}


Measured memory_bytes: 35748
#####segfunc#####
def segfunc(x, y): #演算の選択（今回は最大値）
    return max(x, y)
#################

#####ide_ele#####
ide_ele = -1      #単位元（任意のものとsegfuncした時、その値をかえないようなもの。）
#################

class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(logN)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x): #k番目の要素をxに更新。
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r): #半開区間[l, r)の最大値（segfuncしたもの）を取得。
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

      
#ここから本処理

#やりたいこと: data[i][n] = (左からi番目までを見た時に、最後がnで終わる部分列の最大の長さ)
# 更新: data[i+1][A[i+1]] = max{data[i][n] | n s.t. abs(A[i+1]-n) <= K} +1
#       ※ A[i+1]以外のnについては、data[i+1][n] = data[i][n]

# 高速化が必要
# 考察： 1, iを1ずつ増やすループで、data[i]から値が変更するのは data[i+1][A[i+1]]だけ。
#            →data[i][n]を二次元配列で持つのは無駄が多い。
#             単にdata[n]として、A[i+1]のところだけ更新すれば十分。
#       2, data[A[i+1]]の更新のとき、abs(A[i+1]-n) <= K を満たすnから、
#          data[n]の最大値を選ぶ必要あり。
#            →愚直に調べるとK回かかってしまう。
#             区間[A[i+1]-K, A[i+1]+K]の最大値を素早く知るため、セグメントツリーを使う。

# セグメントツリーでできること：
#      1, 配列の一つの要素を更新する。(O(logN))
#      2, 任意の区間[a,b]の中で、配列data[a:b]の最大値を求める。
#         ※なお、「最大」だけでなく「最小」や「和」、「行列の積」などについても適用可能(結合律と単位元)。

N, K = map(int,input().split())
Num_max = 3*10**5 + 1

A = [int(input()) for _ in range(N)]
# 配列 data = [0,0,0,…](初期値は0番目まで見た時の最長部分列の長さなので全て0) をセグメントツリー化する。
# 初期値、使いたい演算（最大）、その演算の単位元を入力
st = SegTree([0 for _ in range(Num_max+4)], segfunc, ide_ele) #「+4」に意味はないです。十分大きければ良いです。

st.update(A[0], 0)  
for i in range(N):
  l = st.query(max(A[i] - K, 0), min(A[i] + K+1, Num_max)) # 半開区間[A[i]-K, A[i]+K+1)の最大値を取得
  st.update(A[i], l+1)  # data[A[i]]をl+1で更新(73行目の漸化式)。

print(st.query(0, Num_max)) #配列中で最大の要素を取得。


Measured memory_bytes: 127944
#include <stdio.h>
int main(){
  int box[4][13];
  int n,i,C,N,t,d;
  char r, c;
  for(C=1;C<=4;C++){
    for(t=1;t<=13;t++){
      box[C-1][t-1]=0;
    }
  }
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%c",&c);    
    scanf("%c",&c);    
    scanf("%d",&t);
    
   
    if(c=='S'){
      C=1;
    }
    if(c=='H'){
      C=2;
    }
    if(c=='C'){
      C=3;
    }
    if(c=='D'){
      C=4;
    }
   
    box[C-1][t-1]=1;
  }

  

  for(C=1;C<=4;C++){
    for(t=1;t<=13;t++){     
      if(box[C-1][t-1]==0){
	if(C==1){
	  c='S';
	}
	if(C==2){
	  c='H';
	}	
	if(C==3){
	  c='C';
	}
	if(C==4){
	  c='D';
	}	
	
	printf("%c %d\n",c,t);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main{
    static Scanner sc = new Scanner(System.in);

    static long x = sc.nextLong();
    static long y = sc.nextLong();
    static int t = (int)(x+y)/3;

    static long MOD = (int)1e9+7;

    static long[] facts = new long[t+1];

    public static void main(String[] args){
        facts[0] = 1;
        for (int i=1; i<t+1; i++){
            facts[i] = facts[i-1]*i %MOD;
        }


        if ((x+y)%3!=0){
            System.out.println(0);
            return;
        }

        long ans = 0;


        for (int i=0; i<t+1; i++){
            int a = i;
            int b = t-a;
            if (((a+b*2)!=x) || ((a*2+b)!=y)){
                continue;
            }
//            System.out.println(t);
//            System.out.println(a);

            ans += nck(t, a);
            ans %= MOD;
        }
        System.out.println(ans%MOD);


    }
    public static long modpow(long a, long b){
        if (b==0) return 1;
        else if (b==1) return a;
        long x = modpow(a, b/2);
        return b%2==0 ? x*x%MOD : x*(x*a%MOD)%MOD;
    }
    public static long inv(long n){
        return modpow(n, MOD-2);
    }
    public static long nck(int n, int k){
        return n<k ? 0: facts[n]*(inv(facts[n-k])*inv(facts[k])%MOD)%MOD;
    }
}

Measured memory_bytes: 29396
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <stdlib.h>
using namespace std;

int main(void) {
	string s;
	stack<int> stk;
	while (cin>>s) {
		if (s == "+") {
			int a = stk.top();
			stk.pop();
			int b = stk.top();
			stk.pop();
			stk.push(b + a);
		}
		else if (s == "-") {
			int a = stk.top();
			stk.pop();
			int b = stk.top();
			stk.pop();
			stk.push(b - a);
		}
		else if (s == "*") {
			int a = stk.top();
			stk.pop();
			int b = stk.top();
			stk.pop();
			stk.push(b * a);
		}
		else {
			stk.push(atoi(s.c_str()));
		}
	}
	cout << stk.top() << endl;
	return 0;
}


Measured memory_bytes: 3204
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF=1<<29;

vector<P> table[100001]; //隣接リスト to,cost
ll d[100001]; //S→Gのcost
bool used[100001];
priority_queue<P> que;

void dijkstra(ll s){
	fill(d,d+100001,LLONG_MAX);
	fill(used,used+100001,false);
	d[s]=0;
	que.push(P(s,0));

	while(!que.empty()){

		ll Rto=que.top().first, Rcost=que.top().second; //中継点(Relay),S→Rのcost
		que.pop();
		if(used[Rto]) continue;
		if(Rcost > d[Rto]) continue;
		used[Rto]=true;

		for(int i=0;i<table[Rto].size();i++){
			ll to=table[Rto][i].first, cost=table[Rto][i].second; //目的地(G),R→Gのcost
			if(d[to] > cost + Rcost){
				d[to] = cost + Rcost;
				que.push( P(to,d[to]) );
			}
		}

	}
	return;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N;
	cin>>N;
	for(int i=0;i<N-1;i++){
		ll x,y,z;
		cin>>x>>y>>z;
		table[x].push_back(P(y,z));
		table[y].push_back(P(x,z));
	}
	dijkstra(1);
	for(int i=1;i<=N;i++){
		//cout<<d[i];
		if(d[i]%2==0) cout<<0<<endl;
		else cout<<1<<endl;
	}
	return 0;
}

Measured memory_bytes: 7296
# 解説放送の方針
# ダメージが消える右端をキューで管理
# 右端を超えた分は、累積ダメージから引いていく

from collections import deque

N,D,A=map(int,input().split())
XH = [tuple(map(int,input().split())) for _ in range(N)]

XH = sorted(XH)
que=deque()
cum = 0
ans = 0
for i in range(N):
  x,h = XH[i]
  if i == 0:
    r,n = x+2*D,(h+A-1)//A
    d = n*A
    cum += d
    que.append((r,d))
    ans += n
    continue
  while que and que[0][0]<x:
    r,d = que.popleft()
    cum -= d
  h -= cum
  if h<0:
    continue
  r,n = x+2*D,(h+A-1)//A
  d = n*A
  cum += d
  que.append((r,d))
  ans += n
  
print(ans)

Measured memory_bytes: 51116
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  ll a,b,x;
  cin >> a >> b >> x;
  ll left = max(a - 1, 0LL) / x, right = b / x;
  if(!a) right++;
  cout << right - left << endl;
}

Measured memory_bytes: 256