akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#define INF 1<<28
#define F first
#define S second
using namespace std;
 

typedef pair < int, int > P;
vector < P > p[5];
int sx, sy, gx, gy;
int memo[5][5][1111];

int solve(int k, int t, int q){
  
  if(k == 4) return abs(p[t][q].F-gx) + abs(p[t][q].S-gy);
  if(memo[k][t][q]) return memo[k][t][q];
  
  int ans = INF, d = (t+1)%5, c;
  for(int i=0;i<p[d].size();i++){
    c = k?abs(p[t][q].F-p[d][i].F) + abs(p[t][q].S-p[d][i].S):abs(sx-p[d][i].F) + abs(sy-p[d][i].S);
    //if(!k) c = abs(sx-p[d][i].F) + abs(sy-p[d][i].S);
    //else c = abs(p[t][q].F-p[d][i].F) + abs(p[t][q].S-p[d][i].S);
    ans = min(ans, solve(k+1, d, i) + c);
  }
 
  return memo[k][t][q] = ans;
}
 
int main(){
 
  int w,h;
  char c;
 
  while(true){
    cin >> w >> h;
    if(!w && !h) break;
 
    for(int i=0;i<5;i++) p[i].clear();
     
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
    cin >> c;
    if(c == 'S') sx = j, sy = i;
    if(c == 'G') gx = j, gy = i;
    else if(c != '.') p[c-'1'].push_back(P(j,i));
      }
    }
     
    P q = P(0,INF);
    for(int i=0;i<5;i++){
      memset(memo, 0, sizeof(memo));
      if(q.S > solve(0,i,0)) q.F = i+1, q.S = solve(0,i,0);
    }
 
    if(q.S == INF) cout << "NA\n";
    else cout << q.F << " " << q.S << endl;
 
  }
}

Measured memory_bytes: 1372
using System.Collections.Generic;
using static System.Console;

class Program
{
    static void Main()
    {
        var S = NextString();
        var ans = 0;
        var pre = ' ';

        foreach (var c in S)
        {
            if (pre != ' ' && pre != c)
            {
                ans++;
            }
            pre = c;
        }
        WriteLine(ans);
    }

    static string NextString()
    {
        var result = new List<char>();
        while (true)
        {
            int next = Read();
            if (next < 0)
            {
                break;
            }
            var nextChar = (char)next;
            if (!char.IsWhiteSpace(nextChar))
            {
                result.Add(nextChar);
            }
            else if (nextChar != '\r')
            {
                break;
            }
        }
        return string.Join("", result);
    }
}

Measured memory_bytes: 15968
#include <stdio.h>

int main()
{
    int a, b, sum, counter, i;
    while (scanf("%d %d", &a, &b) != -1)
    {
        sum = a + b;
        for (i = 0; sum >= 1; i++)
            sum = sum / 10;
        printf("%d\n", i);
    }
    return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<map>  
#include<set>
#include<iterator>
#include<list>
#include<utility>
#include<cstdlib>
#include<queue>
#include<stack>
#include<bitset>
//#include<bits/stdc++.h>

#define PI  2*acos(0.0)
#define pb push_back


using namespace std;
using ll = long long;
using lli = long long int;
using ld = long double;

	
	
	
	
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
ll n;
cin>>n;
ll ans=0;
for(int i=1;i<n;i++)
{
	ans+=(n-1)/i;
}

	cout<<ans<<"\n";
	
	return 0;
	
	
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(void)
{
    int n, m;
    cin >> n >> m;
    vector<vector<string>> fma(n);

    REP(i,m){
        int p;
        string s;
        cin >> p >> s;
        p--;

        fma[p].push_back(s);
    }

    int accnt = 0;
    int wacnt = 0;

    REP(i,n){
        REP(j, fma[i].size())
        {
            if(fma[i][j] == "AC"){
                accnt++;
                wacnt+=j;
                break;
            }
        }
    }

    cout << accnt << " " << wacnt << endl;

    return 0;
}

Measured memory_bytes: 10368
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int dp[3001][3001];

string common(string &str1,string &str2,int l)
{
    string str;
    // ye common subsequence hoga....
    // aur isse hame print karana hai..
    int i,j;
    i=j=0;
    while(l)
    {
        if(str1[i]==str2[j])
        {
            str.pb(str1[i]);
            i++;
            j++;
            l--;
        }
        else
        {
            if(dp[i][j+1]>=dp[i+1][j])
            {
                j++;
            }
            else
            {
                i++;
            }
        }
    }
    return str;
}

int length(int i,int j,string &str1,string &str2)
{
    if(i>=str1.length() || j>=str2.length())
    {
        return 0;
    }
    else
    {
        if(dp[i][j]!=-1)
        {
            return dp[i][j];
        }
        
        if(str1[i]==str2[j])
        {
            return dp[i][j]=1+length(i+1,j+1,str1,str2);
        }
        else
        {
           
            return dp[i][j]=max(length(i,j+1,str1,str2),length(i+1,j,str1,str2));
        }
    }
}

string solve(string &str1,string &str2)
{
    memset(dp,-1,sizeof(dp));
    return common(str1,str2,length(0,0,str1,str2));
}

int main()
{
    string str1,str2;
    cin>>str1>>str2;
    cout<<solve(str1,str2);
    return 0;
}

Measured memory_bytes: 35968
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
const int N = 2e5 + 5;
const int INF = 0x3f3f3f3f; 
using namespace std;

int n, head[N], cnte, cnt[2][N], S, T, d[N], cur[N], m, id[105][105], inv[105][105], tot;
char s[N]; 
struct edge { int to, nxt, flow; } e[N << 2]; 
queue<int> q; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

inline void adde(int u, int v, int w)
{
	e[++cnte] = (edge) { v, head[u], w }, head[u] = cnte;
	e[++cnte] = (edge) { u, head[v], 0 }, head[v] = cnte; 
}

bool bfs()
{
	q.push(S), memset(d, 0, sizeof(d)), d[S] = 1; 
	while(!q.empty())
	{
		int u = q.front(); q.pop();
		for(int v, i = head[u]; i; i = e[i].nxt)
		{
			v = e[i].to;
			if(e[i].flow && !d[v]) d[v] = d[u] + 1, q.push(v); 
		}
	}
	return d[T]; 
}

int dfs(int u, int a)
{
	if(u == T || !a) return a;
	int f = 0, tmp;
	for(int v, &i = cur[u]; i; i = e[i].nxt)
	{
		v = e[i].to;
		if(e[i].flow && d[v] == d[u] + 1)
		{
			tmp = dfs(v, min(a, e[i].flow));
			f += tmp, a -= tmp, e[i].flow -= tmp, e[i ^ 1].flow += tmp; 
		}
		if(!a) break; 
	}
	if(a) d[u] = -1;
	return f; 
}

int dinic()
{
	int flow = 0;
	while(bfs())
	{
		memcpy(cur, head, sizeof(cur));
		flow += dfs(S, INF); 
	}
	return flow; 
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin); 
#endif
	n = read <int> (), m = read <int> (), cnte = 1, tot = n + m; 
	for(int i = 1; i <= n; i++)
	{
		scanf("%s", s + 1);
		for(int j = 1; j <= m; j++)
		{
			if(s[j] != '.') id[i][j] = ++tot, inv[i][j] = ++tot; 
			if(s[j] == 'S') 
				cnt[0][i]++, cnt[1][j]++, S = id[i][j], adde(S, i, INF), adde(S, j + n, INF); 
			else if(s[j] == 'T') T = id[i][j], cnt[0][i]++, cnt[1][j]++, adde(i, T, INF), adde(j + n, T, INF);
			else if(s[j] == 'o')
			{
				adde(id[i][j], inv[i][j], 1), adde(i, id[i][j], INF), adde(j + n, id[i][j], INF); 
				adde(inv[i][j], i, INF), adde(inv[i][j], j + n, INF); 
			}
		}
	}
	for(int i = 1; i <= n; i++) if(cnt[0][i] == 2) { puts("-1"); return 0; }
	for(int i = 1; i <= m; i++) if(cnt[1][i] == 2) { puts("-1"); return 0; }
	printf("%d\n", dinic()); 
	return 0; 
}


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

int main(){
	int x;
	stack<int> S;
	while(1){
		cin>>x;
		if(x==0){
			if(S.empty())break;
			cout<<S.top()<<endl;
			S.pop();
		}else{
			S.push(x);
		}
	}
	return 0;
}

Measured memory_bytes: 1200
import sys
input = sys.stdin.readline
n, m, s, t = map(int,input().split())
C = [list(map(int,input().split())) for i in range(m)]

s -= 1
t -= 1

# O((V + E)log(V))
# Cは [[スタート頂点, ゴール頂点, 重み], ...] のリスト

M = [[] for i in range(n)]
for i in range(len(C)):
    M[C[i][0]-1].append([C[i][1]-1, C[i][2]])  # 無向グラフなら両方追加
    M[C[i][1]-1].append([C[i][0]-1, C[i][2]])  # 無向グラフなら両方追加

N = [[] for i in range(n)]
for i in range(len(C)):
    N[C[i][0]-1].append([C[i][1]-1, C[i][3]])  # 無向グラフなら両方追加
    N[C[i][1]-1].append([C[i][0]-1, C[i][3]])  # 無向グラフなら両方追加

import heapq

def dijkstra(s, M):
    D = [10**16] * n  # 頂点0からの距離
    P = [-1] * n  # 頂点0からの最短距離において、そこの直前の頂点(経路復元に利用)
    D[s] = 0
    V = [0] * n  # その頂点のD[i]が最短距離と確定したら1
    Q = []  # 優先度付きキュー
    for v in range(n):
        heapq.heappush(Q, [D[v], v])

    le = len(Q)
    while le > 0:
        q = heapq.heappop(Q)
        u = q[1]
        du = q[0]
        if V[u] == 0:
            V[u] = 1
            le -= 1
            for i in range(len(M[u])):
                v = M[u][i][0]
                luv = M[u][i][1]
                if V[v] == 0:
                    alt = du + luv
                    if D[v] > alt:
                        D[v] = alt
                        P[v] = u
                        heapq.heappush(Q, [alt, v])
    return D, P

Ds, _ = dijkstra(s, M)
Dt, _ = dijkstra(t, N)

ANS = [0] * n

# print(Ds,Dt)

ans = 10**16
for i in range(n-1, -1, -1):
    ans = min(ans, Ds[i] + Dt[i])
    ANS[i] = ans

for i in range(n):
    print(10**15 - ANS[i])

Measured memory_bytes: 148872
using System;
using System.Collections.Generic;

class ABC_169_D
{
    static void Main(string[] args)
    {
        long N = long.Parse(Console.ReadLine());

        List<long> factor = new List<long>();

        long limit = (long) Math.Sqrt(N);
        for (long i = 2; i <= limit; i++)
        {
            if (N % i == 0)
            {
                factor.Add(i);
                N /= i;
                i = 1;
                limit = (long)Math.Sqrt(N);
            }
        }

        if(N>1)
        {
            factor.Add(N);
        }

        int ans = 0;
        long current = 0;
        long count = 0;
        long next = 1;
        for (int i = 0; i < factor.Count; i++)
        {
            long n = factor[i];

            if (n == current)
            {
                count++;
                if(count==next)
                {
                    ans++;
                    count = 0;
                    next++;
                }
            }
            else
            {
                ans++;
                current = n;
                count = 0;
                next = 2;
            }
        }

        Console.WriteLine(ans);
    }

}

Measured memory_bytes: 27824
#include <bits/stdc++.h> 
#include <chrono>
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

int main(){
    LL a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(max(b*d,a*c),max(a*d,b*c))<<endl;
    return 0;
}

Measured memory_bytes: 3632
N,K=map(int,input().split())
A=list(map(int,input().split()))

diffs=[]
for i in range(len(A)):
  if A[i]>=K:
    diffs.append(A[i]-K)
    
def gcd(a,b):
  if a>b:
    a,b=b,a
  while a%b>0:
    a,b=b,a%b
  return b

g=A[0]
for i in range(1,len(A)):
  g=gcd(g,A[i])
  
for dif in diffs:
  if dif%g==0:
    print("POSSIBLE")
    break
else:
  print("IMPOSSIBLE")

Measured memory_bytes: 14224
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define N 2200
using namespace std;
int a[N][N],f[N][N],l[N],r[N],b[N],id[N];
int n,m,ans;
char s[N];
int check(int x,int y){
	return ((a[x][y]==a[x-1][y])&&(a[x][y-1]==a[x-1][y-1]))||((a[x][y]!=a[x-1][y])&&(a[x][y-1]!=a[x-1][y-1]));
}
bool cmp(int x,int y){
	return b[x]>b[y];
}
int solve(){
	for(int i=1;i<=n;i++)id[i]=i;
	sort(id+1,id+1+n,cmp);
	memset(l,0,sizeof(l));
	memset(r,0,sizeof(r));
	for(int i=1;i<=n;i++){
		int x=id[i];
		l[x]=x;
		r[x]=x;
		if(l[x-1])l[x]=min(l[x],l[x-1]);
		if(r[x+1])r[x]=max(r[x],r[x+1]);
		r[l[x]]=r[x];
		l[r[x]]=l[x];
		ans=max(ans,(r[x]-l[x]+1)*b[x]+((l[x]-1>0)?b[x]:0));
		l[0]=0;
		r[0]=0;
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%s",s+1);
		for(int j=1;j<=m;j++)a[i][j]=s[j]=='.';
	}
	for(int i=1;i<=m;i++)f[1][i]=i;
	for(int i=2;i<=n;i++){
		f[i][1]=1;
		for(int j=2;j<=m;j++){
			if(check(i,j))f[i][j]=f[i][j-1]+1;
			else f[i][j]=1;
		}
	}
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++)b[j]=f[j][i];
		solve();
	}
	printf("%d\n",ans);
}

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

ll M = 1e+18;

int main(){
	ll n;
	cin >> n;
	ll ans = 1;
	vector<ll> a(n);
	bool flag = false;
	rep(i,n){
		cin >> a[i];
		if(a[i] == 0) flag = true;
	}
	if(flag){
		cout << 0 << endl;
	}else{
		rep(i,n){
			if(ans > M/a[i]){
				cout << -1 << endl;
				return 0;
			}else{
				ans *= a[i];
			}
		}
		cout << ans << endl;
	}
    return 0;
}



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

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

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

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

const ll INF = 1LL << 60;

int main(){
  string s;
  ll k;
  cin >> s >> k;
  int ans = 1;
  int index;
  for (size_t i = 0; i < s.size(); i++) {
    if(s[i] != '1' && k > i){
      ans = s[i] - '0';
      break;
    }
  }
  std::cout << ans << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	ll K;
	vector<ll> V(3, 0);
	cin >> V[0] >> V[1] >> V[2];
	cin >> K;
	for (ll k = 0; k < K; k++) {
		sort(V.begin(), V.end(), [](ll a, ll b) {return a > b; });
		V[0] *= 2;
	}
	cout << V[0] + V[1] + V[2] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=500010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n,a[N],op,oq;
signed main()
{
    n=read(); op=oq=1;
    for(ri int i=1;i<=n;i++)
    {
        a[i]=read();
        if(a[i]<0) op=0;
        if(a[i]>0) oq=0;
    }
    if(op)
    {
        printf("%lld\n",n-1);
        for(ri int i=1;i<n;i++) printf("%lld %lld\n",i,i+1);
    }
    else if(oq)
    {
        printf("%lld\n",n-1);
        for(ri int i=n;i>1;i--) printf("%lld %lld\n",i,i-1);
    }
    else if(!op && !oq)
    {
        int P,Q; P=Q=0;
        int pcp=0,pcq=0;
        for(ri int i=1;i<=n;i++)
        {
            if(a[i]>0)
            {
                if(a[i]>P) P=a[i], pcp=i;
            }
            if(a[i]<0)
            {
                if(-a[i]>Q) Q=-a[i], pcq=i;
            }
        }
        printf("%lld\n",n*2-1);
        if(P>=Q)
        {
            for(ri int i=1;i<=n;i++) printf("%lld %lld\n",pcp,i);
            for(ri int i=1;i<n;i++) printf("%lld %lld\n",i,i+1);
        }
        else
        {
            for(ri int i=1;i<=n;i++) printf("%lld %lld\n",pcq,i);
            for(ri int i=n;i>1;i--) printf("%lld %lld\n",i,i-1);
        }
    }
    return 0;
}

Measured memory_bytes: 3764
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//
//    #pragma GCC optimize("unroll-loops")
//    #pragma GCC optimize("Ofast")
//    #pragma GCC optimize("-O3")
//    #pragma GCC optimize("no-stack-protector")
//    #pragma GCC optimize("fast-math")

#define fi first
#define f first
#define se second
#define s second
#define vi_a vector<int>a;
#define p_b push_back
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ll long long
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define getfiles    ifstream cin("input.txt");ofstream cout("output.txt");
#define pw(x) (1ll << x)
#define sz(x) (ll)x.size()
#define endl "\n"
#define rall(x) x.rbegin(),x.rend()
#define len(a) (ll)a.size()
#define rep(x,l,r) for(ll x=l;x<r;x++)
//#define for(int i=0;i<n;i++) for(ll i=0;i<n;i++)
using namespace std;
//using namespace __gnu_pbds;
ld eps = (ld)1 / 1e6;
ll inf = 1e18, mod2 = 998244353, mod1 = 1e9 + 7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//const ll to[5]={0,4,6,7,9};
//const ll N=2*1e5+1;
const ll R=1e4;
//const ll to[7]={1,2,3,1,3,2,1};
const ll tx[4]={0,0,-1,1};
const ll ty[4]={-1,1,0,0};
const char rev_to[4]={'E','W','N','S'};
const ll N=2*1e5+4;
bool win(ll a,ll b,ll c){
    return (b*b*b*b+b*b*b*a+b*b*a*a+b*a*a*a+a*a*a*a)==c;
}
signed main(){
    fast_io;
    ll n;
    cin>>n;
//    if(n==1){
//        cout<<0<<" "<<-1;
//    }
    for(ll i=1;i<=n;i++){
        if(n%i) continue;
        ll ra=i;
        for(ll j=-10000;j<=10000;j++){
            if(win(j,ra+j,n/i)){
                cout<<j+ra<<" "<<j;
                return 0;
            }
//            if(win(j,n/i+j,i)){
//                cout<<j+n/i<<" "<<j;
//                return 0;
//
//            }
        }
    }
    return 0;
}
/*
    32+4+4=40
    40
    если WA , то чекер говно, поэтому почекай l8 строчку
    YA
    X.X..
    .....
    .....
    ..X..
    .XXX..
    .XXXX
    .XXXX n/2=2+n
*/


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 2e7+10, mod = 998244353;
int n,A,B;

inline int Mod(int x){
	return x>=mod?x-mod:x;
}
inline int power(int a,int b){
	int ret=1;
	for (;b;b>>=1,a=1ll*a*a%mod) if (b&1) ret=1ll*ret*a%mod;
	return ret;
}
int fac[N],ifac[N];
inline void init(int n){
	fac[0]=1;
	For(i,1,n) fac[i]=1ll*fac[i-1]*i%mod;
	ifac[n]=power(fac[n],mod-2);
	Dow(i,n-1,0) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
}
inline int C(int n,int m){
	return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
inline int calc(int x,int y){
	return Mod(C(x+y,x)-C(x+y,x+1)+mod);
}

int main(){
	n=read(),A=read(),B=read(),init(2*n);
	if (!B) return puts("1"),0;
	int ans=0;
	For(i,0,min(n-B-1,A)) ans=(ans+1ll*calc(B-1,i)*C(n-B-i-1+A-i,A-i))%mod;
	if (A+B==n) ans=Mod(ans+calc(B-1,A));
	printf("%d\n",ans);
}

Measured memory_bytes: 159924
import math
N = int(input())
m = int(math.sqrt(N))
a = 0
ans = 0
count = 1

for i in range(1, m+1):
    if N % i == 0:
        a = i

a = max(a, (N//a))

count = int(math.log10(a) + 1)
    
print(count)

Measured memory_bytes: 3188
if __name__ == '__main__':
    from sys import stdin

    while True:
        m, f, r = (int(n) for n in stdin.readline().rstrip().split())

        if m == f == r == -1:
            break

        s = m + f
        result = "F" if m == -1 or f == -1 \
            else "A" if 80 <= s \
            else "B" if 65 <= s \
            else "C" if 50 <= s or 50 <= r \
            else "D" if 30 <= s \
            else "F"

        print(result)



Measured memory_bytes: 5608
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

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

const int MOD = 1000000007;
const char ENDL = '\n';

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int n,l;
    cin >> n >> l;
    VS s(n);
    REP(i,n){
        cin >> s[i];
    }

    SORT(s);

    REP(i,n){
        cout << s[i];
    }
    cout << ENDL;
    
    return 0;
}

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

int v[100000];

int main(){
	
	int n, q, b, c, i, aux;
	ll s = 0;
	cin >> n;
	
	for(i = 0; i < n; i++){
		cin >> aux;
		v[aux]++;
		s+=aux;
	}
	
	cin >> q;
	
	while(q--){
		
		cin >> b >> c;
		
		s += (long long)(c-b) * v[b];
		v[c] += v[b];
		v[b] = 0;
		
		cout << s << endl;
	}
	
	
	return 0;
}


Measured memory_bytes: 3992
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    int ans = a*b-a-b+1;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int N;
void dfs(char c,string S) {
    if(S.size() == N) {
        cout << S << endl;
        return;
    }
    for(char i = 'a'; i <= c; i++) {
        dfs(max((int)c,(int)i+1),S+i);
    }
    return;
}
signed main(){
    cin >> N;
    dfs('a',"");
}


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

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")
}

fn main() {
    let s: i8 = read();
    let w: i8 = read();

    if s > w {
        println!("safe");
        return
    }
    println!("unsafe");
}


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

vector<ll> ans(2e5);
vector<set<ll>> v(2e5);
vector<ll> al(2e5);

void dfs (ll n, ll x) {
  ans[n]+=x;
  al[n]=1;
  for(ll p:v[n]) {
    if(!al[p]) {
      dfs(p,ans[n]);
    }
  }
}

int main() {
  ll n,q;
  cin >> n >> q;
  for(ll i=0;i<n-1;i++) {
    ll a,b;
    cin >> a >> b;
    v[a-1].insert(b-1);
    v[b-1].insert(a-1);
  }
  for(ll i=0;i<q;i++) {
    ll p,x;
    cin >> p >> x;
    ans[p-1]+=x;
  }
  dfs(0,0);
  for(ll i=0;i<n;i++) {
    if(i!=0) {
      cout << " ";
    }
    cout << ans[i];
  }
  cout << endl;
}

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

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

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで降順
#define pb push_back
#define eb emplace_back
#define fst first
#define snd second
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>T add(const T &a, const T &b){return (a+b)%mod;}

ll ext_gcd(ll a, ll b, ll &x, ll &y){ // ax+by=gcd(a,b)なるx,y,gcdを返す
  if(b == 0){
    x = 1; y = 0; return a;
  }
  ll q = a / b;
  ll g = ext_gcd(b, a-q*b, x, y);
  ll z = x - q * y;
  x = y; y = z;
  return g;
}

ll lcm(ll a, ll b){
  ll x, y;
  return a * b / ext_gcd(a,b,x,y);
}


signed main(){
  int a, b, c, d; cin >> a >> b >> c >> d;
  int x = (b+c)/c - (a+c-1)/c;
  int y = (b+d)/d - (a+d-1)/d;
  int l = lcm(c,d);
  int z = (b+l)/l - (a+l-1)/l;
  cout << (b-a+1) - (x+y-z) << endl;
}


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

int main() {
  ll N, K;
  cin >> N >> K;
  ll pi;
  vector<ll> p;
  for (ll i=0;i<N;i++) {
  	cin >> pi;
    p.push_back(pi);
  }
  sort(p.begin(), p.end());
  
  ll sum=0;
  for (ll i=0;i<K;i++) {
  	sum+=p[i];
  }
  cout << sum;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define r(i,a,n) for(int i=a;i<n;i++)
using namespace std;
int main(){
  int n;
  cin>>n;
  while(n--){
    string s,ss;
    cin>>s>>ss;
    int a[ss.size()+2][s.size()+2];
    r(i,0,ss.size()+2)r(j,0,s.size()+2)a[i][j]=0;
    ss=' '+ss;
    s=' '+s;
    r(i,1,ss.size()+1){
      r(j,1,s.size()+1){
        if(ss[i]==s[j])a[i][j]=a[i-1][j-1]+1;
        else a[i][j]=max(a[i-1][j],a[i][j-1]);
      }
    }
    cout<<a[ss.size()-1][s.size()-1]<<endl;
  }
}

Measured memory_bytes: 7072
#include <stdio.h>

int par[12 * 12]; // 島の座標の個数

void init(int n)
{
    for (int i = 0; i < n; i++){
        par[i] = i; // i 番目の頂点のグループは最初は i
    }
}

int find(int x)
{
    if (par[x] == x){
        return (x);
    }
    return (par[x] = find(par[x]));
}

void merge(int x, int y)
{
    x = find(x);
    y = find(y);
    
    if (x != y){
        par[y] = x;
    }
}

int same(int x, int y)
{
    return (find(x) == find(y));
}

int main(void)
{
    int i, j;
    int num;
    int groups[12 * 12];
    char island[13][13];
     
    while (1){
        
        //色々初期化
        num = 0;
        init(12 * 12);
        for (i = 0; i < 12 * 12; i++){
            groups[i] = 0;
        }
        for (i = 0; i < 13; i++){
            for (j = 0; j < 13; j++){
                island[i][j] = 0;
            }
        }
        
        //入力
        for (i = 0; i < 12; i++){
            if (scanf("%s", island[i]) == EOF){
                return (0);
            }
        }
        
        for (i = 0; i < 12; i++){
            for (j = 0; j < 12; j++){
                //001
                //001
                //...みたいな繋がり方
                if (island[i][j] == '1' && island[i + 1][j] == '1'){
                    merge(i * 12 + j, (i + 1) * 12 + j);
                }
                //011
                //...みたいな繋がり方
                if (island[i][j] == '1' && island[i][j + 1] == '1'){
                    merge(i * 12 + j, i * 12 + j + 1);
                }
            }
        }
        
        for (i = 0; i < 12; i++){
            for (j = 0; j < 12; j++){
                if (island[i][j] == '1'){
                    groups[find(i * 12 + j)] = 1;
                }
            }
        }
        
        for (i = 0; i < 12 * 12; i++){
            num += groups[i];
        }
        
        printf("%d\n", num);
    }
    
    return (0);
}

Measured memory_bytes: 972
'use strict';

function main(stdin) {
  const input = stdin.split(' ').map(v => parseInt(v, 10));
  const N = input[0];
  const L = input[1];

  let sum = 0;
  let min = Infinity;

  for (let i = L; i < L + N; ++i) {
    sum += i;
    if (Math.abs(i) < Math.abs(min)) min = i;
  }
  
  console.log(sum - min);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include<bits/stdc++.h>
using namespace std;
using p = pair<int, int>;

int main(){
    int N, D, f, s;
    cin >> N >> D;
    vector<p> R;
    for(int i = 0; i < N; i++){
        cin >> f >> s;
        R.push_back(p(f, s));
    }
    int ans = 0;
    for(p r : R){
        double x = r.first, y= r.second, norm;
        norm = pow(pow(x,2) + pow(y,2), 0.5);
        if(D >= norm) ans++;
    }
    cout << ans << endl;
}

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

ll N, A[200005], A2[200005];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> N;
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
        A2[i] = A[i] - (i+1);
    }
    sort(A2, A2+N);
    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        ans += abs(A[i] - (A2[N/2]+i+1));
    }
    
    cout << ans << "\n";
    
}

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


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

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


#########################
X,Y = map(int,input().split())

if Y > 2 * X or X > 2 * Y:
    print(0)

elif (X+Y) % 3 != 0:
    print(0)

else:
    N = (X+Y) // 3
    x = X - N
    y = Y - N

    print(cmb(x+y,x,mod))

Measured memory_bytes: 88692
#include <iostream>

using namespace std;

int a[110][110];

int main(){
    int N;
    cin >> N;
    for(int i = 0;i < N;i++){
        int n,k;
        cin >> n >> k;
        for(int j = 0;j < k;j++){
            int l;
            cin >> l;
            a[i][l-1] = 1;
        }
    }
    for(int i = 0;i < N;i++){
        for(int j = 0;j < N;j++){
            cout << a[i][j];
            if(j != N-1){
                cout << " ";
            }
        }
        cout << endl;
    }
} 


Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#define INF 100000000
#define INFLL (long long)1e14
#define Loops(i, n) for(int i = 0; i < (int)n; i++)
#define Loops1(i, n) for(int i = 1; i <= (int)n; i++)
long long int A,B;
long long int city[100000];
int N;
long long int ans=0;
int main(void){
	std::cin>>N>>A>>B;
	Loops(i,N){
		std::cin>>city[i];
	}
	Loops(i,N-1){
		long long int tasu=std::min(B,A*(city[i+1]-city[i]));
		ans+=tasu;
	}
	std::cout<<ans<<std::endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define sz(x) int(x.size())
using ll = long long;
using P = pair<int,int>;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;

void factor(ll a,map<ll,ll>& factors){
    for(int i=2;i*i<=a;i++){
        if(0==a%i)
        while(0==a%i){
            a/=i;
            factors[i]++;
        }
    }
    if(1!=a) factors[a]++; 
    return;
}

int main()
{
    ll n;
    cin >> n;
    ll ans=0;

    vector<pair<ll,int>> fs;
  for (ll i = 2; i*i <= n; ++i) {
    int x = 0;
    while (n%i == 0) {
      n /= i;
      ++x;
    }
    fs.emplace_back(i,x);
  }
  if (n != 1) fs.emplace_back(n,1);

    for(auto p : fs){
        ll x = p.second;
        ll b = 1;
        while(b <= x){
            x -= b;
            b++;
            ans++;
        }

    }
    
    
    cout << ans;

    
    return 0;
}

Measured memory_bytes: 19668
using System;
using System.Linq;

namespace Aizu {
    class OnlineJudge {
        static void Main() {
            foreach (var i in Enumerable.Range(1, 30).Except(Enumerable.Range(1, 28).Select(p => int.Parse(Console.ReadLine()))).OrderBy(p => p)) {
                Console.WriteLine(i);
            }
        }
    }
}

Measured memory_bytes: 10184
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
    int n,c=0;
    cin >> n;
    vector<int>x(n);
    for(int i=0;i<n;i++){
        cin >> x[i];
    }
    while(1){
        for(int i=0;i<n;i++){
            if(x[i]%2==0){
                x[i]/=2;
            }else{
                cout << c;
                return 0;
            }
        }
        c++;
        if(count(x.begin(),x.end(),0)==n){
            break;
        }
    }
    cout << c;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n,k,q;
  cin >> n >> k >> q;
  vector<int> a(q), b(n+1,0);
  int i;
  for(i=0;i<q;i++) cin >> a[i];
  for(i=0;i<q;i++) b[a[i]]++;
  for(i=1;i<=n;i++){
    if(b[i]-q+k>0) cout << "Yes" << "\n";
    else cout << "No" << "\n";
  }
  return 0;
}

Measured memory_bytes: 1408
n,m=map(int, input().split())
if(n==1 or m==1):
  if(max(n,m)==1):
    ans=1
  elif(max(n,m)==2):
    ans=0
  else:
    ans=n*m-2
else:
  ans=(n-2)*(m-2)
print(ans)

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

int main(){
    double xs, ys, xt, yt;
    cin >> xs >> ys >> xt >> yt;
    int N;
    cin >> N;
    vector<double> x(N+2), y(N+2), r(N+2);
    x[0] = xs;
    y[0] = ys;
    r[0] = 0;
    x[N+1] = xt;
    y[N+1] = yt;
    r[N+1] = 0;
    for (int i = 1; i <= N; i++) cin >> x[i] >> y[i] >> r[i];
    vector<vector<double>> edge(N+2, vector<double>(N+2, 0));
    for (int i = 0; i <= N+1; i++) {
        for (int j = 0; j <= N+1; j++) {
            if (i == j) continue;
            edge[i][j] = sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j])) - r[i] - r[j];
            if (edge[i][j] < 0) edge[i][j] = 0;
        }
    }
    vector<double> dist(N+2, 99999999999);
    dist[0]=0;
    priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> pq;
    pq.push({0, 0});
    
    while (!pq.empty()) {
        double d = pq.top().first;
        int now = pq.top().second;
        pq.pop();
        if (d > dist[now]) continue;
        for (int nxt = 1; nxt <= N+1; nxt++) {
            if (dist[nxt] > d + edge[now][nxt]) {
                dist[nxt] = d + edge[now][nxt];
                pq.push({dist[nxt], nxt});
            }
        }
    }
    printf("%.15lf\n", dist[N+1]);
    
    return 0;
}


Measured memory_bytes: 14324
#include <stdio.h>
#define A 80
#define B 65
#define C 50
#define D 30
#define AB -1
int main(void)
{
	int m, f, r, a;
	char grade;
	while(scanf("%d%d%d", &m, &f, &r), (m != AB) || (f != AB) || (r != AB)){
		a = m + f;
		if((m == AB) || (f == AB) || (a < D)){
			grade = 'F';
		}else if(a >= A){
			grade = 'A';
		}else if(a >= B){
			grade = 'B';
		}else if(a >= C){
			grade = 'C';
		}else if(a >= D){
			if(r >= C){
				grade = 'C';
			}else{
				grade = 'D';
			}
		}
		printf("%c\n", grade);
	}
	return 0;
}

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

int main() {

    int N;
    cin >>N;
    vector<int> L(2*N);
    for(int i=0;i<2*N;i++){
        cin >>L[i];
    }
    
    sort(L.begin(),L.end());
    int a=0;
    for(int i=0;i<N;i++){
        a+=L[2*i];
    }
    cout <<a;

    return 0;    
}

Measured memory_bytes: 256
import sys

n, k, q = map(int, input().split())
a = [int(sys.stdin.readline().rstrip()) for _ in range(q)]

score = [0] * (n+1)
for i in a:
    score[i] += 1

for i in range(1, n+1):
    if k > q - score[i]:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 49628
#include<stdio.h>
int main(void)
{
	int n,i,a,t=1;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a);
		if(a%2==0)
		{
			if(a%3==0||a%5==0)
			;
			else t=-1;
		}
	}
	if(t==-1)
	printf("DENIED");
	else printf("APPROVED");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repBack(i, n) for (int i = n; i >= 0; i--)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int N;
    cin >> N;
    vector<int> W(N);
    cin >> W[0];
    repX(i,N,1){
        cin >> W[i];
        W[i]+=W[i-1];
    }
    int ans = INF;
    rep(t,N){
        ans = min(abs((W[N-1]-W[t])-W[t]),ans);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
        int N, K;
        int l[50];
        int sum=0;
        cin >> N >> K;
        for (size_t i = 0; i < N; i++) {
                cin >> l[i];
        }
        sort(l,l+N,greater<int>());
        for (size_t i = 0; i < K; i++) {
                sum += l[i];
        }
        cout << sum << endl;

        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sqr(x) ((x)*(x))
using namespace std;
typedef long long ll;
int n;

ll f(int t) {
	ll cnt = 0;
	for (ll x = 1; x*x <= t; x++) {
		for (ll y = 1; y <= t; y++) {
			ll f0 = sqr(x)+sqr(y)+x*y-n;
			if (f0 < 0) {
				ll delta = sqr(x+y)-4*(sqr(x)+sqr(y)+x*y-t), root = sqrt(delta);
				if (root * root == delta) {
					ll tmp = root - (x+y);
					if (tmp % 2 == 0 && tmp >= 2) cnt++;
				}
			} else break;
		}
	}
	return cnt;
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		printf("%lld\n", f(i));
	}
	return 0;
}

Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
int main()
{
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
string s,t;
cin>>s>>t;
long cn=0;
for(int i=0;i<s.size();i++)
{
    if(s[i]!=t[i])cn++;

}
cout<<cn<<endl;
return 0;
}


Measured memory_bytes: 3780
import math
def goodDistance():
	N, D = map(int, input().split())
	X = [0] * (N + 1)
	for i in range(1, N + 1):
		X[i] =  list(map(int, input().split()))
	count = 0
	# print(X)
	for i in range(1, N + 1):
		for j in range(i + 1, N + 1):
			sum = 0
			for k in range(0, D):
				sum += abs(X[i][k] - X[j][k]) ** 2
				distance = math.sqrt(sum)
			# print(i, j,sum)
			if distance.is_integer():
				count += 1
	print(count)

goodDistance()

Measured memory_bytes: 3064
from collections import deque

H, W = map(lambda x: int(x)+4, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())

grid = '#' * W * 2
for _ in range(H-4):
  grid += '##' + input() + '##'
grid += '#' * W * 2

magic_list = []
for i in range(5):
  for j in range(5):
    if (i, j) in [(2, 2), (1, 2), (2, 1), (2, 3), (3, 2)]:
      continue
    else:
      magic_list.append(i-2 + W*(j-2))

move_list = [-1, 1, W, -W]

def bfs(start):
  INF = 10 ** 9
  dist = [INF] * (H*W)
  dist[start] = 0
  q = deque([start])
  while q:
    v = q.popleft()
    dv = dist[v]
    for move in move_list:
      w = v + move
      if grid[w] == '#':
        continue
      dw = dv
      if dw >= dist[w]:
        continue
      dist[w] = dw
      q.appendleft(w)
    for magic in magic_list:
      w = v + magic
      if grid[w] == '#':
        continue
      dw = dv + 1
      if dw >= dist[w]:
        continue
      dist[w] = dw
      q.append(w)
  return dist

ans = bfs( (Ch+1)*W + Cw+1 )[(Dh+1)*W + Dw+1]

if ans == 10**9:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 218116
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 7/10/2018
 
 16:40-16:58 1WA
 17:00-17:10 apply ceil(cur/2) but got 2WA
 
 
 */

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
const int MAX_N=1e5+1;
int N;
LL P[MAX_N];
void solve() {
  int res=0;
  int cur=0;
  REP(i,N) {
    if(P[i]==i) ++cur;
    else {
      res+=(cur+1)/2;
      cur=0;
    }
  }
  if(cur) res+=(cur+1)/2;
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>N;
  REP(i,N) cin>>P[i],P[i]--;
  solve();
  return 0;
}


Measured memory_bytes: 1024
def solve():
    ans = []
    while True:
        n = int(input())
        if n == 0:
            break

        dp = [0] * (n+1)
        dp[0] = 1
        for i in range(1, n+1):
            dp[i] += dp[i - 1]
            if i > 1:
                dp[i] += dp[i - 2]
            if i > 2:
                dp[i] += dp[i - 3]

        ans.append((dp[-1]+3649) // 3650)
    print(*ans, sep='\n')


if __name__ == "__main__":
    solve()


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  ll k;
  cin >> s >> k;
  vl a;
  ll now = 1;
  rep2(i, 1, s.size()) {
    if(s[i - 1] == s[i])
      now++;
    else {
      a.push_back(now);
      now = 1;
    }
  }
  a.push_back(now);
  ll ans = 0;
  if(a.size() == 1) {
    ans = a[0] * k / 2;
  } else if(s[0] == s.back()) {
    rep2(i, 1, a.size() - 1) ans += a[i] / 2;
    ans *= k;
    ll ex = a[0] + a.back();
    ans += a[0] / 2 + a.back() / 2 + ex / 2 * (k - 1);
  } else {
    rep(i, a.size()) ans += a[i] / 2;
    ans *= k;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

int dp[3030][3030][4];

signed main(){
	int R, C, K;
	cin >> R >> C >> K;
	vector<vector<int>>a(R + 10, vector<int>(C + 10));
	REP(i, K) {
		int r, c, v;
		cin >> r >> c >> v;
		--r;
		--c;
		a[r][c] = v;
	}
	dp[0][0][1] = a[0][0];
	REP(i, R) {
		REP(j, C) {
			REP(k, 4) {
				CHMAX(dp[i + 1][j][0], dp[i][j][k]);
				CHMAX(dp[i][j + 1][k], dp[i][j][k]);
				CHMAX(dp[i + 1][j][1], dp[i][j][k] + a[i + 1][j]);
				if(k != 3) {
					CHMAX(dp[i][j + 1][k + 1], dp[i][j][k] + a[i][j + 1]);
				}
			}
		}
	}
	/*REP(i, R + 1) REP(j, C + 1) REP(k, 4) {
		out(i, j, dp[i][j][k]);
	}*/
	int ans = 0;
	REP(i, 4) CHMAX(ans, dp[R - 1][C - 1][i]);
	out(ans);
}

Measured memory_bytes: 358308
n,k = map(int,input().split())
from collections import deque
au = list(map(int,input().split()))
left = [0 for i in range(n)]
right = [0 for i in range(n)]
left[0] = au[0]
right[0] = au[-1]
ans = 0
for i in range(n-1):
    left[i+1] = left[i] + au[i+1]
    right[i+1] = right[i] + au[n-i-2]
p = min(n,k)
for a in range(p+1):
    for b in range(p+1-a):
        d = deque(au)
        x = []
        y = 0
        for i in range(a):
            u = d.popleft()
            x.append(u)
            y += u
        for j in range(b):
            v = d.pop()
            x.append(v)
            y += v
        x.sort(reverse = True)
        for ue in range(k-a-b):
            if len(x) > 0 and x[-1] < 0:
                y -= x.pop()
            else:
                break
        ans = max(ans,y)
print(ans)

Measured memory_bytes: 41840