akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<map>
#define mp make_pair
using namespace std;
int main(){
  while(true){
    int n,a;
    cin>>n;
    if(!n)break;
    char name[n];
    int score;
    multimap<int, int> teams;
    for(int i=0;i<n;i++){
      cin>>name[i];
      score = 0;
      for(int j=0;j<n-1;j++){
	cin>>a;
	if(a==0)score-=100;
	if(a==1)score++;	
      }
      teams.insert(mp(score,i));
    }
    map<int, int>::iterator it = teams.begin();
    while( it != teams.end() ){
      cout << name[(*it).second] << endl;
      it++;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long int

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	int diff = b - a;
	int sum = 0;
	rep(i, diff - 1) sum += i + 1;
	cout << sum - a << endl;


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;



void solve()
{
    ll a, b, c;
    scanf("%lld%lld%lld", &a, &b, &c);
    ll x = 4 * a*b;
    if (c - a - b < 0) {
        printf("No\n"); return;
    }
    ll y = (c - a - b)*(c - a - b);
    if (x < y) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T; scanf("%d", &T);
    while(T--) {
        solve();
    }
#endif
    return 0;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

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

void solve() {

}

int main() {
  string s,t;
  cin >> s >> t;
  int cnt = 0;
  rep(i,(int)s.size()) {
    if( s[i] != t[i] ) ++cnt;
  }
  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 3920
n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))
a = 0
for ti in t:
  # ti in s ?
  low = 0
  high = n - 1
  while low <= high:
    mid = (low + high) // 2
    if s[mid] > ti:
      high = mid - 1
    elif s[mid] < ti:
      low = mid + 1
    else:
      a += 1
      break
print(a)


Measured memory_bytes: 16712
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <complex>
#include <iomanip>
#include <cassert>
 
using namespace std;
 
typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif  
  int h, w, n;
  cin >> h >> w >> n;
  int mx = max(h, w);
  cout << (n + mx - 1) / mx << '\n';
}


Measured memory_bytes: 256
mod = 10 ** 9 + 7

n = int(input())

e = [0] * (10 ** 3 + 1)
for x in range(1, n + 1):
    div = 2
    cnt = 0
    while x % div == 0:
        x //= div
        cnt += 1
    if cnt > 0:
        e[div] += cnt

    for div in range(3, int(n ** 0.5) + 1, 2):
        cnt = 0
        while x % div == 0:
            x //= div
            cnt += 1
        if cnt > 0:
            e[div] += cnt

    if x > 1:
        e[x] += 1

ans = 1
for cnt in e:
    if cnt > 0:
        ans = (ans * (cnt + 1)) % mod
print(ans)


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atCocderCs
{
    class Program
    {
        static int[] matchs;

        static void Main(string[] args)
        {
            var Q = int.Parse(Console.ReadLine());
            var lst = new List<int[]>();
            int imax = 0;
            for (int i = 0; i < Q; i++)
            {
                var arr = Console.ReadLine().Split(' ').Select((obj) => int.Parse(obj)).ToArray();
                lst.Add(arr);
                if (imax < arr[1])
                    imax = arr[1];
            }
            initPrime(imax);

            for (int i = 0; i < lst.Count; i++)
            {
                var L = lst[i][0];
                var R = lst[i][1];
                Console.WriteLine(matchs[R] - matchs[L - 1]);
            }

        }

        static void initPrime(int imax)
        {
            var marr = new bool[imax + 1];
            marr[0] = marr[1] = true;
            for (int i = 2; i <= imax; i++)
            {
                if (!marr[i])
                {
                    for (int j = i + i; j <= imax; j += i)
                        marr[j] = true;
                }
            }

            matchs = new int[imax + 1];
            for (int i = 2; i <= imax; i++)
            {
                if (!marr[i] && !marr[(i + 1) / 2])
                    matchs[i] = matchs[i - 1] + 1;
                else
                    matchs[i] = matchs[i - 1];
            }

        }

    }
}


Measured memory_bytes: 25908
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int a, b, c;
  cin >> a >> b >> c;

  vector<int> d({a, b, c});
  sort(d.begin(), d.end());
  if ((d[0] == d[1] && d[1] != d[2]) || (d[0] != d[1] && d[1] == d[2])) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
x,y,z = 0,0,0
ans = 0
for _ in range(n):
    s = input()
    for i in range(len(s)-1):
        if s[i] == 'A' and s[i+1] == 'B':
            ans += 1
    if s[0] == 'B' and s[-1] == 'A':
        x += 1
    elif s[0] == 'B':
        y += 1
    elif s[-1] == 'A':
        z += 1
    else:
        pass
if x == 0:
    print(ans+min(y,z))
else:
    if y + z > 0:
        print(ans + x + min(y,z))
    else:
        print(ans + x - 1)

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

int main(void)
{
	int a[3];
	scanf("%d %d %d\n",&a[0],&a[1],&a[2]);
	int max_idx = -1, max_a = -1;
	int i;
	for (i=0;i<3;i++){
		if (max_a < 0 || max_a < a[i]){
			max_idx = i;
			max_a = a[i];
		}
	}
	int ans = 0;
	for (i=0;i<3;i++){
		if (max_idx!=i){
			ans+=a[i];
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <utility>
#include <set>
#include <algorithm>
#include <vector>
#define llint long long

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

llint n;
llint A[4], B[4];
llint x[4], y[4];
bool flag[4];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 0; i < 3; i++) cin >> A[i];
	for(int i = 0; i < 3; i++) cin >> B[i];
	
	int cnt = 0;
	for(int i = 0; i < 3; i++){
		if(B[i] >= A[i]) flag[i] = true, cnt++;;
	}
	//cout << cnt << endl;
	
	if(cnt == 0){
		llint ans = 0;
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++){
				int k = n-(i+j);
				if(k < 0) continue;
				ans = max(ans, i%B[0] + i/B[0]*A[0] + j%B[1] + j/B[1]*A[1] + k%B[2] + k/B[2]*A[2]);
			}
		}
		cout << ans << endl;
		return 0;
	}
	if(cnt == 3){
		llint ans = 0;
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++){
				int k = n-(i+j);
				if(k < 0) continue;
				ans = max(ans, i%A[0] + i/A[0]*B[0] + j%A[1] + j/A[1]*B[1] + k%A[2] + k/A[2]*B[2]);
			}
		}
		cout << ans << endl;
		return 0;
	}
	if(cnt == 1){
		int id;
		for(int i = 0; i < 3; i++){
			if(flag[i]) id = i;
		}
		llint tmp = n%A[id] + n/A[id]*B[id], ans = 0;
		llint jd = (id+1)%3, kd = (id+2)%3;
		for(int i = 0; i <= tmp; i++){
			ans = max(ans, i%B[jd] + i/B[jd]*A[jd] + (tmp-i)%B[kd] + (tmp-i)/B[kd]*A[kd]);
		}
		cout << ans << endl;
		return 0;
	}
	if(cnt == 2){
		int id;
		for(int i = 0; i < 3; i++){
			if(!flag[i]) id = i;
		}
		llint tmp = n, ans = 0;
		llint jd = (id+1)%3, kd = (id+2)%3;
		for(int i = 0; i <= tmp; i++){
			ans = max(ans, i%A[jd] + i/A[jd]*B[jd] + (tmp-i)%A[kd] + (tmp-i)/A[kd]*B[kd]);
		}
		ans = ans%B[id] + ans/B[id]*A[id];
		cout << ans << endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;
const int INF=1e9;
using namespace std;

int main(){
    int n, min_index=-1;
    double t, a, h;
    cin>>n>>t>>a;
    double min_value=INF;
    for(int i=0; i<n; i++){
        cin>>h;
        if(abs(t-h*0.006-a)<min_value){
            min_value=abs(t-h*0.006-a);
            min_index=i;
        }
    }
    cout<<min_index+1<<endl;
}


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

int cnt[26];

int main() {
	ios::sync_with_stdio(false);
	string s; cin >> s;
	int n = s.size();
	for (int i = 0; i < n; i++)
		cnt[s[i] - 'a']++;
	long long ans = 1 + (n * 1LL * (n + 1)) / 2;
	for (int i = 0; i < 26; i++)
		ans -= (cnt[i] * 1ll * (cnt[i] + 1)) / 2;
	cout << ans << endl;


	return 0;
}




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


using namespace std;
long long calc_sum(vector<long long>& V){
	long long sum = 0;
    for(long long num : V){
    	sum += num;
    }
  	return sum;
}

vector<long long> comparing(vector<long long>& V1, vector<long long>& V2)
{
    vector<long long> diffs;
    //cerr << "abs" << abs(-5) << endl;
	for(int i = 0; i < V1.size(); i++){
    	long long diff = V1[i] - V2[i];
        if(diff > 0)
          diffs.push_back(diff);
    }
    return diffs;
}

int vari_num(vector<long long> V, long long margin)
{
	int count = 0;
    sort(V.begin(), V.end());
    if(margin == 0)
      return 0;
    else{
      while(margin > 0){
          for(int i = 0; i < V.size(); i++){
              if(margin <= V[i]){
                  break;
              }
          }
           		margin -= V.back();
                cerr << "V.back" << V.back() << endl;
            	V.pop_back();
            	count++;
      }
      return count;
    }

}

int main()
{
    int answer;
    int N;
    vector<long long> over;
    vector<long long> under;
    cin >> N;
    cerr << N << endl;
    vector<long long> A(N);
    vector<long long> B(N);
    for(int i = 0; i < N; ++i){
        string s;
        cin >> s;
		A.push_back(stol(s));
        //cerr << s << endl;
    }
	for(int i = 0; i < N; ++i){
        string s;
        cin >> s;
		B.push_back(stol(s));
        //cerr << s << endl;
    }
    long long margin = calc_sum(A) - calc_sum(B);
    cerr << "margin" << margin << endl;
    over = comparing(A, B);
    under = comparing(B, A);
    long long under_sum = calc_sum(under);
    int vari;
    cerr << "undersum" << under_sum << endl;
    cerr << "undersize" << under.size() << endl;
    vari = vari_num(over, under_sum);
    answer = under.size() + vari;
  	if(margin < 0)
    	cout << -1 << endl;
    else
    	cout << answer << endl;
}

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

int main(int argc, char const *argv[])
{
  int N,Q,tmp=0, result =0, start=0,end=0;
  string S;
  cin >> N >> Q >> S;
  vector<int> l(Q);
  vector<int> r(Q);
  vector<int> t(N);
  for(int i=0;i < Q; i++){
    cin >> l[i];
    cin >> r[i];
  }
  for(int i=1;i < N; i++){
    if(S.at(i-1) == 'A' && S.at(i) == 'C'){
      tmp++;
    }
    // cout << tmp << endl;
    t[i] = tmp;
  }
  for(int i=0;i < Q; i++){
    result = t[r[i]-1] - t[l[i]-1];
    cout << result << endl;
  }
  return 0;
}

Measured memory_bytes: 2176
def main():
    s = input()
    t = input()
    v = [0] * (len(t) + 1)
    dp = [v]
    for i, si in enumerate(s, 1):
        u, v = v, v.copy()
        dp.append(v)
        ll, ul = 0, 0
        for j, ti in enumerate(t, 1):
            uu = u[j]
            if si == ti:
                v[j] = ll = ul + 1
            else:
                if ll > uu:
                    v[j] = ll
                else:
                    ll = uu
            ul = uu
    k = dp[i][j]
    r = ''
    while k:
        if dp[i - 1][j] == k:
            i -= 1
        elif dp[i][j - 1] == k:
            j -= 1
        else:
            k -= 1
            i -= 1
            j -= 1
            r += s[i]
    print(r[::-1])

main()


Measured memory_bytes: 312820
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
int c[310000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<3*a;i++){
		scanf("%d",c+i);
	}
	std::sort(c,c+3*a);
	long long ret=0;
	for(int i=0;i<a;i++){
		ret+=c[3*a-2-i*2];
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 1280
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int k = sc.nextInt();
    for(int i = Math.min(a, b); i >= 1; i--){
      if(a%i == 0 && b%i == 0){
        k--;
      }
      if(k == 0){
        System.out.println(i);
        return;
      }
    }
  }
}

Measured memory_bytes: 21716
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <math.h>
#include <limits.h>

using namespace std;

typedef long long ll;

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) {
    double A, B;
    int H, M;
    cin >> A >> B >> H >> M;

    double minutes = H * 60 + M;
    const double PI = acos(-1.0);

    double ta = 2 * PI / 60 * minutes; // choshin
    double tb = 2 * PI / (60 * 12) * minutes; // tanshin

    double ax = A * sin(ta);
    double ay = A * cos(ta);
    double bx = B * sin(tb);
    double by = B * cos(tb);

    printf("%.10f\n", sqrt(pow((ax - bx), 2) + pow((ay - by), 2)));

    return 0;
}


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

int main(void){
    int n; cin >> n;
    int h[n+1],dp[n+1];
    for(int i=1; i<=n; i++) cin >> h[i];

    dp[1]=0; dp[2]=abs(h[2]-h[1]);
    for(int i=3; i<=n; i++){
        dp[i]=min( dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]) );
    }

    cout << dp[n] << endl;

}

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

unordered_map<long long, int> mp;
const int maxn = 2e5 + 7;
long long a[maxn];
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
	for (int i = 2; i <= n; i++) a[i] += a[i - 1];

	long long cnt = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i] == 0) cnt++;
		cnt += mp[ a[i] ];
		mp[ a[i] ] = mp[ a[i] ] + 1;
	}
	cout << cnt << endl;
	return 0;	
}

Measured memory_bytes: 10056
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }

int prev[100001];
int rank[100001];

void init(int n){
	for(int i=1; i<=n; i++){ prev[i]=i; rank[i]=1; }
}
int root(int x){
	return prev[x]==x?x:(prev[x]=root(prev[x]));
}
void join(int x, int y){
	x=root(x), y=root(y);
	if(x==y) return;
	if(rank[x]<rank[y]){
		prev[x]=y;
	}else if(rank[x]>rank[y]){
		prev[y]=x;
	}else{
		prev[x]=y;
		rank[y]++;
	}
}

int p[100001];
int main(void){
	int n=nextint();
	int m=nextint();
	for(int i=1; i<=n; i++){
		p[i]=nextint();
	}
	init(n);
	for(int i=0; i<m; i++){
		int a=nextint();
		int b=nextint();
		join(a, b);
	}
	int ans=0;
	for(int i=1; i<=n; i++){
		ans+=(root(p[i])==root(i));
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 1280
// {{{ by unolight
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f\n",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
// }}}


void main() {
    int n,ans=0,a=0,b=0,ab=0;
    R(n);
    string s;
    REP(i,n) {
        cin >> s;
        REP(j,SZ(s)-1) if ( s[j]=='A' && s[j+1]=='B' ) ans++;
        if ( s[0]=='B' && s.back()=='A' ) ab++;
        else if ( s[0]=='B' ) b++;
        else if ( s.back()=='A' ) a++;
    }
    if ( a || b ) ans+=ab+min(a,b);
    else ans+=max(ab-1,0);
    W(ans);
}

}} // {{{ main
int main() { unolight::main(); return 0; }
// }}}

Measured memory_bytes: 3792
#include <stdio.h>
int main(void){
    
    int r,c;
    int n,m,a[101][101] = {0};
    
    scanf("%d %d",&r,&c);
    for(n = 0; n < r; n++){
        for(m = 0; m < c; m++){
            scanf("%d",&a[n][m]);
            a[n][c] = a[n][c]+a[n][m];
            a[r][m] = a[r][m]+a[n][m];
        }
        a[r][c] = a[r][c]+a[n][c];
    }
    
    for(n = 0; n <= r; n++){
        for(m = 0; m <= c; m++){
            if(m == c) printf("%d",a[n][m]);
            else  printf("%d ",a[n][m]);
        }
        printf("\n");
    }
    
}

Measured memory_bytes: 2720
/*author : Yashvardhan
Saturday, June 27, 2020
6:00 PM
*/

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

using ll = long long;

#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define rev(Y) reverse(all(Y))

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __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...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e9;
const int ninf = -2e9;

int takemod(int a){return ((a%mod)+mod)%mod;}

int pow(int a, int b, int m)
{
	int ans = 1;
	a %= m;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

int modinv(int a){return takemod( pow( takemod(a), mod-2,mod ) );}

const int N = 1e7 + 5;

int spf[N];

void sieve(){
	spf[1] = 1; 
    for (int i = 2; i< N; i++) spf[i] = i; 
  
    for (int i = 4; i< N; i+=2) spf[i] = 2; 
  
    for (int i = 3; i*i < N; i++){ 
        if (spf[i] == i) { 
            for (int j = i * i; j < N; j += i){
				if (spf[j] == j) spf[j] = i; 
			}
        } 
    } 
}

ll f(int x){
	unordered_map<int, int> mapi;
	while(x != 1){
		mapi[spf[x]]++;
		x /= spf[x];
	}
	
	ll ans = 1;
	for(auto i : mapi){
		ans *= (ll) (i.ss + 1);
	}
	return ans;
}

signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	int n;
	cin >> n;

	sieve();
	ll ans = 0;
	for(int i = 1; i <= n; i++){
		ans += (i * f(i));
	}
	
	cout << ans << endl;

	t2 = clock();
	cerr << endl << t2-t1 << endl;
	
	return 0;
}



Measured memory_bytes: 42736
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef long long ll;

int		compare_string(const void *a, const void *b)
{
	return strcmp(*(const char **)a, *(const char **)b);
}

int main()
{
	long N;
	scanf("%ld", &N);
	char **str;
	long i = 0;

	str = (char**)malloc(sizeof(char*) * N);
	while (i < N)
	{
		str[i] = (char*)malloc(sizeof(char) * 11);
		scanf("%s", str[i]);
		i++;
	}
	long n = 0;
	qsort(str, N, sizeof *str, compare_string);

	i = 0;
	while (i < N - 1)
	{
		// printf("%s ", str[i]);
		if (strcmp(str[i], str[i + 1]) != 0)
			n++;
		i++;
	}
	printf("%ld", n + 1);
	return (0);
}



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

int main(){
	int c[4][13] = {0};
	int t;
	int i;
	char a;
	int b;
	cin >> t;
	for ( i = 0; i<t; i++ ) {
		cin >> a >> b;
		b=b-1;
		if ( a == 'S' ) {
			c[0][b]=1;
		}else if ( a == 'H' ) {
			c[1][b]=1;
		}else if ( a == 'C' ) {
			c[2][b]=1;
		}else if ( a == 'D' ) {
			c[3][b]=1;
		}
	}
	for ( t = 0; t<4; t++ ) {
		if ( t==0 ) {
			a='S';
		}else if ( t==1 ) {
			a='H';
		}else if ( t==2 ) {
			a='C';
		}else if ( t==3 ) {
			a='D';
		}
		for ( i = 0; i<13; i++ ) {
			if ( c[t][i] != 1 ) {
				cout << a << " " << i+1 << endl;
			}
		}
	}
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define INF (1<<22)

int main(){
  while(1){
    string str;
    getline(cin,str);
    int len = str.size();
    char type = str[len-1];
    if(type == 'X') break;
    string ans = "";
    for(int i=0;i<len-2;i++){
      if(i == 0){
	if(type == 'L' || type == 'D'){
	  if(str[i] >= 'A' && str[i] <= 'Z') ans += str[i]+32;
	  else ans += str[i];
	} else {
	  if(str[i] >= 'a' && str[i] <= 'z') ans += str[i]-32;
	  else ans += str[i];
	}
      }
      else if(str[i] >= 'A' && str[i] <= 'Z'){
	if(type == 'D') {
	  ans += '_';
	  ans += (str[i]+32);
	}
	else ans += str[i];
      }
      else if(str[i] == '_'){
	if(type == 'D') ans += str[i];
	else {
	  i++;
	  ans += str[i]-32;
	}
      }
      else ans += str[i];
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1188
s = input()
s_rev = s[2:4] + s[0:2]

is_yymm = True
is_mmyy = True

if int(s[2:4]) > 12 or int(s[2:4]) < 1:
    is_yymm = False
if int(s_rev[2:4]) > 12 or int(s_rev[2:4]) < 1:
    is_mmyy = False

if is_yymm and is_mmyy:
    print('AMBIGUOUS')
elif is_yymm:
    print('YYMM')
elif is_mmyy:
    print('MMYY')
else:
    print('NA')

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repk(i,k,n) for (int i = k; i <= (int)(n); i++)
#define MAX 100010

using namespace std;


int main(){
    double a,b,x;
    cin >> a >> b >> x;

    double half = a*a*b/2;
    double tan,ans;
    if(x>=half){
        ans = atan(2 * (a * a * b - x) / (a * a * a));
    } 
    else{
        ans = M_PI / 2 - atan(2 * x / (a * b * b));
    }

    printf("%.11lf\n",ans * 180.0 / M_PI);


    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(){
	
	int n,k,bank = 1;
	
	scanf("%d" , &n);
	scanf("%d" , &k);
	
	for(int i = 0 ; i < n ; i++){
		if(bank * 2 > bank + k){
			bank += k;
		}
		else{
			bank *= 2;
		}		
	}
	printf("%d" , bank);
	
	return 0;
}

Measured memory_bytes: 1704
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr int MOD_TYPE = 2;
constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

#pragma endregion

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  ll r, g, b, n;
  cin >> r >> g >> b >> n;
  ll cnt = 0;
  rep(ri, 3001) rep(gi, 3001)
  {
    if ((n - r * ri - g * gi) % b != 0)
      continue;
    ll bi = (n - r * ri - g * gi) / b;
    if (bi >= 0)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize ("O3")
//#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	string S;
	cin >> S;

	int A[2020] = {};
	A[0] = 1;

	ll kotae = 0;
	int tmp = 0;
	int are = 1;
	rep(i, S.size()) {
		int j = S.size() - i - 1;
		tmp += (S[j] - '0') * are;
		tmp %= 2019;
		are *= 10;
		are %= 2019;
		kotae += A[tmp]++;
	}
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m;
vector<P1>query[200005];
class segtree
{
public:
	#define s (1<<18)
	ll seg[s*2];
	ll lazy[s*2];
	void lazy_evaluate(int k)
	{
		if(k*2+2>=s*2) return ;
		lazy[k*2+2]+=lazy[k];
		lazy[k*2+1]+=lazy[k];
		seg[k*2+2]+=lazy[k];
		seg[k*2+1]+=lazy[k];
		lazy[k]=0;
	}
	ll update(int beg,int end,int idx,int lb,int ub,ll num)
	{
		if(ub<beg||end<lb)
		{
			return seg[idx];
		}
		if(beg<=lb&&ub<=end)
		{
			lazy[idx]+=num;
			seg[idx]+=num;
			return seg[idx];
		}
		if(lazy[idx])
		{
			lazy_evaluate(idx);
		}
		return seg[idx]=max(update(beg,end,idx*2+1,lb,(lb+ub)/2,num),update(beg,end,idx*2+2,(lb+ub)/2+1,ub,num));
	}
	ll query(int beg,int end,int idx,int lb,int ub)
	{
		if(ub<beg||end<lb)
		{
			return -1000000000000000000LL;
		}
		if(beg<=lb&&ub<=end)
		{
			return seg[idx];
		}
		if(lazy[idx])
		{
			lazy_evaluate(idx);
		}
		return max(query(beg,end,idx*2+1,lb,(lb+ub)/2),query(beg,end,idx*2+2,(lb+ub)/2+1,ub));
	}
}kaede;
//Kaede Takagaki is my wife!
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int L,R,a; scanf("%d%d%d",&L,&R,&a);
		query[L].pb(mp(1,mp(R,a)));
		query[R+1].pb(mp(-1,mp(L,a)));
	}
	ll ans = 0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<query[i].size();j++){
			int ty = query[i][j].fi;
			int za = query[i][j].sc.fi;
			int cs = query[i][j].sc.sc;
			if(ty == 1){
				kaede.update(0,i-1,0,0,s-1,1LL*cs);
			}
			else{
				kaede.update(0,za-1,0,0,s-1,-1LL*cs);
			}
		}
		ll v = kaede.query(0,i-1,0,0,s-1);
		ans = max(ans,v);
		kaede.update(i,i,0,0,s-1,v);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 20992
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;
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;}
string get_str(string s) {
	s+=',';
	string ret="";
	for(int i=0; i<s.size(); i++) {
		if(s[i]==',') ret+="=%ld, ";
		else ret+=s[i];
	}
	return ret;
}
#define dump(...) printf(get_str(#__VA_ARGS__).c_str(),__VA_ARGS__);cout<<endl
 
#define endl '\n'
#define IOS()                     \
	ios_base::sync_with_stdio(0); \
	cin.tie(0)
 
//******************************************************************************
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);
}

vint dist(200020,INF);
vint g[200020];
void dfs(int now,int par){
	for(auto e:g[now]){
		if(dist[e]>dist[now]+1&&e!=par){
			dist[e]=dist[now]+1;
			dfs(e,now);
		}
	}
}

signed main()
{
	//IOS();
	int N;
	cin>>N;
	rep(i,0,N-1){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	dist[0] = 0;
	dfs(0,-1);
	int ma = -1,t;
	rep(i,0,N){
		if(chmax(ma,dist[i])){
			t=i;
		}
	}
	rep(i,0,200020){
		dist[i]=INF;
	}
	dist[t]=0;
	dfs(t,-1);
	ma = -1;
	rep(i,0,N){
		chmax(ma,dist[i]);
	}
	ma++;
	if(ma==1)cout<<"First"<<endl;
	else if(ma==2)cout<<"Second"<<endl;
	else if(ma%3==2)cout<<"Second"<<endl;
	else cout<<"First"<<endl;
}

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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define print_pre(stuff) cout << fixed << setprecision(15) << stuff
#define len length
#define ret0 return 0
#define ret return 

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound

#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN 100001

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

    ll w, h, x, y;
    cin>>w>>h>>x>>y;
    if(x == w/2 && y == h/2 && w%2 == 0 && h%2 == 0){
        print_pre((ld)(w*h)/2);
        print(" "<<1);
    }
    else if((x == w/2 && w%2 == 0) || (y == h/2 && h%2 == 0)){
        print_pre((ld)(w*h)/2);
        print(" "<<0);
    }
    else {
        print_pre((ld)(w*h)/2);
        print(" "<<0);        
    }
    
}



Measured memory_bytes: 256
/*
  AtCoder Beginner Contest 094
  A - Cats and Dogs
*/

#include<iostream>
using namespace std;

int A, B, X;

int main() {
  scanf("%d%d%d", &A, &B, &X);
  if (X < A || A + B < X) printf("NO\n");
  else printf("YES\n");
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
bool isPalindrome(int l,int r,string& s){
  while(l < r){
    if(s[l] != s[r])return false;
  }
  return true;
}
int solve(string& s){
  set<string> strs;
  for(int i = 1,l = s.size();i < l;i++){
    string s1 = s.substr(0,i);
    string s2 = s.substr(i,l-i);
    //cout << s1 <<':' <<  s2 << endl;
    string s1rev = s1;reverse(s1rev.begin(), s1rev.end());
    string s2rev = s2;reverse(s2rev.begin(), s2rev.end());
    //cout << s1rev << ':' <<  s2rev << endl;
    strs.insert(s1    +s2);
    strs.insert(s1    +s2rev);
    strs.insert(s1rev +s2);
    strs.insert(s1rev +s2rev);
    strs.insert(s2    +s1);
    strs.insert(s2    +s1rev);
    strs.insert(s2rev +s1);
    strs.insert(s2rev +s1rev);
  }
  /*for(auto i:strs){
    cout << i << endl;
    }*/
  return strs.size();
}

int main(){
  int n;
  cin >> n;
  cin.ignore();
  for(int i = 0;i < n;i++){
    string s;
    getline(cin,s);
    cout << solve(s) << endl;
  }
}

Measured memory_bytes: 1296
import java.util.*;

public class Main{
  static int H, W;
  static int max = 0;
  static int[] ih = {1,0,-1,0};
  static int[] iw = {0,1,0,-1};
  static char[][] maze;
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    H = Integer.parseInt(S[0]);
    W = Integer.parseInt(S[1]);
    
    maze = new char[H][W];
    for(int i = 0; i < H; i++){
      String T = sc.nextLine();
      for(int j = 0; j < W; j++){
        maze[i][j] = T.charAt(j);
      }
    }
    
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        if(maze[i][j] == '#'){
          continue;
        }
        for(int k = 0; k < H; k++){
          for(int l = 0; l < W; l++){
            if(maze[k][l] == '#' || (i == k && j == l)){
              continue;
            }
            func(i, j, k, l);
          }
        }
      }
    }
    System.out.println(max);
  }
  public static void func(int sh, int sw, int gh, int gw){
    int[][] route = new int[H][W];
    Queue<Integer> qh = new ArrayDeque<>();
    Queue<Integer> qw = new ArrayDeque<>();
    qh.add(sh);
    qw.add(sw);
    
    while(!qh.isEmpty()){
      int nh = qh.poll();
      int nw = qw.poll();
      
      if(nh == gh && nw == gw){
        if(route[gh][gw] > max){
          max = route[gh][gw];
        }
        return;
      }
      
      for(int i = 0; i < 4; i++){
        int fh = nh+ih[i];
        int fw = nw+iw[i];
        
        if(fh < 0 || fh >= H || fw < 0 || fw >= W){
          continue;
        }
        if(maze[fh][fw] == '#' || route[fh][fw] > 0){
          continue;
        }
        
        qh.add(fh);
        qw.add(fw);
        route[fh][fw] = route[nh][nw]+1;
      }
    }
  }
}

Measured memory_bytes: 147688
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n, x, cnt = 0, ans = 1;
	cin >> n >> x;

	for(int i=0;i<n;i++){
		int l;
		cin >> l;
		cnt += l;
		if(cnt<=x) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  n = int(input())
  total = 0

  if n <= 2:
    print(0)
    return

  for i in range(1, n):
    if i * (i + 1) >= n:
      break
    elif n % i != 0:
      continue
    else:
      total += n // i - 1

  print(total)


if __name__ == '__main__':
  main()



Measured memory_bytes: 2940
/*input
9
*/
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define sz(a) int((a).size())
#define pb push_back
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())     
#define rep(i,j,n) for(ll i=j;i<n;i++)
#define mp make_pair
#define N 998244353
#define PI acos(-1.0)
//if (s.find('R') != std::string::npos)
//s.replace(s.find("10"), sizeof("10") - 1, "");
using namespace std;

int main()
{
  // added the two lines below 
  ios_base::sync_with_stdio (false); 
  cin.tie(NULL);
  cout.tie(0);
  
  ll a,b,c;
  cin>>a>>b>>c;
  cout<<min(a+b,min(a+c,b+c));
  }

Measured memory_bytes: 256
#include <stdio.h>
#define MAXN 50050
//coin changing problem dp
int main ()
{
  int n, m, i, j;
  long int dp[MAXN];
  
  scanf ("%d %d", &n, &m);
  for (i = 1; i <= n; i++)
    {
      dp[i] = 0;
    }
  int d[m + 1];
  for (i = 1; i <= m; i++)
    {
      scanf ("%d", &d[i]);
      dp[d[i]] = 1;
    }
  for (i = 2; i <= n; i++)
    {
      long int min = MAXN;
      if (dp[i] == 0)
	{			//cal
	//get minimal ele
	  for (j = 1; j <= m; j++)
	    {
	      if (d[j] < i)
		{
		  if (dp[i - d[j]] < min)
		    min = dp[i - d[j]];
		    
		}
	    }
	  //printf ("min:%ld,%ld\n", min,i);
	  if(min!=MAXN)  
	  dp[i] = min + 1;
	}


    }
  //for(i = 1; i<=m; i++)
  //printf ("%ld,%ld\n", dp[5*d[i]],5*d[i]);
  printf ("%ld\n", dp[n]);
  //n = 50001;printf("%d",n);
  return 0;
}

Measured memory_bytes: 3136
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);
        int count = 0;
        boolean flag = true;
        for (int i = 0; i < n; i++) {
            if (x >= a[i]) {
                x -= a[i];
                count++;
            } else {
                flag = false;
                break;
            }
        }
        if (flag && x > 0){
            count--;
        } 
        

        System.out.println(count);
    }
}

Measured memory_bytes: 35844
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n-1); i >= 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;
ll lim=1e18;

int main() {
	int n; cin >> n;
	vint a(n);
	rep(i,n) cin >> a[i];
	int now=1;
	int ans=0;
	rep(i,n) {
		if(a[i]!=now) ans++;
		if(a[i]==now) now++;
	}
	if(now==1) cout << -1 << endl;
	else cout << ans << endl;
}

Measured memory_bytes: 4016
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <numeric>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
int INF = 1e9;
int main(){
	string s;cin >> s;
	if(s.size()==2){
		if(s[0]==s[1]) cout << 1 << " " << 2 << endl;
		else cout << -1 << " " << -1 << endl;
		return 0;
	}
	rep(i,s.size()-2){
		if(s[i]==s[i+1]){
			cout << i+1 << " " << i+2 << endl;
			return 0;
		}else if(s[i]==s[i+2]){
			cout << i+1 << " " << i+3 << endl;
			return 0;
		}else if(s[i+1]==s[i+2]){
			cout << i+2 << " " << i+3 << endl;
			return 0;
		}
	}
	printf("-1 -1\n");
	return 0;
} 
 

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

using namespace std;

const int MAXN = 10000;

long result[MAXN];
long cnr(int n, int k)
{
	result[0] = 1;
	for (int i = 1; i <= n; i++)
	{
		result[i] = 1;
		for (int j = i - 1; j >= 1; j--)
		{
			result[j] = result[j - 1] + result[j];
		}
	}

	return result[k];
}

 int n, p;
 int numO, numE;

 int main()
 {
	 cin >> n >> p;
	 int tmp;
	 numO = numE = 0;
	 for (int i = 0; i < n; ++i)
	 {
		 cin >> tmp;
		 if (tmp & 0x01)
			 numO++;
		 else
			 numE++;
	 }

	 long x = 0;
	 long y = 0;
	 if (p == 0)
	 {
		 for (int i = 0; i <= numO; i += 2)
			 x += cnr(numO, i);
	 }
	 else
	 {
		 for (int i = 1; i <= numO; i += 2)
			 x += cnr(numO, i);
	 }
	 for (int i = 0; i <= numE; i++)
		 y += cnr(numE, i);
	 cout << x*y << endl;

	 return 0;
 }

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

const int MXN = 2e5, IINF = 1e9 + 10, INF = 1e18 + IINF + 10, MOD = 1000000007;
const ld PI = 4.0 * atanl(1.0), PREC = .000001;
const char nl = '\n';

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.end(), x.begin()
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)(x).size()
#define ins insert

int n, m, t, a[MXN];

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

int main() {
  fast();
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size(); ++i) {
    cout << s[i];
    if (i < t.size()) cout << t[i];
  }
  return 0;
}



Measured memory_bytes: 3520
use std::io::*;
use std::str::FromStr;

fn main() {
    let mut s: Vec<char> = read::<String>().chars().collect();
    let mids :String = (s.len() - 2).to_string();
    let first:String = s.first().unwrap().to_string();
    let last:String = s.last().unwrap().to_string();
    println!("{}{}{}",first,mids,last);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

Measured memory_bytes: 4352