akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	var tmp = ReadIntArray();
	int a = tmp[0], b = tmp[1];
	int ans = Math.Max(a+b, a-b);
	ans = Math.Max(ans, a*b);
	WriteLine(ans);
    }
}


Measured memory_bytes: 13396
from collections import defaultdict
N,  Q = map(int ,input().split())

d = defaultdict(list)
for _ in range(N-1):
    a, b = map(int, input().split())
    d[a].append(b)
    d[b].append(a)

dp = [0]*N
used = [False]*N

for _ in range(Q):
    p, x = map(int, input().split())
    dp[p-1] += x

q = [1]
used[0] = True

while q:
    x = q.pop()
    
    for i in d[x]:
        if used[i-1]==True:
            continue
        dp[i-1] += dp[x-1]
        used[i-1] = True
        q.append(i)

print(*dp)

Measured memory_bytes: 66848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////


int main(){fastio
    
    ll n=3;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll sum=0;rep(i,0,n-1)sum+=a[i];
    if(sum>=22)cout<<"bust";
    else cout<<"win";
    return 0;
}


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

int main(){
    int n,k;
    while(scanf("%d%d",&n,&k)!=EOF){
        int ans = 0;
        for(int i = 1;i <= n;++i){
            if(i == 1) ans = k;
            else ans *= k-1;
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
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();
		if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		} else {
			System.out.println("a == b");
		}
	}
}

Measured memory_bytes: 26176
n, m = map(int, input().split())

V = [set() for _ in range(n)] # 隣接リスト
for a, b in [[*map(lambda x: int(x)-1, input().split())] for _ in range(m)]:
    V[a].add(b)
    V[b].add(a)

from collections import deque, Counter
G = [-1] * n # グループ色分け
for s in range(n): # BFS
    dq = deque([s])
    while dq:
        p = dq.popleft()
        if G[p] >= 0: continue
        G[p] = s # 色付け
        for c in V[p]: dq.append(c)

print(max(Counter(G).values())) # 最大メンバ数


Measured memory_bytes: 94044
H, W = map(int, input().split())
mnr = 10**18
for i in range(1, H):
    w1 = W//2
    w2 = W-w1
    s1, s2, s3 = i*W, w1*(H-i), w2*(H-i)
    t = max([s1, s2, s3]) - min([s1, s2, s3])
    mnr = min(mnr, t)
H, W = W, H
for i in range(1, H):
    w1 = W//2
    w2 = W-w1
    s1, s2, s3 = i*W, w1*(H-i), w2*(H-i)
    t = max([s1, s2, s3]) - min([s1, s2, s3])
    mnr = min(mnr, t)
if H % 3 == 0 or W % 3== 0:
    mnr = 0
if H % 3:
    mnr = min(W, mnr)
if W % 3:
    mnr = min(H, mnr)
print(mnr)


Measured memory_bytes: 41948
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793




int main(){
    int d,t,s;
    cin >> d >> t >> s;
    if(d<=t*s)cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair <int, int>
#define pll pair <ll, ll>
#define gcd __gcd
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

const ll L = 3e3+10;

ll dp[L][L];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    string s, t;
    cin >> s >> t;

    for(ll i=0; i<sz(s); i++)
    {
        for(ll j=0; j<sz(t); j++)
        {
            if(s[i]==t[j])
            {
                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1);
            }

            else
            {
                dp[i+1][j+1] = max(dp[i+1][j+1], max(dp[i+1][j], dp[i][j+1]));
            }
        }
    }

    string ans = "";
    int i = s.size(), j = t.size();
    while(i > 0 && j > 0){
        if(dp[i][j] == dp[i-1][j]) i--;
        else if(dp[i][j] == dp[i][j-1]) j--;
        else{
            i--; j--;
            ans = s[i] + ans;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
struct Node{
	int p,l,r,b;
} T[25];
int D[25],H[25];

void getD(int u,int d){
	D[u] = d;
	if(T[u].r!=-1) getD(T[u].r,d+1);
	if(T[u].l!=-1) getD(T[u].l,d+1);
}
int getH(int u){
	int h1=0,h2=0;
	if(T[u].l!=-1) h1 = getH(T[u].l)+1;
	if(T[u].r!=-1) h2 = getH(T[u].r)+1;
	return H[u] = max(h1,h2);
}

int main()
{
	int n,l,r,in; 
	cin>>n;
	for(int i=0;i<n;i++) 
		T[i].p = T[i].b = -1;
	for(int i=0;i<n;i++){
		scanf("%d%d%d",&in,&l,&r);
		T[in].l = l;
		T[in].r = r;
		T[l].p = T[r].p = in;
		T[l].b = r;
		T[r].b = l;
	}

	int root;
	for(int i=0;i<n;i++)
		if(T[i].p==-1) root = i,i = n;
	getD(root,0);
	getH(root);

	for(int i=0;i<n;i++){
		printf("node %d: parent = %d, ",i,T[i].p);
		printf("sibling = %d, ",T[i].b);
		int deg = (T[i].l!=-1)+(T[i].r!=-1);
		printf("degree = %d, ",deg);
		printf("depth = %d, height = %d, ",D[i],H[i]);
		if(T[i].p==-1) printf("root\n");
		else if(!deg) printf("leaf\n");
		else printf("internal node\n");
	}
	return 0;
}



Measured memory_bytes: 3212
import sys
from math import *
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n, m, k = map(int, input().split())
    fgraph = [list() for i in range(n)]
    bgraph = [list() for i in range(n)]
    cgraph = [list() for i in range(n)]
    
    rks = [None] *n
    sys.setrecursionlimit(10**9)
    def dfs(graph,s,r):
        if rks[s] is None:
            rks[s] = r

        for i in range(len(graph[s])):
            if rks[graph[s][i]-1] is not None:
                continue
            dfs(graph, graph[s][i]-1,r)

    for i in range(m):
        a,b = map(int, input().split())
        fgraph[a-1].append(b)
        fgraph[b-1].append(a)

    # print(fgraph)
    #print(bgraph)
    # 連結成分に対してid的なindexをつける
    c = -1
    for i in range(n):
        if rks[i] is None:
            c += 1
            dfs(fgraph, i, c)
    
    for i in range(k):
        c,d = map(int, input().split())
        if rks[c-1] == rks[d-1]:
            bgraph[d-1].append(c)
            bgraph[c-1].append(d)

    counter = Counter(rks)
    for i in range(n):
        # counter[rks[i]] 連結成分のサイズ
        # len(fgraph[i]) 友達の数
        # len(bgraph[i]) 連結成分内のブロックの数
        # 1 自分
        print(counter[rks[i]] - len(fgraph[i]) - len(bgraph[i]) - 1)

if __name__ == '__main__':
    main()


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

using ll = long long;
using namespace std;
constexpr ll inf = 1e15;
constexpr ll mod = 1e9+7;

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

    ll H, W;
    cin>>H>>W;

    ll ans = inf;
    for (int n = 0; n < (1<<4); n++) {
        ll h = H, w = W;
        ll mx = 0, mn = inf;
        bool flag = false;
        ll _h = h, _w = w;
        if (n & 1) {
            if (n & (1<<1)) _w = w/3;
            else _w = (w+1)/3;
            if (w == _w) continue;
            w -= _w;
        } else {
            if (n & (1<<1)) _h = h/3;
            else _h = (h+1)/3;
            if (h == _h) continue;
            h -= _h;
        }
        mx = max(mx, _h*_w);
        mn = min(mn, _h*_w);
        _h = h;
        _w = w;
        if (n & (1<<2)) {
            if (n & (1<<3)) _w = w/2;
            else _w = (w+1)/2;
            if (w == _w) continue;
            w -= _w;
        } else {
            if (n & (1<<3)) _h = h/2;
            else _h = (h+1)/2;
            if (h == _h) continue;
            h -= _h;
        }
        mx = max(mx, _h*_w);
        mn = min(mn, _h*_w);
        mx = max(mx, h*w);
        mn = min(mn, h*w);
        ans = min(ans, mx - mn);
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
int main(){
	int N,M;
	cin>>N>>M;
	double l[20],a[20],b[20];
	rep(i,N) cin>>l[i]>>a[i]>>b[i];
	double ans=0;
	rep(i,1<<N){
		vector<int> vc;
		rep(j,N) if((i>>j)&1) vc.pb(j);
		if(vc.size()!=M) continue;
		double as=0;
		rep(jj,M) rep(kk,jj){
			int j=vc[jj],k=vc[kk];
			as+=(l[j]-l[k])*(l[j]-l[k])+(a[j]-a[k])*(a[j]-a[k])+(b[j]-b[k])*(b[j]-b[k]);
		}
		ans=max(ans,as);
	}
	printf("%.12f\n",ans);
}

Measured memory_bytes: 1268
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=100010;
struct data{
	int x,y;
}b[N];
int n,ans=0;
int a[N];
bool cmp(data x,data y)
{
	return x.x<y.x;
}
int main()
{
	scanf("%d",&n);
	for(int k=1;k<=n;k++)
	{
		int x;
		scanf("%d",&x);
		b[k].x=x;
		b[k].y=k;
	}
	sort(b+1,b+1+n,cmp);
	for(int k=1;k<=n;k++)
		a[b[k].y]=k;
	for(int k=1;k<=n;k+=2)
	{
		if((a[k]&1)==0) ans++;
	}
	printf("%d",ans);
	return 0;
}

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

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

Measured memory_bytes: 3608
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define mid (l+r>>1)

using namespace std;
const int N=500005;
char s[N];
int n,a[N],c[N];

bool check(int x)
{
	int lim=0;
	c[n+1]=0;
	rep(i,1,n) c[i]=a[i];
	c[1]+=9*x;
	rep(i,1,n) c[i+1]+=c[i]/10,c[i]%=10;
	rep(i,1,n+1) lim+=c[i];
	return lim<=9*x;
}

int main()
{
	scanf("%s",s+1),n=strlen(s+1);
	rep(i,1,n) a[i]=s[n-i+1]-'0';
	rep(i,1,n) a[i]=a[i]*9;
	rep(i,1,n) a[i+1]+=a[i]/10,a[i]%=10;
	if(a[n+1]) ++n;
	int l=1,r=n*20;
	while(l<=r) check(mid)?r=mid-1:l=mid+1;
	printf("%d\n",r+1);
	return 0;
}

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

int main (){
  	ll X, Y;
    cin>>X>>Y;
    if((X+Y)%3>0||X-2*Y>0||Y-X*2>0){
        cout<<0<<endl;
    }
    else{
        ll T=(X+Y)/3;
      	ll N=X-T;//TCNが答え
        ll M=T-N;
      	//cout<<T<<" "<<N<<" "<<M<<endl;
        vector<ll> Kai(T+1);
        Kai.at(0)=1;
        for(ll i=1; i<T+1; i++){
            Kai.at(i)=Kai.at(i-1)*(i);
            Kai.at(i)%=K;
        }
        ll MM=Kai.at(M);
        ll NN=Kai.at(N);
        ll MN=MM*NN;
      	//cout<<NN<<" "<<MM<<endl;
        MN%=K;
        ll MNMN=MN;
        vector<ll> Ni(0);
        ll Y=1;
      	Ni.push_back(Y);
        while(Y<=K){
            Y*=2;
          	Ni.push_back(Y);
        }
      	//cout<<Ni.at(5)<<endl;
        ll NiSize=Ni.size();
        vector<ll> KKofNi(NiSize);
        ll KK=K-2;
        for(ll i=NiSize-1;i --; i>=0){
            if(KK/Ni.at(i)>0){
                KKofNi.at(i)=1;
                KK -= Ni.at(i);
            }
            else{
                KKofNi.at(i)=0;
            }
        }
      	for(int i=0; i<NiSize; i++){//s
          	
          	//cout<<KKofNi.at(i)<<" ";
          	//cout<<Ni.at(i)<<" ";
        }
      	//cout<<endl;
      	//cout<<endl;//g
        ll MNRui=1;
        for(ll i=0; i<NiSize; i++){
            if(KKofNi.at(i)==1){
                ll H=MN;
                for(ll j=0; j<i; j++){
                    H=H*H;
                    H%=K;
                }
                MNRui*=H;
                MNRui%=K;
            }
        }
      //cout<<Kai.at(T)<<" "<<MNRui<<endl;
        ll Ans=Kai.at(T)*MNRui;
        Ans%=K;
        cout<<Ans<<endl;





        

    }
}
 

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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int n; cin >> n;
	vector<int> ans(n);

	for (int i = 0; i < n; i++) {
		int val; cin >> val;

		ans[val-1] = i + 1;
	}

	for (int i = 0; i < n; i++) {
		cout << ans[i];
		if (i == n - 1) {
			cout << endl;
		}
		else {
			cout << " ";
		}
	}

	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
  ll n,m;
  cin>>n>>m;
    char a[n][m];
    for(int i=0;i<n;i++)
    {
      for(int j=0;j<m;j++)
      {
        cin>>a[i][j];
      }
    }
    for(int i=0;i<n;i++)
    {
      ll count=0;
      for(int j=0;j<m;j++)
      {
        if(a[i][j]=='.')
          count++;

      }
      if(count==m){
      for(int j=0;j<m;j++)
        a[i][j]='*';
    }
    }

    /*for(int i=0;i<n;i++)
    {ll f=0;
      for(int j=0;j<m;j++)
      {
        if(a[i][j]=='*')
          {
            f=1;
          continue;
        }
        else
          cout<<a[i][j];
      }
      if(!f)
        cout<<endl;
    }*/

    for(int j=0;j<m;j++)
    {
      if(a[0][j]=='.'||a[0][j]=='*')
      {ll count=0;
        for(int k=0;k<n;k++)
        {
          if(a[k][j]=='.'||a[k][j]=='*')
          {
            count++;
          }

        }
        if(count==n)
        {
          for(int k=0;k<n;k++)
          {
            a[k][j]='*';
          }
        }
      }
    }
     for(int i=0;i<n;i++)
    {
        ll f=0;
      for(int j=0;j<m;j++)
      {
        if(a[i][j]=='.'||a[i][j]=='#')
        { f=1;
           cout<<a[i][j];
            }
      }
        if(f)
        cout<<endl;
      }
    
}
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define LL long long
#define PI 3.14159265359
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}




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

	while (N != 0) {
		vector<double> s(N);
		rep(i, N) cin >> s[i];

		double dist = 0;
		double avg = accumulate(s.begin(), s.end(), 0)/N;
		rep(i, N) dist += (s[i] - avg)*(s[i] - avg) / N;
		printf("%.8f\n", sqrt(dist));
		cin >> N;
	}
	return 0;
}



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

using namespace std;

const int MAX_N = 1e5 + 5;
const int MAX_L = 20;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;

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

string S;
int N;
int dp[MAX_N][13];

void solve() {
    cin >> S;
    N = S.size();
    S = "#" + S;
    dp[0][0] = 1;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < 13; j++) {
            if (S[i] == '?')
                for (int k = 0; k <= 9; k++)
                    (dp[i][(j * 10 + k) % 13] += dp[i - 1][j]) %= MOD;
            else
                (dp[i][(j * 10 + S[i] - '0') % 13] += dp[i - 1][j]) %= MOD;
        }
    }
    cout << dp[N][5];
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int tc; tc = 1;
    for (int t = 1; t <= tc; t++) {
        //cout << "Case #" << t  << ": ";
        solve();
    }
}


Measured memory_bytes: 5484
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;

void add(int &a, int b) {
    a += b;
    while (a >= MOD) 
        a -= MOD;
    while (a < 0)
        a += MOD;
}

char comp(int x, int y) {
    if (x < y)
        return '<';
    return '>';
}

int main() {
    int n; cin >> n;
    string s; cin >> s;
    
    vector<vector<int>> dp(n, vector<int> (n + 1, 0));
    vector<vector<int>> part(n, vector<int> (n + 1, 0));

    dp[0][1] = 1;
    part[0] = vector<int> (n + 1, 1);
    part[0][0] = 0;

    auto getSum = [&] (int lf, int rt, auto& part) {
        int ans = part[rt];
        if (lf - 1 >= 0)
            add(ans, -part[lf - 1]);
        return ans;
    };

    for (int i = 1; i < n; i += 1)
        for (int j = 1; j <= n; j += 1) {
            if (j <= i + 1) {
                if (s[i - 1] == '<')
                    dp[i][j] = getSum(1, j - 1, part[i - 1]);
                else
                    dp[i][j] = getSum(j, n, part[i - 1]);
            }
            part[i][j] = dp[i][j];
            add(part[i][j], part[i][j - 1]);
        }

    int ans = 0;
    for (int i = 1; i <= n; i += 1)
        add(ans, dp[n - 1][i]);

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

Measured memory_bytes: 70784
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int H,W,K;
  cin >> H >> W >> K;
  v(string) G(H);
  rep(i,H) {
    cin >> G[i];
  }
  int id = 0;
  int j = 0;
  vvi ans(H,vi(W,0));
  vi ids(W,-1);
  int e = 0;
  vi backup(W,INF);
  rep(i,H) {
    //show(id);
    
    vi c;
    rep(k,W) {
      if(G[i][k]=='#') {
        c.push_back(k);
      }
    }
    //show(sz(c));
    if(sz(c) == 0) {
      if(ids[0] == -1) {
        e++;
      } else {
        j = 0;
        while(j < W) {
          ans[i][j] = ids[j];
          j++;
        }
      }
      continue;
    }
    j = 0;
    id++;
    rep(x,sz(c)){
      while(j <= c[x]) {
        ans[i][j] = id;
        ids[j] = id;
        j++;
      }
      id++;
    }
    id--;
    //show(j);
    //show(id);
    while(j < W) {
      ans[i][j]= id;
      ids[j] = id;
      j++;
    }
    if(backup[0] == INF) {
      backup = ids;
    }
  }
  //show(e);
  if(e > 0) {
    rep(i,e) {
      rep(k,W) {
        ans[i][k] = backup[k];
      }
    }
  }
  rep(i,H) {
    rep(j,W) {
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
int main()
{
    int n;
    cin>>n;
    vector<int> a(n),b(n),c(n);
    for(int i= 0 ;i < n ; i++)
        cin>>a[i]>>b[i]>>c[i];
    vector<vector<int> > d(n,vector<int>(3,INT_MIN));
    d[0][0] = a[0],d[0][1] = b[0],d[0][2] = c[0];
    for(int i = 1 ; i < n ; i++)
    {
        d[i][0] = max(d[i - 1][1],d[i - 1][2]) + a[i];
        d[i][1] = max(d[i - 1][0],d[i - 1][2]) + b[i];
        d[i][2] = max(d[i - 1][1],d[i - 1][0]) + c[i];



    }
    cout<<*max_element(d[n - 1].begin(),d[n-1].end())<<endl;
    
}

Measured memory_bytes: 6912
#include <iostream>
int main(){
        std::string S;
        std::cin>>S;
        long long zero=0,one=0,length=S.length();
        for(int i=0; i<length; i++) {
                if(S[i]=='0') zero++;
                else one++;
        }
        std::cout<<2*std::min(zero,one);
        return 0;
}


Measured memory_bytes: 512
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		String w = sc.next();
		String last = w.substring(w.length() - 1, w.length());
		HashMap<String, String> wordList = new HashMap<String, String>();
		String ans = "Yes";
		wordList.put(w, w);

		for (int i = 1; i < n; i++) {
			w = sc.next();
			if (!last.equals(w.substring(0, 1)))
				ans = "No";
			if (wordList.containsKey(w))
				ans = "No";
			else
				wordList.put(w, w);
			last = w.substring(w.length() - 1, w.length());
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 21844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		int[] values = new int[N];
		for (int i = 0; i < N; i++) {
			values[i] = sc.nextInt();
		}
		int ans = 0;
		
		int i = 0;
		for (; i < N; i++) {
			int tot = 0, j;
			for (j = i; j < N && values[j] == values[i]; j++) {
				tot++;
			}
			ans += tot/2;
			i = j - 1;
		}
		
		out.println(ans);
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


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

int main() {
  string S;
  cin >> S;
  ll N = S.size() + 1;
  vector<ll> A;
  ll count = 1;
  
  for (ll i = 1; i < N-1; i++) {
    if (S[i-1] == '>' && S[i] == '<') {
      A.push_back(count);
      count = 1;
      continue;
    }
    if (S[i-1] == '<' && S[i] == '>') {
      A.push_back(count);
      count = 1;
      continue;
    }
    count += 1;
  }
  A.push_back(count);
  
  ll sum = 0;
  ll AS = A.size();
  for (ll i = 0; i < AS; i += 2) {
    if (S[0] == '<') {
      if (i == AS -1) {
        sum += A[i];
        continue;
      }
      sum += max(A[i], A[i+1]);
    }
    if (S[0] == '>') {
      if (i == 0) {
        sum += A[i];
        i--;
        continue;
      }
      if (i == AS -1) {
        sum += A[i];
        continue;
      }
      sum += max(A[i],A[i+1]);
    }
  }
  
  for (ll i = 0; i < AS; i++) {
    sum += ((A[i]-1) * A[i] / 2);
  }
  
  cout << sum << endl;
}

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

int main(){
//srandom((unsigned long)time(NULL));
string s;
cin>>s;
long long k;
cin>>k;
long long x;
for(long long i=0;i<s.size();i++){
    if(s[i]!='1'){
        if(k-1>=i){
        cout<<s[i]<<endl;
        return 0;
        }else{
            cout<<1<<endl;
            return 0;
        }
    }
}
cout<<1<<endl;

return 0;
}

Measured memory_bytes: 256
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"internationalization"# => r#"i18n"#,
r#"smiles"# => r#"s4s"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        s: chars,
    }

    format!("{}{}{}", s[0], s[1..s.len()-1].len(),s[s.len()-1]).to_string()
}

Measured memory_bytes: 4352
N,M = map(int, input().strip().split(' '))
AB = [list(map(int, input().strip().split(' '))) for _ in range(N)]
AB = sorted(AB, key=lambda x: x[0])
now_price = 0
remain_count = M
for a,b in AB:
  bay = min(remain_count, b)
  now_price += a*bay
  remain_count -= bay
print(now_price)

Measured memory_bytes: 29728
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int S,a,b;
  cin>>S;
  
  a=S/100;
  b=S%100;
  
  if(a>0&&a<=12){
    if(b>0&&b<=12){
      cout<<"AMBIGUOUS"<<endl;
    }
    else{
      cout<<"MMYY"<<endl;
    }
  }
  
  else if(b>0&&b<=12){
    cout<<"YYMM"<<endl;
  }
  else{
    cout<<"NA"<<endl;
  }
  
}

Measured memory_bytes: 256
function main(_stdin) {
    const stdin = _stdin.trim().split('');

    const points = [];
    const lakes = [];

    points.push({x:0, y:0, end: 0});
    for (let ref = 0, l = stdin.length; ref < l; ref++) {
        const r = points[ref];
        if (stdin[ref] === '\\') {
            points.push({x: r.x + 1, y: r.y - 1, end: 0});
        } else if (stdin[ref] === '/') {
            points.push({x: r.x + 1, y: r.y + 1, end: 1});
        } else {
            points.push({x: r.x + 1, y: r.y, end: 0});
        }
    }

    let l = points.length-1;
    while(l) {
        if (points[l].end === 1) {
            let i = l - 1;
            while(i > 0  && points[l].y !== points[i].y) {
                i--;
            }
            if (points[i].y === points[l].y) {
                lakes.push(points.slice(i, l + 1));
                l = i;
            } else {
                l--;
            }
        } else {
            l--;
        }
    }

    const vol = lakes.length;
    const areas = lakes.map(points => {
        const zeroDiff = 0 - points[0].y;
        let cnts = 0;
        for (let i = 1, l = points.length; i < l; i++) {
            const ref = points[i-1];
            const diff = Math.abs(points[i].y + zeroDiff);
            // 下がっている
            if (ref.y > points[i].y) {
                cnts += diff - 1 + 0.5;
            } else if (ref.y < points[i].y){
                cnts += diff + 0.5;
            } else {
                cnts += diff;
            }
        }
        return cnts;
    });


    const total = areas.length ? areas.reduce((a, b) => a+b) : 0;
    console.log(total);
    areas.push(vol);
    console.log(areas.reverse().join(' '));
}


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




Measured memory_bytes: 19856
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  string s;
  cin>>s;
  s='x'+s;
  int N=s.size();
  vector<vector<int>> dp(N+1,vector<int>(5));
  for(int i=1;i<N;i++){
    for(int j=1;j<5;j++){
      for(int k=1;k<5;k++){
        if(i-j<0||i+k>N){continue;}
        if(s.substr(i-j,j)!=s.substr(i,k)){
          chmax(dp[i+k][k],dp[i][j]+1);
        }
      }
    }
  }
  cout<<*max_element(dp[N].begin(),dp[N].end())<<endl;
  return 0;
}

Measured memory_bytes: 14236
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False


def main():
    R, G, B, N = map(float, input().split())
    cnt = 0

    for r in range(0, 3000 // int(R) + 1):
        for g in range(0, 3000 // int(G) + 1):
            b = (N - R * r - G * g) / B
            # print(b)
            if b >= 0 and is_integer_num(b):
                # print(r, g, b)
                cnt += 1

    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 41580
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pi,int>
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
bool pr(int x)
{
    if(x<2)
        return 0;
    for(int i=2;i*i<=x;i++)
        if(x%i==0)
        return 0;
    return 1;
}
int main()
{
    go;
    int x;
    cin>>x;
    for(int u=x;;u++)
    {
        if(pr(u))
            return cout<<u,0;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>

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

    long long int n;

    while (std::cin >> n, n) {
        std::array<long long int, 7> arr{{}};
        int age;
        for (; n--;) {
            std::cin >> age;
            age = (age < 70 ? age : 60);
            ++arr[age / 10];
        }

        for (const auto& cnt : arr) {
            std::cout << cnt << std::endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long A, B, C;
	cin >> A >> B >> C;
	if (A >= C)
	{
		cout << A - C <<endl<< B;
	}
	else if (A + B >= C) {
		cout << 0 << endl << B + A - C;
	}
	else
	{
		cout << 0<<endl << 0;
	}
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) x*=i;
    return x;
}

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

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



int main(){
    ll n,sum=0;
    cin>>n;
    rrep(i,n-1) sum+=i;
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int n,s[10],t;

int main()
{
	while(scanf("%d",&n),n)
	{
		rep(i,10)s[i]=0;
		rep(i,n)scanf("%d",&t),s[t]++;
		rep(i,10)
		{
			if(s[i]==0)putchar('-');
			rep(j,s[i]+1)putchar(j==s[i]?'\n':'*');
		}
	}
	return 0;
}

Measured memory_bytes: 0
import sys
from fractions import gcd
n, x, d = map(int, input().split())
if x == d == 0:
	print(1);sys.exit()
elif d == 0:
	print(n+1);sys.exit()
if x < 0 and x + (n-1) * d < 0:
	x, d = -x, -d
if x >= 0 and d < 0:
	x, d = x + (n-1) * d, -d
g = gcd(x, d);ans = 1
if x >= 0:
	for i in range(1, n+1):
		k = max((i- d//g) *(2*n -1 -i +d//g)//2 -x//g, i *(i-1) //2 -1)
		ans += max((i * (2*n-1-i)) //2 -k, 0)
else:
	for i in range(1, n+1):
		overlap_u = min((i -d//g) *(2*n -1 -i +d//g) //2 -x//g, i *(2*n-1-i) //2)
		overlap_l = max((i -d//g) *(i -d//g -1) //2 -x//g, i *(i-1) //2)
		ans += i *(2*n-1-i) //2 -i *(i-1) //2 +1 -max(overlap_u -overlap_l+1, 0)
print(ans)

Measured memory_bytes: 67048
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A,B,C;
  vector<int>vec(3);
  for(int i=0;i<3;i++) cin>>vec.at(i);
  sort(vec.begin(),vec.end());
  A=vec.at(0);
  B=vec.at(1);
  C=vec.at(2);
  if(A/B==1&&B/C==1)cout<<1;
  else if(A/B==1&&B/C!=1)cout<<2;
  else if(A/B!=1&&B/C==1)cout<<2;
  else cout<<3;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Data.Char (ord, isDigit)
import Data.Bits
import Data.Int
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B

skipReadInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
skipReadInt b
  | B.null b
  = Nothing
  | otherwise
  = let b'  = B.dropWhile (\c -> c /= '-' && not (isDigit c)) b
        neg = B.head b' == '-'
        b'' = if neg then B.tail b' else b'
    in  Just $ first (fromIntegral . (if neg then ((-1) *) else id)) $ go b'' 0
 where
  go b acc
    | B.null b = (acc, b)
    | isDigit (B.head b) = go
      (B.tail b)
      (shiftL acc 1 + shiftL acc 3 + ord (B.head b) - ord '0')
    | otherwise = (acc, b)

solve :: Int -> VU.Vector Int16 -> Int32
solve n hs = fst dp
 where
  -- dp[i]: minimal cost of moving from 1st to i-th place
  dp :: (Int32, Int32)
  dp = VU.foldl'
    (\(!dp1, !dp2) (!i, !v) -> if i == 0
      then (0, dp1)
      else if i == 1
        then (dp1 + abs (fromIntegral $ v - hs VU.! 0), dp1)
        else
          ( min (dp1 + abs (fromIntegral $ v - hs VU.! (i - 1)))
                (dp2 + abs (fromIntegral $ v - hs VU.! (i - 2)))
          , dp1
          )
    )
    (-1, -1)
    (VU.indexed hs)

main = do
  n  <- (\vec -> (vec VU.! 0)) . VU.unfoldrN 1 skipReadInt <$> B.getLine
  hs <- VU.unfoldrN n skipReadInt <$> B.getLine
  print $ solve n hs


Measured memory_bytes: 1916
h,w=map(int,input().split())
S=[]
for _ in range(h):
    s=list(map(str,input()))
    S.append(s)
def check(x,y):
    if S[x][y]=='#':
        return 1
    else:
        return 0
for i in range(h):
    for j in range(w):
        if S[i][j]=='.':
            count=0
            for ii in range(i-1,i+2):
                for jj in range(j-1,j+2):
                    if ii>=0 and jj>=0 and ii<=h-1 and jj<=w-1:
                        if ii!=i or jj!=j:
                            count+=check(ii,jj)
            S[i][j]=count


for i in range(h):
    for j in range(w):
        print(S[i][j],end='')
    print()

Measured memory_bytes: 47852
#include<stdio.h>
#include<utility>
#include<algorithm>

using namespace std;

int A[500001];
int n;

void maxHeapify(int A[], int i){
    int l = 2 * i;
    int r = 2 * i + 1;

    int largest;
    if(l <= n && A[l] > A[i]){
        largest = l;
    }
    else{
        largest = i;
    }
    if(r <= n && A[r] > A[largest]){
        largest = r;
    }

    if(largest != i){
        swap(A[i], A[largest]);
        maxHeapify(A, largest);
    }
}

void buildMaxHeap(int A[]){
    for(int i = n / 2; i >= 1; i--){
        maxHeapify(A, i);
    }
}

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

    for(int i = 1; i <= n; i++){
        scanf("%d", &A[i]);
    }

    buildMaxHeap(A);

    for(int i = 1; i <= n; i++){
        printf(" %d", A[i]);
    }
    printf("\n");
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    string s;
    cin >> s;

    constexpr int64_t M = 'z' - 'a' + 1;

    unordered_map<int64_t, int64_t> m;
    m[0] = 0;
    bitset<M> bs;
    for (auto c : s) {
        auto i = c - 'a';
        bs.flip(i);

        if (!m.count(bs.to_ulong())) {
            m[bs.to_ulong()] = numeric_limits<int64_t>::max();
        }
        auto bs2 = bs;
        for (auto j : irange(0L, M)) {
            bs2.flip(j);
            if (m.count(bs2.to_ulong())) {
                m[bs.to_ulong()] = min(m[bs.to_ulong()], m[bs2.to_ulong()] + 1);
            }
            bs2.flip(j);
        }

        // cerr << bs << ":" << m[bs.to_ulong()] << endl;
    }

    if (bs.none()) {
        cout << 1 << endl;
    } else {
        cout << m[bs.to_ulong()] << endl;
    }
}

Measured memory_bytes: 8652
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<long long> A(N);
	for (auto i = 0; i < N; ++i)
	{
		cin >> A[i];
	}

	vector<long long> list;
	list.push_back(A[0]);
	for (auto i = 1; i < N; ++i)
	{
		auto temp = A[i];
		auto low = 0;
		auto high = (int)list.size() - 1;
		while (high >= low)
		{
			auto mid = (high + low) / 2;
			if (list[mid] < temp)
			{
				high = mid - 1;
			}
			else
			{
				low = mid + 1;
			}
		}
		if (low >= list.size())
		{
			list.push_back(temp);
		}
		else
		{
			list[low] = temp;
		}
	}

	cout << list.size() << endl;

	return 0;
}

Measured memory_bytes: 2168
#include <iostream>
#include <iomanip>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

int check_ind(int n, int w) {
	for (int i = (100/w)+1; i > 0; i--) {
		if ( !(n < i*w) ) {
				return i;
		}
	}
	return 0;
}

int main(void) {
	int n,w;
	cin >> n >> w;

	while ( n != 0 || w != 0 ) {
		std::vector<int> data( (100/w)+1, 0 );
		int l = data.size();
		int temp,ind;
		for (int i = 0; i < n; i++) {
			cin >> temp;
			ind = check_ind(temp, w);
			data[ind]++;
		}

		int max = 0;
		int valc = 0;
		for (int i = 0; i < l; i++) {
			if ( data[i] > max ) {
				max = data[i];
			}
			if ( data[i] > 0 ) {
				valc = i;
			}
		}

		double ink = 0.01;
		for (int i = 0; i < l-1; i++) {
			if (data[i] > 0) {
				ink += (double)data[i]/max * (double)(valc-i)/(valc); 
			}
		}

		cout << std::setprecision(12) << ink << endl;
		cin >> n >> w;
	}

	return 0;
}

Measured memory_bytes: 3208
S = input()
last = len(S)-1
result = 1
for i in range(len(S)-1):
    if last%2 > 0:
  	    last -= 1
    else:
        half =int(last/2)
        if S[0:half-1] == S[half:last-1]:
            result = last
            break
        else:
            last -= 2
print(result)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

const double PI = acos(-1);

int main() {
    int a, b, h, m;
    cin >> a >> b >> h >> m;

    double angh = 60 * h + m, angm = m;
    angh /= 12*60;
    angm /= 60;
    angh *= PI * 2;
    angm *= 2 * PI;

    double theta = abs(angh - angm);

    double res = a * a + b * b - 2 * a * b * cos(theta);
    res = sqrt(res);
    cout << fixed << setprecision(15) << res << endl;
    return 0;
}

Measured memory_bytes: 4256
n, m = map(int, input().split())
C = [1]*n
P = [0]*n
P[0] = 1

for i in range(m):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    if P[x] != 0:
        if C[x] == 1:
            P[x] = 0
            C[x] -= 1
            P[y] = 1
            C[y] += 1
        else:
            C[x] -= 1
            P[y] = 1
            C[y] += 1
    else:
        C[x] -= 1
        C[y] += 1
    #print(i)
    #print(P)
    #print(C)
print(sum(P))


Measured memory_bytes: 76020
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

a = int(arr_data[0][0])
b = int(arr_data[0][1])

#print(a,b)

if a>=1:
    
    print("Positive")
    
elif a<=0 and 0<=b:
    
    print("Zero")
    
else:
    
    if abs(a-b) % 2==0:
        
        print("Negative")
        
    else:
        print("Positive")
    


Measured memory_bytes: 3064
import math
import sys
def input():
    return sys.stdin.readline().rstrip('\n')

def calc(A, B, H, M):
    a = abs((H * 60 + M) / 720 - M / 60) * 2
    if a > 1:
        a = 2 - a
    return math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(a * math.pi))

    

(A, B, H, M) = tuple([int(s) for s in input().split()])
print(calc(A, B, H, M))

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

int main()
{
  	int k;
  int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cin >> k;
  cout << a[k-1] << endl;
	return 0;
}

Measured memory_bytes: 256
#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++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }



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

  int n;
  cin >> n;
  vi l(n);
  int s = sz(l);
  rep(i,n) cin >> l[i];
  sort(all(l));
  ll ans = 0;
  for(int i = 0; i < s-2; i++) {
    for(int j = i+1; j < s-1; j++) {
      auto it = lower_bound(all(l), l[i]+l[j]);
      it--;
      if(l.begin() + j < it) ans += it - (l.begin() + j);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256