akhauriyash/Code-Regression huggingface dataset:
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define LOWER(s)    transform(ALL((s)),(s).begin(),TL<char>)
# define UPPER(s)    transform(ALL((s)),(s).begin(),TU<char>)
# define FOR(i,a,b)  for(LL i=(a);i<(b);i++)
# define RFOR(i,a,b) for(LL i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

LL a, b, k;
vector<int> v;
int main() {
	cin >> a >> b >> k;
	for (int i = a; i < a + k; i++)if(i<=b)v.emplace_back(i);
	for (int i = b - k + 1; i <= b; i++)if(a<=i)v.emplace_back(i);
	sort(ALL(v));
	UNIQ(v);
	REP(i, v.size()) {
		cout << v[i] << endl;
	}
}

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

int main()
{
  int64_t N, K;
  cin >> N >> K;
  int64_t a = N % K;
  int64_t b = abs(N % K - K);
  int64_t ans = min(a, b);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(a,b,c) for(int a=b; a<(int)c; a++)
#define REPD(a,b,c) for(int a=b; a>(int)c; a--)
#define rep(a,b) REP(a,0,b)
#define repd(a,b) REPD(a,b,0)
typedef long long int ll;
using namespace std;

int main(){
  int p1, p2;
  int x;
  while(true){
    cin >> p1 >> p2 >> x;
    if(p1==0 && p2==0 && x==0) break;
    p1 += 100;
    p2 += 100;
    int ans = 0;
    REP(i,1,x){
      for(int j=1; ;j++){
        int tmp = i*p1/100 + j*p1/100;
        if(tmp == x){
          int sum = i*p2/100 + j*p2/100;
          ans = max(sum,ans);
          break;
        }
        if(tmp > x) break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int in(){
    int x;
    cin>>x;
    return x;
}
int main(){
    int n=in(),q=in();
    vector<int>ans(q,-1);
    tuple<int,int,int>work[n];
    for(int i=0;i<n;i++){
        int s=in(),t=in(),x=in();
        work[i]={x,s,t};
    }
    sort(work,work+n);
    set<pair<int,int>>people;
    for(int i=0;i<q;i++)people.insert({in(),i});
    for(int i=0;i<n;i++){
        int x=get<0>(work[i]),s=get<1>(work[i]),t=get<2>(work[i]);
        for(auto itr=people.lower_bound({s-x,0});
        itr!=people.lower_bound({t-x,0});itr=people.erase(itr)){
            ans[(*itr).second]=x;
        }
    }
    for(int i:ans)cout<<i<<endl;
    return 0;
}

Measured memory_bytes: 15676
N = int(input())
L = list(map(int,input().split()))
L.sort()
L.append(1000000)
M = [0]*((10**5)+1)
c = 0
d = 1
num = L[0]
if N == 1:
  print(1)
elif N == 2:
  if abs(L[0]-L[1]) <=1 :
    print(2)
  else:
    print(1)
else:
  while c <= N-1:
    if L[c] == L[c+1]:
      d += 1
      c += 1
    else:
      M[num] = d
      d = 1
      c += 1
      num = L[c]
  M.insert(0,0)
  M.append(0)
  ans = 0
  for i in range(len(M)-2):
    if M[i]+M[i+1]+M[i+2] >= ans:
      ans = M[i]+M[i+1]+M[i+2]
  print(ans)

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

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

using namespace std;

int main(){
  vector<int> t(3);
  cin>>t[0]>>t[1]>>t[2];
  sort(t.begin(), t.end());
  cout<<( (t[2]==t[0]) ? "Yes" : "No" )<<endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
stock = [chr(i) for i in range(97, 97 + 26)]
full, count, j = 26, 1, 1
while (count + full <= n):
    count += full;    j += 1;    full *= 26
q = n - count
s = []
for k in range(j):
    s.append(stock[q % 26])
    q //= 26
print("".join(s[::-1]))

Measured memory_bytes: 8976
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const int INF = 1e9;
const int MOD = 1000000007;
const ll MX = 1e18;
        
        
int main() {
        int n;
        cin >> n;
        vector<P> vote(n);
        rep(i,n){
                cin >> vote[i].first >> vote[i].second ;
        }
        ll t = 0,a = 0;

        rep(i,n){
                if(i == 0){ t = vote[i].first; a = vote[i].second;}
                else{
                        ll k = max((t+vote[i].first-1)/vote[i].first,(a+vote[i].second-1)/vote[i].second);
                        t = k * vote[i].first;
                        a = k * vote[i].second;
                }
                //cout << t << " " << a << endl;
                
        }
        cout << t + a << endl;

}




Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    ll cnt = 0;
    for(ll i = 0; i<= 100 ; ++i) {
        if (A <= i & i < B & C <= i & i < D) cnt++;
    }
    print(cnt);
    return 0;
}


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

int main() {
    int N, K;
    scanf("%d%d\n", &N, &K);

    int i;
    long int happy = 0;
    char direction;
    char prevDirection = 0;
    for (i = 0; i < N; i++) {
        scanf("%c", &direction);
        if (prevDirection == direction) {
            happy++;
        }
        prevDirection = direction;
    }

    if (happy + (K * 2) > N - 1) {
        happy = N-1;
    } else {
        happy += K*2;
    }
    printf("%ld", happy);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long long INF = 1e18;
//const ll mod = 1000000007;
ll H, W, K;
ll dp[3005][3005][5];
ll dh[2] = {1, 0};
ll dw[2] = {0, 1};
ll a[3005][3005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W >> K;
    for(int i = 0; i < K; i++) {
        ll h, w, v;
        cin >> h >> w >> v;
        h--;
        w--;
        a[h][w] = v;
    }
    for(int h = 0; h < H; h++) {
        for(int w = 0; w < W; w++) {
            for(int k = 3; k >= 0; k--) {
                chmax(dp[h][w][k+1], dp[h][w][k] + a[h][w]);
            }
            for(int k = 0; k <= 3; k++) {
                chmax(dp[h+1][w][0], dp[h][w][k]);
                chmax(dp[h][w+1][k], dp[h][w][k]);
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i <= 3; i++) {
        chmax(ans, dp[H-1][W-1][i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 426188
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    int m;
    cin >> m;
    cout << 48-m << endl;
}

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

int main()
{
	int n;
    cin >> n;
    long long int a[n];
    long long int prod=1;
    for(int i=0;i<n;i++)
    {
    	cin >> a[i];
    }
  	sort(a,a+n);
  	for (int i = 0; i < n; ++i)
  	{
  		if(a[i]==0)
    	{
    		prod=0;
    		break;
    	}
      	else if(a[i] > MOD/prod)
        {
          prod=-1;
          break;
        }
      	else
        	prod*=a[i];
  	}

  	cout << prod ;
	return 0;
}

/*

Get-Content in.txt | ./a > out.txt



*/


Measured memory_bytes: 4420
from sys import stdin, setrecursionlimit
#input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

a, b, c, d = map(int, input().split())
#A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]
#ABC = [list(map(int, input().split())) for _ in range(N)]
#S = input()
#S = [input() for _ in range(N)]

print(max(a * c, a * d, b * c, b * d))

Measured memory_bytes: 65396
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)9*1e18

/* Debug Begins */ 
# define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(bool f) { if(f) return "True"; else return "False";}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
int Nerr;
template<typename A> string to_string(A *p) {return to_string(vector<A>(p, p + Nerr));}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
/***************************************************************/

int power(int x, unsigned int y, unsigned int m)
{
    if (y == 0)
        return 1;
    int p = power(x, y/2, m) % m;
    p = (p *1ll* p) % m;
    return (y%2 == 0)? p : (x *1ll* p) % m;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    int TESTS=1;
    // cin>>TESTS;
    while(TESTS--)
    {   
        int n;
        cin >> n;
        int count[15] = {};
        for(int i = 13; i>=0; i--){
            if(n < power(26, i, INF)) continue;
            int c = n / power(26, i, INF);
            count[i] = c;
            n -= c * power(26, i, INF);
        }
        rep(j,0,100)
        for(int i = 13; i>=0; i--){
            if(count[i] == 0 and count[i+1]){
                count[i+1]--;
                count[i] = 26;
            }
        }
        // rep(i,0,10) trace(count[i]);
        string ans;
        for(int i = 13; i>=0; i--){
            if(count[i]){
                // trace
                ans.pb('a'+count[i]-1);
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3648
import itertools

def calc(str, tup):
  l = []
  idx = 0
  for i in tup:
    l.append(int(str[idx:i]))
    idx = i
  l.append(int(str[idx:]))
  return sum(l)

def solve(s):
  l = [i for i in range(1, len(s))]
  ans = 0
  for c in range(len(l)+1):
    for v in itertools.combinations(l,c):
      ans += calc(s, v)
  return ans

if __name__ == "__main__":
  s = input()
  print(solve(s))


Measured memory_bytes: 3064
#include <cstdio>
#include <cstdint>
#include <cctype>
#include <cassert>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>

std::vector<std::string> decode(const std::string& s) {
  std::vector<std::string> res(1);
  for (size_t i = 0; s[i]; ++i) {
    if (isdigit(s[i])) {
      res.back() += std::string(s[i]-'0', '.');
    } else if (s[i] == 'b') {
      res.back() += "b";
    } else if (s[i] == '/') {
      res.emplace_back();
    }
  }
  // for (size_t i = 0; i < res.size(); ++i)
  //   fprintf(stderr, "%s\n", res[i].c_str());

  return res;
}

std::string encode(const std::vector<std::string>& z) {
  std::string res;
  for (const auto& zi: z) {
    size_t dots = 0;
    for (size_t i = 0; i <= zi.length(); ++i) {
      if (zi[i] == '.') {
        ++dots;
      } else {
        if (dots) res += dots+'0';
        dots = 0;
        if (zi[i] == 'b') res += 'b';
      }
    }
    res += '/';
  }
  assert(res.back() == '/');
  res.pop_back();
  return res;
}

int testcase_ends() {
  char buf[131072];
  scanf("%s", buf);
  std::string s = buf;
  if (s == "#") return 1;

  auto z = decode(s);
  size_t a, b, c, d;
  scanf("%zu %zu %zu %zu", &a, &b, &c, &d);

  --a;
  --b;
  --c;
  --d;
  assert(z[a][b] == 'b');
  assert(z[c][d] == '.');
  std::swap(z[a][b], z[c][d]);

  printf("%s\n", encode(z).c_str());
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2788
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n  = sc.nextInt();
    String S = sc.next();
    char[] s = S.toCharArray();
    
    int e = 0;
    int w = 0;
    for(int i = 0; i < n ; i++){
      if(s[i] =='E'){
        e++;
      }else{
        w++;
      }
    }
    
    int min = 300000;
    int eChange = e;
    int wChange = 0;
    for(int i = 0; i < n; i++){
      if(s[i] == 'E'){
        eChange--;
      }
      
      if(eChange + wChange <= min){
        min = eChange + wChange;
      }
      
      if(s[i] == 'W'){
        wChange++;
      }
    }
    
    
    System.out.println(min);
    
  }
}

Measured memory_bytes: 42940
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

typedef long long LL;
const int N = 1e5 + 50;
const int incol[] = { 1, 2, 0 };
const int outcol[] = { 2, 0, 1 };

struct edge {
  int nxt, to;
} e[N << 1];
int fir[N], cnt = 0;
int n, m, col[N], tms[4], ce;
bool bad;

inline void addedge(int x, int y) {
  e[++ cnt] = (edge) { fir[x], y }; fir[x] = cnt;
}

inline void Dfs(int x) {
  int exp;
  tms[col[x]] ++;
  for (int i = fir[x]; i; i = e[i].nxt) {
    ce ++;
    if (i & 1) exp = outcol[col[x]];
    else exp = incol[col[x]];
    if (~ col[e[i].to]) {
      if (exp != col[e[i].to]) bad = 1;
    }
    else {
      col[e[i].to] = exp; Dfs(e[i].to);
    }
  }
}

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, x, y; i <= m; i ++) {
    scanf("%d%d", &x, &y);
    addedge(x, y); addedge(y, x);
  }
  memset(col, -1, sizeof col);
  LL ans = 0;
  for (int i = 1; i <= n; i ++)
    if (col[i] == -1) {
      ce = 0;
      tms[0] = tms[1] = tms[2] = 0;
      bad = 0; col[i] = 0; Dfs(i);
      if (bad) {
        int sum = tms[0] + tms[1] + tms[2];
        ans += (LL) sum * sum;
      }
      else if (tms[0] && tms[1] && tms[2])
        ans += (LL) tms[0] * tms[1] + (LL) tms[0] * tms[2] + (LL) tms[1] * tms[2];
      else ans += ce >> 1;
    }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 4352
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

class union_find{
private:
    std::vector<unsigned long long>par,sz,rank;
    unsigned long long cnt;
public:
    union_find(unsigned long long n)
    :par(n),sz(n,1),rank(n,0),cnt(n)
    {
        iota(par.begin(),par.end(),0);
    }
    unsigned long long count()const
    {
        return cnt;
    }
    unsigned long long find(unsigned long long n)
    {
        return par[n]==n?par[n]:par[n]=find(par[n]);
    }
    unsigned long long size(unsigned long long n)
    {
        return sz[find(n)];
    }
    bool is_same(unsigned long long x,unsigned long long y)
    {
        return find(x)==find(y);
    }
    void unite(unsigned long long x,unsigned long long y)
    {
        x=find(x);y=find(y);
        if(x!=y){
            if(rank[x]<rank[y]){
                par[x]=y;
                sz[y]+=sz[x];
            }else{
                par[y]=x;
                sz[x]+=sz[y];
                if(rank[x]==rank[y])++rank[x];
            }
            --cnt;
        }
    }
};

int main()
{
    ll n=in(),m=in(),k=in();
    vector<ll>cnt_direct_friend(n);
    union_find uf(n);
    for(int i=0;i<m;++i){
        ll a=in()-1,b=in()-1;
        ++cnt_direct_friend[a];
        ++cnt_direct_friend[b];
        uf.unite(a,b);
    }
    vector<ll>cnt_tf_but_blocked(n);
    for(int i=0;i<k;++i){
        ll c=in()-1,d=in()-1;
        if(uf.is_same(c,d)){
            ++cnt_tf_but_blocked[c];
            ++cnt_tf_but_blocked[d];
        }
    }
    for(int i=0;i<n;++i){
        if(i!=0)cout<<' ';
        cout<<uf.size(i)-(1+cnt_direct_friend[i]+cnt_tf_but_blocked[i]);
    }
    cout<<endl;
}


Measured memory_bytes: 4736
#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<string>
#include<vector>
using namespace std;
long long n,a[1000000],ans;
int main(){
	cin>>n;
	for (int i=0;i<n;i++) cin>>a[i];
	for (int i=0;i<n;i++) a[i]=a[i]-i-1;
	sort(a,a+n);
	if (n%2==1)
		for (int i=0;i<n;i++) ans+=abs(a[i]-a[n/2]);
	else
		for (int i=0;i<n;i++) ans+=abs(a[i]-(a[n/2]+a[n/2-1])/2);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
def main():
    N = int(input())
    a = [int(i) for i in input().split()]
    a.sort()
    diff = 0
    for i, ai in enumerate(reversed(a)):
        if i % 2 == 0:
            diff += ai
        else:
            diff -= ai
    print(diff)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
//My Conquest Is the Sea of Stars.
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define gcd __gcd
#define pb push_back
#define mp make_pair
#define lowbit(x) x & (-x)
#define PII  pair<int, int> 
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for(__typeof(b) i = a; i <= (b); i++)
#define Rep(i, a, b) for(__typeof(a) i = a; i >= (b); i--)
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)1e6 + 5;
const ll INF = 0x3f3f3f3f3f3f3f3f;
using namespace std;

int main()
{
	int n, k; cin >> n >> k;
	if(n & 1) n = n / 2 + 1;
	else n = n / 2;
	puts(n >= k ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(1000):
        target = str(i).zfill(3)
        pointer = 0
        subS = S
        for digit in target:
            pointer = subS.find(digit)
            if pointer == -1:
                break
            else:
                subS = subS[pointer+1:]
        if pointer != -1:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()



Measured memory_bytes: 44892
N, A, B = map(int, input().split())
S = list(input())

passed = 0
foreign = 0

for i, s in enumerate(S):
    if s == "a" and passed < A + B:
        print("Yes")
        passed += 1
    elif s == "b":
        foreign += 1
        if passed < A + B and foreign <= B:
            print("Yes")
            passed += 1
        else:
            print("No")
    else:
        print("No")


Measured memory_bytes: 4712
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll MOD = 998244353;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
	return bin_pow(x, MOD - 2);
}

const int N = (int)3e6 + 5;
ll f[N], rf[N];

ll getC(int n, int k) {
	if (k < 0 || k > n) return 0;
	return mult(f[n], mult(rf[k], rf[n - k]));
}
ll solve(int S, int n, int m) {
	ll ans = 0;
	for (int k = 0; k <= m; k++) {
		if (k > S) continue;
		if ((S - k) & 1) continue;
		ans = add(ans, mult(getC(n, k), getC((S - k) / 2 + n - 1, n - 1)));
	}
	return ans;
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	f[0] = 1;
	for (int i = 1; i < N; i++)
		f[i] = mult(f[i - 1], i);
	rf[N - 1] = rev(f[N - 1]);
	for (int i = N - 1; i > 0; i--)
		rf[i - 1] = mult(rf[i], i);

	ll ans = 0;
	int n, m;
	scanf("%d%d", &n, &m);
	ans = sub(solve(3 * m, n, m), mult(n, add(solve(m - 1, n - 1, m - 1), solve(m - 2, n, m))));
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 47104
//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
#include <climits>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define F first
#define S second
#define OUT(x) cout << x << "\n"
#define int long long
using namespace std;
using point = pair< int,int >;

signed main() {
    int n;
    cin >> n;
    int x, y, b, p;

    REP (i, n) {
        scanf("%lld%lld%lld%lld", &x, &y, &b, &p);
        OUT(min(x * b + y * p, (x * max(5LL, b) + y * max(2LL, p)) / 10 * 8));
    }
    return 0;
}




Measured memory_bytes: 3232
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  string s;
  int start=0,end;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='A'){
      start=i;
      break;
    }
  }
  for(int j=s.size()-1;j>=0;j--){
    if(s[j]=='Z'){
      end=j;
      break;
    }
  }
  cout<<end-start+1<<endl;
}

Measured memory_bytes: 832
#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define dpr(x) cerr<<#x<<": "<<x<<endl;
#define dprc(c) do{cerr<<#c<<":";for(auto&_i:(c)){cerr<<" "<<_i;}cerr<<endl;}while(0)
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int INF = 1e9+7;
#define all(c) (c).begin(), (c).end()
#define tr(i,c) for(auto i=(c).begin();i!=(c).end();i++)
#define rtr(i,c) for(auto i=(c).rbegin();i!=(c).rend();i++)
#define rep(i,b) for(auto i=0;i<(b);i++)
#define pb push_back
#define sz(c) int((c).size())

struct lake {
  int pos;
  int capa;
};

int A;
stack<int> left_slope;
stack<lake> lakes;

void merge_lakes(lake& lk) {
}

int main(int argc, char **argv)
{
  int c, cpos;

  cpos = 0;
  while ((c = getchar()) != EOF) {
    if (c == '\\') left_slope.push(cpos);
    else if (c == '/' && sz(left_slope)) {  // ?????´????????¢??????????????°?????????????????????
      int l = left_slope.top(); left_slope.pop();
      lake lk = {
        l,
        cpos - l, // ??°??????????????£?????¨?±???¨???(0.5 + (cpos - left - 1) + 0.5)
      };
      A += lk.capa;
      // l ?????? ?????´?????????????????¨??¨ lk ???????????????
      while (sz(lakes)) {
        lake r = lakes.top(); lakes.pop();
        if (r.pos < lk.pos) {
          lakes.push(r);
          break;
        }
        lk.capa += r.capa;
      }
      lakes.push(lk);
    }
    cpos++;
  }

  vector<int> v;
  while (sz(lakes)) {
    lake lk = lakes.top(); lakes.pop();
    v.pb(lk.capa);
  }
  reverse(all(v));
  printf("%d\n", A);
  printf("%d", sz(v));
  for (auto& x:v) {
    printf(" %d", x);
  }
  putchar('\n');
  return 0;
}

Measured memory_bytes: 3272
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <list>
#include <queue>
using namespace std;

int inf = (1 << 30);
int mod = 1e9 + 7;
int64_t inf64 = (1LL << 60);

template <typename T>
T gcd(T a, T b) {
    if(b == 0) return a;
    else return gcd(b, a % b);
}

template <typename T>
T lcm(T a, T b) {
    T g = gcd(a, b);
    return a / g * b;
}

bool check(vector<int> a, int index, int key){
    if(a[index] >= key) return true;
    else return false;
}

int lower_bound(vector<int> a, int key){
    int left = -1, right = a.size();
    while(right - left > 1){
        int mid = left + (left + right) / 2;
        if(check(a, mid, key)) right = mid;
        else left = mid;
    }
    return right;
}

int main(){

    int K, S;
    cin >> K >> S;

    int ans = 0;
    for(int X = 0; X <= K; X++){
        for(int Y = 0; Y <= K; Y++){
                if(0 <= (S - X - Y) && (S - X - Y) <= K) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/*************************************
 * @contest:      dwacon6th-prelims.
 * @user_name:    hkxadpall.
 * @time:         2020-01-11.
 * @language:     C++.
 * @upload_place: AtCoder.
*************************************/ 

#include <bits/stdc++.h>
using namespace std;

typedef signed char          int8;
typedef unsigned char       uint8;
typedef short                int16;
typedef unsigned short      uint16;
typedef int                  int32;
typedef unsigned            uint32;
typedef long long            int64;
typedef unsigned long long  uint64;

template <typename Int>
inline Int read()       
{
    Int flag = 1;
    char c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}

template <typename Int>
inline Int read(char &c)       
{
    Int flag = 1;
    c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}

template <typename Int>
inline void write(Int x)
{
    if (x < 0) putchar('-'), x = ~x + 1;
    if (x > 9) write(x / 10);
    putchar((x % 10) | 48);
}  

template <typename Int>
inline void write(Int x, char nextch)
{
    write(x);
    putchar(nextch);
}

#define P 1000000007

int n;
long long x[100007];
long long pre[100007], nxt[100007];
long long t, ans;
long long Except(int i) 
{ 
    if (!i) return nxt[1];
    else return pre[i - 1] * nxt[i + 1] % P; 
}

int main()
{
    n = read<int>();
    for (int i = 1; i <= n; i++) x[i] = read<int>();
    pre[0] = 1;
    nxt[n] = 1;
    for (int i = 1; i <= n - 1; i++) pre[i] = (pre[i - 1] * i) % P;
    for (int i = n - 1; i >= 1; i--) nxt[i] = (nxt[i + 1] * i) % P;
    for (int i = 1; i < n; i++) {
        t = (t + Except(i)) % P;
        // printf("t = %lld.\n", t);
        ans = (ans + (x[i + 1] - x[i]) * t) % P;
    }
    write(ans);
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
using namespace std;
typedef long long ll;
ll dp[101][101][305];
int main( void )
{
  ios::sync_with_stdio(false);
  int N;
  ll W, w, v, w1;
  cin >> N >> W;
  for( int i=0; i<N; i++ ){
    cin >> w >> v;
    if( i==0 ) w1 = w;
    for( int j=0; j<=i; j++ ){
      for( int k=0; k<=3*i; k++ ){
        dp[i+1][j+1][k] = dp[i][j+1][k];
      }
      for( int k=0; k<=3*i; k++ ){
        dp[i+1][j+1][k+(w-w1)] = max( dp[i][j+1][k+(w-w1)], dp[i][j][k] + v );
      }
      //cout << "dp[" << i+1 << "][" << j+1 << "] ";
      //for( int k=0; k<=3*i; k++ ){
      //  cout << dp[i+1][j+1][k] << ' ';
      //}
      //cout << endl;
    }
  }
  ll ret = 0;
  for( int j=0; j<=N; j++ ){
    for( int k=0; k<305; k++ ){
      if( j*w1 + k <= W ){
        ret = max( ret, dp[N][j][k] );
      }
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 22528
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  String N = sc.next();
  if(N.charAt(0) == N.charAt(1) && N.charAt(0) == N.charAt(2))
    System.out.println("Yes");
  else if(N.charAt(1) == N.charAt(2) && N.charAt(1) == N.charAt(3))
    System.out.println("Yes");
  else{System.out.println("No");}
}
}


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

using namespace std;

typedef long long ll;

int n;
int a[20],b[20];

struct Node
{
	int face, val;
} c[20];

int d[20];

int solve(int s)
{
	int ret=0;
	for (int i=0;i<n;i++)
	{
		if ((1<<i)&s) // B-side
		{
			c[i+1].face = 1;
			c[i+1].val = b[i+1];
			d[i+1] = b[i+1];
		}
		else // A side
		{
			c[i+1].face = 0;
			c[i+1].val = a[i+1];
			d[i+1] = a[i+1];
		}
	}
	
	sort(d+1,d+n+1);
	
	for (int i=1;i<=n;i++) // 构造答案 
	{
		bool flag = 0;
		for (int j=i;j<=n;j++)
			if ( (c[j].val == d[i]) && (c[j].face == (j-i)%2) )
			{
				flag=1;
				ret+=j-i;
				for (int k=j-1;k>=i;k--)
				{
					swap(c[k],c[k+1]);
					c[k+1].face^=1;
				} 
				break;
			}
		if (!flag) return 2*1e9;
	}
	
	return ret;
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=n;i++)
	{
		cin>>b[i];
	}
	
	int ans=2*1e9;
	for (int i=0;i<(1<<n);i++)
	{
		ans=min(ans,solve(i));
	}
	
	if (ans== 2*1e9) ans=-1;
	printf("%d\n",ans);
}


Measured memory_bytes: 3804
N = int(input())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
if A == B:
    print(0)
    exit()

min_b = sum(A)
for a,b in zip(A,B):
    if a <= b: continue
    min_b = min(min_b, b)
print(sum(A) - min_b)


Measured memory_bytes: 4852
loop do
  n = gets.to_i
  exit if n == 0

  str = gets.chomp
  n.times do
    p = 0
    res = ""
    count = 1
    until p == str.length do
      char = str[p]
      if (p+1) == str.length || char != str[p+1]
        res += count.to_s
        res += char
        count = 1
      else
        count += 1
      end
      p = p + 1
    end
    str = res
  end
  puts str
end

Measured memory_bytes: 113108
#include<iostream>
#include<string>
#include<vector>

using namespace std;
#define int long long

const int inf = 1e18;

string t;
int num, ten;
int ans;
vector<int> used(10);
int N;

void solve(int depth, string n, int m) {

    //cout<<depth<<" "<<n<<" "<<m<<" ans = "<<ans<<" ten = "<<ten<<endl;
    
    if(depth == N) {
// cout<<"[][]"<<endl;
        // cout<<min(abs(ans - num), abs(ten - abs(ans - num)))<<" <>  "<< min(abs(m - num), abs(ten - abs(m - num)))<<endl;
        if(min(abs(ans - num), abs(ten - abs(ans - num))) < min(abs(m - num), abs(ten - abs(m - num)))) {
            ans = m;
            t = n;
        } else if(min(abs(ans - num), abs(ten - abs(ans - num))) == min(abs(m - num), abs(ten - abs(m - num)))){
            if(ans > m) {
                ans = m;
                t = n;
            }
        }

        return ;
    }

    for(int i = 0; i < used.size(); i++){
        if(used[i]) continue;
        
        used[i] = true;

        n[depth] = '0' + i;
        
        m = m * 10 + i;

        solve(depth+1, n, m);

        m /= 10;
        
        used[i] = false;
    }
}

int my_stoi(string s){
    int res = 0;

    for(int i = 0; i < s.size(); i++){
        res = res * 10 + s[i] - '0';
    }

    return res;
}
     
signed main(){

    string s, hoge;

    cin>>s;

    num = my_stoi(s);
    ans = num;

    N = s.size();

    ten = 1;

    for(int i = 0; i < N; i++) ten *= 10;

    //cout<<"<><>"<<endl;
    hoge.resize(N, '0');
   

    solve(0, hoge, 0);
    
    cout<<t<<endl;
    
    return 0;
}



Measured memory_bytes: 3216
#include <iostream>
#define rep(i,n) for (int i = 0; i < (n);; ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;
int x, a, b, c, d;
int main() {
	cin >> x;
	a= x / 100;
	b = x % 100; //2dig
	c = b / 10; //十の位
	d = b % 10;
	if (a == 7 || d == 7 || c == 7) {
		cout << "Yes";
	}else cout << "No";
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
// #include <cmath>
#include <vector>

using namespace std;


int main(){

  vector<char> vec ;
  for (int i =0 ; i<6;i++){
    char hold;
    cin >> hold;
    vec.push_back(hold);
  }
  if ((vec[2] == vec[3])&& (vec[4]==vec[5])){
    cout << "Yes";
  }else{
    cout << "No";
  }


  return  0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics;

namespace ABC{
    public class Program{
        public static void Main(){
            //出力を高速化する用
            var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
            Console.SetOut(sw);
            //実行時間計測する用
            var watch = new Stopwatch();
            bool isTest = false;
            watch.Start();
            //ファイルから読み込む用
            TextReader reader;
            var filename = "";
            if(filename == String.Empty){
                reader = Console.In;
            }else{
                reader = new StreamReader(filename);
            }

            //a-zの文字配列
            //var alphabet = Enumerable.Range('a', 'z'-'a'+1).Select(c=>Convert.ToChar(c)).ToArray();
            //a-zをキーにして回数をカウントする辞書
            var dict = new Dictionary<char, int>();
            var input = reader.ReadLine();
            foreach (var c in input)
            {
                if(dict.ContainsKey(c)){
                    dict[c]++;
                }else{
                    dict[c] = 1;
                }
            }
            var ans = "";
            foreach(var v in dict.Values){
                if(v%2==1){
                    ans = "No";
                    break;
                }
            }
            if(ans == String.Empty){
                ans = "Yes";
            }
            Console.WriteLine(ans);
            watch.Stop();
            if(isTest){
                System.Console.WriteLine($"実行時間{watch.ElapsedMilliseconds}ミリ秒");
            }
            Console.Out.Flush();
        }
    }
}

Measured memory_bytes: 13280
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		@SuppressWarnings("unchecked")
		ArrayList<Integer>[] list = new ArrayList[10001];
		for(int i=1;i<10001;i++){
			list[i] = new ArrayList<Integer>();
			for(int j=1;j*j<=i;j++) if(i%j==0) list[i].add(j);
		}
		
		while(true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(a==0 && b==0) break;
			
			int[] c = new int[4];
			int min = Integer.MAX_VALUE;
			for(int aa : list[a]){
				for(int bb : list[b]){
					c[0] = aa;
					c[1] = a/aa;
					c[2] = bb;
					c[3] = b/bb;
					Arrays.sort(c);
					min = Math.min(min, (c[3]-c[2])*(c[3]-c[2])+(c[2]-c[1])*(c[2]-c[1])+(c[1]-c[0])*(c[1]-c[0]));
				}
			}
			System.out.println(min);
		}
	}
}

Measured memory_bytes: 26576
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;



int main(){
    ll n;
    cin>>n;
    vector<double> a(n);
    for(auto &i:a){cin>>i;}
    vector<vector<double>> A(n+1,vector<double>(n+1,0));
    A[0][0]=1;
    for(int i=0;i<n;i++){
        for(int t=0;t<n;t++){
            A[i+1][t]+=A[i][t]*(1-a[i]);
            A[i+1][t+1]+=A[i][t]*a[i];
        }
    }
    double ans=0;
    for(ll i=(n+1)/2;i<=n;i++){ans+=A.back()[i];}
    cout<<fixed<<setprecision(12)<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 70784
#include<stdio.h>
int main(){
	int i, n = 5, sum = 0, ave;
	int data[5];
	for( i = 0; i < n; i++){
		scanf("%d", &data[i]);
	}
	
	for( i = 0; i < n; i++){
		if(data[i] < 40){
			data[i] = 40;
		}
		sum += data[i];
	}
	
	ave = sum / n;
	printf("%d\n", ave);
	return 0;
}

Measured memory_bytes: 596
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    H = il()

    flower = [0] * N
    ret = 0
    for i in range(N):
        if flower[i] == H[i]: continue

        j = i
        while N > j:
            if H[j] == flower[j]: break
            j += 1

        diff = H[i] - flower[i]
        mi = MAX
        for n in range(i, j):
            mi = min(mi, H[n] - flower[n])
            flower[n] += min(diff, mi)
        ret += diff

    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10164
#include <bits/stdc++.h>
using namespace std;
 
int main(){
int N, M, ans = 0;
  cin >> N >> M;
int x[M];
int y[M - 1];  

if(N >= M){
  cout << 0 << endl;
  return 0;
}
  
else{  
  for(int i = 0;i < M;i++) cin >> x[i];
  sort(x, x + M);
  
  for(int i = 0;i < M - 1;i++) y[i] = abs(x[i + 1] - x[i]);  
  sort(y,y + M - 1);
  
  for(int i = 0;i < M - N;i++) ans += y[i];
  
  cout << ans << endl;  
  return 0;
  
}    
}

Measured memory_bytes: 1024
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

constexpr int inf = 2147483647;
constexpr int64_t inf64 = 9223372036854775807;
constexpr int mod = 1e9+7;

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

  int n, l;
  cin >> n >> l;

  int res = 0, mini = inf;
  bool m;
  rep(i,n) {
  	res += l+i;
  	mini = min(mini, abs(l+i));
  	if(l+i < 0) m = true;
  	else m = false;
  }

  if(m) cout << res + mini << endl;
  else cout << res - mini << endl;
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  int t[n];
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  int m;
  cin >> m;
  int p[m], x[m];
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> x[i];
  }

  for (int i = 0; i < m; i++) {
    int ans = 0;
    for (int j = 0; j < n; j++) {
      if (j == p[i] - 1) {
	ans += x[i];
      } else {
	ans += t[j];
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define fi first
#define sec second
ll mod = 1000000007;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n; cin >> n;
  n = 1 - n;
  cout << n << "\n";
  return 0;
}

Measured memory_bytes: 3636
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		String t = sc.next();
		System.out.println((""+t.charAt(0))+(t.length()-2)+(""+t.charAt(t.length()-1)));
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 39100
#include <cstdio>

using namespace std;

int main(void) {
    double a, b;
    while (scanf("%lf %lf", &a, &b) != EOF) {
        int x, y;
        x = (int)(a * 100);
        y = (int)(b * 100);
        if (x < 3550 && y < 7100) {
            puts("AAA");
        } else if (x < 3750 && y < 7700) {
            puts("AA");
        } else if (x < 4000 && y < 8300) {
            puts("A");
        } else if (x < 4300 && y < 8900) {
            puts("B");
        } else if (x < 5000 && y < 10500) {
            puts("C");
        } else if (x < 5500 && y < 11600) {
            puts("D");
        } else if (x < 7000 && y < 14800) {
            puts("E");
        } else {
            puts("NA");
        }
    }
    return 0;
}

Measured memory_bytes: 1036
def main():
    N, C = [int(n) for n in input().split()]
    D = []
    for i in range(C):
        D.append([int(n) for n in input().split()])
    grid = []
    for i in range(N):
        grid.append([int(n) for n in input().split()])
    # マスの種類ごとに出てくる色と数を記録
    dic = [{}, {}, {}]
    for h, row in enumerate(grid):
        for w, col in enumerate(row):
            i = ((h+1)+(w+1))%3
            c = col - 1
            if not (c in dic[i].keys()):
                dic[i][c] = 0
            dic[i][c] += 1

    result = 1e18
    for to_zero in range(C):
        for to_one in range(C):
            for to_two in range(C):
                if to_zero == to_one or to_one == to_two or to_two == to_zero:
                    continue
                to_li = [to_zero, to_one, to_two]
                cost = 0
                for i, to in enumerate(to_li):
                    for fr, num in dic[i].items():
                        cost += D[fr][to] * num
                result = min(result, cost)
    print(result)
                
     

if __name__ == "__main__":
    main()

Measured memory_bytes: 45532
#include<bits/stdc++.h>
using namespace std;
const int MAX=2e5+10;
int Ar[MAX],LeftR[MAX],RightL[MAX];
int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    string A;cin >> A;
    for(int i=0;i<A.size();i++){
        if(A[i]=='R'){
            LeftR[i]=i;
        }
        else LeftR[i]=LeftR[i-1];
    }
    for(int i=A.size()-1;i>=0;i--){
        if(A[i]=='L'){
            RightL[i]=i;
        }
        else RightL[i]=RightL[i+1];
    }
    /*for(int i=0;i<A.size();i++)
        cout<<LeftR[i]<<" ";
    cout<<endl;
    for(int i=0;i<A.size();i++)
        cout<<RightL[i]<<" ";
    cout<<endl;
    for(int i=0;i<A.size();i++){
        cout<<"curr = "<<i<<endl;
        int next=i;
        if(A[i]=='L'){
            next--;
        }
        else{
            next++;
        }
        cout<<"next after 1 turn "<<next<<endl;
        if(A[next]=='L'){
            next--;
        }
        else{
            next++;
        }
        Ar[next]++;

        cout<<"next after 2 turn "<<next<<endl;


    }*/
    //A.push_back('X');
    for(int i=0;i<A.size();i++){
        /*if(A[i]=='R'&&A[i+1]=='L'){
                Ar[i]++;
                Ar[i+1]++;
                i++;
                continue;
        }*/
        if(A[i]=='L'){
                int len =i-LeftR[i];
                if(len&1)Ar[LeftR[i]+1]++;
                else Ar[LeftR[i]]++;

        }
        else{
                int len =RightL[i]-i;
                if(len&1)Ar[RightL[i]-1]++;
                else Ar[RightL[i]]++;
        }
    }
    for(int i=0;i<A.size();i++)cout<<Ar[i]<<" ";
    return 0;
}


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

ll arr[12];

int main(){
    ll t,a,mx=-1;
    cin>>t;
    ll ans=0;
    for(ll x=0; x<t; x++){
        cin>>arr[x];
        ans+=arr[x];
        mx=max(mx,arr[x]);
    }
    ans-=(mx/2);
    cout<<ans;
    return 0;
}



Measured memory_bytes: 256