akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct node{
    int key;
    struct node *parent,*left,*right;
}node;
#define N 500000

int m;
node t[N],*NIL,*root;

void insert(node *t,node *z){
    node *y=NIL;
    node *x=root;
    while(x!=NIL){
        y=x;
        if(z->key<x->key)x=x->left;
        else x=x->right;
        z->parent=y;
    }
    if(y==NIL)root=z;
    else if(z->key<y->key)y->left=z;
    else y->right=z;

}

void inparse(node *u){
  if(u==NIL)return;
  inparse(u->left);
  printf(" %d",u->key);
  inparse(u->right);
}

void preparse(node *u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preparse(u->left);
  preparse(u->right);
}

node* find(int k){
    node *x=root;
    while(x!=NIL&&k!=x->key){
        if(k<x->key)x=x->left;
        else x=x->right;
    }
    return x;
}

int main(){
    int i,n;
    char str[6];
    node *z,*a;

    scanf("%d",&m);
    for(i=0;i<m;i++){
        scanf("%s",str);
        if(strcmp(str,"insert")==0){
        
            scanf("%d",&n);
            
            z=(node*)malloc(sizeof(node));
            z->key=n;
            
            z->left=NIL;
            z->right=NIL;
            insert(t,z);
        }
        else if(strcmp(str,"print")==0){
            inparse(root); 
            printf("\n"); 
            preparse(root);
            printf("\n");  
        }
        else if(strcmp(str,"find")==0){
            scanf("%d",&n);
            a=find(n);
            if(a==NIL)printf("no\n");
            else printf("yes\n");
        }
    }
    return 0;
}



Measured memory_bytes: 20472
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define INT_MAX 2147483647
#define LLINT_MAX 9223372036854775807
#define mod 1000000007
#define ll long long int
using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.rbegin(), t.rend());
	if (s.compare(t) < 0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define int long long
const int inf = 100100100100100;
const int mod = 1000000007;

const int maxn = 15;
int n, m;
int dist[maxn][maxn];
int dp[1<<maxn][maxn];

int dfs(int s, int v){

    if(dp[s][v] >= 0){
        return dp[s][v];
    }

    if(s == (1<<n)-1 && v == 0){
        return dp[s][v] = 0;
    }

    int ans = inf;
    rep(u,0,n){
        if(!(s >> u & 1)){
            ans = min(ans, dfs(s | 1 << u, u) + dist[v][u]);
        }
    }

    dp[s][v] = ans;
    return ans;


}

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

    
    cin >> n >> m;

    memset(dp,-1,sizeof(dp));
    fill(dist[0],dist[0]+maxn*maxn,inf);

    

    
    rep(i,0,m){
        int f, t, c;
        cin >> f >> t >> c;
        dist[f][t] = c;
    }
    int ans = dfs(0,0);
    cout << (ans == inf ? -1 : ans) << endl;

}


Measured memory_bytes: 7008
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#define ll long long
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
using namespace std;
int main() {
  ll a,b;
  cin >> a >> b;
  b++;
  ll ai[40],bi[40];
  ll t = 1;
  ll ans = 0;
  ll mn = 0;
  REP(i,40){
    ai[i] = max(mn,a%(t*2)-t) + a/(t*2)*t;
    bi[i] = max(mn,b%(t*2)-t) + b/(t*2)*t;
    if((bi[i]-ai[i])%2==1) ans += t;
    t *= 2;
  }
  //REP(i,40){
  //  cout << ai[i] << ",";
  //}
  //cout << endl;
  //REP(i,40){
  //  cout << bi[i] << ",";
  //}
  //cout << endl;
  cout << ans << endl;
  
  return 0;
}


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

int main() {
	int n;
	cin >> n;
	vector<int> cnt(n + 1);
	for (int x = 1; x*x <= n; x++) for (int y = 1; y*y <= n; y++) for (int z = 1; z*z <= n; z++) {
		int t = x * x + y * y + z * z + x * y + y * z + z * x;
		if (t <= n) cnt[t]++;
	}
	REP(i, 1, n) {
		cout << cnt[i] << endl;
	}
}

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

int main()
{
    long long n;
    cin >> n;
    int city[n+1];
    int MAX[n];
    for(int i=0; i<=n; i++)
        cin >> city[i];
    for(int i=0; i<n; i++)
        cin >> MAX[i];
    long long ans = 0;
    for(int i=0; i<n; i++)
    {
        long long ex=0;
        if(MAX[i]>=city[i])
        {
            ans+= city[i];
            ex = MAX[i] - city[i];
        }
        else if(MAX[i]<city[i])
        {
            ans+=MAX[i];
        }
        if(ex)
        {
            if(ex>=city[i+1])
            {
                ans+= city[i+1];
                city[i+1] -= city[i+1];
            }
            else if(ex<city[i+1])
            {
                ans+=ex;
                city[i+1] -= ex;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
//This code was made by Chinese_zjc_
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#define int long long
#define INF 0x3fffffffffffffff
using namespace std;
inline int rd(int &ddd)
{
	char tmp=getchar();
	int xxx=1;
	ddd=0;
	while(('0'>tmp||tmp>'9')&&tmp!='-'&&tmp!=EOF)
	{
		tmp=getchar();
	}
	if(tmp==EOF)
	{
		return EOF;
	}
	if(tmp=='-')
	{
		xxx=-1;
		tmp=getchar();
	}
	while('0'<=tmp&&tmp<='9')
	{
		ddd=(ddd<<3)+(ddd<<1)+(tmp^48);
		tmp=getchar();
	}
	return ddd*=xxx;
}
inline char rd(char &ddd)
{
	char tmp=getchar();
	while(tmp==' '||tmp=='\n')
	{
		tmp=getchar();
	}
	if(tmp==EOF)
	{
		return EOF;
	}
	return ddd=tmp;
}
inline int max(const int &A,const int &B)
{
	return A<B?B:A;
}
inline int min(const int &A,const int &B)
{
	return A<B?A:B;
}
int n,ans;
signed main()
{
	rd(n);
	if(n<10)
	{
		printf("%lld",n);
		return 0;
	}
	else
	{
		if(n<100)
		{
			printf("9");
			return 0;
		}
		else
		{
			if(n<1000)
			{
				printf("%lld",n-90);
				return 0;
			}
			else
			{
				if(n<10000)
				{
					printf("909");
					return 0;
				}
				else
				{
					if(n<100000)
					{
						printf("%lld",n-9090);
						return 0;
					}
					else
					{
						printf("%lld",90909);
						return 0;
					}
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
const int N = 1e6 + 5;

ll a[N];
ll b[N];

int main(){
  ll n;
  cin >> n;
  rep(i,n+1){
    cin >> a[i];
  }
  rep(i,n){
    cin >> b[i];
  }
  ll ans = 0;
  rep(i,n){
    ans += min(a[i],b[i]);
    b[i] -= min(a[i],b[i]);
    ans += min(a[i+1],b[i]);
    a[i+1] -= min(a[i+1],b[i]);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct UnionFind {
    UnionFind(int n) {
        rank.assign(n, 0);
        parent.resize(n);
        for (int i = 0; i < n; ++i) {
            parent[i] = i;
        }
    }

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

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

    void unit(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)
            return;

        if (rank[x] < rank[y]) {
            parent[x] = y;
        }
        else {
            parent[y] = x;
            if (rank[x] == rank[y])
                rank[x]++;
        }
    }

    vector<int> rank;
    vector<int> parent;
};

pll A[200005];
ll B[200005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    UnionFind uf(N);
    REP(i, M) {
        cin >> A[i].first >> A[i].second;
        uf.unit(A[i].first - 1, A[i].second - 1);
    }
    memset(B, sizeof(B), 0);
    REP(i, N) {
        B[uf.find(i)]++;
    }

    ll ans = 0;
    REP(i, N) {
        ans = std::max(ans, B[i]);
    }
    cout << ans << endl;

    return 0;
}

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

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

vector<int> v[8];
int n,m;

int ma(int now,int d){
    if(d==((1<<n)-1)){
        return 1;
    }
    int ans=0;
    for(auto itr:v[now]){
        if(d&(1<<itr)){
        }else{
            ans+=ma(itr,d|(1<<itr));
        }
    }
    return ans;
}

int main(){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    cout<<ma(0,1)<<endl;

    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vi vector <ll> 
#define qu queue <ll>
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl;
*/
ll a[200010];

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


void solve()
{
    ll n; cin >> n;
    ll k;
    for (ll i = 0; i < n-1; i++)
    {
        cin >> k; a[k]++;
    }
    for (ll i = 1; i <= n; i++) nout(a[i]);
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 5212
/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

clock_t time_p=clock();
void aryanc403()
{
#ifdef ARYANC403
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/priank/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s;
    vector<vi> e;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

void prt(bool fl=true)
{
    cout<<(fl?"First":"Second")<<endl;
    exit(0);
}

lli dfs(lli u,lli p)
{
    lli cnt=0;
    for(auto x:e[u])
    {
        if(x==p)
            continue;
        cnt+=dfs(x,u);
    }
    if(cnt>1)
        prt();
    return 1-cnt;
}

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>n;
    e.resize(n+1,vi());

    fo(i,n-1)
    {
        cin>>u>>v;
        e[u].pb(v);
        e[v].pb(u);
    }

    prt(dfs(i,-1));

}   aryanc403();
    return 0;
}


Measured memory_bytes: 6400
#[allow(unused_imports)]
use std::collections::HashSet;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let nl = read_vec::<i32>();
    let n = nl[0];
    let l = nl[1];

    let answer = solve(n, l);
    println!("{}", answer);
}

fn solve(n: i32, l : i32) -> i32 {
    let total = (l + l + n - 1) * n / 2;
    if l > 0 {
        return total - l;
    }
    if l + n - 1 >= 0 {
        return total;
    }
    return total - (l + n - 1);
}


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

struct UnionFindTree {
    vector<int> par;
    UnionFindTree(int n) : par(n) { // 全部根として初期化
        rep(i, n) par[i] = i;
    }
    int root(int x) { // 根を再帰的に探索
        if ( par[x] == x ) return x;
        else return par[x] = root(par[x]);
    }
    void unite(int x, int y) { // 異なる根の木を統合
        int rx = root(x);
        int ry = root(y);
        if ( rx != ry ) par[rx] = root(ry); // 根が異なる場合のみ統合
    }
    bool same(int x, int y) { // xとyが同じ根に属する場合はtrue, 属さない場合はfalse
        return (root(x) == root(y));
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> p(n);
    rep(i, n) {
        cin >> p[i];
        --p[i];
    }
    UnionFindTree uf_tree(n);
    rep(i, m) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        uf_tree.unite(x, y);
    }
    int ans = 0;
    rep(i, n) if ( uf_tree.same(i, p[i]) ) ++ans;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
    a.append(str(input()))
for i in range(m):
    b.append(str(input()))  

for p in range(n-m+1):
    for q in range(n-m+1):
        ans=0
        for i in range(m):

            row = str(a[q+i])
            cut = str(row[p:p+m])

            if cut == b[i]:
                ans += 1
                
            # print(row,cut,b[i],ans)

        if ans == m:
            print('Yes')
            exit()

print('No')

        


Measured memory_bytes: 3064
/*
    ASEEN AAN 
            PINDAN AALE JATT!!!
                                */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
//#include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
lli M=1000000007;   
lli INF=1e17;
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcount(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctz(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clz(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffs(n)//index of first one bit!!
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ost;
lli n,q,z,x,y,k,m;
const double pi1=3.14159265358979323846;
//unordered_map<pair<ll,lli>,lli> mp;
lli me(lli a,lli b,lli M)
{
    if(b==0)
    return 1;
    else if(b%2==0)
    return me((a*a)%M,b/2,M);
    else
    return (a%M*me((a*a)%M,(b-1)/2,M)%M)%M;
}
lli mI(lli a,lli m)
{
    return me(a,m-2,m);
}
//lli tot=0;
vector<lli> pf(string s) {
    int n = (int)s.length();
    vector<lli> pi(n);
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        while (j > 0 && s[i] != s[j])
            j = pi[j-1];
        if (s[i] == s[j])
            j++;
        pi[i] = j;
    }
    return pi;
}
//map<ll,lli> dp;
//set<lli> s[100005];
int main()
{
    ios_base::sync_with_stdio(0);
    cin>>n>>k;
    lli d=n-k+1;
    d=n-k;
    if(k==1)
    cout<<0;
    else
    cout<<d;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

int main() {
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<long long> A(X), B(Y), C(Z);

    rep(i, X) cin >> A[i];
    rep(i, Y) cin >> B[i];
    rep(i, Z) cin >> C[i];

    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    sort(B.begin(), B.end());
    reverse(B.begin(), B.end());
    sort(C.begin(), C.end());
    reverse(C.begin(), C.end());

    priority_queue<pair<ll, tuple<int, int, int>>> q;
    q.push(make_pair(A[0] + B[0] + C[0], make_tuple(0, 0, 0)));
    set<int> s;
    s.insert(0);

    vector<ll> ans;
    while (ans.size() < K) {
        auto v = q.top();
        q.pop();
        ans.push_back(v.first);

        rep(i, 3) {
            int a = get<0>(v.second);
            int b = get<1>(v.second);
            int c = get<2>(v.second);

            if (i == 0) a++;
            if (i == 1) b++;
            if (i == 2) c++;

            if (a != X && b != Y && c != Z) {
                int hash = (a << 20) + (b << 10) + c;
                if (s.find(hash) == s.end()) {
                    s.insert(hash);
                    q.push(make_pair(A[a] + B[b] + C[c], make_tuple(a, b, c)));
                }
            }
        }
    }

    rep(i, K) cout << ans[i] << endl;
}

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

int main(){
  int N; cin >>N;
  long long sum,sumsq;
  sum = 0; sumsq = 0;
  for(int i=0;i<N;i++){
    int x; cin >>x;
    sum += x;
    sumsq += x*x;
  }
  cout << (sum*sum - sumsq)/2 << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
const int maxn=185+3;
int n,m;
int c[maxn][maxn];
int L[maxn][maxn];
int U[maxn][maxn];
int fl[maxn][maxn][maxn];
int fu[maxn][maxn][maxn];
int gl[maxn][maxn][maxn];
int gu[maxn][maxn][maxn];
char ch;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j){
			scanf(" %c",&ch),c[i][j]=(ch=='#');
			L[i][j]=(j==1 ? 1 : (c[i][j-1]==c[i][j] ? L[i][j-1]+1 : 1));
			U[i][j]=(i==1 ? 1 : (c[i-1][j]==c[i][j] ? U[i-1][j]+1 : 1));
		}
	for(int x=1;x<=n;++x)
		for(int y=1;y<=m;++y){
			for(int xx=x,Min=666;xx<=n;++xx){
				if(xx>x && c[xx][y]!=c[xx-1][y])Min=0;
				fl[x][y][xx]=Min=std::min(Min,L[xx][y]);
			}
			for(int yy=y,Min=666;yy<=m;++yy){
				if(yy>y && c[x][yy]!=c[x][yy-1])Min=0;
				fu[x][y][yy]=Min=std::min(Min,U[x][yy]);
			}
		}
	for(int ans=0;"Jumbo tql";++ans){
		if(fl[1][m][n]==m || fu[n][1][m]==n)
			return printf("%d\n",ans),0;
		memcpy(gl,fl,sizeof(gl));
		memcpy(gu,fu,sizeof(gu));
		for(int x=1;x<=n;++x)
			for(int y=1;y<=m;++y){
				for(int xx=x;xx<=n;++xx)fl[x][y][xx]+=gl[x][y-gl[x][y][xx]][xx];
				for(int yy=y;yy<=m;++yy)fu[x][y][yy]+=gu[x-gu[x][y][yy]][y][yy];
			}
		for(int x=1;x<=n;++x)
			for(int y=1;y<=m;++y){
				for(int xx=x,X=1;xx<=n;++xx,++X)
					for(int yy=y-fl[x][y][xx]+1;yy<=y && fu[xx][yy][y]<X;++yy)
						fu[xx][yy][y]=X;
				for(int yy=y,Y=1;yy<=m;++yy,++Y)
					for(int xx=x-fu[x][y][yy]+1;xx<=x && fl[xx][yy][x]<Y;++xx)
						fl[xx][yy][x]=Y;
			}
	}return 0;
}


Measured memory_bytes: 104192
n,p=map(int,input().split())
if n==1:
    print(p)
    exit()
elif p==1:
    print(1)
    exit()
elif n>60:
    print(1)
    exit()
l=[]#Pの約数
for i in range(1,int(p**0.5)+1):
    if p%i==0:
        l.append(i)
#print(l)
s=[]
for i in range(len(l)):
    if l[i]**n<=p and p%(l[i]**n)==0:
        #print(l[i],l[i]**n)
        s.append(l[i])
    if l[i]**n>p:
        break
print(s[-1])

Measured memory_bytes: 9452
#include <stdio.h>
#include<string.h> //strcmp???strncmp??¢??°????????????????????????

int main(void){
    char str[1000],str1[1000];
    char ord[10];
    char print[] = "print";
    char reverse[] = "reverse";
    char replace[] = "replace";
    int n,i;
    //??????????????????scan
    scanf("%s\n",str);
    //???????????°???scan
    scanf("%d",&n);
    for(i=0;i<n;i++){
        int a,b,t,k;
        //???????????????
        scanf("%s ",ord);
        scanf("%d %d",&a,&b);
        //a~b???print
        if(strcmp(ord,print)==0){
           for(t=a;t<=b;t++){
               printf("%c",str[t]);
           }
           printf("\n");
        }
        //a~b???reverse
        else if(strcmp(ord,reverse)==0){
            k = b;
            for(t=a;t<=b;t++){
                str1[t]=str[k];
                k--;
            }
            for(t=a;t<=b;t++){
                str[t]=str1[t];
            }
        }
        //a~b???p???replace
        else if(strcmp(ord,replace)==0){
            char p[b-a+1];
            scanf("%s\n",p);
            k=0;
            for(t=a;t<=b;t++){
                str[t]=p[k];
                k++;
            }
        }
    }
    return 0; /*0?????????*/
}

Measured memory_bytes: 1816
class UnionFind:
    def __init__(self,size):
        self.par = [i for i in range(size)]
        self.rank = [0 for _ in range(size)]
        
    def find(self,x):
        if self.par[x]==x:
            return x
        else:
            self.par[x]=self.find(self.par[x])
            return self.par[x]
    
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x]>self.rank[y]:
            self.par[y]=x
        else:
            self.par[x]=y
            if self.rank[x]==self.rank[y]:
                self.rank[y]+=1
    
    def same(self,x,y):
        x = self.find(x)
        y = self.find(y)
        return x==y
    
n,m = map(int,input().split())
tree = UnionFind(n)
for i in range(m):
    x,y,z = map(int,input().split())
    x -= 1
    y -= 1
    tree.union(x,y)

tmp = [tree.find(i) for i in range(n)]
print(len(set(tmp)))

Measured memory_bytes: 17952
#include<bits/stdc++.h>
using namespace std;
#define nl '\n' 
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pii pair <int,int>
ll mod=1000000007;
int dp[1001][1001];
int main()
{
	int n;cin>>n;
	int a[n],b[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i];
	}
	int f=0;
	for(int i=0;i<n-2;i++)
	{
		if(a[i]==b[i]&& a[i+1]==b[i+1]&& a[i+2]==b[i+2]){
			f=1;
			break;
		}
	}
	if(f)
		cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;
//int dy[] = {0, 0, -1, 1};
//int dx[] = {1, -1, 0, 0};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string a, b, c; cin >> a >> b >> c;
    if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) {
        cout << "YES" << endl;
    } else cout << "NO" << endl;
    
}


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

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


Measured memory_bytes: 3632
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    auto XS = readln.split.to!(long[]);
    if (M-N <= 0) {
        writeln(0);
        return;
    }
    sort(XS);
    long[] ds;
    foreach (i; 0..M-1) ds ~= XS[i+1] - XS[i];
    sort(ds);
    writeln(reduce!"a + b"(0L, ds[0..M-N]));
}

Measured memory_bytes: 4332
n = int(input())
h = list(map(int, input().split(' ')))

dp = [0]*n

for i in range(1,n):
    if i>=2:
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
    else:
        dp[i] = abs(h[1]-h[0])
print(dp[-1])

Measured memory_bytes: 20476
#include <iostream>
#include <vector>
using namespace std;
int main(){
	int n,x;	cin>>n>>x;
	if(x==1||x==2*n-1){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	vector<int> ret(2*n-1,x);
	int left=1,right=x+1;
	int pos=0;
	while(left<x&&right<2*n){
		ret[n+2*pos]=right++;
		ret[n-2-2*pos]=left++;
		if(left==x||right==2*n)	break;
		ret[n+2*pos+1]=left++;
		ret[n-3-2*pos]=right++;
		pos++;
	}
	if(left==x){
		for(int i=0;i<2*n-1;i++){
			if(i==n-1)	continue;
			if(ret[i]==x)	ret[i]=right++;
		}
	}
	else{
		for(int i=0;i<2*n-1;i++){
			if(i==n-1)	continue;
			if(ret[i]==x)	ret[i]=left++;
		}
	}
	for(int i=0;i<2*n-1;i++){
		cout<<ret[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 2304
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    a,b=map(int, input().split())
    if a>0:
        print('Positive')
    elif a<=0 and b>=0:
        print('Zero')
    elif b<0 and (b-a)%2==0:
        print('Negative')
    else:
        print('Positive')
resolve()

Measured memory_bytes: 3060
#include <iostream>
#include <string>

using namespace std;

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

    int red = 0;
    int blue = 0;

    for(int i = 0; i < N; i++){
        if(str[i] == 'R'){
            red++;
        }else{
            blue++;
        }
    }
    if(red > blue){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    //cout << red << endl;
    //cout << blue << endl;
}

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

int main()
{
    string s;
    int argmnt[100000];

    cin >> s;


    for (int i = 0; i < s.length(); i++) argmnt[i] = 1;

    for (int i = 0; i < s.length()-1; i++)
    {
        if (s[i] == 'R' && s[i+1] == 'R')
        {
            argmnt[i+2] += argmnt[i];
            argmnt[i] = 0;
        }
    }

    for (int i = s.length() - 1; i > 0; i--)
    {
        if (s[i] == 'L' && s[i - 1] == 'L')
        {
            argmnt[i - 2] += argmnt[i];
            argmnt[i] = 0;
        }
    }

    for (int i = 0; i < s.length(); i++) cout << argmnt[i] << " ";

    cout << endl;

    return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys
import numpy as np


def solve(N: int, S: str):
    ans = []
    for c in list(S):
        o = ord(c)+N
        o -= 26 if o>90 else 0
        ans.append(chr(o))

    print("".join(ans))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 12628
#include <bits/stdc++.h>
using namespace std;
static const int INF = 0x3f3f3f3f; 
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }

class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
        string s;
        in >> s;
        int ans = INF;
        int len = s.size();
        vector<char> chr;
        for (char c = 'a'; c <= 'z'; c++) {
            string t = "", u = s;
            for (int i = 0; i < len; i++)
            {
                int cnt = 0;
                for (int j = 0; j < u.size(); j++)
                {
                    if (u[j] == c) cnt++;
                }
                if (cnt == u.size())
                {
                    amin(ans, i);
                    break;
                }

                for (int j = 1; j < u.size(); j++)
                {
                    t += (u[j] == c || u[j - 1] == c ? c : u[j]);
                }
                u = t;
                t = "";
            }
        }
        out << ans << endl;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}

#include <fstream>
#include <iostream>

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long llong;
#define MAX 600000
#define INFTY 2000000000

int merge(vector<int>& vec, int left, int mid, int right)
{
    int n1 = mid - left;
    int n2 = right - mid;
    vector<int> vec_L;
    vector<int> vec_R;
    vec_L.reserve(n1 + 1);
    vec_R.reserve(n2 + 1);

    for (int i = 0; i < n1; i++)
    {
        vec_L[i] = vec[left + i];
    }
    for (int i = 0; i < n2; i++)
    {
        vec_R[i] = vec[mid + i];
    }
    vec_L[n1] = INFTY;
    vec_R[n2] = INFTY;
    int i = 0;
    int j = 0;
    int cnt = 0;
    for (int k = left; k < right; k++)
    {
        if (vec_L[i] <= vec_R[j]) {
            vec[k] = vec_L[i];
            i++;
        } else {
            vec[k] = vec_R[j];
            j++;
        }
        cnt++;
    }
    return cnt;
}
void merge_sort(vector<int>& vec, int left, int right, int& cnt)
{
    int mid = 0;
    if (left+1 < right)
    {
        mid = (left + right) / 2;
        merge_sort(vec, left, mid, cnt);
        merge_sort(vec, mid, right, cnt);
        cnt += merge(vec, left, mid, right);
    }
}

int main()
{
    vector<int> vec;
    vec.reserve(MAX);
    int n = 0;
    int m = 0;
    scanf("%d",&n);

    for (int i = 0; i < n; i++)
    {
        scanf("%d",&m);
        vec.push_back(m);
    }

    int cnt = 0;
    merge_sort(vec, 0, n, cnt);

    for (int i = 0; i < n; i++)
    {
        if (i == n - 1)
        {
            printf("%d\n", vec[i]);
        }
        else
        {
            printf("%d ", vec[i]);
        }
    }
    printf("%d\n", cnt);
}


Measured memory_bytes: 6856
//
//  main.cpp
//  ervb
//
//  Created by Kanak Gautam on 21/04/20.
//  Copyright © 2020 Kanak Gautam. All rights reserved.
//
 
 
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#define pb push_back
#define mk make_pair
#define endl "\n"
#define mod 1000000007
using namespace std;
typedef long long int lli;
typedef long double ld;
priority_queue <lli, vector<lli>, greater<lli> > ti;
vector <lli> p[2000005],g,b(2000005,0),f(2000005,0),ans(2000005,0);
vector <vector<lli>> a(2000005,vector<lli>(26,0));
lli vis[200005];
map <pair<lli,lli>,lli> mp;
set<pair<lli, lli> > s;
set<lli> st;
map<lli,lli> np,v;
queue<lli> qy;
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
      
}
lli bpow(lli a, lli b) {
    lli res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return res%mod;
}
lli fact(lli i)
{
    f[0]=1;
    for(lli k=1;k<=i;k++)
    {
        (f[k]=f[k-1]*k)%=mod;
    }
    return f[i];
}
lli isprime(lli n)
{
    if(n==1)
        return 0;
    for(lli i=2;i<=sqrt(n);i++)
        if(n%i==0)
            return 0;
    return 1;
}
bool cmp(lli i,lli j)
{
    return p[i].size()<p[j].size();
}
/*void sieve()
{
    for(lli i=2;i<=5000000;i++)
    {
        if(b[i]==0)
        {
        for(lli j=2;i*j<=5000000;j++)
        {
            b[i*j]=1;
        }
        }
    }
}*/
int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    lli n;cin>>n;
    vector <string> s(n);
    lli nxt=1;
    for(lli i=0;i<n;i++)
    {
        cin>>s[i];
        lli node =0;
        reverse(s[i].begin(),s[i].end());
        for(lli j=0;j<s[i].size();j++)
        {
            p[i].pb(node);
            if(a[node][s[i][j]-'a']==0)
            {
                a[node][s[i][j]-'a']=nxt;
                nxt++;
            }
            node=a[node][s[i][j]-'a'];
        }
        f[node]=1;
    }
    lli ans=0;
    for(lli i=0;i<n;i++)
    {
        set<char>gh;
        for(lli j=s[i].size()-1;j>=0;j--)
        {
            gh.insert(s[i][j]);
            for(auto ch:gh)
            {
                ans+=f[a[p[i][j]][ch-'a']];
            }
        }
    }
    cout<<ans-n<<endl;
}



Measured memory_bytes: 600804
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(){
  ll total=0,mi=1000000,ma=-1000000,n=0, num;
  cin >> n;
  
  for(ll i=0; i<n; i++){
    cin >> num;
    total += num;
    ma = max(ma, num);
    mi = min(mi, num);        
  }

  cout << mi << " " << ma << " " << total << endl;
}



Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    
    int table[9];
    vector<bool> t(10,false);

    rep(i,9) cin >> table[i];
    map<int,int> mp;
    rep(i,9){
            mp[table[i]] = i+1;
    }

    int k;
    cin >> k;
    int tmp;
    rep(i,k){
        cin >> tmp;
        if(mp[tmp] != 0){
            t[mp[tmp]] = true;
        } 
    }

    if(t[1] == true && t[2] == true && t[3] == true ){
        cout<< "Yes" << endl;
        return 0;
    }
    if(t[4] == true && t[5] == true && t[6] == true ){
        cout<< "Yes" << endl;
        return 0;
    }
    if(t[7] == true && t[8] == true && t[9] == true ){
        cout<< "Yes" << endl;
        return 0;
    }
    if(t[1] == true && t[4] == true && t[7] == true ){
        cout<< "Yes" << endl;
        return 0;
    }
    if(t[2] == true && t[5] == true && t[8] == true ){
        cout<< "Yes" << endl;
        return 0;
    }
    if(t[3] == true && t[6] == true && t[9] == true ){
        cout<< "Yes" << endl;
        return 0;
    }
    if(t[1] == true && t[5] == true && t[9] == true ){
        cout<< "Yes" << endl;
        return 0;
    }
    if(t[3] == true && t[5] == true && t[7] == true ){
        cout<< "Yes" << endl;
        return 0;
    }
    
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3612
a,b,c,x,y = map(int, input().split())

piza = a*x+b*y
if min(x,y)==x:
  if piza > c*2*x + b*(y-x): piza = c*2*x + b*(y-x)
  if piza > c*2*y: piza = c*2*y
else:
  if piza > c*2*y + a*(x-y): piza = c*2*y + a*(x-y)
  if piza > c*2*x: piza = c*2*x
print(piza)

Measured memory_bytes: 3064
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <assert.h>
#include <math.h>
#include <memory.h>
#include <stdio.h>

#include <algorithm>
#include <complex>
#include <ctime>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define left asdgashgrketwjklrej
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd
#define prev asdgSHJsfgsdfhdsh
#define hash asdgasdgasdgdfrywewery

#define eps 1e-12
#define M_PI 3.141592653589793
#define bsize 1024

#define ldouble long double
using namespace std;

#define bs 998244353

const int N = 610031;

long long tests,n,A[N];
long long V[2][100];
long long ok;
string st;

void expand(int id,long long x){
	for (int i=60;i>=0;--i){
		if (V[id][i]==-1)
			continue;
		if (x&(1ll<<i)){
			x^=V[id][i];
		}
	}
	if (x==0)
		return;
	int hi=60;
	while (!(x&(1ll<<hi)))
		--hi;
	V[id][hi]=x;
}

bool is_subspace(int id1,int id2){
	for (int i=0;i<=60;i++){
		if (V[id1][i]==-1)
			continue;
		long long Q=V[id1][i];
		for (int j=60;j>=0;--j){
			if (V[id2][j]==-1)
				continue;
			if (Q&(1ll<<j))
				Q^=V[id2][j];
		}
		if (Q)
			return false;
	}
	return true;
}

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

  cin>>tests;
  for (;tests;--tests){
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>A[i];
	}
	cin>>st;
	for (int i=0;i<=60;i++){
		V[0][i]=-1;
		V[1][i]=-1;
	}
	ok=1;
	for (int i=n;i>=1;--i){
		if (st[i-1]=='0')
			expand(0,A[i]);
		else
			expand(1,A[i]);
		if (!is_subspace(1,0))
			ok=0;
	}
	if (ok)
		cout<<0<<endl;
	else
		cout<<1<<endl;
  }

  cin.get(); cin.get();
  return 0;
}


Measured memory_bytes: 3592
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner read = new Scanner (System.in);
        int can = 0;
        int a = read.nextInt();
        for (int i=1; i <= a ; i++)
            can = can + i;
        
        System.out.println(can);
    }
    
}

Measured memory_bytes: 35596
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x=sc.nextInt();
        int n=sc.nextInt();
        int[] p=new int[n];
        for(int i=0;i<n;i++) {
        	p[i]=sc.nextInt();
        }
        for(int i=0;i<=100;i++) {
        	int num1=x-i,num2=x+i;
        	int count1=0,count2=0;
        	for(int j=0;j<n;j++) {
        		if(p[j]==num1)	count1++;
        		if(p[j]==num2)	count2++;
        	}
        	if(count1==0) {
        		System.out.println(num1);
        		break;
        	}else if(count2==0) {
        		System.out.println(num2);
        		break;
        	}
        }
    }
}


Measured memory_bytes: 35816
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define deb(x) cout<<#x<<" "<<x<<endl;
#define debarr(a) cout<<#a<<endl;for(auto i: a) cout<<i<<" ";
#define se second
#define cnt(i) __builtin_popcountll(i)
#define pb emplace_back
#define append(j) pb(j)
#define print(p) cout<<p<<endl;
#define mp make_pair
#define len(w) w.size()
#define tuple(p,q) mp(p,q)
#define tc while(t--)
#define fo(n) for(int i=0;i<n;i++)
#define foj(m,n) for(int j=m;j<n;j++)
#define INF 9999999999
#define pra(a,n) fo(n)cout<<a[i]<<" ";cout<<endl;
#define vp vector<pair<int,int>>
#define vc vector<int>
#define all(v) (v.begin(),v.end())
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pp pair<ll,ll>
#define ispow2(x)  x && (!(x&(x-1)))
#define copy(a,b,n) copy_n(a,n,b) 
#define create(a,m,n) iota(a,a+n,m)
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define maximum(a,n)  ll* i1,maxi; i1 = std::max_element(a, a+n);maxi=*i1 
#define minimum(a,n)  ll* i1,mini; i1 = std::min_element(a, a+n);mini=*i1 
using namespace std;
ll n,m,k,s,dis[100005]={0},vis[100005]={0},x,y,g,h;
#define MAXN (ll)1e6+5
string a[100005];
const ll mod=1e9+7;

		
signed main(){
    fio
    cin>>n>>m;
    fo(n)
    cin>>a[i];
    ll dp[n+1][m+1]={0};
    fo(n)
    for(ll j=0;j<m;j++)
    {dp[i][j]=0;
    if(i+j==0)
    dp[i][j]=1;
    else if(a[i][j]=='.')
    dp[i][j]=(((i>0)?dp[i-1][j]:0)%mod+((j>0)?dp[i][j-1]:0)%mod)%mod;}
    //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
    cout<<dp[n-1][m-1];
    
    
    return 0;
}

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


ll N,ans;

int main(void){
    cin >> N;
    if(N%2==1){cout << 0 << endl;return 0;}
    
    N = N/2;
    ll x=5;
    while(x<=N){
        ans +=N/x;
        x*=5;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import math
a,b,h,m = map(int, input().split())
angleh = (30 * h + 0.5 * m) % 360
anglem = 6 * m % 360
if angleh > anglem:
    angle = angleh - anglem
else:
    angle = anglem - angleh
print(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(angle * math.pi / 180)))

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	int n; cin >> n;
	ll ttl = 0;
	rep(i, 0, n) { int t; cin >> t; ttl += t - 1; }
	cout << ttl << endl;
}


Measured memory_bytes: 256
//AtCoder Begginner Contest 088 A
#include <iostream>
//#include <algorithm>
using namespace std;

int main(){
	int N;
	int A;
	cin >> N >> A;
	int amari = N % 500;
	
	string res;
	if(amari<=A){
		res = "Yes";
	}else{
		res = "No";
	}
	
	cout << res << endl;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<pair<pair<string, int>, int>> x(n);
  for (int i = 0; i < n; i++) {
    string s;
    int p;
    cin >> s >> p;
    x.at(i) = make_pair(make_pair(s, -p), i + 1);
  }
  
  sort(x.begin(), x.end());
  
  for (int i = 0; i < n; i++) {
    pair<pair<string, int>, int> y = x.at(i);
    cout << y.second << '\n';
  }
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Match Matching
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 10000;
const int MAX_M = 9;
const int MAX_C = 7;

const int cs[] = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

/* typedef */

typedef vector<int> vi;
typedef pair<int,int> pii;

/* global variables */

int cds[MAX_C + 1], cns[10];
pii ps[MAX_C + 1];
int dp[MAX_C + 1][MAX_N + 1], prvs[MAX_C + 1][MAX_N + 1];
vi dv[MAX_C + 1][MAX_N + 1];

/* subroutines */

inline void setmax(int &a, int b) { if (a < b) a = b; }

/* main */

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

  for (int i = 0; i < m; i++) {
    int ai;
    scanf("%d", &ai);
    int ci = cs[ai];
    if (cds[ci] < ai) cds[ci] = ai;
  }

  int k = 0;
  for (int c = 0; c <= MAX_C; c++)
    if (cds[c] > 0) ps[k++] = pii(cds[c], c);
  sort(ps, ps + k, greater<pii>());
  
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;
  prvs[0][0] = -1;

  for (int i = 0; i < k; i++) {
    int &ci = ps[i].second;

    for (int j = 0; j <= n; j++)
      if (dp[i][j] >= 0)
	for (int j1 = j, d1 = dp[i][j]; j1 <= n; j1 += ci, d1++)
	  if (dp[i + 1][j1] < d1 ||
	      (dp[i + 1][j1] == d1 && dv[i + 1][j1] < dv[i][j])) {
	    dp[i + 1][j1] = d1;
	    dv[i + 1][j1] = dv[i][j];
	    dv[i + 1][j1].push_back(d1 - dp[i][j]);
	    prvs[i + 1][j1] = j;
	  }
  }

  vi &v = dv[k][n];
  for (int i = 0; i < k; i++) {
    int ch = ps[i].first + '0';
    for (int j = 0; j < v[i]; j++) putchar(ch);
  }
  putchar('\n');

  return 0;
}


Measured memory_bytes: 4608
SA = list(input())
SB = list(input())
SC = list(input())

nextp = SA.pop(0)
while True:
    if nextp == 'a':
        if len(SA) > 0:
            nextp = SA.pop(0)
        else:
            print('A')
            break
    elif nextp == 'b':
        if len(SB) > 0:
            nextp = SB.pop(0)
        else:
            print('B')
            break
    else:
        if len(SC) > 0:
            nextp = SC.pop(0)
        else:
            print('C')
            break


Measured memory_bytes: 3064
import bisect
import heapq
N, M = map(int, input().split())
X = [[] for _ in range(M)]
for i in range(N):
    a, b = map(int, input().split())
    if a <= M:
        X[a-1].append(-b)
ans = 0
heap = []
for i in range(M):
    for b in X[i]:
        heapq.heappush(heap, b)
    if len(heap) > 0:
        ans -= heapq.heappop(heap)
print(ans)

def TLE():
    X.sort(key=lambda x: (-x[1], x[0]))
    days = [i for i in range(1, M+1)]
    ans = 0
    for a, b in X:
        if len(days) == 0:
            break
        if days[-1] < a:
            continue
        index = bisect.bisect_right(days, a)
        if index > 0 and days[index-1] >= a:
            days.pop(index-1)
        elif index > 0 and days[index-1] <a:
            days.pop(index) 
        elif index == 0 and days[0] >= a:
            days.pop(0)
        else:
            continue
        ans += b
    print(ans)
# TLE()

Measured memory_bytes: 72480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
const ll MOD=1000000007;

int main(){
    int N;
    cin >> N;
    vector<ll> A(N),B(N);
    rep (i,N){
        cin >> A[i] >> B[i];
    }
    ll ans=0;
    for (int i=N-1;i>=0;i--){
        A[i]+=ans;
        ll x=(A[i]+B[i]-1)/B[i];
        ans+=x*B[i]-A[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
object Main {
  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readInt()
    val words = for( _ <- (1 to n).toList) yield io.StdIn.readLine()
    val result = check (words) match {
      case Right(_) => "Yes"
      case Left(_) => "No"
    }

    println(result)
  }


  def check(words: List[String]): Either[Unit, Unit] = {
    def loop(words: List[String], used: List[String] = Nil): Either[Unit, Unit] = {
      words match {
        case Nil => Right()
        case x::xs =>
          if (used.isEmpty) loop(xs, x :: used)
          else if (x.head != used.head.last) Left()
          else if(used.contains(x)) Left()
          else loop(xs, x::used)
      }
    }

    loop(words)
  }
}


Measured memory_bytes: 25540
#include<map>
#include <iostream>
#include<vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(long long)(n);++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    ll ans = 0;
    rep(i, n) {
        cin >> a[i];
        ans += a[i]-1;
    }
    cout << ans << endl;

}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
char s[maxn];
int prf[maxn][26],maxv[26];
int ansi,ansj;
const int inf=(~0u)>>2;
bool check(int n)
{
	for(int i=0;i<26;++i)maxv[i]=n+1,prf[n+1][i]=-inf;
	for(int i=n,j;i>0;--i)
	{
		j=s[i]-'a';
		//cerr <<prf[maxv[j]][j]<<" "<<prf[i-1][j]<<endl;
		if(prf[maxv[j]][j]>prf[i-1][j]&&maxv[j]-i+1>=2)
		{
			ansi=i;
			ansj=maxv[j];
			return true;
		}
		if(prf[maxv[j]][j]<prf[i][j])
			maxv[j]=i;
	}
	return false;
}
int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1);
	for(int i=1;i<=n;++i)
	{
		for(int j=0;j<26;++j)
			prf[i][j]+=prf[i-1][j];
		++prf[i][s[i]-'a'];
	}
	for(int i=1;i<=n;++i)
		for(int j=0;j<26;++j)
			prf[i][j]=2*prf[i][j]-i;
	if(check(n))
		printf("%d %d\n",ansi,ansj);
	else puts("-1 -1");
	return 0;
}


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

int fcost(vector<int> heights)
{
    int n = heights.size();
    if (n < 2) return 0;
 
    vector<int> cost(n + 2, numeric_limits<int>::max());
    cost[0] = 0;
 
    for (int i = 0; i < n; ++i)
    {
        cost[i + 1] = min(cost[i+1], cost[i] + abs(heights[i+1] - heights[i]));
        cost[i + 2] = min(cost[i+2], cost[i] + abs(heights[i+2] - heights[i]));
    }
 
    return cost[n - 1];
}

int main()
{
	int n;
	cin>>n;
	vector <int> h(n);
	for(int i = 0; i < n; i++)
	{
		cin>>h[i];
	}
	cout<<fcost(h)<<"\n";
	return 0;
}

Measured memory_bytes: 1408
import itertools
import collections

n, m = map(int, input().split())

a = [list(sorted(map(int, input().split()))) for i in range(m)]
a.sort()

cnt = 0

for i in itertools.permutations(range(2, n + 1), (n - 1)):
    li = [1] + list(i)
    if sum(list(sorted(edge)) in a for edge in zip(li, li[1:])) == n - 1:
        cnt += 1

print(cnt)

Measured memory_bytes: 3316