akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;


int n;
string s;
string foo(string st){
	//cout<<st<<endl;
	if(st[1]>='0'&&st[1]<='9'){
		int j=0;
		vint v;
		while(st[j]=='['){
			j++;
			//cout<<"s[j]"<<" "<<s[j]<<endl;
			string ts=st.substr(j);
			//cout<<"ts "<<ts<<endl;
			stringstream tss;
			tss<<ts;
			int a;
			tss>>a;
			//cout<<" a "<<a<<endl;
			v.PB(a);
			//cout<<"push "<<a/2+1<<" "<<a<<endl;
			while(st[j]>='0'&&st[j]<='9') j++;
			j++;
			//cout<<"st[j] "<<st[j]<<endl;
		}
		int a=0;
		sort(ALL(v));
		/*
		cout<<"vv\n";
		rep(i,v.size()){
			cout<<v[i]<<endl;
		}
		cout<<"end vv\n";
		
		*/
		rep(i,v.size()/2+1){
			a+=v[i];
		}
		stringstream ss1;
		//ss1<<"[";
		ss1<<a;
		//ss1<<"]";
		string res;
		ss1>>res;
		return res;
	}
	else{
		stringstream ss1;
		for(int i=0;i<st.size();i++){
			int c=0,c2=0;
			string ttt;
			for(int j=i;j<st.size();j++){
				c2++;
				if(st[j]=='[') c++;
				else if(st[j]==']') c--;
				if(c==0){
					//cout<<st.substr(j)<<endl;
					ttt=st.substr(i+1,c2-2);
					i=j;
					break;
				}
			}
			//cout<<"foo\n";
			ss1<<"[";
			ss1<<foo(ttt);
			ss1<<"]";
			//cout<<"foo end\n";
		}
		string res;
		ss1>>res;
		//if(res[0]=='[') res=foo(res);
		return res;
	}
	return "";
}
int main(){
    cin>>n;
    rep(i,n){
        cin>>s;
    	stringstream ss3;
    	rep(j,s.size()){
    		int c=0;
    		if(!(s[j+c]>='0'&&s[j+c]<='9')){
    			while(!(s[j+c]>='0'&&s[j+c]<='9')){
    				//cout<<c<<endl;
    				c++;
    			}
    			ss3<<s.substr(j,c);
    			j+=c-1;
    		}
    		else{
    			string tt=s.substr(j);
    			//cout<<tt<<endl;
    			stringstream ss4;
    			ss4<<tt;
    			int a;
    			ss4>>a;
    			//cout<<"a "<<a<<endl;
    			a=a/2+1;
    			ss3<<a;
    			while(s[j]!=']') j++;
    			j--;
    		}
    	}
    	ss3>>s;
    	//cout<<s<<endl;
    	string ans=foo(s.substr(1,s.size()-2));
    	int a;
    	while(ans[0]=='['){
    		ans=foo(ans);
    		//cin>>a;
    	}
    	cout<<ans<<endl;
    	
    }
	
    return 0;
}


/*
[[[99][59][63][85][51]][[1539][7995][467]][[51][57][79][99][3][91][59]]]
[[99 59 63 85 51][1539 7995 467][51 57 79 99 3 91 59]]
26+30+32  + 1004  + 87
88 1004 87

[[[[9][7][3]][[3][5][7]][[7][9][5]]][[[9][9][3]][[5][9][9]][[7][7][3]]][[[5][9][7]][[3][9][3]][[9][5][5]]]]
6+5+7 7+8+6 7+4+6
19 21 17
11 13 10
22
36





*/

Measured memory_bytes: 1360
a = input().split()
b = int(a[0] + a[1])
c = -1
i = 0
j = 0
while(j < 100100):
  if(b == j):
    c = b
  i+=1
  j = i*i
if(c != -1) :
  print('Yes')
else :
  print('No')

Measured memory_bytes: 3064
I0 = lambda :map(int,input().split())
I1 = lambda :int(input())
I2 = lambda :list(map(int,input().split()))
#####################################################


'''from sys import stdin,setrecursionlimit
#from copy import deepcopy
 
setrecursionlimit(10**6)
input=stdin.readline'''

def dfs(p,father=-1):
    for i in tree[p]:
        if i == father:
            continue
        counter[i]+=counter[p]
        dfs(i,p)

n ,q = I0()
counter = [0]*n
tree = [[] for i in range(n)]
for i in range(n-1):
    a,b=I0()
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

for i in range(q):
    p,x = I0()
    counter[p-1]+=x
    

#dfs(0)
stack = [0]
seen = dict()
seen[0] = 1
while stack:
    yy = stack.pop()
    for i in tree[yy]:
        if seen.get(i,-1) == -1:
            seen[i] = 1
            counter[i]+=counter[yy]
            stack.append(i)
            
print(*counter)



Measured memory_bytes: 117064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  string S;
  cin >> S;
  int cnt = 0;
  for(char c: S) if(c=='o') cnt++;
  cout << ((15-S.size()+cnt>=8) ? "YES" : "NO") << endl;
  return 0;
}


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

using namespace std ;

const int MAX = 2e5 + 10 ;

int arr[MAX] ;
int n ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n ;
	int x = 0 ;
	for(int i = 0 ; i < n ; ++i)
	{
		cin>>arr[i] ;
		x ^= arr[i] ;
	}
	x ^= arr[0] ;
	cout<<x<<" " ;
	x ^= arr[0] ;
	for(int i = 1 ; i < n ; ++i)
		cout<<(x ^ arr[i])<<" " ;
	cout<<"\n" ;
	return 0 ;
}		

Measured memory_bytes: 4364
#include <iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);

    int n, l, r;
    int c = 0;
   
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> l >> r;
        for (int j = l; j <= r; j++)
            c++;
    }
    cout << c << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n, sum = 0;
    cin >> n;
    for(int i = 1; i <= n; i++){
        if(i % 3 != 0 && i % 5 != 0){
            sum = sum + i;
        }
    }
    cout << sum;
    return 0;
}

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

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

Measured memory_bytes: 3600
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>

using namespace std;

int main(){
	int a,b,c,i,s;
	scanf("%d",&a);
	putchar('\n');
	scanf("%d",&b);
	for(i=1,c=1;i<=a;i++)
		{
			if(b>c)
			c=c*2;
		else
			c=c+b;
}
printf("%d",c);
return 0;
}


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

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
ll MOD = 1000000007;

void solve(){
	map<int,int> m;
	m[1] = 1;m[3] = 1;m[5] = 1;m[7] = 1;m[8] = 1;m[10] = 1;m[12] = 1;
	m[4] = 2;m[6] = 2;m[9] = 2;m[11] = 2;
	m[2] = 3;
	int a,b;
	cin >> a >> b;
	if(m[a] == m[b]) P("Yes");
	else P("No");

}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10,mod=998244353;
int n,k,dp[N];
struct node{
    int l,r;
}e[11];
int main(){
    scanf("%d%d",&n,&k);
    dp[1]=1;
    for(int j=1;j<=k;++j){
        scanf("%d%d",&e[j].l,&e[j].r);
    }
    for(int i=2;i<=n;++i){
        dp[i]=dp[i-1];
        for(int j=1;j<=k;++j){
            int nr=i-e[j].l,nl=i-e[j].r;
            if(nr<1)continue;
            nl=max(nl,1);
            dp[i]=(dp[i]+dp[nr])%mod;
            dp[i]=(dp[i]-dp[nl-1])%mod;
            dp[i]=(dp[i]+mod)%mod;
        }
    }
    ll ans=(dp[n]-dp[n-1]+mod)%mod;
    printf("%lld\n",ans);
    return 0;
}


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

int main()
{
	long long n;
	char s[10];
	//char top[]={'M','A','R','C','H'};
	long long c[5]={0};
	long long ans=0;
	scanf("%lld",&n);

	for(int i=0;i<n;i++){
		scanf("%s",s);
		if(s[0]=='M'){c[0]++;}
        if(s[0]=='A'){c[1]++;}
        if(s[0]=='R'){c[2]++;}
        if(s[0]=='C'){c[3]++;}
        if(s[0]=='H'){c[4]++;}
	}

	for(int i=0;i<5;i++){
		for(int j=i+1;j<5;j++){
			for(int k=j+1;k<5;k++){
				ans+=c[i]*c[j]*c[k];
			}
		}
	}
	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

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

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << (c >= a && c <= b ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
    //window_wide A
    int A;

    //curtain_wide N
    int B;

    std::cin >> A >> B;

    int len = B * 2;

    if(A <= len){
        std::cout << "0" << std::endl;
    }else{
        std::cout << A - len << std::endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ

int main()
{
    int x = 0;
    int y = 0;
    cin >> x >> y;
    array<int, 12> ar = {1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
    if (ar[x - 1] == ar[y - 1])
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    return 0;
}

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

const int MOD = 1e9 + 7;
const int N = 1e5 + 10;

int n, last[3] = {0,-1,-1}, dp[N];
string s;

int main() {
    cin >> s;
    int n = s.size();
    s = ' ' + s;
    bool rep = 0;
    for (int i = 0; i < (int) s.size()-1; i++) rep |= s[i] == s[i+1];
    if (!rep) return cout << 1, 0;

    dp[0] = 1;
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        int x = s[i]-'a'+1;
        sum += x;
        if (sum >= 3) sum -= 3;

        dp[i] = 0;
        for (int c = 1; c <= 2; c++) {
            int j = last[(sum+3-c)%3];
            if (j >= 0) {
                dp[i] += dp[j];
                if (dp[i] >= MOD) dp[i] -= MOD;
            }
        }
        if (sum == 0) {
            ++dp[i];
            if (dp[i] >= MOD) dp[i] -= MOD;
        }
        last[sum] = i;
    }
    cout << (dp[n] + MOD- (sum == 0)) % MOD << endl;
    return 0;
}


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

int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    vector <int> nums;
    int now = 1;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if(s[i] == (char)('0' + now)) cnt++;
        else {
            nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if (cnt != 0) nums.push_back(cnt);

    if (nums.size() % 2 == 0) nums.push_back(0);

    int Add = 2 * k + 1;

    int ans = 0;

    int left = 0;
    int right = 0;
    int tmp = 0;

    for (int i = 0; i < nums.size(); i += 2){
        int nextleft = i;
        int nextright = min(i + Add, (int)nums.size());

        while(nextleft > left) {
            tmp -= nums[left];
            left++;
        }

        while (nextright > right) {
            tmp += nums[right];
            right++;
        }

        ans = max(tmp, ans);
    }

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

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

int main()
{
  int h, w;
  cin >> h >> w;
  bool grid[h][w];
  uint path_count[h][w];
  const uint mod = 1'000'000'007;

  for (auto row = 0; row < h; row++) {
    for (auto col = 0; col < w; col++) {
      char c;
      cin >> c;
      grid[row][col] = c == '#' ? false : true;
      path_count[row][col] = 0;
    }
  }
  path_count[0][0] = 1;
  for (auto i = 0; i < h + w - 1; i++) {
    for (auto row = 0; row < h && i - row >= 0; row++) {
      auto col = i - row;
      if (col >= w) continue;
      if (!grid[row][col]) continue;
      if (col != w - 1 && grid[row][col + 1]) {
        path_count[row][col + 1] += path_count[row][col];
        path_count[row][col + 1] %= mod;
      }
      if (row != h - 1 && grid[row + 1][col]) {
        path_count[row + 1][col] += path_count[row][col];
        path_count[row + 1][col] %= mod;
      }
    }
  }
  cout << path_count[h - 1][w - 1] << endl;
}


Measured memory_bytes: 5120
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<complex>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/




int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	int n;
	
	cin >> n;
	string s;

	cin.ignore();
	getline(cin, s);
	string ans;
	for (int i = 0; i < n; i++)
	{
		ans.push_back(s[i]);
		ans.push_back(s[i + n+1]);
	}
	cout << ans << endl;






	return 0;
}


Measured memory_bytes: 256
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[int(input())-1])

Measured memory_bytes: 38416
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
using namespace std;

int n;
int a[100000];

signed main() {
	cin >> n;
	
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] % 2) cnt++;
	}
	if (cnt % 2) cout << "NO" << endl;
	else cout << "YES" << endl;
	return 0;
}

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

const ll N_MAX = 500;

ll N, M, Q;
vector<ll> L, R, p, q;
int train[N_MAX+1][N_MAX+1];
int train_sum[N_MAX+1][N_MAX+1];

void solve(){
  memset(train, 0, sizeof(train));
  memset(train_sum, 0, sizeof(train_sum));
  
  for(ll i = 0; i < M; i++){
    train[L[i]][R[i]] += 1;
  }

  for(ll i = 1; i <= N; i++){
    for(ll j = i; j <= N; j++){
      train_sum[i][j] = train_sum[i][j-1] + train[i][j];
    }
  }

  for(ll i = 0; i < Q; i++){
    ll ans = 0;
    for(ll j = p[i]; j <= q[i]; j++){
      ans += train_sum[j][q[i]];
    }
    cout << ans << endl;
  }
}


int main() {
  cin >> N >> M >> Q;

  for(ll i = 0; i < M; i++){
    ll s, t; cin >> s >> t;
    L.push_back(s);
    R.push_back(t);
  }

  for(ll i = 0; i < Q; i++){
    ll s, t; cin >> s >> t;
    p.push_back(s);
    q.push_back(t);
  }
  solve();
}

Measured memory_bytes: 11092
#include <iostream>

using namespace std;

long long fact (int n)
{
	if (n == 0)
	return 1;
	
	return n * fact(n - 1);
}

int main()
{
	int n;
		
	cin >> n;
	
	
	cout << fact(n) << endl;
	
	return 0;
}

Measured memory_bytes: 1156
n=int(input())
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
lc=list(map(int,input().split()))

ans=sum(lb)
lt=[]
for i in range(len(la)-1):
  if la[i]+1==la[i+1]:
    lt.append(la[i])

for j in lt:
  ans+=lc[j-1]

print(ans)

Measured memory_bytes: 9192
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn=1e5+111;
set<int> st;
struct node{
    int h;
}nn[maxn];
int flag[maxn];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i) scanf("%d",&nn[i].h);
    int ans=n;
    while(m--){
        int a,b;
        scanf("%d%d",&a,&b);
        if(nn[a].h>=nn[b].h&&flag[b]==0) --ans,flag[b]=1;
        if(nn[a].h<=nn[b].h&&flag[a]==0) --ans,flag[a]=1;
    }
    printf("%d\n",ans);
    return 0;
}

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

const int64_t MOD = 998244353;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

template<typename T>
vector<T> compress(vector<T> A){
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());
    return A;
}

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

    vector<int64_t> pw18(N+1, 1);
    int64_t B = int64_t(1e18) % MOD;
    for(int i=1; i<=N; i++) pw18[i] = pw18[i-1] * B % MOD;

    auto mex = [](vector<int>& V){
        V = compress(V);
        int sz = V.size();
        for(int i=0; i<sz; i++) if(V[i] != i) return i;
        return sz;
    };
    
    vector<int64_t> sum[3];
    int sz[3];
    for(int k=0; k<3; k++){
        int M;
        cin >> M;
        vector<int> edges[100000];
        while(M--){
            int a, b;
            cin >> a >> b;
            a--; b--;
            if(a > b) swap(a, b);
            edges[a].push_back(b);
        }
        vector<int> G(N);
        for(int i=N-1; i>=0; i--){
            vector<int> V;
            for(int j : edges[i]) V.push_back(G[j]);
            G[i] = mex(V);
        }
        sz[k] = *max_element(G.begin(), G.end()) + 1;
        sum[k].resize(sz[k]);
        for(int i=0; i<N; i++) add(sum[k][G[i]], pw18[i+1]);
    }

    int64_t ans = 0;
    for(int i=0; i<sz[0]; i++) for(int j=0; j<sz[1]; j++){
        int k = i^j;
        if(k < sz[2]) add(ans, sum[0][i] * sum[1][j] % MOD * sum[2][k]);
    }

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


Measured memory_bytes: 6008
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
s = [ni() for _ in range(n)]

sm = sum(s)

s.sort()
not10min = sm

for si in s:
    if si%10 != 0:
        not10min = si
        break

if sm%10 == 0:
    print(sm - not10min)
else:
    print(sm)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 H, W, K;
  cin >> H >> W >> K;
  vector<string> c(H);
  for (i64 i = 0; i < H; i++)
    cin >> c[i];
  i64 ans = 0;
  for (i64 i = 0; i < (1 << H); i++)
    for (i64 j = 0; j < (1 << W); j++)
    {
      i64 cnt = 0;
      for (i64 k = 0; k < H; k++)
        for (i64 l = 0; l < W; l++)
          if (c[k][l] == '#' && !((i >> k) & 1) && !((j >> l) & 1))
            cnt++;
      if (cnt == K)
        ans++;
    }
  cout << ans << endl;
  return 0;
}


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


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

Measured memory_bytes: 1156
# coding: utf-8
from math import sqrt
from itertools import permutations

def main():
    N = int(input())
    ans = 0.0
    P = [i for i in range(N)]
    C = [list(map(int, input().split())) for _ in range(N)]
    for p in permutations(P):
        for i in range(N - 1):
            ans += sqrt(((C[p[i + 1]][0] - C[p[i]][0]) ** 2) + ((C[p[i + 1]][1] - C[p[i]][1]) ** 2))

    for i in range(2, N + 1):
        ans /= i

    print(ans)

if __name__ == "__main__":
    main()


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

#define pb push_back

typedef long long ll;

using namespace std;

const int MOD = 1000000007;

ll n;
ll dp[1000010], s[1000010];

int main() {
	cin >> n;
	dp[n] = n;
	dp[n + 1] = 1;
	s[n] = n + 1;
	s[n + 1] = 1;
	for (int i = n - 1; i >= 1  ; --i) {
		dp[i] = ((n - 1) * 1ll * (n - 1) + i + dp[i + 1] + s[i + 3] + MOD) % MOD;
		s[i] = (s[i + 1] + dp[i]) % MOD;
	}
	cout << dp[1] << endl;
	return 0;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
#define N 200010
#define ll long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
struct Info{ll x,y,we;}a[N];
int n,x,f[N],fa[N];
ll ans;
bool operator <(Info x,Info y){if (x.x*y.y!=x.y*y.x)return x.x*y.y<x.y*y.x;return x.we<y.we;}
set<Info> s;
int que(int x){if (f[x]!=x) f[x]=que(f[x]);return f[x];}
void get(ll x){
	int y=que(fa[x]);
	f[x]=y;
	ans+=a[y].x*a[x].y;
	if (y!=1)s.erase(a[y]);
	a[y].x+=a[x].x;a[y].y+=a[x].y;
	if (y!=1)s.insert(a[y]);
}
int main(){
	read(n);
	for (int i=1;i<=n;i++)f[i]=i;
	for (int i=2;i<=n;i++)read(fa[i]);
	for (int i=1;i<=n;i++){
		read(x);a[i].we=i;
		if (x==0)a[i].y=1;else a[i].x=1;
	}
	for (int i=2;i<=n;i++) s.insert(a[i]);
	for (int i=1;i<n;i++){
		auto x=s.begin();Info no=*x;s.erase(x);
		get(no.we);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 18944
from collections import defaultdict
from collections import OrderedDict
N = int(input())
ans = dict()
for _ in range(N):
    k = str(input())
    if k in ans:
        ans[k]+=1
    else:
        ans.update({k:1})
groupedByValue = defaultdict(list)
for key, value in sorted(ans.items()):
    groupedByValue[value].append(key)
l = groupedByValue[max(groupedByValue)]
for i in l:
    print(i)

Measured memory_bytes: 45844
number = int(input())
i = 1
l = list()
while i <= number:
  k,v = input().split()
  l.append((k,int(v),i))
  i += 1
# print(l)
sorted_list = sorted(l, key=lambda s:s[1], reverse=True)
sorted_list2 = sorted(sorted_list, key=lambda s:s[0])
#print(sorted_list2)
for k in sorted_list2:
  print(k[2])

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF 2000000000LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int h,w,n;
vector<int> hi;
vector<int> wi;
int a[100001],b[100001];
vector<int> hindex[1000000];
ll sum[10],all;
vector<P> check;
int main(void){
	scanf("%d%d%d",&h,&w,&n);
	for(int i=0;i<n;i++){
		scanf("%d%d",&a[i],&b[i]);
		for(int j=-2;j<=2;j++){
			if(a[i]+j>=1 && a[i]+j<=h)hi.push_back(a[i]+j);
			if(b[i]+j>=1 && b[i]+j<=w)wi.push_back(b[i]+j);
			for(int k=-2;k<=2;k++){
				if(a[i]+j>=1 && a[i]+j+2<=h){
					if(b[i]+k>=1 && b[i]+k+2<=w){
						check.push_back(P(a[i]+j,b[i]+k));
					}
				}
			}
		}
		
	}
	sort(hi.begin(),hi.end());
	hi.erase(unique(hi.begin(),hi.end()),hi.end());
	sort(wi.begin(),wi.end());
	wi.erase(unique(wi.begin(),wi.end()),wi.end());
	sort(check.begin(),check.end());
	check.erase(unique(check.begin(),check.end()),check.end());
	for(int i=0;i<n;i++){
		a[i]=lower_bound(hi.begin(),hi.end(),a[i])-hi.begin();
		//b[i]=lower_bound(wi.begin(),wi.end(),b[i])-wi.begin();
		hindex[a[i]].push_back(b[i]);
	}
	for(int i=0;i<hi.size();i++){
		sort(hindex[i].begin(),hindex[i].end());
	}
	for(int i=0;i<check.size();i++){
		int x=lower_bound(hi.begin(),hi.end(),check[i].first)-hi.begin();
		int y=check[i].second;
		int cnt=0;
		for(int j=0;j<3;j++){
			if(hindex[x+j].size()==0)continue;
			int g=lower_bound(hindex[x+j].begin(),hindex[x+j].end(),y)-hindex[x+j].begin();
			for(int k=g;k<hindex[x+j].size();k++){
				if(hindex[x+j][k]>=y+3)break;
				cnt++;
			}
		}
		sum[cnt]++;
		all++;
	}
	sum[0]+=(h-2LL)*(w-2LL)-all;
	for(int i=0;i<10;i++){
		printf("%lld\n",sum[i]);
	}
	return 0;
}

Measured memory_bytes: 63204
S = input()

if len(S) % 2 == 0:
    m = int(len(S) / 2)
else: 
    m = int(len(S) / 2) + 1

ans = 0
for i in range(0, m):
    if S[i] != S[len(S) - 1 - i]:
        ans += 1

print(ans)

Measured memory_bytes: 3060
// inputに入力データ全体が入る
function Main(input) {
	ans = 'No' 
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.trim().split("\n");
	s0 = input[0].split(' ').map((n) => (parseInt(n)))
	s1 = input[1].split(' ').map((n) => (parseInt(n)))
	s2 = input[2].split(' ').map((n) => (parseInt(n)))
	arr = s0.concat(s1)
	arr = arr.concat(s2)

	b = input.slice(3)

	for (i = 0; i <= b.length + 1; i++) {
		for (j = 0; j <= arr.length + 1; j++) {
			if (arr[i] == b[j]) {
				arr[i] = 'b'
			}
		}
	}

	if ((arr[0] == arr[1] && arr[0] == arr[2] && arr[0] == 'b') || 
    (arr[3] == arr[4] && arr[3] == arr[5] && arr[3] == 'b') || 
    (arr[6] == arr[7] && arr[6] == arr[8] && arr[6] == 'b') || 
    (arr[0] == arr[3] && arr[0] == arr[6] && arr[0] == 'b') || 
    (arr[1] == arr[4] && arr[1] == arr[7] && arr[1] == 'b') || 
    (arr[2] == arr[5] && arr[2] == arr[8] && arr[2] == 'b') || 
    (arr[0] == arr[4] && arr[0] == arr[8] && arr[0] == 'b') || 
    (arr[2] == arr[4] && arr[2] == arr[6] && arr[2] == 'b')) {
		ans = 'Yes'
	}


	//出力
	console.log(ans)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main(require('fs').readFileSync('./input.txt', 'utf-8'));

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

int main(){
  int E,Y;
  cin >> E >> Y;

  switch(E){
    case 0:
      if(1868<=Y && Y<=1911){
        cout << "M" << Y-1867 << endl;
      }else if(1912<=Y && Y<=1925){
        cout << "T" << Y-1911 << endl;
      }else if(1926<=Y && Y<=1988){
        cout << "S" << Y-1925 << endl;
      }else if(1989<=Y && Y<=2016){
        cout << "H" << Y-1988 << endl;
      }
      break;
    case 1:
      cout << Y+1867 << endl;
      break;
    case 2:
      cout << Y+1911 << endl;
      break;
    case 3:
      cout << Y+1925 << endl;
      break;
    case 4:
      cout << Y+1988 << endl;
      break;
  }

  return 0;
}



Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include<iomanip>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;
ll mod=1e9+7;
ll modn(ll a,ll mod)
{
  a%=mod;
  if(a<0)a+=mod;
  return a;
}
long long modinv(long long a,long long mod)
{
  long long cnt=a,res=1;
  long long m=mod-2;
  while(m>0)
  {
    if(m%2)res*=cnt;
    cnt=cnt*cnt;
    cnt%=mod;
    res%=mod;

    m>>=1;
  }
  //cout<<a<<"modinv"<<res<<endl;
  return res;
}
ll c(ll num,ll d)
{
  if(num==1 || num==d || d==0)return 1;
  return modn(modn(c(num-1,d-1)*num,mod)*modinv(d,mod),mod);
}

int  main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout<<setprecision(10);
  ll n,m;
  cin>>n>>m;
  map<ll,ll> pd;
  ll sqrtm=sqrt(m)+1;
  ll tm=m;
  repi(i,2,sqrtm+1000)
  {
    while(tm%i==0){pd[i]++;tm/=i;}
    if(tm==1)break;
  }
  if(tm>1)pd[m]++;
  ll res=1;
  for ( auto p : pd)
  {
    //cout<<p.first<<" "<<p.second<<endl;
    res=modn((ll)res*c(p.second+n-1,p.second),mod);
  }
  cout<<res<<endl;

  return 0;

}


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

int main(){
  char S[100];
  long int K;
  scanf("%s%ld",S,&K);
  int len = strlen(S);
  int p = 1;
  int not1;
  for(int i = 0;i < len;i++){
    if(S[i]-'0' != 1){
      p = S[i]-'0';
      not1 = i;
      break;
    }
  }
  if(K > 100){
    printf("%d\n",p);
    return 0;
  }else if(not1+1 > K){
    printf("%d\n",1);
    return 0;
  }else{
    printf("%d\n",p);
    return 0;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

int dx[] = {0, -1, 1, 0};
int dy[] = {-1, 0, 0, 1};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    bool flg = true;

    if( s[0] != 'A' ) flg = false;
    if( 'A' <= s[1] && s[1] <= 'Z' ) flg = false;

    bool tmp_flg = false;
    for( int i = 2; i <= s.size() - 2; ++i ) {
        if( tmp_flg && 'A' <= s[i] && s[i] <= 'Z' ) flg = false;
        if( s[i] == 'C' ) tmp_flg = true;
        
    }
    if( !tmp_flg ) flg = false;
    if( 'A' <= s[s.size() - 1] && s[s.size() - 1] <= 'Z' ) flg = false;

    if( flg ) cout << "AC";
    else cout << "WA";
    cout << endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}













int main()
{
     int n;
     cin>>n;
     int a[n];
     for(int i=0;i<n;i++)cin>>a[i];
    bool rem=false;
    ll res=0;
     for(int i=0;i<n;i++){
          
          if(rem&&a[i]>0){
               a[i]--;res++;
          }
          res+=a[i]/2;
          //cout<<res<<"\n";
          rem=a[i]%2==0?false:true;
     }
     cout<<res;
}
 
 
 
 

 
 
 
 
 
 
 
 
 
 
 
 
 



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

llong N;

void rec(llong cur, int use, llong & counter) {
	if (cur > N) return;
	if (use == 0b111) counter++;

	rec(cur * 10 + 7, use | 0b100, counter);
	rec(cur * 10 + 5, use | 0b010, counter);
	rec(cur * 10 + 3, use | 0b001, counter);
} 


int main(void) {
	cin >> N;
	llong res = 0;
	rec(0, 0, res);
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, i, ac=0, wa=0, tle=0, re=0; cin>>n;
    for(i=0; i<n; i++)
    {
        string s; cin>>s;
        if(s=="AC") ac++;
        else if(s=="WA") wa++;
        else if(s=="RE") re++;
        else tle++;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;


    return 0;
}


Measured memory_bytes: 3624
import bisect,sys
import math
from collections import deque

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac =fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV
        
    return CONV()



sys.setrecursionlimit(200005)


def main():
    N = iRaw()
    ans = 0
    for a in range(1,N+1):
        for b in range(1,N+1):
            for c in range(1,N+1):
                ans+=math.gcd(a,math.gcd(b,c))
    return ans

if __name__ == "__main__":
    print(main())


Measured memory_bytes: 73928
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int N; cin >> N&&N;) {
		vector<int> v(N); rep(i, 0, N) { cin >> v[i]; }
		stack<int> zero, one;
		zero.push(-1);
		one.push(-1);
		rep(i, 0, N) {
			if (i & 1) {
				if (v[i]) {
					while (zero.top() > one.top())zero.pop();
					one.push(i);
				}
				else {
					while (zero.top() < one.top())one.pop();
					zero.push(i);
				}
			}
			else {
				if (v[i])one.push(i);
				else zero.push(i);
			}
		}
		vector<pair<int, int>> tmp;
		while (zero.size() > 1) {
			tmp.emplace_back(zero.top(), 0);
			zero.pop();
		}
		while (one.size() > 1) {
			tmp.emplace_back(one.top(), 1);
			one.pop();
		}
		sort(all(tmp));
		dump(tmp);
		int ans = 0;
		if (tmp.front().second == 0)ans += tmp.front().first + 1;
		rep(i, 1, tmp.size()) {
			if (tmp[i].second == 0)ans += tmp[i].first - tmp[i - 1].first;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3276
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Diagnostics;
using static System.Console;
using static System.Math;


namespace AtCoder
{
    class AtCoderrr
    {
        static void Main(string[] args)
        {
            long[] s = ReadLine().Split(' ').Select(long.Parse).ToArray();
            long n = s[0];
            long m = s[1];
            long ans = 0;

            if (n == 1 && m == 1)
            {
                ans = 1;
            }
            else if (n == 1 && m > 1)
            {
                ans = m - 2;
            }
            else if (n >1 && m==1)
            {
                ans = n - 2;
            }
            else
            {
                ans = (m - 2) * (n - 2);
            }
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstdio>
#define F(i,n) for(int i=0;i<(int)(n);i++)
#define INF 100000000
#define ll long long

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

int main() {
	int n, p;
	int a;
	int b[51];
	int all;
	int ans;
	while (1) {
		cin >> n >> p;
		if (n == 0 && p == 0)break;
		a = 0;
		all = p;
		F(i, n)b[i] = 0;
		while (1) {
			if (p == 0) {
				p = b[a];
				b[a] = 0;
			}
			else {
				b[a]++;
				p--;
				if (p == 0 && b[a] == all) {
					ans = a;
					break;
				}
			}
			a = (a + 1) % n;
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
	int r, c;
	int a[101][101];
	cin >> r >> c;
	for(int i = 0; i < r; i++){
		for(int j = 0; j < c; j++) cin >> a[i][j];
	}
	for(int i = 0; i < r+1; i++) a[i][c] = 0;
	for(int j = 0; j < c+1; j++) a[r][j] = 0;
	for(int i = 0; i < r; i++){
		for(int j = 0; j < c; j++){
			a[i][c] += a[i][j];
			a[r][j] += a[i][j];
			a[r][c] += a[i][j];
		}
	}
	for(int i = 0; i < r+1; i++){
		cout << a[i][0];
		for(int j = 1; j < c+1; j++){
			cout << " " << a[i][j];
		}
		cout << endl;
	}

	return 0;
}

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

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) REP (i, 0, n)
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;

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

int main() {
	int n;
	while (cin >> n, n) {
		int a[n], ans = -10000000;
		rep (i, n) cin >> a[i];
		int dp[n];
		dp[0] = a[0];
		REP (i, 1, n) {
			dp[i] = max(dp[i - 1] + a[i], a[i]);
		}
		rep(i, n) {
			ans = max(ans, dp[i]);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long 
int main()
{
	ll int n,we;
    cin>> n >> we ;
   	vector<ll int>dp(1e5+2,1e12),w(n),v(n);
    dp[0]=0;
    for(int i=0;i<n;i++){
        cin>> w[i]>>v[i];
    }
    for(int j=0;j<n;j++){
    	for(int i=1e5+1;i>0;i--){
            if(i>=v[j]){
                 dp[i]=min(dp[i],w[j]+dp[i-v[j]]);
            }
        }
    }
    //for(auto i:dp)cout<<i<<" ";
    int ans=0;
    for(int i=1;i<1e5+2;i++){
        if(dp[i]<=we)ans=max(ans,i);
    }
   	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4048
#include<cstdio>
const int N=3003,M=1e9+7;
inline int Mod(int a){return a<M?a:a-M;}
int n,f[N][N];char a[N];
signed main(){
	scanf("%d%s",&n,a+2);
	f[1][1]=1;
	for(int i=2;i<=n;i++)
	  for(int j=1;j<=i;j++){
		if(a[i]=='<')f[i][j]=Mod(f[i][j-1]+f[i-1][j-1]);
		if(a[i]=='>')f[i][j]=Mod(f[i][j-1]+Mod(f[i-1][i-1]-f[i-1][j-1]+M));
	  }printf("%d",f[n][n]);
	return 0;
}

Measured memory_bytes: 34048
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cstring>

using P = std::pair<int, int>;

constexpr int MAX_N = 1000;

int w, h, n;
int x[2][MAX_N], y[2][MAX_N];
bool board[MAX_N * 3 + 1][MAX_N * 3 + 1];

int compression(int W, int X[2][MAX_N]) {
	std::vector<int> res;

	for (int i = 0; i < 2; ++i) {
		for (int j = 0; j < n; ++j) {
			for (int k = -1; k <= 1; ++k) {
				if (0 <= X[i][j] + k&&X[i][j] + k < W)
					res.push_back(X[i][j] + k);
			}
		}
	}

	std::sort(res.begin(), res.end());
	res.erase(std::unique(res.begin(), res.end()), res.end());

	for (int i = 0; i < 2; ++i) {
		for (int j = 0; j < n; ++j)
			X[i][j] = std::lower_bound(res.begin(), res.end(), X[i][j]) - res.begin();
	}

	return res.size();
}

int dx[] = { 0,-1,0,1 }, dy[] = { -1,0,1,0 };

void dfs(int x, int y) {
	std::stack<P> stk;
	stk.push(P(x, y));

	while (!stk.empty()) {
		P p = stk.top(); stk.pop();
		board[p.second][p.first] = true;

		int nx, ny;
		for (int i = 0; i < 4; ++i) {
			nx = p.first + dx[i];
			ny = p.second + dy[i];
			if (0 <= nx && 0 <= ny&&
				nx < w&&ny < h&&!board[ny][nx])
				stk.push(P(nx, ny));
		}
	}
}

int main() {
	while (1) {
		std::cin >> w >> h;
		if (w + h == 0)
			break;

		std::memset(board, false, sizeof(board));

		std::cin >> n;
		for (int i = 0; i < n; ++i) {
			std::cin >> x[0][i] >> y[0][i]
				>> x[1][i] >> y[1][i];
			--x[1][i];
			--y[1][i];
		}
		w = compression(w, x);
		h = compression(h, y);

		for (int i = 0; i < n; ++i) {
			for (int j = y[0][i]; j <= y[1][i]; ++j) {
				for (int k = x[0][i]; k <= x[1][i]; ++k)
					board[j][k] = true;
			}
		}

		int ans = 0;

		/*for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j)
				std::cout << board[i][j];
			std::cout << std::endl;
		}*/

		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) {
				if (!board[i][j]) {
					dfs(j, i);
					++ans;
				}
			}
		}

		std::cout << ans << std::endl;

	}
	return 0;
}

Measured memory_bytes: 15552
/*
author: Apoorv Singh
*/
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define For(i, a, b) for (long long i = a; i < b; ++i)
#define Forr(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define ll long long 
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

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

template <class X>
void printarr(X arr[], int n) {
	for (int i = 0; i < n; ++i)
		cout << arr[i] << ' ';
	cout << endl;
}
 
template <class T, class cmp = less<T>> using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
 
ll modulo = 1e9 + 7;

ll fpow(ll a, ll n) {
	ll ans = 1;
	while (n) {
		if (n&1) ans = (ans*a);
		a = (a*a); n = n >> 1;
	}
	return ans;
}

void solve() {
	ll n;
	cin >> n;
	ll ans = 0;
	for (ll i = 1; i <= n; ++i) {
		ll x = n/i;
		ll a = i;
		ans += (x*(2*a + (x-1)*i))/2;
	}		
	cout << ans << endl;	
}

int main() {
	fast_io();
	int t = 1;
	// cin >> t;
	while (t--) solve();
	return 0;
}

Measured memory_bytes: 3636
package main

import (
	"bufio"
	"fmt"
	"strconv"
)

type ByValue []float64

func (s ByValue) Len() int           { return len(s) }
func (s ByValue) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s ByValue) Less(i, j int) bool { return s[i] < s[j] }

func input() string {
	var s string
	_, _ = fmt.Scan(&s)
	return s
}

func inputLn() string {
	var s string
	_, _ = fmt.Scanln(&s)
	return s
}

func inputByScanner(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func convListStrToInt(strList []string) []int {
	intList := make([]int, len(strList))
	for k, v := range strList {
		intV, _ := strconv.Atoi(v)
		intList[k] = intV
	}
	return intList
}

func convListStrToFloat(strList []string) []float64 {
	intList := make([]float64, len(strList))
	for k, v := range strList {
		intV, _ := strconv.Atoi(v)
		intList[k] = float64(intV)
	}
	return intList
}

func main() {
	n, _ := strconv.Atoi(inputLn())
	aList := make([]int, n+1)
	for i := 0; i < n+1; i++ {
		var intV int
		if i == n {
			intV, _ = strconv.Atoi(inputLn())
		} else {
			intV, _ = strconv.Atoi(input())
		}
		aList[i] = intV
	}
	res := 0
	bList := make([]int, n)
	for i := 0; i < n; i++ {
		b, _ := strconv.Atoi(input())
		bList[i] = b

		if aList[i] >= bList[i] {
			aList[i] -= bList[i]
			res += bList[i]
			} else {
				bList[i] -= aList[i]
				res += aList[i]
				aList[i] = 0
				if aList[i+1] >= bList[i] {
					aList[i+1] -= bList[i]
					res += bList[i]
				} else {
					res += aList[i+1]
				aList[i+1] = 0
			}
		}
	}
	fmt.Println(res)
}


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

void countHR();
void move(string str);

int mask = (1 << 4) - 1, pointMask = (1 << 4), now = 1, outCnt = 0, cnt = 0;

int main(){
    int n;
    cin >>n;
    for(int i = 0; i < n; i++){
        now = 1; outCnt = 0; cnt = 0;
        while(outCnt < 3){
            string str;
            cin >>str;
            move(str);
        }
        cout <<cnt <<endl;
    }
    return 0;
}

void move(string str){
    if(str == "HIT"){
        now = (now << 1) + 1;
        if((now & pointMask) != 0){
            cnt++;
            now = (now & mask);
        }
    } else if(str == "HOMERUN"){
        countHR();
    } else if(str == "OUT"){
        outCnt++;
    }
}

void countHR(){
    for(int countMask = 1; countMask < 16; countMask = (countMask << 1)){
        if((now & countMask) != 0){
            cnt++;
        }
    }
    now = 1;
}

Measured memory_bytes: 0
H,W=list(map(int,input().split()))

A = [input() for i in range(H)]

prevend=0
for i in range(H):
    for j in range(W):
        if A[i][j] == '#' and j < prevend:
            print ("Impossible")
            exit()
        elif j>0 and A[i][j-1] == '#' and A[i][j] == '.':
            prevend = j-1
            break
        elif j==W-1:
            prevend =W-1

prevend = 0
for j in range(W):
    for i in range(H):
        if A[i][j] == '#' and i < prevend:
            print ("Impossible")
            exit()
        elif i>0 and A[i-1][j] == '#' and A[i][j] == '.':
            prevend = i-1
            break
        elif i==H-1:
            prevend =H-1


print("Possible")


Measured memory_bytes: 3064
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
max_ans = 0
time = 0
ac = 0
bc = 0
for i in range(n):
    if time + a[i] <= k:
        ans += 1
        time += a[i]
        ac += 1
    else:
        break
for i in range(m):
    if time + b[i] <= k:
        ans += 1
        time += b[i]
        bc += 1
    else:
        break
max_ans = ans
while (bc!=m) and (ac!=0):
    time -= a[ac-1]
    ac -= 1
    ans -= 1
    while time + b[bc] <= k:
        ans += 1
        time += b[bc]
        bc += 1
        max_ans = max(ans, max_ans)
        if bc == m:
            break
print(max_ans)


Measured memory_bytes: 40764
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n],b[n],c[n],nowa,nowb,now=0;
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>b[i];
	for(int i=0;i<n;i++) c[i]=i+1;
	do
	{
		bool flag=1;
		now++;
		for(int i=0;i<n;i++)
		{
			if(a[i]!=c[i])
			{
				flag=0;
				break;
			}
		}
		if(flag) nowa=now;
		flag=1;
		for(int i=0;i<n;i++)
		{
			if(b[i]!=c[i])
			{
				flag=0;
				break;
			}
		}
		if(flag) nowb=now;
	}while(next_permutation(c,c+n));
	cout<<abs(nowa-nowb)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
typedef long long int ll;

int N;
int a[100];

double abs(double a){
	if(a < 0) return -a;
	else return a;
}

int main(){
	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%d", &a[i]);
	int sum = 0;
	for(int i = 0; i < N; i++) sum += a[i];
	double average = (double)sum / (double)N;
	double min_diff = 1000000.0;
	int res;
	for(int i = 0; i < N; i++){
		if(min_diff > abs(average - (double)a[i])){
			min_diff = abs(average - (double)a[i]);
			res = i;
		}
	}
	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 128