akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int k, s;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> k >> s;
	int cnt = 0;
	for (int x = 0; x <= k; x++) {
		for (int y = 0; y <= k; y++) {
			if (s-x-y >= 0 && s-x-y <= k) cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#define _LIBCPP_DEBUG 0

#include<bits/stdc++.h>

using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

int main() {

    int N, M;
    cin >> N >> M;
    vector<ll> dp(N + 1, 1);
    for (int i = 0; i < M; ++i) {
        int tmp; cin>>tmp;
        dp[tmp] = 0;
    }

    int ind = 0;
    for (int i = 0; i <= N; ++i) {
        if (dp[i]==0 || i==0 || i==1) {
            continue;
        } else {
            dp[i] = dp[i - 1] + dp[i - 2];
            dp[i] %= MOD;
        }

    }

    cout << dp[N] << endl;


    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct PalindromicTree{
  struct node{
    map<char,int> nxt;
    int len,suf,hei,app,cnt;
  };
  string s;
  vector<node> v;
  vector<int> ord;
  int n,suff;
  PalindromicTree(){}
  PalindromicTree(string s_){init(s_);build();}
  bool addchar(int pos){
    char ch=s[pos];
    int cur=suff;
    while(1){
      if(pos-1-v[cur].len>=0&&s[pos-1-v[cur].len]==ch) break;
      cur=v[cur].suf;
    }
    if(v[cur].nxt.count(ch)){
      suff=v[cur].nxt[ch];
      v[suff].cnt++;
      return false;
    }
    suff=n++;
    v[suff].len=v[cur].len+2;
    v[suff].app=pos;
    v[suff].cnt=1;
    v[cur].nxt[ch]=suff;
    
    if(v[suff].len==1){
      v[suff].suf=1;
      v[suff].hei=1;
      return true;
    }
    while(1){
      cur=v[cur].suf;
      if(pos-1-v[cur].len>=0&&s[pos-1-v[cur].len]==ch){
	v[suff].suf=v[cur].nxt[ch];
	break;
      }
    }
    v[suff].hei=v[v[suff].suf].hei+1;
    return true;
  }
  
  void init(string s_){
    s=s_;
    v.clear();
    v.resize(s.length()+10);

    n=2;
    suff=1;
    v[0].app=v[1].app=-1;
    v[0].len=-1;v[1].len=0;
    v[0].suf=v[1].suf=0;
    v[0].hei=v[1].hei=0;
  }
  
  void calcOrder(){
    ord.clear();
    ord.push_back(0);
    ord.push_back(1);
    for(int i=0;i<(int)ord.size();i++){
      for(auto &p:v[ord[i]].nxt) ord.push_back(p.second);
    }
  }
  
  void calcCount(){
    assert(ord.size());
    for(int i=(int)ord.size()-1;i>=0;i--){
      v[v[ord[i]].suf].cnt+=v[ord[i]].cnt;
    }
    v[0].cnt=v[1].cnt=0;
  }

  void build(){
    for(int i=0;i<(int)s.size();i++) addchar(i);
    calcOrder();
    calcCount();
  }
  
};

struct RollingHash{
  typedef unsigned long long ull;
  string S;
  ull B;
  vector<ull> hash,p;
  int len;
  RollingHash(){}
  RollingHash(string S,ull B=1000000007LL):S(S),B(B){init();};
  void init(){
    len=S.length();
    hash.resize(len+1);
    p.resize(len+1);
    hash[0]=0;p[0]=1;
    for(int i=0;i<len;i++){
      hash[i+1]=hash[i]*B+S[i];
      p[i+1]=p[i]*B;
    }
  }
  //S[l,r)
  ull find(int l,int r){
    return hash[r]-hash[l]*p[r-l];
  }
};


signed main(){
  string s,t;
  cin>>s>>t;
  PalindromicTree p1(s),p2(t);
  RollingHash r1(s),r2(t);
  map<int,int> m1[55555],m2[55555];
  for(int i=0;i<(int)p1.n;i++){
    PalindromicTree::node& u=p1.v[i];
    if(u.app<0) continue;
    //cout<<s.substr(u.app-u.len+1,u.len)<<":"<<u.cnt<<endl;
    m1[u.len][r1.find(u.app-u.len+1,u.app+1)]=u.cnt;
  }
  //cout<<endl;
  for(int i=0;i<(int)p2.n;i++){
    PalindromicTree::node& u=p2.v[i]; 
    if(u.app<0) continue;
    //cout<<t.substr(u.app-u.len+1,u.len)<<":"<<u.cnt<<endl;
    m2[u.len][r2.find(u.app-u.len+1,u.app+1)]=u.cnt;
  }
  int ans=0;
  for(int i=1;i<=(int)s.length();i++){
    for(auto p:m1[i]){
      ans+=m2[i][p.first]*p.second;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 34860
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <cmath>
#include <limits.h>
using namespace std;
typedef long long LL;
const int N=200;

int n,a[N];

int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
	}
	int ans=0,c=0;
	for(int i=1;i<=n;i++) {
		if(a[i]!=a[i-1]) {
			ans+=c/2;
			c=1;
		}
		else c++;
	}
	ans+=c/2;
	printf("%d\n",ans);
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	if (n==1)
	{
		cout<<"Hello World\n";
	}
	else
	{
		int a,b;
		cin>>a>>b;
		cout<<a+b<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << a+b+c << "\n";
    return 0;
}


Measured memory_bytes: 3088
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;

#define REP(i,e,s) for(register int i=e; i<=s; i++)
#define DREP(i,e,s) for(register int i=e; i>=s; i--)
#define ll long long
#define DE(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG(a) DE("DEBUG: %d\n",a)
int read() {
	int x=0,f=1,ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=10+10;

char s[MAXN];
int a[MAXN],len;
ll ans;

ll calc() {
	ll x=0,b=0;
	a[len]=1;
	REP(i,1,len) {
		if(!a[i]) x=x*10+s[i]-'0';
		else {x=x*10+s[i]-'0';b+=x;x=0;}
	}
	return b;
}

int count() {
	int x=0;
	REP(i,1,len-1) x=x*2+a[i];

	return x;
}

int len2,have[10000+10];

void dfs(int k) {
	if(k>len) return ;

	if(!have[count()]) {
		//REP(i,1,len) printf("%d ",a[i]);
		//puts("");
		have[count()]=1;

		ans+=calc();
	}

	for(int i=0; i<=1; i++) {
		a[k]=i;
		dfs(k+1);	
	}
}

int main() {
	scanf("%s",s+1);
	len=strlen(s+1);
	len2=len-1;
	dfs(1);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  int a,b,c,d;
  d = N%10;
  N /= 10;
  c = N%10;
  N /= 10;
  b = N%10;
  N /= 10;
  a = N;

  //全探索
  for(int i=0 ; i<(1<<3) ; i++){
    vector<int> use;
    vector<char> usechar;
    int itmp = i;
    for(int j=0;j<3;j++){
      if(itmp%2==1){
        use.push_back(1);
        usechar.push_back('+');
      }
      else {
        use.push_back(-1);
        usechar.push_back('-');
      }
      itmp /= 2;
    }

    int sum;
    sum = a + b*use[0] + c*use[1] + d*use[2];
    if(sum == 7){
      cout << a << usechar[0] << b << usechar[1] << c << usechar[2] << d << "=7" << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int X;
    cin >> X;
    for(int k=1;X-k*100>=0;k++){
        int a=X-k*100;
        if(0<=a&&a<=5*k){
            cout << 1 << endl;
            //cout << k << endl;
            return 0;
        }
    }
    cout <<0<< endl;
    return 0;
}



Measured memory_bytes: 256
class Combination:
    """階乗とその逆元のテーブルをO(N)で事前作成し、組み合わせの計算をO(1)で行う"""
    def __init__(self, n, MOD):
        self.fact = [1]
        for i in range(1, n + 1):
            self.fact.append(self.fact[-1] * i % MOD)
        self.inv_fact = [0] * (n + 1)
        self.inv_fact[n] = pow(self.fact[n], MOD - 2, MOD)
        for i in reversed(range(n)):
            self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % MOD
        self.MOD = MOD

    def factorial(self, k):
        """k!を求める O(1)"""
        return self.fact[k]

    def inverse_factorial(self, k):
        """k!の逆元を求める O(1)"""
        return self.inv_fact[k]

    def permutation(self, k, r):
        """kPrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r]) % self.MOD

    def combination(self, k, r):
        """kCrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD


def way4(ball, box):
    """ball: False / box: True / constraints: None
    -> ans = combination(box + ball - 1, ball)
    """
    return comb.combination(ball + box - 1, ball)


n, k = map(int, input().split())
MOD = 10 ** 9 + 7
comb = Combination(10 ** 4, MOD)

print(way4(n, k))


Measured memory_bytes: 6344
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin>>n;
  
  int mx = 0;
  map<string, int> poll;
  
  while(n--) {
    string s;
    cin>>s;
    
    if(poll.find(s) == poll.end()) {
      poll.insert(make_pair(s, 1));
      mx = max(poll[s], mx); 
    }
    else {
      poll[s]++;
      mx = max(poll[s], mx); 
    }
 }
    map<string, int> ::iterator it = poll.begin();
    vector<string> res;
    for(; it!= poll.end(); it++) {
      if(it->second == mx)
        res.push_back(it->first);
    }
    
    sort(res.begin(), res.end());
    
    for(int i=0; i<res.size(); i++)
    	cout<<res[i]<<endl;
	return 0;
}


Measured memory_bytes: 26868
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for (int i = (a); i < (int)(n); i++)
#define repc(i, a, n) for (int i = (a); i <= (int)(n); i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
#define DBG(str) cerr << (str) << endl;
#define DispVec(vec)                                                           \
  cerr << "DispVec:";                                                          \
  for (auto v : vec)                                                           \
    cerr << v << " ";                                                          \
  cerr << endl;
ll comb(int n, int r) {
  if (n < r)
    return 0;
  double c = 1;
  cerr << "comb(" << n << "," << r << ")";
  for (int i = 0; i < r; i++) {
    c *= (double)(n - i) / (i + 1);
  }
  cerr << ":" << c << endl;
  return (long long)round(c);
}

ll frac(int n) {
  static vector<int> f(1e5, -1);
  f[0] = 1;
  if (f[n] != -1)
    return f[n];
  else {
    cerr << "frac:" << to_string(f[n]) << endl;
    f[n] = n * frac(n - 1);

    return f[n];
  }
}
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];
  vector<ll> cs(n + 1, 0);
  cs[0] = 0;
  rep(i, 1, n + 1) cs[i] = cs[i - 1] + a[i - 1];
  DispVec(cs);
  map<ll, int> m;
  rep(i, 0, cs.size()) m[cs[i]]++;
  ll sum = 0;
  for (auto v : m) {
    cerr << ":" << v.first << " " << v.second << endl;
    sum += comb(v.second, 2);
  }
  cout << sum;

  return 0;
}


Measured memory_bytes: 15872
fn main() {
    proconio::input! {
        n: usize,
        a: [u64; n],
    }

    let mut m = 0;
    let mut r = 0;
    for i in 0..n {
        if a[i] > m {
            m = a[i]
        } else {
            r += m - a[i];
        }
    }

    println!("{}", r);
}


Measured memory_bytes: 5632
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define all(_obj) _obj.begin(),_obj.end()
#define F first
#define S second
#define INF 1e18
#define pll pair<ll, ll> 
#define vll vector<ll>
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=1e5+11;
inline ll max(ll a,ll b) {return ((a>b)?a:b);}
inline ll min(ll a,ll b) {return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b) {if(b==0) return a;a%=b;return gcd(b,a);}
inline vll read(int n) {vll v(n);for (int i = 0; i < v.size(); i++)cin>>v[i];return v;}
void sol()
{
cin>>x;
cout<<10-(x/200);









return ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    //cin>>test;
    for(int i=1;i<=test;i++)
    sol();
}


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

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
int MOD=1e9+7;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime[1000001];
vi primes;
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for(int p=2;p<1000001;p++)
        if(prime[p])
            primes.pb(p);
}
ll fact[100005];
ll finv[100005];
void factorial(int n){
    fact[0]=1;
    finv[0]=1;
    for(int i=1;i<=n;i++)
        fact[i]=fact[i-1]*i,fact[i]%=MOD,finv[i]=fermat_inv(fact[i]);
}
ll ncr(ll n,ll r)
{
    if(n<r)
        return -1;
    else{
        ll x=finv[r]*finv[n-r]%MOD;
        return fact[n]*x%MOD;
    }
}

int dfs(vi adj[],int vis[],int i)
{
    if(vis[i])
        return 0;
    vis[i]=1;
    int ans=1;
    for(int j:adj[i]){
        if(vis[j])
            continue;
        ans+=dfs(adj,vis,j);
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int t=1;
    //cin>>t;
    //SieveOfEratosthenes(1000000);
    //factorial(100005);
    while(t--){
        int n,m;
        cin>>n>>m;
        vi adj[n+1];
        for(int i=0;i<m;i++){
            int a,b;
            cin>>a>>b;
            adj[a].pb(b);
            adj[b].pb(a);
        }
        ll ans=0;
        int vis[n+1]={0};
        for(int i=1;i<=n;i++){
            if(vis[i])
                continue;
            ans=max(ans,dfs(adj,vis,i));
        }
        cout<<ans;
    }
}

Measured memory_bytes: 24620
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

int main() {
	IN(int, n);
	map<int, int> mp;
	incII(i, 2, n) {
		IN(int, a);
		mp[a]++;
	}
	inc1(i, n) { OUT(mp[i]); }
}


Measured memory_bytes: 12980
#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn, dd, tmp, ll, ans = 0;
	cin >> nn >> dd;
	int64 xx[nn][dd];
	for(int64 ii = 0;ii < nn;ii++)
	{
		for(int64 jj = 0;jj < dd;jj++)
		{
			cin >> xx[ii][jj];
		}
	}
	for(int64 ii = 0;ii < nn - 1;ii++)
	{
		for(int64 jj = ii + 1;jj < nn;jj++)
		{
			tmp = 0;
			for(int64 kk = 0;kk < dd;kk++)
			{
				tmp += (xx[ii][kk] - xx[jj][kk]) * (xx[ii][kk] - xx[jj][kk]);
			}
			ll = 1;
			while(ll * ll < tmp)
			{
				ll++;
			}
			if(ll * ll == tmp)
			{
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String args[]){
		try{
			new Main();
		}catch(IOException e){
			e.printStackTrace();
		}
	}
	
	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = in.readLine();
	
		int size = Integer.parseInt(line);
		Node[] nodes = new Node[size];
		for(int i=0; i<size; i++){
			line = in.readLine();
			String[] tmp = line.split(" ");
			int id = Integer.parseInt(tmp[0])-1;
			nodes[id] = new Node();
			int n_to = Integer.parseInt(tmp[1]);
			for(int j=2; j<2+n_to; j++){
				int to = Integer.parseInt(tmp[j])-1;
				nodes[id].add_edge(to, 1);
			}
		}
		
		line = in.readLine();
		size = Integer.parseInt(line);
		for(int i=0; i<size; i++){
			Node[] clone = deepClone(nodes);
			line = in.readLine();
			String[] tmp = line.split(" ");
			int s = Integer.parseInt(tmp[0])-1;
			int g = Integer.parseInt(tmp[1])-1;
			int ttl = Integer.parseInt(tmp[2]);
			int total = calcCost(clone, s, g);
			if(ttl >= total && total != -1){
				System.out.println(total);
			}else{
				System.out.println("NA");
			}
		}
	}
	
	public int calcCost(Node[] nodes, int s, int g){
		List<Node> que = new ArrayList<Node>();
		nodes[s].cost = 1;
		que.add(nodes[s]);
		Node done = null;
		while(que.size()!=0){
			done = que.get(0);
			que.remove(0);
			done.visited = true;
			for(int i=0; i<done.edge_to.size(); i++){
				int cost = done.cost + done.edge_cost.get(i);
				int to = done.edge_to.get(i);
				if(nodes[to].cost < 0 || cost < nodes[to].cost){
					nodes[to].cost = cost;
					if(!que.contains(nodes[to])){
						que.add(nodes[to]);
					}
				}
			}
		}
		return nodes[g].cost;
	}
	
	public Node[] deepClone(Node[] nodes){
		int m = nodes.length;
		Node[] clone = new Node[m];
		for(int i=0; i<m; i++){
			clone[i] = new Node(nodes[i]);
		}
		return clone;
	}
}

class Node{
	int cost;
	boolean visited;
	List<Integer> edge_to;
	List<Integer> edge_cost;
	
	public Node(){
		this.cost = -1;
		this.visited = false;
		this.edge_cost = new ArrayList<Integer>();
		this.edge_to = new ArrayList<Integer>();
	}
	
	public Node(Node n){
		this.cost = n.cost;
		this.visited = n.visited;
		this.edge_to = new ArrayList<Integer>(n.edge_to);
		this.edge_cost = new ArrayList<Integer>(n.edge_cost);
	}
	
	public void add_edge(int to, int cost){
		this.edge_cost.add(cost);
		this.edge_to.add(to);
	}
}

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

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


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int h,w,a,b;
map<int,int>m;
multiset<int>s;

int main(){
    cin>>h>>w;
    for(int i=0;i<w;i++) m[i]=i,s.insert(0);
    for(int i=0;i<h;i++){
        cin>>a>>b;
        a--;
        auto pos=m.lower_bound(a);
        int mx=-1;
        while(pos!=m.end()&&pos->first<=b){
            mx=max(mx,pos->second);
            int x=pos->first-pos->second;
            s.erase(s.find(x));
            m.erase(pos++);
        }
        if(mx!=-1&&b<w){
            s.insert(b-mx);
            m[b]=mx;
        }
        cout<<(s.empty()?-1:*s.begin()+i+1)<<endl;
    }
}




Measured memory_bytes: 22316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = 998244353;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main(){
    int n;
    cin >> n;
    vector<int> ans(n);
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        ans[a-1] = i+1;
    }
    for(int i=0;i<n;i++){
        cout << ans[i] << " \n"[i==n-1];
    }
    return 0;
}

Measured memory_bytes: 1152
def getval():
    n,m = map(int,input().split())
    g = [[] for i in range(n)]
    for i in range(m):
        x,y = map(int,input().split())
        g[x-1].append(y-1)
    return n,m,g

def main(n,m,g):
    d = [-1 for i in range(n)]
    visited = [False for i in range(n)]
    temp = [[] for i in range(n)]
    #Loop through each vertex
    for i in range(n):
        #If already computed: pass
        if d[i] != -1:
            continue
        q = [[i,-1]]
        prev = [-1]
        while q:
            idx = q.pop(-1)
            cur = idx[0]
            #If not visited
            if not visited[cur]:
                visited[cur] = True
                #If there are vertices that can be reached
                if g[cur]:
                    prev.append(cur)
                    #Append to q
                    for j in g[cur]:
                        q.append([j,cur])
                    continue
                #No vertices to be reached
                else:
                    d[cur] = 0
                    temp[idx[1]].append(0)
            #If it has been visited in some way
            else:
                #If the distance hasn't been computed
                if d[cur] == -1:
                    d[cur] =  1 + max(temp[cur])
                if idx[1] != -1:
                    temp[idx[1]].append(d[cur])
            #If this is the first vertex
            if prev[-1] == -1:
                break
            #If the next vertex has the same parent vertex
            if q:
                if q[-1][1]==idx[1]:
                    continue
            #Otherwise, return to the parent node
            par = prev.pop(-1)
            q.append([par,prev[-1]])

    print(max(max(d),0))

if __name__=="__main__":
    n,m,g = getval()
    main(n,m,g)

Measured memory_bytes: 107676
def find_power(n):
    # 0!からn!までのびっくりを出してくれる関数
    powlist=[0]*(n+1)
    powlist[0]=1
    powlist[1]=1
    for i in range(2,n+1):
        powlist[i]=powlist[i-1]*i%(10**9+7)
    return powlist

def find_inv_power(n):
    #0!からn!までの逆元を10**9+7で割ったあまりリストを作る関数
    powlist=find_power(n)
    check=powlist[-1]
    first=1
    uselist=[0]*(n+1)
    secondlist=[0]*30
    secondlist[0]=check
    secondlist[1]=check**2
    for i in range(28):
        secondlist[i+2]=(secondlist[i+1]**2)%(10**9+7)
    a=format(10**9+5,"b")
    for j in range(30):
        if a[29-j]=="1":
            first=(first*secondlist[j])%(10**9+7)
    uselist[n]=first
    for i in range(n,0,-1):
        uselist[i-1]=(uselist[i]*i)%(10**9+7)
    return uselist

n=int(input())
lists=list(map(int,input().split()))
import collections
c=collections.Counter(lists)
d=c.most_common()
number=d[0][0]
listss=[]
for i in range(n+1):
    if lists[i]==number:
        listss.append(i+1)
a,b=listss[0],listss[1]

powlist=find_power(n+1)
invlist=find_inv_power(n+1)
def combi(n,r):
    a=powlist
    b=invlist
    if n<r:
        return 0
    elif n>=r:
        return (a[n]*b[r]*b[n-r])%(10**9+7)
    
for i in range(1,n+2):
    if i==1:
        print(n)
    elif 2<=i and i<=n+1-(b-a):
        print((combi(n-1,i)+combi(n-1,i-2)+2*combi(n-1,i-1)-combi(n+a-b,i-1))%(10**9+7))
    else:
        print(combi(n+1,i)%(10**9+7))
        

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

const int MAXN = 112345;
const int INF = 1e9;

int h[MAXN], dp[MAXN];
int k;

int solve (int n) {

    if(n == 0) return 0;
    if(dp[n] != INF) return dp[n];

    for(int i = 1; i <= k; i++) {
        if(n-i >= 0)
            dp[n] = min(dp[n], solve(n-i) + abs(h[n] - h[n-i]));
    }

    return dp[n];
}

void imprime(int n) {

    cout << endl;
    for(int i = 0; i < n; i++) {
        cout << dp[i] << " ";
    }
    cout << endl;
}

int main() {

    for(int i = 0; i < MAXN; i++)
        dp[i] = INF;
    dp[0] = 0;

    int n;
    scanf("%d%d", &n, &k);

    //imprime(n);

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

    cout << solve(n-1) << endl;

    //imprime(n);

    return 0;
}


Measured memory_bytes: 4224
#include <stdio.h>
int *read(int *ct)
{
	static char ch;
	*ct = 0;
	while ((ch = fgetc(stdin)) != '\n') *ct += ch - '0';
	return ct;
}

int  main(void)
{
	int count;
	while ( 0 != * read(&count)) fprintf(stdout,"%d\n",count);
	
	return 0;
}

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

int main(){
	int a, b,k;
	cin >> a >> b>>k;
	int count = 0;
	int mod = min(a,b);
	while (1) {
		if (a%mod == 0 && b%mod == 0) {
			count++;
		}
		if (count == k) {
			cout << mod << endl;
			break;
		}
		mod--;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define F first
#define S second
#define MP make_pair
#define INF (1<<29)

typedef pair<pair<double, int>,pair<int, int> > P;

struct Edge{
  int to,d,c;
  Edge(int to, int d, int c):to(to),d(d),c(c){}
};

int N,M;
vector<Edge>G[32];
double dist[32][32][32];

void dijkstra(int s){
  rep(i,32) rep(j,32) rep(k,32)dist[i][j][k] = INF;
  priority_queue<P, vector<P>, greater<P> >q;
  dist[0][s][31] = 0.0;
  q.push(MP(MP(0.0, 0),MP(s, 31)));
  
  while(!q.empty()){
    P p = q.top(); q.pop();
    int d = p.F.F, speed = p.F.S, cur = p.S.F, prev = p.S.S;
    if(dist[speed][cur][prev] < d) continue;
    for(int d=-1;d<=1;d++){
      int sp = speed+d;
      if(sp <= 0 || sp > 30) continue;
      rep(i,G[cur].size()){
	Edge e = G[cur][i];
	if(e.to == prev) continue;
	if(sp <= e.c && dist[sp][e.to][cur] > dist[speed][cur][prev] + (double)e.d/sp){
	  dist[sp][e.to][cur] = dist[speed][cur][prev] + (double)e.d/sp;
	  q.push(MP(MP(dist[sp][e.to][cur], sp), MP(e.to, cur)));
	}
      }
    }
  }
}

int main(){
  while(scanf("%d%d",&N,&M) && N||M){
    rep(i,32) G[i].clear();
    int s, g;
    scanf("%d%d",&s,&g); s--; g--;
    rep(i,M){
      int x,y,d,c;
      scanf("%d%d%d%d",&x,&y,&d,&c); x--;y--;
      G[x].push_back(Edge(y,d,c));
      G[y].push_back(Edge(x,d,c));
    }

    dijkstra(s);
    double res = INF;
    rep(i,32) res = min(res, dist[1][g][i]);
    if(res>INF-1) puts("unreachable");
    else printf("%.12lf\n", res);
  }
  return 0;
}

Measured memory_bytes: 1824
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(void){
    ll N=0;
    string S="";
    cin >> N >>S;
    if(S.size()<=N){
        cout<<S;
    }
    else{
        for(ll i=0;i<N;i++){
            cout<<S.at(i);
        }
        cout<<"...";
    }
    
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
using namespace std;
int main() {
  int R;
  cin >>R;
  if(R<1200) cout << "ABC"<<endl;
  else if(R<2800) cout <<"ARC"<<endl;
  else cout <<"AGC"<<endl ;
}


Measured memory_bytes: 256
//--- pC ---//
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Scanner scanner;
	int inf = (int)1e9;

	public Solution() {
		scanner = new Scanner(System.in);

		// scanner.nextLine();
		while (scanner.hasNext()) {
			run_case();
		}
	}
	private void run_case() {
		// scanner.nextLine();
		int[] tarr = strToIntArray(scanner.nextLine());
		int N = tarr[0], M = tarr[1];
		int[] res = new int[N];
		for (int i=0; i<M; i++) {
			tarr = strToIntArray(scanner.nextLine());

			if (res[tarr[0] - 1] != 0 && res[tarr[0] - 1] != tarr[1]) {
				System.out.println("-1");
				return;
			}
			if (N!=1 && tarr[0]==1 && tarr[1]==0) {
				System.out.println("-1");
				return;
			}

			res[tarr[0] - 1] = tarr[1];
		}

		if (N != 1 && res[0] == 0) res[0] = 1;
		StringBuilder sb = new StringBuilder();
		for (int i=0; i<N; i++) {
			sb.append(res[i]);
		}
		System.out.println(sb.toString());

		return;
	}

	private double getAver(int[] arr) {
		double sum = 0.0;
		for (int u: arr) sum += u;

		return Math.round(sum / arr.length);
	}

	private int[] strToIntArray(String str) {
	    String[] vals = str.split("\\s+");
	    int sz = vals.length;
	    int[] res = new int[sz];
	    for (int i=0; i<sz; i++) {
	        res[i] = Integer.parseInt(vals[i]);
	    }
	    return res;
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
 
#define rep for(int i = 0;i<n;i++)
const int MOD = 1000000007;
 
int main(){
    int n;cin >> n;
    int a[n];rep{
        cin >> a[i];
    }
    int ans = 0;
    int i = 0;
    while(i<n-1){
        int sum = 0;
        while(a[i]>=a[i+1] and i<n-1){
            sum++; i++;
        }
        i++;
        ans = max(ans,sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int MAX=1e5+10;

int main(){
	int N, K;
	cin>>N>>K;
	int A[MAX], B[MAX];
	rep(i,N)cin>>A[i]>>B[i];
	
	int l=0;
	rep(i,30)if((K>>i) & 1)l=i+1;
	
	ll ans=0;
	rep(a,N){
		if((A[a] | K )== K)ans=ans+(ll)B[a];
	}
	rep(d,l)if((K>>d) & 1){
		ll tmp=0;
		int P=0;
		rep(i,l){
			if(i<d)P = P | (1<<i);
			else if(i>d) P = P | (K & (1<<i));
		}
		rep(a,N){
			if((A[a] | P) == P)tmp=tmp+(ll)B[a];
		}
		ans=max(ans, tmp);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
lines = $stdin.read
array = lines.split("\n")

class Dfs
  attr_accessor :mat,:inc

  def initialize(mat)
    @mat = mat.dup
    @inc = 1
  end

  def dfs(x,y)

    @mat[x][y] = @inc if @mat[x][y] == 1

    #@mat.each{|r| p r}

    dxy = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]]
    for i in 0...dxy.length
      dx,dy = dxy[i].first,dxy[i].last
      nx,ny = x+dx,y+dy
      if 0<=nx and nx<@mat.length and 0<=ny and ny<@mat.first.length
        dfs(nx,ny) if @mat[nx][ny]==1
      end
    end

  end
end

# 0=sea,1=island

i = 0
until array[i].nil?
  w,h = array[i].split(" ").map(&:to_i)
  exit 0 if w==0 and h==0

  # puts "w=#{w},h=#{h}"
  m = Array.new(h).map{Array.new(w,0)}
  array[i+1...i+h+1].each_with_index do |line,idx|
    m[idx] = line.split(" ").map(&:to_i)
  end

  dfs,ans = Dfs.new(m),0

  for y in 0...w
    for x in 0...h
      # puts "x=#{x},y=#{y}"
      if dfs.mat[x][y]==1
        dfs.inc = dfs.inc + 1
        dfs.dfs(x,y)
      end
    end
  end

  #dfs.mat.each{|r| p r.max}
  #puts ""

  ans = dfs.mat.map(&:max).max-1
  ans = if ans<0
          0
        else
          ans
        end
  puts ans

  i+=(h+1)
end


Measured memory_bytes: 13720
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            int n = scanner.nextInt();
            if (n == 0) {
                break;
            }

            ArrayList<Integer> s = new ArrayList<Integer>();
            for (int i = 0; i < n; i++) {
                s.add(scanner.nextInt());
            }
            double m = 0;
            for (int i = 0; i < s.size(); i++) {
                m += s.get(i);
            }
            m /= s.size();

            double x = 0;
            for (int i = 0; i < s.size(); i++) {
                x += (s.get(i) - m) * (s.get(i) - m);
            }
            System.out.println(Math.sqrt(x / s.size()));
        }
        scanner.close();
    }
}



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

int main() {
  int N;
  cin >> N;
  int sum = 0;
  int n = N;
  while(n > 0){
    sum+=n % 10;
    n /= 10;
  }
  if(N % sum == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int h, w;
    while (1) {
        scanf("%d %d", &h, &w);
        if (h == 0 && w == 0) {break;}
        for (int i=0; i<h; i++) {
            for (int j=0; j<w; j++) {
                if (i % 2 == 0){
                    if (j % 2 == 0) {
                        printf("#");
                    } else {
                        printf(".");
                    }
                } else {
                    if (j % 2 == 0) {
                        printf(".");
                    } else {
                        printf("#");
                    }
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2052
#include <stdio.h>

int main(void)
{
	int n,T,c[100],t[100];
	int min=10000;
	
	scanf("%d%d",&n,&T);
	
	int i=0;
	
	while(i<n){
		
 		scanf("%d%d",&(c[i]),&(t[i]));
		
		if(t[i]>T){
			c[i]=c[i]+20000;
		}
		
		if(min>c[i]){
			min=c[i];
		}
		
		i++;
	}
	
	if(min==10000){
		printf("TLE\n");
	}else{
		printf("%d\n",min);
	}
	return 0;
}

Measured memory_bytes: 128
mod=10**9+7
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a=ii()
l=list(mi())
b=ii()
lst=[0]*(100001)
m=sum(l)
for j in l:
  lst[j]+=1
for k in range(b):
  x,y=mi()
  g=lst[x]
  m+=(y-x)*g
  lst[x]=0
  lst[y]+=g
  print(m)

Measured memory_bytes: 80152
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

constexpr int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n - 1); }

const int mod = TEN(9) + 7;

signed main()
{
	int n;cin>>n;
	if (n==1) {
		cout<<"Hello World\n";
	}else{
		int a,b;cin>>a>>b;
		cout<<(a+b)<<endl;
	}
}




Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int W, H, x, y, r;

    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

    if (((x + r) <= W) && ((x - r) >= 0) && ((y + r) <= H) && ((y - r) >= 0)) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 584
from itertools import*
N,K,Q,*A=map(int,open(0).read().split())
s=sorted
print(min((s(sum((v[:max(0,-~len(v)-K)]for v in(k*s(v)for k,v in groupby(A,lambda a:a>=Y))),[]))[Q-1:]or[2e9])[0]-Y for Y in A))

Measured memory_bytes: 61404
n = int(input())
B = [int(i) for i in input().split()]
ans = []

while B:
  L = []
  for i in range(len(B)):
    if B[i] == i+1:
      L.append(B[i])
      
  if L:
    ans.append(L[-1])
    B.pop(L[-1]-1)
  else:
    print(-1)
    exit()
  
for i in ans[::-1]:
  print(i)

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

signed main() 
{
	int n;
    cin >> n;
    map<string , int> m;
    rep(i,n)
    {
        string s;
        cin >> s;
        m[s]++;
    }
    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl; 
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000
int main(){
    typedef pair<int,int> P;
    int x,y,sx,sy,gx,gy;
    int dirx[4] = {0,1,0,-1};
    int diry[4] = {1,0,-1,0};
    cin >> x >> y;
    char m[x][y];
    sx = 0;sy = 0;gx = x-1;gy = y-1;
    int dotcount = 0;
    int dist[x][y];
    int ans = -1;
    rep(i,x){
        rep(j,y){
            cin >> m[i][j];
            dist[i][j] = INF;
            if(m[i][j] == '.')dotcount++;
        }
    }
    queue<P> que;
    que.push(P(sx,sy));
    dist[sx][sy] = 0;
    while(que.size() != 0){
        P place = que.front();
        int nowx = place.first;
        int nowy = place.second;
        que.pop();
        if(nowx == gx && nowy == gy){
            ans = dotcount - dist[gx][gy] -1;//-1はスタート地点を除くため
            break;
        }
        rep(i,4){
            int nextx = nowx+dirx[i];
            int nexty = nowy+diry[i];
            if(nextx >= x||nextx < 0||nexty >= y||nexty < 0) continue;//枠外に注意
            if(dist[nextx][nexty] == INF && m[nextx][nexty]== '.'){//INFじゃないなら探索済み
                que.push(P(nextx,nexty));
                dist[nextx][nexty] = dist[nowx][nowy]+1;//距離は現在地までの距離+1
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;

ll dp[3007][3007];
int main(){
    ll n,t;
    cin>>n>>t;
    vector<lP>food(n);
    rep(i,n){
        cin>>food[i].second>>food[i].first;
    }
    sort(food.begin(),food.end());
    dp[0][0]=0;
    rep(i,n)rep(j,t){
        if(i==0){        
            dp[i][j]=0;
        }
        if(j<food[i].second){
            dp[i+1][j]=dp[i][j];
            
        }
        else dp[i+1][j]=max(dp[i][j],dp[i][j-food[i].second]+food[i].first);
    }
    int index=n,tt=t-1;

    while(index>0){
        if(dp[index][tt]==dp[index-1][tt])break;
        tt-=food[index-1].second;
        index--;
    }
    ll ans=dp[n][t-1];
    //cout<<ans<<endl;
    if(index!=0)ans+=food[index-1].first;
    ans=max(ans,dp[n-1][t-1]+food[n-1].first);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define cont continue
#define rep(i, n) for(int i = 0 ; i < (n) ; i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INF = 987654321;
bool isprime[10000001] = {};
vector<ll> prime;
ll dp[10000001] = {};
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false); 
  memset(isprime, true, sizeof(isprime));
  isprime[1] = false;
  for(ll i = 2 ; i <= sqrt(10000000) ; i++) {
    if(isprime[i]) {
      dp[i] = i;
      prime.pb(i);
    }
    for(ll j = i * i ; j <= 10000000 ; j += i) {
      if(dp[j] == 0) dp[j] = i; 
      isprime[j] = false;
    }
  }
  ll N;
  cin >> N;
  ll ans = 0;

  for(int i = 1 ; i <= N ; i++) {
    ll cur = i;
    ll tmp = 0;
    if(i == 1) {
      ans++;
      cont;
    }
    if(dp[cur] == 0) {
      ans += i * 2;
    }
    else {
      ll cnt = 1;
      while(dp[cur] != 0) {
        ll t = cur;
        ll cnt2 = 0;
        while(t % dp[cur] == 0) {
          t /= dp[cur];
          cnt2++;
        }
        cur = t;
        cnt *= (cnt2 + 1);
      }
      if(cur > 1) cnt *= 2;
      ans += cnt * i;
    }
  }
  cout << ans << endl;
} 

Measured memory_bytes: 91544
def GCD(x,y):
    if y==0:
        return x
    return GCD(y,x%y)

def func(x):
    if x <= 1:
        return []
    for i in range(2,int(x**0.5)+1):
        if x%i == 0:
            count = 0
            while x%i==0:
                x //= i
                count += 1
            return [[i,count]]+func(x)
    return [[x,1]]
MOD = 10**9+7
N = int(input())
A = list(map(int,input().split()))
lcm = [0]*(10**6)
for i in A:
    for a,b in func(i):
        lcm[a] = max(lcm[a],b)
L = 1
for i in range(2,10**6):
    L *= pow(i,lcm[i],MOD)
    L %= MOD
ans = 0
for i in A:
    ans += L*pow(i,MOD-2,MOD)
    ans %= MOD
print(ans)



Measured memory_bytes: 55900
#include <bits/stdc++.h>
#define SpeeD ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
#define endl '\n'
//pair<int, int> *p=new pair<int, int>[n];
//std::vector<pair<int,int>> vp;
//v.push_back(make_pair(x,y))
//pair<int, int> p[1000001];
//string *s=new string [n];
//int freq[e];
//freq[a[i]-'a']++; freq[a[i]]++;
using namespace std;
ll n, t, m, c1, c2, c, x, y, sum, mn = 999999999, avg, pos, dif, j, dis, mx, xi, yi, q;
vector<ll>v;
set<int>s;
map<string, ll >mp;
bool PE ( int x )
{
    for ( int i = 2; i * i <= x; i++ )
        if ( x % i == 0 )
            return false;
    return true;
}
bool PR ( string s )
{
    int n = s.length();
    for ( int i = 0; i < n / 2; i++ )
        if ( s[i] != s[n - i - 1] )
            return false;
    return true;
}

int main ( void )
{
    cin>>n>>t;
    cout<<n*t;
   
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
/*
    p = 
*/
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn], best[maxn];
int n;
long long cnt[maxn];
int main() {
#ifdef LDT
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    best[1] = 1;
    for (int i = 1; i <= n; ++i) {
        best[i] = best[i - 1];
        if (a[i] > a[best[i]]) best[i] = i;
    }
    int cur = best[n];
    map<int, int> st;
    for (int j = cur + 1; j <= n; ++j)
        st[a[j]] += 1;
    while (cur != 1) {
        int nxt = best[cur - 1];
        pair<int, int> ele = {a[nxt], 1};
        cnt[cur] += a[cur] - a[nxt];
        while (st.size() && st.rbegin()->first >= a[nxt]) {
            int diff = st.rbegin()->first - a[nxt];
            cnt[cur] += 1ll * diff * st.rbegin()->second;
            
            ele.second += st.rbegin()->second;
            auto it = st.end();
            --it;
            st.erase(it);
        }
        for (int j = nxt + 1; j < cur; ++j)
            st[a[j]] += 1;
        st[ele.first] += ele.second;
        cur = nxt ;
    }
    st[a[1]] += 1;
    for (auto it : st)
        cnt[1] += 1ll * it.first * it.second;
    for (int i = 1; i <= n; ++i)
        cout << cnt[i] << '\n';
    return 0;
}

Measured memory_bytes: 5888
#include <stdio.h>

int main(void){

	int a,b,c;

	scanf("%d %d %d",&a,&b,&c);

	if ((a < b) && (b < c)){
		printf("%d %d %d\n",a,b,c);
	}else if((a < b) && (b > c)){
		if(a < c){
			printf("%d %d %d\n",a,c,b);
		}else{
			printf("%d %d %d\n",c,a,b);
		}
	}else if ((a > b) && (a > c)){
		if(b > c){
			printf("%d %d %d\n",c,b,a);
		}else{
			printf("%d %d %d\n",b,c,a);
		}
	}
	return 0;
}

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

int main()
{
  int a,b,c,N;

  cin>>N;

  for(int i=0;i<N;i++){
    cin>>a>>b>>c;
    if((a*a==(b*b+c*c)) || (b*b==(a*a+c*c)) || (c*c==(a*a+b*b)))
      cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }

  return 0;
}



Measured memory_bytes: 3000
#include <stdio.h>
#include <string.h>
#define MAXLINE 200

void
rotate(char *, int);

void
flip(char *, int, int);

int
main(void)
{
    char str[MAXLINE + 1];
    int h, n, hSum;
    while (scanf("%200s", str) && str[0] != '-') {
        hSum = 0;
        for (scanf("%d", &n); n > 0; n--) {
            scanf("%d", &h);
            hSum += h;
        }
        rotate(str, hSum);
        printf("%s\n", str);
    }
}

void
rotate(char *str, int r)
{
    r %= strlen(str);
    if (r) {
        flip(str, 0, r - 1);
        flip(str, r, strlen(str) - 1);
        flip(str, 0, strlen(str) - 1);
    }
}

void
flip(char *str, int st, int end)
{
    char tmp;
    for ( ; st < end; st++, end--) {
        tmp = str[st];
        str[st] = str[end];
        str[end] = tmp;
    }
}



Measured memory_bytes: 2048
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}"<<endl;
  return o;
}

//逆元　a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m; 
  if (u < 0) u += m;
  return u;
}
ll const mod = 1e9+7;

// combination
const int MAX = 510000;
const ll MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// べき乗
ll modpow(ll x, ll n) {
    x = x%MOD;
    if(n==0) return 1;  //再帰の終了条件

    else if(n%2==1) {
        return (x*modpow(x, n-1))%MOD;  //nが奇数ならnを1ずらす
    }
    else return modpow((x*x)%MOD, n/2)%MOD;  //nが偶数ならnが半分になる
}

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i,N) cin >> A[i];
  ll ans = 0;
  rep(i,N) {
    if (i==0) continue;
    ans += max((ll) 0,A[i-1]-A[i]);
    chmax(A[i],A[i-1]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 4840