akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, m; scanf("%d%d", &n, &m);
    vector<vector<pair<int, int>>> cond(n + 1);
    for (int i = 0; i < m; ++i) {
        int l, r, x; scanf("%d%d%d", &l, &r, &x);
        cond[r].emplace_back(l, x);
    }
    vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(n + 1, vector<int>(n + 1)));
    constexpr int kMod = 1'000'000'000 + 7;
    dp[0][0][0] = 1;
    for (int r = 0; r < n; ++r) {
        for (int g = 0; g < n; ++g) {
            for (int b = 0; b < n; ++b) {
                if (dp[r][g][b] == 0) continue;
                int pos = max(max(r, g), b) + 1;
                {
                    int nr = pos, ng = g, nb = b;
                    bool ok = true;
                    for (auto p : cond[pos]) {
                        int cnt = (nr >= p.first) + (ng >= p.first) + (nb >= p.first);
                        ok &= cnt == p.second;
                    }
                    if (ok) (dp[nr][ng][nb] += dp[r][g][b]) %= kMod;
                }
                {
                    int nr = r, ng = pos, nb = b;
                    bool ok = true;
                    for (auto p : cond[pos]) {
                        int cnt = (nr >= p.first) + (ng >= p.first) + (nb >= p.first);
                        ok &= cnt == p.second;
                    }
                    if (ok) (dp[nr][ng][nb] += dp[r][g][b]) %= kMod;
                }
                {
                    int nr = r, ng = g, nb = pos;
                    bool ok = true;
                    for (auto p : cond[pos]) {
                        int cnt = (nr >= p.first) + (ng >= p.first) + (nb >= p.first);
                        ok &= cnt == p.second;
                    }
                    if (ok) (dp[nr][ng][nb] += dp[r][g][b]) %= kMod;
                }
            }
        }
    }
    int ans = 0;
    for (int r = 0; r <= n; ++r) {
        for (int g = 0; g <= n; ++g) {
            for (int b = 0; b <= n; ++b) {
                if (r == n || g == n || b == n) (ans += dp[r][g][b]) %= kMod;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 110336
#include <iostream>

using namespace std;

main(){
  int ih, im, is, oh, om, os;
  while(cin >> ih >> im >> is >> oh >> om >> os){
    int in=ih*3600+im*60+is;
    int out=oh*3600+om*60+os;
    int ans=out-in;
    int ah=ans/3600;
    ans-=ah*3600;
    int am=ans/60;
    ans-=am*60;
    int as=ans;
    printf("%d %d %d\n", ah, am, as);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}


int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	// freopen("settling.in", "r", stdin);
	// freopen("settling.out", "w", stdout);

	int n;
	ll d;
	cin >> n >> d;

	int ans = 0;

	for(int i = 0; i < n; i++){
		ll x, y;
		cin >> x >> y;

		if(x * x + y * y <= d * d)
			ans++;
	}

	cout << ans << endl;

	return 0;
}


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

const int INF =1001001001;
const ll BIG = 1000000007;
/*
int main(){
    int k;
    cin>>k;
    vector<ll> a;
    for(int i=1; i<=9;i++) a.push_back(i);
    while(1){
        if(k<=k.size()){
            cout << a[k-1] <<endl;
            return 0;
        }
        k -= s.size();
        vector<ll> old;
        swap(old,a);
        for(ll x: old){
            for(int i=-1; i<=1; i++){
                int d = x*10+i;
                if(d<0||d>9) continue;
                ll nx = x*10+d;
                a.push_back(nx);
            }
        }
    }
    return 0;
}
*/

int main(){
    int k;
    cin >> k;
    vector<ll> a;
    for(int i=1; i<=9; i++) a.push_back(i);
    while(1){
        if(k<=a.size()){
            cout << a[k-1] << endl;
            return 0;
        }
        k -= a.size();
        vector<ll> old;
        swap(old,a);
        for(ll x: old){
            for(int i=-1; i<=1; i++){
                int d = x%10+i;
                if(d<0||d>9) continue;
                ll nx = x*10+d;
                a.push_back(nx);
            }
        }
    }
    return 0;

}

Measured memory_bytes: 1712
from bisect import bisect_right

while True:
    N, M = [int(x) for x in input().split()]
    if N == 0 and M == 0:
        break

    _P = [0] * N

    for i in range(N):
        _P[i] = int(input())
    _P.append(0)

    P = list(set(x + y for x in _P for y in _P))
    P.sort()

    ans = 0

    for p in P:
        if p > M // 2:
            break
        i = bisect_right(P, M - p)
        ans = max(ans, p + P[i - 1])

    print(ans)



Measured memory_bytes: 74208
n, m = map(int, (input().split()))
h = list(map(int, input().split()))
p = [1]*n
max = 0
for i in range(m):
    a, b = map(int, (input().split()))
    if h[a-1] <= h[b-1]:
        p[a-1] = 0
    if h[a-1] >= h[b-1]:
        p[b-1] = 0
print(sum(p))


Measured memory_bytes: 20076
import sys
input = sys.stdin.readline
def marge(A, left, right, mid):
    cnt = 0
    n1 = mid - left
    n2 = right - mid
    L = [0] * (n1 + 1)
    R = [0] * (n2 + 1)
    for i in range(n1):
        L[i] = A[left + i]
    for i in range(n2):
        R[i] = A[mid + i]
    L[n1] = 10 ** 9 + 1
    R[n2] = 10 ** 9 + 1
    i = 0
    j = 0
    for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return cnt
def margesort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        cnt1 = margesort(A, left, mid)
        cnt2 = margesort(A, mid, right)
        return cnt1 + cnt2 + marge(A, left, right, mid)
    return 0

def main():
    n = int(input())
    A = list(map(int, input().split()))
    cnt = margesort(A, 0, n)
    print(' '.join(list(map(str, A))))
    print(cnt)

if __name__ == '__main__': main()


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

// limit
#define mod1 22439423LL
#define mod2 42342432LL
#define mod3 56454765LL
#define mod4 66867574LL
#define oo 1000000007LL
#define OO 1000000000000000007LL
#define maxN 1000007

// loop
#define fto(i, x, y) for(int i = (x); i <= (y); ++i)
#define fdto(i, x, y) for(int i = (x); i >= (y); --i)
#define ftoa(i, x, y, a) for(int i = (x); i <= (y); i += a)
#define fdtoa(i, x, y, a) for(int i = (x); i >= (y); i -= a)
#define ftosqrt(i, x, y) for(int i = (x); i*i <= (y); ++i)
#define ftoit(it, var) for (__typeof(var.begin()) it = var.begin(); it != var.end(); ++it)
#define fdtoit(rit, var) for (__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); ++rit)

// debug
#define debug cout << "*" << endl;
#define bug1d(a, x, y) { cout << #a << ": "; fto(_, x, y) cout << a[_] << ' '; cout << endl; }
#define bug2d(a, x, y, u, v) { cout << #a << ": " << endl; fto(i, x, y) {fto(j, u, v) cout << a[i][j] << ' '; cout << endl;}; cout << endl;}
#define bug(a) cout << #a << " = " << a << endl;
#define bug2(a, b) cout << #a << " = " << a << "; "; cout << #b << " = " << b << endl;
#define bug3(a, b, c) cout << #a << " = " << a << "; "; cout << #b << " = " << b << "; "; cout << #c << " = " << c << endl;

// operation
#define mp make_pair
#define pb push_back
#define pf push_front
// structure
#define ii pair<int, int>
#define iii pair<ii, int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>
#define matrix vector<vi>

// get value
#define FF first
#define SS second

// data type
#define ll long long
#define ull unsigned long long

// function
#define lb lower_bound
#define ub upper_bound

// const value
#define pi 3.14159265358979323846264338327950288419716939937510

using namespace std;

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T min(T a, T b, T c, T d) {
    return min(a, min(b, min(c, d)));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

template <class T>
T max(T a, T b, T c, T d) {
    return max(a, max(b, max(c, d)));
}

bool cmp(const ii& a, const ii& b) {return (a.FF > b.FF || (a.FF == b.FF && a.SS >= b.SS));}
ll GCD(ll a, ll b) {return (a%b) ? GCD(b, a%b) : b;}

const string namePro = "tmp";

ll a[maxN];

int main() {

    ll cur = 0LL, t;
    int n;

    scanf("%d%lld", &n, &t);
    fto (i, 1, n) scanf("%lld", &a[i]);

    ll ans = t;
    fto (i, 1, n) {
        ans += min(a[i]-cur, t);
        cur = a[i];
    }

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

Measured memory_bytes: 1792
/*
	Code written by Talant I.D.
*/
 
#include <bits/stdc++.h> 
 
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tiii;
 
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define lb lower_bound 
#define ub upper_bound 
#define mp make_pair
#define mt make_tuple
#define mod ll(1e9+7)
#define eps double(1e-9)
#define PI 2*acos(0.0)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define curMod 998244353
 
inline bool isvowel(char ch){
	ch = tolower(ch);
	return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'y');
}
 
inline bool isprime(int n){
	if(n < 2 || (n % 2 == 0 && n != 2))
		return false;
	for(int i = 3; i*i <= n; i += 2)
		if(n%i == 0) return false;
	return true;
}

int main(){
	do_not_disturb
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	
	int n, in1 = 1, in2 = 1, i;
	cin >> n;
	vector <int> v(n), s(n);
	for(auto &to : v) cin >> to;
	for(auto &to : s) cin >> to;
	vector <int> h = v;
	sort(all(h));
	do{
		if(v == h){
			break;
		}
		in1++;
	}
	while(next_permutation(all(h)));
	sort(all(h));
	do{
		if(s == h){
			break;
		}
		in2++;
	}
	while(next_permutation(all(h)));
	
	cout << abs(in1-in2);
	return 0;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
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(a>b){a=b;return 1;}return 0;}
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  int n,taka,aoki;
  cin>>n>>taka>>aoki;
  taka--;aoki--;
  vector<vector<ll>> adj(n);
  vector<ll> deg(n);
  rep(i,n-1){
    int u,v;
    cin>>u>>v;
    u--;v--;
    adj[u].emplace_back(v);
    adj[v].emplace_back(u);
    deg[u]++;deg[v]++;
  }

  auto calcdist = [&](ll s){
    queue<pll> que;
    que.emplace(s,0);
    vector<ll> dist(n,INF);
    while(!que.empty()){
      ll v,c;
      tie(v,c) = que.front();
      que.pop();
      if(chmin(dist[v],c)){
        for(auto nv:adj[v]){
          if(dist[nv]!=INF)continue;
          que.emplace(nv,c+1);
        }
      }
    }
    return dist;
  };

  auto dist1 = calcdist(aoki);
  auto dist2 = calcdist(taka);

  ll ans = -1;
  rep(i,n){
    if(dist1[i]>dist2[i]){
      chmax(ans,dist1[i]-1);
    }
  }
  cout<<(ans)<<endl;


}


Measured memory_bytes: 8876
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val S = sc.next()
  val f = (s: String) => s == s.reverse
  val i = (S.length - 1) / 2
  println(if (f(S) && f(S.take(i)) && f(S.reverse.take(i))) "Yes" else "No")
}


Measured memory_bytes: 55380
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <stack>
using namespace std;
using ll = long long;
using ull = unsigned long long;
int main(int argc, char *argv[]) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);//incompatible with `while (cin >> ...)'
    int K;
    cin >> K;
    if (K & 1){
        int t = K >> 1;
        cout << t * (t + 1);
    }
    else {
        int t = K >> 1;
        cout << t * t;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

int main(){
  int n, m; cin >> n >> m;
  vvi G(n);
  rep(i, m){
    int a,b,c; cin >> a >> b >> c;
    a--; b--;
    G[a].pb(b); G[b].pb(a);
  }

  queue<int> q;
  vi dist(n,-1);

  int ans = 0;
  rep(i, n){
    if(dist[i] != -1) continue;
    ans++;
    dist[i] = 0; q.push(i);
    while (!q.empty()) {
      int v = q.front(); q.pop();
      for(auto nv : G[v]){
        if(dist[nv] != -1) continue;
        dist[nv] = dist[v] + 1;
        q.push(nv);
      }
    }
  }

  std::cout << ans << '\n';
}


Measured memory_bytes: 6904
s = int(input())
def p(n):
    if n%2 ==0:
        return n//2
    else:
        return 3*n+1
l = [s]
cnt = 1
while True:
    cnt +=1
    s = p(s)
    if s in l:
        print(cnt)
        exit()
    else:
        l.append(s)

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
using ll = long long;

int main() {
    FAST;

    char c;
    cin >> c;
    cout << ((c > 'Z') ? 'a' : 'A');

    return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
using namespace std;

int main(){
    int a,b;cin>>a>>b;
    if(a<=8&&b<=8)cout<<"Yay!"<<endl;
    else cout<<":("<<endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
def cumsum(x):
    return list(np.cumsum(x))

def cumsum_number(N,K,x):
    ans=[0]*(N-K+1)
    number_cumsum = cumsum(x)
    number_cumsum.insert(0,0)
    for i in range(N-K+1):
        ans[i]=number_cumsum[i+K]-number_cumsum[i]
    return ans
"""
int #整数
float #小数

#for
for name in fruits: #fruitの頭から操作
    print(name)

#リスト
list0 = [] #リスト生成
list0 = [1,2,3,4] #初期化
list0 = [0]*10 #[0,0,0,0,0,0,0,0,0,0]
list1= [i for i in range(10)] #>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list1 = list(map(int, input().split()))　# 複数の入力をリストに入れる
number=[int(input()) for i in range(int(input()))] #複数行の入力をリストに
list1 = list1 + [6, 7, 8] #リストの追加
list2.append(34) #リストの追加　最後に（）内が足される
list.insert(3,10) #リストの追加　任意の位置（追加したい位置,追加したい値）
len(list4) #リストの要素数
max(sa) #list saの最小値
list5.count(2) #リスト(文字列も可）内の2の数
list1.sort() #並び替え小さい順
list1.sort(reverse=True)  #並び替え大きい順
set(list1) #list1内の重複している要素を削除し、小さい順に並べる
sum([2,3,   ,3]) #リストの合計

abs(a) #aの絶対値
max(a,b) min(a,b) #最大値　最小値
text1 = text1.replace("34","test") #text1内の"34"を"test"に書き換える(文字列内の文字を入れ替える)

exit(0) #強制終了

cumsum(リスト) #累積和をリストで返す
cumsum_number(N,K,x) #N個の数が含まれるリストx内のK個からなる部分和をリストで返す
"""
X=int(input())
happy=0
if X>=500:
    happy += 1000*(X//500)
    X -= 500*(X//500)
if X>=5:
    happy += 5*(X//5)
print(happy)


Measured memory_bytes: 26956
import collections
N = int(input())
A = list(map(int, input().split()))
d = [[x, y] for x, y in collections.Counter(A).items() if y > 1]
d.sort(reverse=True)
if len(d) > 0:
    if d[0][1] >= 4:
        print(d[0][0]**2)
    elif len(d) > 1:
        print(d[0][0]*d[1][0])
else:
    print(0)

Measured memory_bytes: 18592
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+100;
const int mod = 1e9+7;
int main() {
	int a,b;
	sd(a);sd(b);
	ll ans=a;ans*=b;
	ans/=gcd(a,b);
	plld(ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
  string S;
  cin >> S;
  
  if(S=="Sunny"){
    cout << "Cloudy";
  }else if(S=="Cloudy"){
    cout << "Rainy";
  }else{
    cout << "Sunny";
  }
  return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
xyz=[]
for _ in range(n):
	x,y,z=map(int,input().split())
	xyz.append([x,y,z])
def two(i):
	return "0"*(3-len(bin(i)[2:]))+bin(i)[2:]
ans=0
for i in range(8):
	p=two(i)
	for j in range(3):
		if p[j]=="1":
			for k in range(n):
				xyz[k][j]*=-1
	now=0
	xyz.sort(key=lambda x:-sum(x))
	for j in range(m):
		now+=sum(xyz[j])
	ans=max(ans,now)
	for j in range(3):
		if p[j]=="1":
			for k in range(n):
				xyz[k][j]*=-1
print(ans)

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

using namespace std;

int a, b, c;

int main(){
	scanf("%d%d", &a, &b);

	if(a <= 5) c = 0;
	else if (a < 13) c = b / 2;
	else c = b;

	printf("%d\n", c);
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long a,b,c,d;
  cin>>a>>b>>c>>d;
  int flag=1;
  while(a>0&&c>0)
  {
    if(flag==1)
     { c=c-b;
      flag=0; 
    }
    else
    {a=a-d;
     flag=1;
    }
  }
  if(a<=0)
  { cout<<"No"<<endl;
   }
  else
  {
  cout<<"Yes"<<endl;}

}

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

using namespace std;

typedef unsigned long long ull;

ull solve(ull N, ull A, ull B) {
    ull count = 0, ans = 0;
    if ((B-A)%2 == 0)
        return (B-A)/2;

    if ((A-1) < (N-B)) {
        count = A;
        B -= A;
        A = 1;
        ans = (B-A)/2 + count;
    }
    else {
        count = N-B+1;
        A += N-B+1;
        B = N;
        ans = (B-A)/2 + count;
    }

    return ans;
}

int main() {
    ull N,A,B;
    cin >> N >> A >> B;
    cout << solve(N,A,B);
}


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

using namespace std;

int main() {
    int n;
    string s;
    cin >> n;
    vector<string> vec(n, "");
    for (int i=0; i<n; ++i) {
        cin >> s;
        sort(s.begin(), s.end());
        vec[i] = s;            
    }
    sort(vec.begin(), vec.end());
    vector<int> nums(n, 0);
    string prev = "";
    int index = -1;
    for (auto& e : vec) {
        if (e!=prev) ++index;
        ++nums[index];
        prev = e;
    }
    long long res = 0;
    for (auto& e : nums) {
        if (e==0 || e==1) continue;
        res += (long long)e * (e-1) / 2;
    }
    cout << res << endl;
}


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

int main() {
  int a;
  cin >> a;
  int div, sur;
  div += a / 100;	sur = a % 100;
  div += sur / 10;	sur = a % 10;
  div += sur / 1;
  cout << div << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sum = 0;


		do {
			sum = 0;
			String n = sc.nextLine();


			if(n.equals("0")) {
				break;
			}

			String tmp[] = n.split("");

			for (int i = 0; i < tmp.length; i++) {
				sum += Integer.parseInt(tmp[i]);
			}

			System.out.println(sum);
		}while(true);

		sc.close();

	}

}


Measured memory_bytes: 27388
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

int main(void){
    int a, b;
    cin >> a >> b;

    if((a == 1 || b == 1) && (a == 2 || b == 2)){
        cout << 3 << endl;
    } else if((a == 2 || b == 2) && (a == 3 || b == 3)){
        cout << 1 << endl;
    } else if((a == 3 || b == 3) && (a == 1 || b == 1)){
        cout << 2 << endl;
    }
}


Measured memory_bytes: 256
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N_ = 10**5+1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N_ + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N, K=list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()

# min
min_ = 0
for n in range(N-K+1):
    min_ += A[n]*cmb(N-1-n, K-1, mod)

# max
max_ = 0
for n in reversed( range(K-1, N) ):
    max_ += A[n]*cmb(n, K-1, mod)

#mod = 10**9+7
print( (max_-min_)%mod )


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

using namespace std;

struct P { int l, r, s; };

int N, X;
vector<P> p;

bool check(vector<int> &lion)
{
    for (int i = 0; i < (int)p.size(); i++) {
        int sum = 0;
        for (int j = p[i].l; j <= p[i].r; j++) {
            sum += lion[j];
        }
        if (sum != p[i].s) return 0;
    }
    return 1;
}

vector<int> res;

void rec(int idx, vector<int> lion)
{
    if (idx == N) {
        if (check(lion)) {
            res = lion;
            throw 0;
        }
        return;
    }

    for (int i = X; i >= 0; i--) {
        lion.push_back(i);
        rec(idx + 1, lion);
        lion.pop_back();
    }       
}

int main()
{
    int M;
    cin >> N >> X >> M;
    p.resize(M);
    for (int i = 0; i < M; i++) {
        cin >> p[i].l >> p[i].r >> p[i].s;
        p[i].l--; p[i].r--;
    }
    
    try {
        rec(0, vector<int>());
    } catch(...) {}

    if (res.size() > 0) {
        for (int i = 0; i < N; i++) {
            if (i > 0) cout << " ";
            cout << res[i];
        }
        cout << endl;
    } else {
        cout << -1 << endl;
    }    
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    sort(a.begin(), a.end(), greater<int>());  // a[0:N] を大きい順にソート
    int Alice = 0;
    int Bob = 0;
    for (int i = 0; i < N; ++i) {
        if (i % 2 == 0) {  // Alice のターン
            Alice += a[i];
        } else {  // Bob のターン
            Bob += a[i];
        }
    }
    cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
//##define FOR(k) "int i=0;i<k;i++"
//特定文字の個数を数える
int search(string s){
	int n=s.size();
	int num = 0;

	for(int i=0;i<n;i++){
		if(s[i] == '1'){
			num++;
		}
	}
	return num;
}

int main(){
    int n,k;
    string s;
    char t;
    cin >> n>>s>>k;
    t = s[k-1];
    for(int i=0;i<s.length();i++){
        if(s[i]!=t){
            s[i]='*';
        }
    }
    cout << s << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 1e5 + 7;
bool first_win(vector <int> a) {
    int n = a.size();
    vector <int> pref(n + 1), post(n + 1);
    for (int i = 0; i < n; ++i)
        pref[i + 1] = __gcd(pref[i], a[i]);
    for (int i = n - 1; i >= 0; --i)
        post[i] = __gcd(post[i + 1], a[i]);
    int sum = 0;
    for (int i = 0; i < n; ++i)
        sum += a[i];
    if ((sum - n) % 2 == 1)
        return 1;
    for (int i = 0; i < n; ++i) {
        if (a[i] > 1) {
            int d = __gcd(__gcd(pref[i], post[i + 1]), a[i] - 1);
            if (d > 1) {
                vector <int> b = a;
                for (int j = 0; j < n; ++j) 
                    b[j] /= d;      
                if (!first_win(b))
                    return 1;
            }    
        }
    }   
    return 0;
}   

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n;
    cin >> n;
    vector <int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    if (first_win(a))
        cout << "First" << endl;
    else
        cout << "Second" << endl;
}   

Measured memory_bytes: 75520
#include<stdio.h>
int main()
{
	int a[3],count,i;
	char s[3];
	while(scanf("%s",s)!=EOF)
	{
		count=0;
		for(i=0;i<3;i++)
		{
			a[i]=s[i]-'0';
			if(a[i]==1)count++;
		}
		printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 128
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 1e-8;

long long int N, M, K, H, W, L, R;

pair<int,int> Search(string &s, int depth, int num) {
	vector<int>v;
	string t;
	for (int i = num; i < s.size(); i++) {
		if (s[i] == '[') {
			auto box = Search(s, depth + 1, i + 1);
			v.push_back(box.first);
			i = box.second;
		}
		else if (s[i] == ']') {
			if (!t.empty()) {
				v.push_back(stoi(t) / 2 + 1);
				t.clear();
			}
			sort(v.begin(), v.end());
			int n = v.size();
			int ret = 0;
			for (int j = 0; j <= n / 2; j++) {
				ret += v[j];
			}
			return { ret,i };
		}
		else {
			t.push_back(s[i]);
		}
	}
}

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

	cin >> N;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		cout << Search(s, 1, 1).first << endl;
	}
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<long long> L(n,0);
  long long ma =0;
  long long ans =0;
  for(int i=0;i<n;i++){
    cin >> L[i];
  }
  sort (L.begin(),L.end());
  

  for(int i=0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      for(int k=j+1;k<n;k++){
        ma = max({L[i],L[j],L[k]});
        if((L[i]!=L[j]&&L[i]!=L[k]&&L[j]!=L[k])&&(ma<L[i]+L[j]+L[k]-ma)) ans++;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3596
A, B, Q = list(map(int,input().split()))
s = [float("-inf")]
t = [float("-inf")]
x = []
for i in range(A):
  s.append(int(input()))
for i in range(B):
  t.append(int(input()))
for i in range(Q):
  x.append(int(input()))
s.append(float("inf"))
t.append(float("inf"))
xs = list(x)
xs.sort()
sl = {}
sr = {}
tl = {}
tr = {}
i = 0
for j in range(1, A+2):
  while i<Q and xs[i]<s[j]:
    sl[xs[i]] = s[j-1]
    sr[xs[i]] = s[j]
    i += 1
i = 0
for j in range(1, B+2):
  while i<Q and xs[i]<t[j]:
    tl[xs[i]] = t[j-1]
    tr[xs[i]] = t[j]
    i += 1
for xi in x:
  sli = sl[xi]
  sri = sr[xi]
  tli = tl[xi]
  tri = tr[xi]
  p = [
    xi - min(sli,tli),
    max(sri,tri) - xi,
    min(sri-xi,xi-tli)*2+max(sri-xi,xi-tli),
    min(tri-xi,xi-sli)*2+max(tri-xi,xi-sli),
  ]
  print(min(p))

Measured memory_bytes: 48564
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;typedef vector<ll> vll;
#define fill(a) memset(a, 0, sizeof (a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define _ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int maxn = 2000100;

int main(){
        _ios;

        int n; cin >> n;
        ll ans = 1;
        rep1(i,1,n){
                ans = (ans*i)%mod;
                ans%=mod;
        }
        cout<<ans<<endl;


return 0;
}



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

using namespace std;

// ok[i][j] := elm[i] が s[j] で受理されるか
bool ok[12][5000];
// dp[i][j] := s[i] までで j(mask) が受理されるか
bool dp[5000][1 << 12];

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

    int n, m;
    while (cin >> n >> m, n || m)
    {
        vector<string> elm(n);
        for (int i = 0; i < n; i++)
            cin >> elm[i];
        string s = "";
        for (int i = 0; i < m; i++)
        {
            string a;
            cin >> a;
            s += a;
        }
        int m = s.size();
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                ok[i][j] = false;
        for (int i = 0; i < m; i++)
            for (int j = 0; j < (1 << n); j++)
                dp[i][j] = false;
        for (int i = 0; i < n; i++)
        {
            int sz = elm[i].size();
            for (int j = 0; j <= m - sz; j++)
            {
                if (elm[i] == s.substr(j, sz))
                {
                    ok[i][j + sz - 1] = true;
                    dp[j + sz - 1][1 << i] = true;
                }
            }
        }
        for (int i = 0; i < m; i++)
        {
            for (int j = 1; j < (1 << n); j++)
            {
                if (!dp[i][j])
                    continue;
                for (int k = 0; k < n; k++)
                {
                    int sz = elm[k].size();
                    if (i + sz >= m)
                        continue;
                    if ((j >> k) & 1)
                        continue;
                    if (!ok[k][i + sz])
                        continue;
                    dp[i + sz][j ^ (1 << k)] = true;
                }
            }
        }
        int ret = 0;
        for (int i = 0; i < m; i++)
            if (dp[i][(1 << n) - 1])
                ret++;
        cout << ret << endl;
    }
}



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

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

using namespace std;

int main(){
  int n;cin>>n;
  vector<double> a(n);
  double m=0;
  rep(i,n){
    cin>>a[i];
    m+=a[i];
  }
  m/=n;

  int ri=0;
  rep(i,n){
    if(abs(m-a[i]) < abs(m-a[ri]))ri=i;
  }

  cout<<ri;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
priority_queue<int,vector<int>,greater<int> >P[maxn];
int main()
{
	int n,m,Q;scanf("%d%d%d",&n,&m,&Q);
	while(Q--)
	{
		int x,y;scanf("%d%d",&x,&y);
		P[y].push(x);
	}
	int x=1,y=1,ans=n;
	for(int i=1;i<=m;i++)
	{
		int bottom=n;
		if(!P[i].empty())
			bottom=P[i].top()-1;
		ans=min(ans,bottom);
		x++;
		while(!P[i+1].empty()&&P[i+1].top()<x)
			P[i+1].pop();
		while(x<=n&&!P[i+1].empty()&&P[i+1].top()==x)
			P[i+1].pop(),x++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 10368
#include <stdio.h>

int isprime(int x){
    int i;
    
    if (x < 2) {
        return 0;
    } else if (x == 2) {
        return 1;
    }
    
    if (x % 2 == 0) {
        return 0;
    }
    
    for (i = 3; i * i <= x; i += 2) {
        if (x % i == 0) {
            return 0;
        }
    }
    
    return 1;
}

int main(){
    int n, x;
    int i;
    int ans = 0;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        scanf("%d\n", &x);
        
        if (isprime(x)){
            ans++;
        }
    }
    
    printf("%d\n", ans);
    
    return 0;
}



Measured memory_bytes: 2080
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	ll ans=INFLL;
	cin >>n;
	ll cnt=0LL;
	V a(n+2,0LL);
	rep(i,n){
		cin>>a[i+1];
		cnt+=abs(a[i]-a[i+1]);
	//	clog<<cnt<<" ";
	}
	cnt+=abs(a[n]-a[n+1]);
	//clog<<cnt<<endl;
	ans=cnt;
	rep(i,n){
	//	clog << abs(a[i] - a[i + 2]) << " ::: " << abs(a[i] - a[i + 1]) <<" "<<abs(a[i + 1] - a[i + 2]) <<endl;
		cout << (cnt + abs(a[i] - a[i + 2]) - abs(a[i] - a[i + 1]) - abs(a[i + 1] - a[i + 2])) << endl;
	}
//	cout<<ans<<endl;
}

Measured memory_bytes: 2048
import numpy as np
N,K = map(int,input().split())
A = np.array(input().split(),dtype=int)
I = np.arange(N)
for i in range(K):
  X = np.zeros(N+1,int)
  np.add.at(X,np.maximum(I-A,0),1)
  np.add.at(X,np.minimum(I+A+1,N),-1)
  A = X.cumsum()[:-1]
  if np.all(A==N):
    break
print(*A)

Measured memory_bytes: 50224
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int X; cin >> X;
    int Y; cin >> Y;
    string ans = "No";
    while(true){
        if(Y % 2 == 1){
            break;
        }
        int tmp = X * 2;
        if(tmp == Y){
            ans = "Yes";
            break;
        }
        else{
            for(int i = 0; i < X; i++){
                tmp += 2;
                if(tmp == Y){
                    ans = "Yes";
                    break;
                }
            }
        }
        break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#region using
using System;
using System.Collections.Generic;
using System.Linq;
using IEnumerable = System.Collections.IEnumerable;
using IEnumerator = System.Collections.IEnumerator;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;
using TextReader = System.IO.TextReader;
using System.Text;
#endregion

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var N = consoleReader.Int;
            return 800 * N - N / 15 * 200;
        }


        #region いつもの
#pragma warning disable
        private ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader(Console.In)).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
    }
    static class Ext
    {
        public static Dictionary<TKey, int> GroupCount<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) => source.GroupBy(keySelector).ToDictionary(g => g.Key, g => g.Count());
        public static Dictionary<TKey, int> GroupCount<TKey>(this IEnumerable<TKey> source) => source.GroupCount(i => i);
    }
    public class ConsoleReader { private string[] ReadLineSplit() => textReader.ReadLine().Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries); private string[] line = Array.Empty<string>(); private int linePosition; private TextReader textReader; public ConsoleReader(TextReader tr) { textReader = tr; } public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public string String { get { if (linePosition >= line.Length) { linePosition = 0; line = ReadLineSplit(); } return line[linePosition++]; } } public class SplitLine { private string[] splited; public SplitLine(ConsoleReader cr) { splited = cr.ReadLineSplit(); cr.line = Array.Empty<string>(); } public int[] Int => String.Select(x => int.Parse(x)).ToArray(); public int[] Int0 => String.Select(x => int.Parse(x) - 1).ToArray(); public long[] Long => String.Select(x => long.Parse(x)).ToArray(); public double[] Double => String.Select(x => double.Parse(x)).ToArray(); public string[] String => splited; } public SplitLine Split => new SplitLine(this); public class RepeatReader : IEnumerable<ConsoleReader> { ConsoleReader cr; int count; public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; } public IEnumerator<ConsoleReader> GetEnumerator() => Enumerable.Repeat(cr, count).GetEnumerator(); System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator(); public IEnumerable<string> String => this.Select(cr => cr.String); public IEnumerable<int> Int => this.Select(cr => cr.Int); public IEnumerable<int> Int0 => this.Select(cr => cr.Int - 1); public IEnumerable<long> Long => this.Select(cr => cr.Long); public IEnumerable<double> Double => this.Select(cr => cr.Double); } public RepeatReader Repeat(int count) => new RepeatReader(this, count); }
    #endregion
}


Measured memory_bytes: 11092
macro_rules! read {
    () => {{
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf
    }};
    ( Vec<$t:ty> ) => {
        read!()
            .trim()
            .split_whitespace()
            .map(|x| x.parse::<$t>().unwrap())
            .collect::<Vec<_>>()
    };
    ( $( $t:ty ),* ) => {{
        let buf = read!();
        let mut iter = buf.split_whitespace().collect::<Vec<_>>().into_iter();
        ( $( iter.next().unwrap().parse::<$t>().unwrap() ),* )
    }};
}

fn main() {
    let x = read!(usize);
    let s = read!(String);
    println!(
        "{}",
        if s.len() <= x {
            s
        } else {
            [&s[0..x], "..."].join("")
        }
    )
}


Measured memory_bytes: 2120
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String[] sAry = s.split("/");
		String ans = (sAry[1].matches("0[1-4]")) ?
				"Heisei" : "TBD";
		System.out.println(ans);
	}
}


Measured memory_bytes: 23252
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		
		if(A == B && A != C && B != C)
		System.out.println("Yes");
		else if(A == C && A != B && B != C)
		System.out.println("Yes");
		else if(C == B && A != B && A != C)
		System.out.println("Yes");
		else
		System.out.println("No");

	}
}

Measured memory_bytes: 35768
# ABC153 E Crested Ibis vs Monster
f=lambda:map(int,input().split())
H,N=f()
# dp[n][h]:=nthまでで体力をh削るときの最小魔力
INF=10**9
dp=[[INF]*(H+1) for _ in [0]*(N+1)]

for i in range(N+1):
    if i!=0:
        a,b=f()
    else:
        a,b=0,0
    for j in range(H+1):
        if i==0:
            if j==0:
                dp[i][j]=0
            else:
                dp[i][j]=INF
        else:
            dp[i][j]=min(dp[i-1][j],dp[i][max(j-a,0)]+b)

print(dp[N][H]) 

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

int main() {
  int n;
  cin >> n;
  
  int a[n];
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a+n);
  
  int i = 0;
  int num = 0;
  while(i < n) {
    if(a[i] == a[i+1]) {
      i += 2;
    }
    else {
      i++;
      num ++;
    }
  }
  
  cout << num << endl;    
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#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
const int N=200005,inf=1e9+5;
int a[N],b[N];
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n,mn=inf;
  ll ans=0;
  cin>>n;
  rep(i,1,n+1)
    {
      cin>>a[i]>>b[i];
      ans+=a[i];
      if(a[i]>b[i])
	mn=min(mn,b[i]);
    }
  if(mn==inf)
    {
      cout<<0<<endl;
      return 0;
    }
  ans-=mn;
  cout<<ans<<endl;
  return 0 ;
}


Measured memory_bytes: 384
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int x = 1,l;
        String s = "1";
        char[] c;
        int cnt;
        while( !s.equals("0")){
            cnt = 0;
            s = sc.next();
            c = s.toCharArray();
            if(s.equals("0")) break;
            l = s.length();
            for(int i = 0;i<l;i++){
                cnt += c[i] - '0';
            }
            System.out.printf("%d%n",cnt);
            
        }
        sc.close();
        
        
    }
}




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

using namespace std;
using ll = long long;

const int nax = 305;
double p[nax][nax][nax], ev[nax][nax][nax];
// ev[a][b][c] - the expected number of operations so far to get to state (a, b, c)
// easier: p-bility of getting to this state at all

signed main() {
    int n;
    scanf("%d", &n);
    vector<int> cnt(4);
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        ++cnt[x];
    }
    p[cnt[1]][cnt[2]][cnt[3]] = 1;
    for (int c = n; c >= 0; c--) {
        for (int b = n; b >= 0; b--) {
            for (int a = n; a >= 0; a--) {
                if (!a && !b && !c) {
                    continue;
                }
                if (a + b + c > n) {
                    continue;
                }
                // dp[a][b][c]
                double p_waste = (double) (n - (a + b + c)) / n;
                // p_waste + p_waste^2 + ... = S
                // 1 + S = S / p_waste
                double ev_waste = p_waste / (1 - p_waste) + 1;
                ev[a][b][c] += ev_waste * p[a][b][c];
                // remove 1 -> dp[a-1][b][c]
                // we will eventually choose one of a+b+c
                if (a != 0) {
                    double p_go = (double) a / (a + b + c);
                    p[a - 1][b][c] += p[a][b][c] * p_go;
                    ev[a - 1][b][c] += ev[a][b][c] * p_go;
                }
                // remove 2 -> dp[a+1][b-1][c]
                if (b != 0) {
                    double p_go = (double) b / (a + b + c);
                    p[a + 1][b - 1][c] += p[a][b][c] * p_go;
                    ev[a + 1][b - 1][c] += ev[a][b][c] * p_go;
                }        
                // remove 3
                if (c != 0) {
                    double p_go = (double) c / (a + b + c);
                    p[a][b + 1][c - 1] += p[a][b][c] * p_go;
                    ev[a][b + 1][c - 1] += ev[a][b][c] * p_go;
                }
            }
        }
    }
    printf("%.10lf\n", ev[0][0][0]); // + cnt[1] + 2 * cnt[2] + 3 * cnt[3]);
    return false;
}

Measured memory_bytes: 438528
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    string S;
    cin >> S;
    int N = (int)S.size();
    int mx = 0;
    int cnt = 0;
    for(int i = 0; i < N;){
        if(S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T'){
            cnt++;
            mx = max(mx, cnt);
        }else{
            cnt = 0;
        }
        i++;
    }
    cout << mx << endl;
    return 0;
}

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

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	int n; cin >> n;
	ll m = 0, ans = 0;
	for (int i = 0; i < n; i++) {
		ll a; cin >> a;
		m = max(m, a);
		ans += m - a;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

Measured memory_bytes: 256