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

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<" "<<y<<endl
#define pl(x)                   out<<x
#define p2l(x,y)                out<<x<<" "<<y
#define p1d(a,n)                for(int ix=0;ix<n;ix++) out<<a[ix]<<" "; out<<endl
#define p2d(a,n,m)              for(int ix=0;ix<n;ix++){ for(int jx=0;jx<m;jx++) out<<a[ix][jx]<<" "; out<<endl;}
#define range(v)                v.begin(),v.end()
#define w(x)                    while(x--)
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2
int log10(int n){
    int res = 0;
    while(n!=0) {n/=10; res++;}
    return res - 1;
}

int first_digit(int n){
    return n%10;
}
int last_digit(int n){
    int exp = log10(n);
    int div = pow(10, exp);
    return n/div;
}

int possible_numbers(int last, int first, int n_total, int n_first, int n_last, int n){
    int tot = 0;
    if(last<n_last){
        f(k, 0, n_total - 1){
            tot+=pow(10, k);
        }
        if(last==first) tot += 1;
    }else if(last == n_last){
        f(k, 0, n_total - 2){
            tot+=pow(10, k);
        }
        if(last==first) tot += 1;

        f(i,1,n+1){
            if(log10(i) == n_total - 1){
                if(last_digit(i) == last && first_digit(i) == first) tot ++;
            }
        }
        if(n_total == 1) tot--;
    }else{
        f(k, 0, n_total - 2){
            tot+=pow(10, k);
        }
        if(last==first && n_total>1) tot += 1;
    }

    return tot;
}
class DHandstand2 {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n;
        s(n);
        int n_first = first_digit(n);
        int n_last = last_digit(n);
        int n_total = log10(n) + 1;
        int total = 0;

        f(i,1,10){
            f(j,1,10){
                total+=possible_numbers(i,j,n_total, n_first, n_last, n)*possible_numbers(j,i,n_total, n_first, n_last, n);
            }
        }
        out<<total<<endl;
	}
};


integer main() {
	DHandstand2 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
}


Measured memory_bytes: 256
import bisect
import sys
input = sys.stdin.readline
a, b, q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(a)] + [INF]
t = [-INF] + [int(input()) for i in range(b)] + [INF]
ans = ['' for _ in range(q)]
for i in range(q):
    x = int(input())
    idxs = bisect.bisect(s, x)
    idxt = bisect.bisect(t, x)
    ans[i] = str(min(x - min(s[idxs - 1], t[idxt -1]),
                     x - s[idxs - 1] + (t[idxt] - s[idxs - 1]),
                     t[idxt] - x + (t[idxt] - s[idxs - 1]),
                     x - t[idxt - 1] + (s[idxs] - t[idxt - 1]),
                     s[idxs] - x + (s[idxs] - t[idxt - 1]),
                     max(s[idxs], t[idxt]) - x,
                     x - min(s[idxs - 1], t[idxt -1])))
print('\n'.join(ans))


Measured memory_bytes: 21360
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int64_t> hs(n);
    for (auto& h : hs)
    {
        cin >> h;
    }
    sort(hs.begin(), hs.end());
    int64_t ans = 0;
    for (int i = 0; i < n - k; i++)
    {
        ans += hs[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define IL inline
#define _ 100005
#define ll long long
using namespace std ;

IL int gi(){
    int data = 0 , m = 1; char ch = 0;
    while(ch!='-' && (ch<'0'||ch>'9')) ch = getchar();
    if(ch == '-'){m = 0 ; ch = getchar() ; }
    while(ch >= '0' && ch <= '9'){data = (data<<1) + (data<<3) + (ch^48) ; ch = getchar(); }
    return (m) ? data : -data ; 
}

int f[_],q[_],q2[_],K[_],fa[_],B[_],tot,tot2,n,m,dsu[_],dep[_],U,V,sum ; 
int Ans ; bool cov[_] ;vector<int> edge[_] ;
IL int Find(int x) {return x^dsu[x] ? dsu[x]=Find(dsu[x]):x ; }
namespace cpp1{
	void dfs(int u , int From) {
		for(auto v : edge[u]) {
			if(v != From) dfs(v , u) , f[u] -= f[v] ;
		}f[u] ++ ; Ans += abs(f[u]) ;
	}
	IL void main() {
		dfs(1 , 0) ; if(f[1]!=0) puts("-1") ; else cout << Ans << endl ;
	}
}
namespace cpp2{
	void dfs1(int u , int From) {
		for(auto v : edge[u])
			if(v != From) dep[v] = dep[u] + 1 , fa[v] = u , dfs1(v,u) ;
	}
	void dfs2(int u , int From) {
		for(auto v : edge[u])
			if(!cov[v] && v != From) dfs2(v , u) , f[u] -= f[v] ;
		f[u] ++ ; Ans += abs(f[u]) ; return ;
	}
	IL void main() {
		dfs1(1 , 0) ;
		while(U ^ V) {
			if(dep[U] > dep[V]) q[++ tot] = U , cov[U] = true , U = fa[U] ;
			else q2[++ tot2] = V , cov[V] = true , V = fa[V] ; 
		}q[++ tot] = U ; cov[U] = true ;
		while(tot2) q[++ tot] = q2[tot2 --] ;
		for(int i = 1; i <= tot; i ++) dfs2(q[i] , 0) , Ans -= abs(f[q[i]]) , sum += f[q[i]] ;
		K[1] = 1 ; B[1] = 0 ;
		for(int i = 2; i <= tot; i ++) K[i] = - K[i - 1] , B[i] = f[q[i]] - B[i - 1] ;
		if(sum & 1) puts("-1") , exit(0) ;
		if(tot & 1) {
			int x = f[q[1]] - B[tot] ; x >>= 1 ;
			for(int i = 1; i <= tot; i ++) Ans = Ans + abs(K[i] * x + B[i]) ;
		}
		else {
			sum = f[q[1]] ; for(int i = 2; i <= tot; i ++) sum = f[q[i]] - sum ; if(sum!=0) puts("-1"),exit(0) ;
			for(int i = 1; i <= tot; i ++) if(K[i] < 0) B[i] = - B[i] ;
			sort(B + 1 , B + tot + 1) ;
			for(int i = 1; i <= tot; i ++) Ans = Ans + abs(B[i] - B[(tot + 1) >> 1]) ; 
		}cout << Ans << endl ;
	}
}

int main() {
	n = gi() ; m = gi() ;
	for(int i = 1; i <= n; i ++) dsu[i] = i ;
	for(int i = 1,u,v,fu,fv; i <= m; i ++) {
		u = gi() , v = gi() ; fu = Find(u) ; fv = Find(v) ;
		if(fu != fv) edge[u].push_back(v),edge[v].push_back(u),dsu[fu] = fv ;
		else U = u , V = v ; 
	}
	if(n != m) cpp1::main() ;
	else cpp2::main() ; return 0 ; 
}


Measured memory_bytes: 13824
/*************
 *
 *ALDS1-9_B
 *Binary Search Tree
 *
 *2020/07/20
 *
 *
 *
 *************/
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

typedef struct node{
  long long key;
  struct node* left;
  struct node* right;
} Node;

const int max_buffer = 32;

Node* createdNode(long long key){
  Node *new_node;
  new_node = (Node*)(calloc(1,sizeof(Node)));

  new_node->key = key;
  new_node->left = NULL;
  new_node->right = NULL;

  return new_node;
}

Node* insert(Node *T,Node *z){

  Node* current_node = T;

  if(current_node == NULL){
    T = z;
  }
  else{
    while(1){
      if(z->key < current_node->key){
	if(current_node->left != NULL) {
	  current_node = current_node->left;
	}
	else {
	  current_node->left = z;
	  break;
	}
      }
      else {
	if(current_node->right != NULL) {
	  current_node = current_node->right;
	}
	else {
	  current_node->right = z;
	  break;
	}
      }
    }
  }
  return T;
}

bool find(Node *node,long long key){
  if(node == NULL) return false;
  
  if(node->key == key) return true;
  else {
    if(key < node->key){
      return find(node->left,key);
    }else {
      return find(node->right,key);
    }
  }
}
  
void print_inorder(Node *node){

  if(node->left != NULL) print_inorder(node->left);

  printf(" %lld",node->key);
  
  if(node->right != NULL) print_inorder(node->right);
}

void print_preorder(Node *node){

  
  printf(" %lld",node->key);
  
  if(node->left != NULL) print_preorder(node->left);
  if(node->right != NULL) print_preorder(node->right);

  return;
}

int main(void){
  int n;
  char string[max_buffer];
  char order[8];//最長命令数(=6)と'\0'
  long long key=0;
  Node *root = NULL;
  Node *input_node =NULL;
  
  fgets(string,sizeof(string),stdin);
  sscanf(string,"%d",&n);
  
  for(int i=0;i<n;i++){
    
    fgets(string,sizeof(string),stdin);
    sscanf(string,"%s %lld",order,&key);

    switch(string[0]){
    case 'i':
      input_node = createdNode(key);
      root = insert(root,input_node);
      break;
    case 'p':
      if(root != NULL){
	print_inorder(root);
	printf("\n");
	print_preorder(root);
	printf("\n");
      }
      break;
    case 'f':
      if(find(root,key) == true) printf("yes\n");
      else printf("no\n");
      break;
    default:
      printf("\"%s\" is error.",string);
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 15116
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;

vector<int> g[5010];
int directed[5010];
vector<int> res;

int main(void){
	int n, m; cin >> n >> m;
	for(int i = 0; i < m; i++){
		int a, b; cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		directed[b]++;
	}

	stack<int> s;
	bool is_unique = true;
	for(int i = 0; i < n; i++){
		if(directed[i] == 0) s.push(i);
	}
	while(not s.empty()){
		if(s.size() >= 2) is_unique = false;

		int x = s.top(); s.pop();
		res.push_back(x);
		for(int i = 0; i < (int)g[x].size(); i++){
			int nx = g[x][i];
			if(--directed[nx] == 0) s.push(nx);
		}
	}

	for(int i = 0; i < n; i++) printf("%d\n", res[i]+1);
	for(int i = 0; i < n-1; i++){
		if(find(begin(g[res[i]]), end(g[res[i]]), res[i+1]) == g[res[i]].end()){
			printf("1\n");
			return 0;
		}
	}
	printf("0\n");
	// printf("%d\n", not is_unique);

	return 0;
}



Measured memory_bytes: 3880
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        java.util.Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int ans = 0;
        for (int i=0; i<3; i++){
            if (a % 10 == 1)
                ans++;
            a /= 10;
        }
        System.out.println(ans);
        }
}

Measured memory_bytes: 21588
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
void YN(bool flg){cout<<(flg?"YES":"NO")<<endl;}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<endl;}
void yn(bool flg){cout<<(flg?"yes":"no")<<endl;}
signed main(){
	int l,r,a,b,c,d;
	cin>>a>>b>>c>>d;
	l=a+b;r=c+d;
	if(l>r) cout<<"Left"<<endl;
	if(l==r) cout<<"Balanced"<<endl;
	if(l<r) cout<<"Right"<<endl;
}

Measured memory_bytes: 256
N, M = list(map(lambda x: int(x), input().split(" ")))
ppl = []
chk = []
for i in range(N):
  ppl.append(list(map(lambda y: int(y), input().split(" "))))
for j in range(M):
  chk.append(list(map(lambda z: int(z), input().split(" "))))

goal = [0] * N
for i in range(N):
  stu = ppl[i]
  min_d = -1
  dest = 0

  for j in range(M):
    point = chk[-j-1]
    d = abs(stu[0] - point[0]) + abs(stu[1] - point[1])
    if min_d < 0 or d <= min_d:
      min_d = d
      dest = M - j
  
  goal[i] = dest

print("\n".join([str(g) for g in goal]))
      

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

#define pb  push_back
#define ll  long long
#define INF 0x3f3f3f3f
#define pii pair<int, int>
#define ull unsigned long long int

const int t = 105;
int p[t], v[t];
ll ans[t][100005];
int n, w;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n >> w;
    for (int i = 0; i < n; i++) 
        cin >> p[i] >> v[i];
    
    for (int i = n; i >= 0; i--) {
        for (int j = 1; j <= w; j++) {
            ll passa = ans[i + 1][j];
            if (j - p[i] < 0) {
                ans[i][j] = passa;
                continue;
            }
            ll pega = ans[i + 1][j - p[i]] + v[i];
            ans[i][j] = max(pega, passa);
        }
    }
    cout << ans[0][w] << "\n";
    
    //cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}

Measured memory_bytes: 80128
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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 main(void){

    int N;
    cin >> N;
    
    if(floor(floor(N/1.08)*1.08) == N) cout << floor(N/1.08) << endl;
    else if(floor(ceil(N/1.08)*1.08) == N) cout << ceil(N/1.08) << endl;
    else cout << ":(" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
    int W , H , x , y , r ;
    std::cin >> W >> H >> x >> y >> r ;
    
    if( x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H ) {
        std::cout << "Yes" ;
    } else {
        std::cout << "No" ;
    }
    
    std::cout << std::endl ;
}


Measured memory_bytes: 3124
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
	int i=0,ans=0,N;
	string str;
	cin>>str;
	N=str.size();
	if(N!=1){
	while(i<N){
		i++;
		if(str[i]==str[i-1]){
			ans++;
			i++;
			while((str[i]!=str[i-1])&&(i<N)){
				ans++;
				i++;
				
			}
		}
	}
	}
	cout<<min(ans,N-ans);
			
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
long long modpow(long long a, long long b, long long m){
  long long ans = 1;
  while (b > 0){
    if (b % 2 == 1){
      ans *= a;
      ans %= m;
    }
    a *= a;
    a %= m;
    b /= 2;
  }
  return ans;
}
map<long long, long long> mp;
long long modinv(long long a, long long m){
  if (mp.count(a)){
    return mp[a];
  } else {
    long long ans = modpow(a, m - 2, m);
    mp[a] = ans;
    return ans;
  }
}
int main(){
  int p;
  cin >> p;
  vector<int> a(p);
  for (int i = 0; i < p; i++){
    cin >> a[i];
  }
  vector<vector<long long>> P(p + 1);
  P[0] = vector<long long>(1, 1);
  for (int i = 0; i < p; i++){
    P[i + 1] = vector<long long>(i + 2, 0);
    for (int j = 0; j <= i; j++){
      P[i + 1][j] -= P[i][j] * i % p;
      P[i + 1][j + 1] += P[i][j];
    }
    for (int j = 0; j <= i + 1; j++){
      P[i + 1][j] += p;
      P[i + 1][j] %= p;
    }
  }
  vector<int> ans(p, 0);
  for (int i = 0; i < p; i++){
    if (a[i] == 1){
      vector<int> add(p, 0);
      if (i == 0){
        for (int j = 0; j < p; j++){
          add[j] = P[p][j + 1];
        }
      } else {
        int inv = modinv(i, p);
        add[0] = (p - P[p][0]) * inv % p;
        for (int j = 1; j < p; j++){
          add[j] = (p + add[j - 1] - P[p][j]) * inv % p;
        }
      }
      long long c = 1;
      for (int j = 0; j < p; j++){
        if (j != i){
          c *= (i - j + p) % p;
          c %= p;
        }
      }
      int coef = modinv(c, p);
      for (int j = 0; j < p; j++){
        ans[j] += add[j] * coef;
        ans[j] %= p;
      }
    }
  }
  for (int i = 0; i < p; i++){
    cout << ans[i];
    if (i < p - 1){
      cout << ' ';
    }
  }
  cout << endl;
}

Measured memory_bytes: 39104
// In The Name Of Allah

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

#define F first
#define S second
#define pp pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

const int maxx = 1e6 + 19;
const int inf = 1e18 + 19;
const int mod = 1000000007LL;

int n, m;

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    if (m == 1 || m == (2 * n) - 1)
        return cout << "No", 0;
    else {
        cout << "Yes" << endl;
        for (int i = 0; i < 2 * n - 1; i++)
            cout << (i + m - n + 2 * n - 1) % (2 * n - 1) + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll k;cin>>k;
  lque q;rep(i,9) q.push(i+1);
  rep(i,k-1) {
    ll t=q.front(),v=t%10;q.pop();
    if(v!=0) q.push(t*10+v-1);
    q.push(t*10+v);
    if(v!=9) q.push(t*10+v+1);
  }
  print(q.front());
  return 0;
}

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

int main(){
    int n; cin >> n;
    int a = 0, b = 0, c = 0, d = 0;
    while(n--){
        string s; cin >> s;
        if(s == "AC") a++;
        else if(s == "WA") b++;
        else if(s == "TLE") c++;
        else d++;
    }
    cout << "AC x " << a << endl;
    cout << "WA x " << b << endl;
    cout << "TLE x " << c << endl;
    cout << "RE x " << d << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <numeric>
using namespace std;
using Int = long long;
#define DUMP(range) do{for(auto& x:range){cout<<x<<' ';}cout<<endl;}while(0)
int main()
{
    int N, A; cin >> N >> A;
    map<pair<int, int>, Int> S1, S2;
    for (int i = 0; i < N; i++) {
        int x; cin >> x;
        S2[make_pair(x, 1)] += 1;
        for (auto& p : S1) {
            int n, c;
            tie(n, c) = p.first;
            S2[make_pair(n, c)] += p.second;
            S2[make_pair(n+x, c+1)] += p.second;
        }
        S1.swap(S2);
        S2.clear();
    }
    Int ans = 0;
    for (int i = 1; i <= N; i++) {
        ans += S1[make_pair(A*i, i)];
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
const int MAXN = 100100;

int N;
ll arr[MAXN];

ll res()
{
    ll ctot = 0;
    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        ctot += arr[i];
        if (i % 2 == 0)
        {
            if (ctot <= 0)
            {
                ans += 1 - ctot;
                ctot = 1;
            }
        }
        else
        {
            if (ctot >= 0)
            {
                ans += ctot + 1;
                ctot = -1;
            }
        }
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> arr[i];

    ll a = res();
    for (int i = 0; i < N; i++)
        arr[i] = -arr[i];
    a = min (a, res());
    cout << a << "\n";
}

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

using namespace std;

int main(){
	int n;

	cin >> n;

	while(n != 0){
		int point[1005];
		int max = 0, min = 0;

		for(int i=0; i<n; i++){
			cin >> point[i];
		}

		for(int i=1; i<n; i++){
			if(point[max] < point[i])
				max = i;
			else if(point[i] < point[min] )
				min = i;
		}

		point[max] = 0;
		point[min] = 0;

		int sum = 0;

		for(int i=0; i<n; i++)
			sum += point[i];

		//cout << sum << endl;

		cout << sum/(n-2) << endl;

		cin >> n;
	}

	return 0;
}

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    string s;
    cin >> n >> s >> k;
    int kk = k - 1;
    for(int i = 0; i < n; i++){
        if(s[i] == s[kk]){
            cout << s[i];
        }
        else{
            cout << "*";
        }
    }

    return 0;
}


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

#define PI acos(-1)
#define hell 1000000007
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
#define endl "\n"
#define out(n) cout<<n<<" "
#define outl(n) cout<<n<<endl
#define line cout<<endl
#define bug(n) {outl(n);return;}
#define N 100005
ll n,d;
void solve(){
    cin>>n>>d;
    d*=2;d++;
    bug(n/d+(n%d!=0));
}
void prep(){
    
}
int main(){
    io;
    ll t=1;
    // cin>>t;
    prep();
    fix(12);
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
from collections import Counter


def get_result(data):
    N = data[0][0]
    A = data[1]
    L = [0 for _ in range(N)]
    R = [0 for _ in range(N)]
    for i in range(N):
        L[i] = i + A[i] + 1
        R[i] = i + 1 - A[i]

    L_cnt = Counter(L)
    R_cnt = Counter(R)
    ans = 0
    max_key = max(R_cnt.keys())
    for i in range(max_key+1):
        ans += L_cnt[i] * R_cnt[i]
    return ans


if __name__ == '__main__':
    raw_data = [val.rstrip() for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)


Measured memory_bytes: 64980
S = input()

cnt =0
for i in range(1<<(len(S)-1)):
    num = int(S[0])
    for j in range(len(S)- 1):
        if i & (1 << j):
            cnt += num
            num = 0
        num = num*10 + int(S[j+1])
    cnt += num

print(cnt)


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;
//using static System.Math;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
    readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    int N;
    void solve()
    {
        N = cin.nextint;
        var D = new long[N, N];
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                D[i, j] = cin.nextint;
            }
        }

        var A = new bool[N, N];
        for (int k = 0; k < N; k++)
        {
            for (int i = 0; i < N; i++)
            {
                //bool flag = true;
                for (int j = 0; j < N; j++)
                {
                    if (D[i, j] > D[i, k] + D[k, j])
                    {
                        WriteLine(-1);
                        return;
                    }
                    if (D[i, j] == D[i, k] + D[k, j] && i != k && k != j)
                    {
                        A[i, j] = true;
                    }
                }

            }
        }
        long ans = 0;
        for (int i = 0; i < N; i++)
        {
            for (int j = i + 1; j < N; j++)
            {
                if (!A[i, j])
                {
                    ans += D[i, j];
                }
            }
        }
        WriteLine(ans);

    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 19544
n = int(input()); summ = 0;
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
for i in range(n):
    summ = summ + b[a[i]-1]
    if i>0:
        if a[i] == a[i-1] + 1:
            summ = summ + c[a[i-1]-1]
print(summ)

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

int main() {
  long long a, b, k, ans1, ans2;
  cin >> a >> b >> k;
  if (k - a > 0){
    ans1 = 0;
    k = k - a;
  }
  else{
    ans1 = a - k;
    k = 0;
  }
  if (k > b) {
    ans2 = 0;
  }
  else{
    ans2 = b - k;
  }
  cout << ans1 << " " <<ans2;
}

Measured memory_bytes: 256
import math
A, B, H, M = map(int, input().split())

xa = A * math.sin(H * math.pi / 6 + M * math.pi / 360)
ya = A * math.cos(H * math.pi / 6 + M * math.pi / 360)
xb = B * math.sin(M * math.pi / 30)
yb = B * math.cos(M * math.pi / 30)

l = math.sqrt((xb - xa) ** 2 + (yb - ya) ** 2)
print(l)

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

int main(){

    int n;
    bool right=true;
    set<string> s;
    char prec;

    cin>>n;

    for(int i=0;i<n;i++){
        string w; cin>>w;
        if(i>=1&&w[0]!=prec) right=false;
        if(s.count(w)) right=false;
        else s.insert(w);
        prec=w[w.size()-1];
    }

    cout<<(right?"Yes":"No")<<endl;

    return 0;
}

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

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  int k=max(A,max(B,C));
  if(k==A){
    cout << B*C/2<<endl;
  }else if(k==B){
    cout << A*C/2<<endl;
  }else if(k==C){
    cout << A*B/2<<endl;
  }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using ll = long long;
using namespace std;

void solve() {
    int n, m;
    cin>>n>>m;
    vector< int > pre[100001]; int p[100000], y[100000];
    for(int i=0;i<m;i++)
        cin>>p[i]>>y[i], pre[p[i]].push_back(y[i]);
    for(int i=0;i<n;i++)
        sort(pre[i+1].begin(),pre[i+1].end());
    for(int i=0;i<m;i++){
        ll final = (ll)p[i]*1000000 + ll(lower_bound(pre[p[i]].begin(), pre[p[i]].end(), y[i])-pre[p[i]].begin()) +1;
        printf("%012lld\n",final);
    }
    

}

int main() 
{
    std::ios::sync_with_stdio(false); \
        std::cin.tie(NULL);
    int test;
    test =1 ;
    while (test--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 10000
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){

  int N;
  cin >> N;

  double a[N];

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

  double inverse = 0;

  for(int i=0;i<N;i++){
  	inverse += 1.0/a[i];
  	//cout << inverse <<endl;
  }

  cout << fixed << setprecision(6) << 1.0/inverse <<endl;

  return 0;
}




Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll LINF = 1001002003004005006LL;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n; cin >> n;
    int ans = 0;
    vector<int> f(n);
    rep(x,110) {
        rep(y,110) {
            rep(z, 110) {
                if (x>0 && y>0 && z>0) {
                    int t = x*x + y*y + z*z + x*y + y*z + z*x;
                    if (t<=n) {
                        f[t-1]++;
                    }
                }        
            }
        }
    }
    rep(i,n) cout << f[i] << endl;
    return 0;
}

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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

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

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21724
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

signed main() {
	string s;
	cin >> s;
	
	if (s.substr(0, s.size()) <= "2019/04/30") {
		cout << "Heisei" << endl;
	}
	else {
		cout << "TBD" << endl;
	}
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000
 
struct Card {
  char suit;
  int value;
};
 
struct Card L[MAX/2+2], R[MAX/2+2];
 
void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for(int i=0;i<n1;i++) L[i] = A[left + i];
  for(int i=0;i<n2;i++) R[i] = A[mid  + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for(k=left; k<right; k++) {
    if(L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}
 
void mergeSort(struct Card A[], int n, int left, int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}
 
int partition(struct Card A[], int n, int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j].value <= x.value) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}
 
void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if(p<r) {
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}
 
int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;
 
  scanf("%d", &n);
 
  for(i=0;i<n;i++) {
    scanf("%s %d",S,&v);
    A[i].suit =  B[i].suit  = S[0];
    A[i].value = B[i].value = v;
  }
 
  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);
 
  for(i=0;i<n;i++) {
    // ????????????????????¨??????????????????????????????????????????
    if(A[i].suit != B[i].suit) stable = 0;
  }
 
  if(stable==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++) {
    printf("%c %d\n",B[i].suit,B[i].value);
  }
 
  return 0;
}

Measured memory_bytes: 4080
MAIN : {
	my $s1 = <STDIN>;
	chomp $s1;
	my ($a, $b, $c) = split(" ", $s1);
	
	my $m = int($b / $a);
	
	if ($m > $c) {
		print STDOUT $c, "\n";
	}
	else {
		print STDOUT $m, "\n";
	}
}

__END__


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

#define PB push_back
#define ALL(v) (v).begin(), (v).end()
#define SZ size()
#define FOR(i, a, n) for(long long (i) = (a); (i) < (n); (i)++)
#define REP(i, n) FOR((i), 0, (n))
#define SHOW(v) cout << (v) << endl
#define SHOW2(a, b) cout << (a) << " " << (b) << endl
#define SHOW3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl
#define GET(v) cin >> (v)
#define GET2(a, b) cin >> (a) >> (b)
#define GET3(a, b, c) cin >> (a) >> (b) >> (c)
#define MOD 1000000007
template<class T> void GETV(T &v) { REP(i, v.size()) { GET(v[i]); } }
template<class T> void SHOWV(T &v) { REP(i, v.size()) { SHOW(v[i]); } }

typedef long long ll;

int main()
{
    string s;
    cin >> s;
   
    ll white = 0;
    ll black = 0;
    vector<ll> wdx;
    vector<ll> bdx;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == 'B') {
            black++;
            bdx.PB(i);
        }
        else {
            white++;
            wdx.PB(i);
        }
    }
    
    ll cnt = 0;
    while(s[s.size() - 1 - cnt] == 'B') {
        cnt++;
    }
    
    ll ans = 0;
    for(int i = bdx.size() - cnt - 1; i >= 0; i--) {
        ans += s.size() - cnt - bdx[i] - 1;
        cnt++;
    }
    
    cout << ans << endl;
    
    return 0;
}


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

int main () {
  int N , pre , ans = 1 ;
  cin >> N >> pre ;
  for(int i = 0 ; i < N -1 ; i++ ){
    int a ;
    cin >> a ;
    if(pre<=a){
      ans++ ;
      pre = a ;
    } else {
    }
  }
  cout << ans << endl ;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

//container util
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQUE(a)  (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define RREP(i,n) RFOR(i,n,0)

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";

const int INF = 1e9;
const double EPS = 1e-10;

int n;

int main() {
	cin >> n;
	REP(i,n){
		int a, b;
		cin >> a >> b;
		a =a%b;
		if(!a)a=b;
		cout<<a<<endl;
	}
}

Measured memory_bytes: 3104
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
		int K = sc.nextInt();
		PriorityQueue<Integer> pq = new PriorityQueue<>(Comparator.reverseOrder());
		ArrayList<Integer> al = new ArrayList<>();
		char[] c = sc.next().toCharArray();
		int temp = 1;
		for(int i=0; i<N-1;i++){
			if (c[i] == c[i+1]){temp += 1;}
			else{
				al.add(temp);
				temp = 1;
			}
		}
		al.add(temp);
		int Ans = 0;
		if(al.size()<K*2+1){Ans = N-1;}
		else{Ans = N-al.size()+2*K;}
		System.out.println(Ans);
	}
}

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

int main() {
  int H,W;
  cin >> H >> W;
  
  string S="",s,z="";
  
  for(int i=0 ; i < W+2 ;i++){
    z = z + '.';
  }
  //cout << z << endl;
  
  S = z;
  for(int i=0 ; i<H ; i++){
    cin >> s;
    S = S + '.'+ s + '.';
    //cout << S << endl;
  }
  S += z;
 
  //出力
  for(int i=0 ; i < (H+2)*(W+2) ; i++){
    //cout << S.at(i);
    if(i%(W+2) == W + 1){
      //cout << endl;
    }
  }
  //cout << "--------------" << endl;
  for(int i=0 ; i < (H+2)*(W+2) ; i++){
    //cout << S.at(i);
    if(i%(W+2)==(W+1)){
        //cout << endl;
    }
  }
  
  //cout << "--------------" << endl;
  int flag = 0;
  for(int i=0 ; i < (H+2)*(W+2) ; i++){
    if((0<=i && i<=W+1) || i%(W+2)==0 || (H+2)*(W+2) - (W+2) < i){
      //flag++;
      //cout << flag << endl;
      continue;
    }
    if(i%(W+2)==(W+1)){
        cout << endl;
      continue;
    }
    
    //いよいよ計算
    
    int count = 0;
    int x = W + 2;
    //cout << "S(9):" << S.at(9);
    if(S.at(i)=='#'){
      cout << '#';
      //cout << i;
    }
    
    else if(S.at(i)=='.'){
      if(S.at(i-x)=='#'){
        count++;
      }if(S.at(i-x-1)=='#'){
        count++;
      }if(S.at(i-x+1)=='#'){
        count++;
      }
      
      if(S.at(i-1)=='#'){
        count++;
      }if(S.at(i+1)=='#'){
        count++;
      }
      
      if(S.at(i+x)=='#'){
        count++;
      }if(S.at(i+x-1)=='#'){
        count++;
      }if(S.at(i+x+1)=='#'){
        count++;
      }
      cout << count;
      //cout << S.at(i);
    }
  }
}


Measured memory_bytes: 256
a,b,c = map(int,input().split(" "))
cdiv = []
for i in range(1,c//2+1):
    if c%i == 0:
        cdiv.append(i)
cdiv.append(c)
countn = 0
for divisor in cdiv:
    if divisor >= a and divisor <= b:
        countn += 1
print(countn)


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int a,b,p;
  while(cin>>a>>b>>p,a){
    int l=b-a+1;

    vector<int> dp(l,0);
    map<int, int> sm;
    for(int i=a;i<=b;i++){
      sm[i]=0;
      dp[i-a]=1;

      string s=to_string(i);
      if(s.size()==to_string(i-1).size()){
        sm[i]+=sm[i-1];
        sm[i]%=p;

        dp[i-a]+=sm[i-1];
        dp[i-a]%=p;
      }

      while(s.size()>1){
        s.pop_back();
        dp[i-a]+=sm[stoll(s)];
        dp[i-a]%=p;
      }

      sm[i]+=dp[i-a];
      sm[i]%=p;
    }

    int ans=0;
    for(int d:dp) ans+=d,ans%=p;
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 8556
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define Endl endl

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int ceil_(int a, int b) { return (a + (b - 1)) / b; }
int positive_surplus(int &a) { return (a + MOD) % MOD; }
int bpm(int x, unsigned int y) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (unsigned int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}
template <class T>
void cumulative_sum(T &container) {
  for (int i = 0; i < container.size() - 1; i++) container[i + 1] += container[i];
}

class AAC {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    string S;
    cin >> S;
    if (S == "ABC") cout << "ARC" << endl;
    if (S == "ARC") cout << "ABC" << endl;
  }
};


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


Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>

using namespace std;

const int MAX_N = 200000;

int R[MAX_N];

int main()
{
	int n,minr;
	int max = -1000000000;
	cin >> n;
	for(int i=0;i<n;i++){
		scanf("%d",&R[i]);
	}
	minr = R[0];
	for(int i=1;i<n;i++){
		if(max < R[i] - minr){
			max = R[i]-minr;
		}
		if(R[i] < minr){
			minr = R[i];
		}
	}
	cout << max << "\n";
}

Measured memory_bytes: 4000
let () =
  Scanf.scanf "%d %d %s" @@ fun n q s ->
  let ss = Array.init (n+1) (fun i -> 
    if i > 1 && s.[i-2] = 'A' && s.[i-1] = 'C' then 1 else 0) in
  for i = 1 to n do ss.(i) <- ss.(i) + ss.(i-1); done;
  Array.init q (fun _ -> Scanf.scanf " %d %d" (fun x y -> x, y))
  |> Array.iter (fun (l,r) ->
      let v = ss.(r) - ss.(l-1) in
      let v = if l > 1 && s.[l-2] = 'A' && s.[l-1] = 'C' then v-1 else v in
      Printf.printf "%d\n" v)


Measured memory_bytes: 7936
H, W = map(int, input().split())
S = [input() for _ in range(H)]
D = {}
center_of_center = (H % 2) * (W % 2)
center_of_H = (H % 2) * (W >> 1)
center_of_W = (W % 2) * (H >> 1)
for i in range(H):
  for j in range(W):
    if S[i][j] in D:
      D[S[i][j]] += 1
    else:
      D[S[i][j]] = 1
odd, half_odd, four = 0, 0, 0
odds = []
half_odds = []
fours = []
for i in D:
  if D[i] % 2:
    odd += 1
    odds.append(i)
  else:
    if (D[i] >> 1) % 2:
      half_odds.append(i)
      half_odd += 1
    else:
      four += 1
      fours.append(i)
if odd != center_of_center:
  print("No")
else:
  if odd != 0:
    D[odds[0]] -= 1
    if D[odds[0]] % 4 == 2:
      half_odd += 1
    else:
      four += 1
  if (center_of_H + center_of_W) % 2 != half_odd % 2 or center_of_H + center_of_W < half_odd:
    print("No")
  else:
    print("Yes")

Measured memory_bytes: 9176
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int powmod(int a, int n, int mod) {
	if (n == 0) return 1;
	if (n % 2 == 0) return powmod((a * a) % mod, n / 2, mod);
	return (a * powmod(a, n - 1, mod)) % mod;
}

int mod = 1000000007;
int fact[201];
int factInv[201];

void init() {
	int i;
	fact[0] = 1;
	factInv[0] = 1;
	for (i = 1; i <= 200; i++) {
		fact[i] = (i * fact[i - 1]) % mod;
		factInv[i] = powmod(fact[i], mod - 2, mod);
	}
}

int nPk(int n, int k) {
	if (n < k) return 0;
	return (fact[n] * factInv[n - k]) % mod;
}

int n, x;
int s[200];
int dp[100002];

int getCnt(int l, int r) {
	int x = lower_bound(s, s + n, l) - s;
	int y = lower_bound(s, s + n, r) - s;
	return y - x;
}

int MAX = 100001;
//int MAX = 30;

signed main() {
	int i, j;
	
	init();
	cin >> n >> x;
	rep(i, n) cin >> s[i];
	sort(s, s + n);
	
	dp[MAX] = 1;
	for (i = MAX; i > 0; i--) {
		if (dp[i] == 0) continue;
		//cout << "dp[" << i << "] = " << dp[i] << endl;
		if (i == MAX) {
			int a = getCnt(0, i + 1);
			int b = getCnt(x + 1, i + 1);	//x+1以上i+1未満
			dp[x] += dp[i] * nPk(a, b) % mod;
			dp[x] %= mod;
		}
		else {
			for (j = 0; j < n; j++) {	//Sj
				if (s[j] > i) break;
				//cout << "i, s[j] = " << i << ", " << s[j] << endl;
				int y = i % s[j];
				int a = getCnt(0, i + 1) - 1;
				int b = getCnt(y + 1, i + 1);
				if (s[j] > y) b--;
				//cout << "y, a, b = " << y << ", " << a << ", " << b << endl;
				//cout << "nPk(a, b) = " << nPk(a, b) << endl;
				//cout << endl;
				dp[y] += dp[i] * nPk(a, b) % mod;
				dp[y] %= mod;
			}
		}
	}
	
	int ans = 0;
	for (i = 0; i < s[0]; i++) {
		ans += dp[i] * i;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
	
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if (n / 100 == n % 10) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 22608
N, M = map(int,input().split())
s = [None]*M
c = [None]*M
for i in range(M):
    s[i], c[i] = map(int,input().split())
if N != 1:
    for n in range(10**(N-1), 10**N):
        st = str(n)
        f = True
        for i in range(M):
            if st[s[i]-1] != str(c[i]):
                f = False
                break
        if f:
            print(n)
            exit(0)
    print(-1)
else:
    for n in range(0, 10):
        st = str(n)
        f = True
        for i in range(M):
            if st[s[i]-1] != str(c[i]):
                f = False
                break
        if f:
            print(n)
            exit(0)
    print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)

using namespace std;

int main(void) {

	long long a;
	long long b;

	cin >> a >> b;

	vector<long long> vec;

	vec.push_back(a+b);
	vec.push_back(a-b);
	vec.push_back(a*b);

	sort(vec.begin(), vec.end());

	cout << vec[2];

}




Measured memory_bytes: 256