akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    ll n;
    string s;
    cin >> n;
    cin >> s;
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        string a = s.substr(0, i);
        string b = s.substr(i, n);
        sort(a.begin(), a.end());
        a.erase(unique(a.begin(), a.end()), a.end());
        sort(b.begin(), b.end());
        b.erase(unique(b.begin(), b.end()), b.end());
        ll cnt = 0;
        for (auto& e1: a) {
        	for (auto& e2: b) {
              cnt += e1 == e2;
        	}
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
H,W,M=map(int, input().split())
sumh=[0]*H
sumw=[0]*W
bomb=[]
for i in range(M):
  h,w=map(int, input().split())
  sumh[h-1]+=1
  sumw[w-1]+=1
  bomb.append((h,w))

maxh=max(sumh)
maxw=max(sumw)
ch=sumh.count(maxh)
cw=sumw.count(maxw)

cnt=0
for h,w in bomb:
  if sumh[h-1]==maxh and sumw[w-1]==maxw:
    cnt+=1

if cnt==ch*cw:
  print(maxh+maxw-1)
else:
  print(maxh+maxw)

Measured memory_bytes: 54216
def main():
    while True:
        try:
            a, b = map(int, input().split())
            
            gcd = rec(a, b)
            lcm = a * b / gcd

            print(gcd, int(lcm))
        except:
            break

def rec(i, j):
    if i % j == 0:
        return j
    return rec(j, i % j)

if __name__ == '__main__':
    main()

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

#define int long long
#define fi first
#define se second
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) ct(v[i])
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int n,m,a,b;
vector<int> v[200000];

main() {
    cin >> n >> m,n--;
    rep(i,m) cin >> a >> b,v[a-1].pb(b-1);
    rep(i,v[0].size()) rep(j,v[v[0][i]].size()) if (v[v[0][i]][j] == n) {ct("POSSIBLE")return 0;}
    ct("IMPOSSIBLE")
}


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

int main() {
	
	int n; cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++) cin>>a[i];
	
	int dp[n+1];
	dp[1]=0;
	dp[2]=abs(a[2]-a[1]);
	
	for(int i=3;i<=n;i++) {
		dp[i]=min((dp[i-1]+abs(a[i]-a[i-1])),(dp[i-2]+abs(a[i]-a[i-2])));
	}
	
	cout<<dp[n]<<endl;
	return 0;
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

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

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

int n;
vi es[100000];

int dfs(int v){
  vi u;
  for(int to : es[v]){
    u.emplace_back(dfs(to));
  }

  sort(all(u));
  reverse(all(u));

  int ret = 0;
  rep(i, 0, sz(u)){
    chmax(ret, u[i]+i+1);
  }
  return ret;
}

signed main(){
  cin >> n;
  rep(i, 1, n){
    int a;
    cin >> a;
    a--;
    es[a].emplace_back(i);
  }

  cout << dfs(0) << endl;

  return 0;
}


Measured memory_bytes: 13568
#include<stdio.h>
#include<string.h>

int main(void)
{
   int i, a, x=0;
   char s[101];

   scanf("%s",s);

   a=strlen(s);

   for(i=0;i<a/2;i++)
      if(s[i]!=s[a-i-1])
         x++;

   printf("%d\n",x);
   return 0;
}

Measured memory_bytes: 128
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end
def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
require 'prime'
a, b = gsmi

ap = a.prime_division
bp = b.prime_division

putsend(1) if a==1||b==1

# 1のぶんを含める
cnt = 1
ap.each do |x,y|
  idx = bp.index{|n|n[0]==x}
  cnt+=1 unless idx.nil?
end

puts cnt


Measured memory_bytes: 2300
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>

using namespace std;

template<class T> inline void coupon(T & a) {
	a /= 2;
}

int main(void) {
	int n, m; cin >> n >> m;
	long long a;
	priority_queue<long long> que;

	for (int i = 0; i < n; i++) {
		scanf("%lld", &a);
		que.push(a);
	}

	int root;
	for (int i = 0; i < m; i++) {
		root = que.top();
		coupon(root);
		que.pop();
		que.push(root);
	}

	long long sum = 0;
	for (int i = 0; i < n; i++) {
		sum += que.top();
		que.pop();
	}
	cout << sum << endl;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if ((A + B) > (C + D)) {
    cout << "Left" << endl;
  }
  
  else if ((A + B) < (C + D)) {
    cout << "Right" << endl;
  }
  
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
from functools import reduce
from math import gcd
def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    M = max(A)

    if reduce(gcd, A) != 1:
        print("not coprime")
        return

    # linear sieve
    sieve = list(range(M + 1))
    primes = []
    for i in range(2, M + 1):
        if sieve[i] == i:
            primes.append(i)
        for p in primes:
            if sieve[i] < p or i * p > M:
                break
            sieve[i * p] = p

    # prime factorization
    used = [False] * (M + 1)
    for a in A:
        primes = set()
        while a != 1:
            p = sieve[a]
            primes.add(p)
            a //= p
        for p in primes:
            if used[p]:
                print("setwise coprime")
                return
            used[p] = True
    print("pairwise coprime")
resolve()

Measured memory_bytes: 193532
/**
	������������ Author : Avi J Patel ������������
	������������ University : DA-IICT ������������
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair 
#define mt make_tuple
#define N 100000
#define ff first
#define ss second
#define si size()
#define MOD 998244353
#define large 10000000000000001

#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
/*void calc()
{
	for(int i=0;i<2005;i++)
	{
		a[i][0]=1;
		a[i][i]=1;
		for(int j=1;j<i;j++)
		{
			a[i][j]=(a[i-1][j-1]+a[i-1][j])%MOD;	
		}
	}
}*/
int main()
{
	int n;
	cin>>n;
	vector<int> a(n);
	for(int  i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]!=i+1)
		{
			if(a[a[i]-1]!=i+1)
			{
				cout<<"NO";
				return 0;
			}
			cnt++;
		}
	}
	if(cnt==2 || cnt==0){
		cout<<"YES";
	}
	else
	cout<<"NO";
}









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

int main(void){
    int n,k; cin >> n >> k;
    string s; cin >> s;
    int front=0,end=0;
    while(s[front]=='1' && front < n){
        front++;
    }
    front--;
    while(0<k && front < n){
        k--;front++;
        while(s[front]=='0' && front < n){
            front++;
        }
        while(s[front]=='1' && front < n){
            front++;
        }
        front--;
    }
    // cout << end << ' ' << front << endl;

    ll ans = front - end + 1;
    while(front<n-1){
        front++;
        while(front < n && s[front]=='0'){
            front++;
        }
        while(s[front]=='1' && front < n){
            front++;
        }
        front--;
        while(s[end]=='1' && end < n){
            end++;
        }
        while(s[end]=='0' && end < n){
            end++;
        }
        // cout << end << ' ' << front << endl;
        ll tmp = front - end + 1;
        if(ans < tmp) ans = tmp;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(){
  int a, b, c,save;
  scanf("%d %d %d",&a,&b,&c);
  if(b>c){
  save = c;
  c = b;
  b = save;
  }
  if(a>b){
  save = b;
  b = a;
  a = save;
  }
  if(b>c){
  save = c;
  c = b;
  b = save;
  }
  printf("%d %d %d\n",a,b,c);

  return 0;
}

Measured memory_bytes: 596
S = input()
man = 0
cnt = 0
l = ['A', 'C', 'G', 'T']
for s in S:
    res = False
    for i in l:
        if s == i:
            cnt += 1
            res = True
    if res == False:
        cnt = 0
    if man < cnt:
        man = cnt
print(man)

Measured memory_bytes: 3060
n, m = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
Dis = [0]*(m-1)

if n >= m:
    print(0)
    exit()

for i in range(m-1):
    diff = abs(X[i]-X[i+1])
    Dis[i] = diff

Dis.sort()

for i in range(n-1):
    Dis.pop()

print(sum(Dis))

Measured memory_bytes: 13968
program answer
  implicit none
  integer :: A, B, C, K, i

  read(*,*) A, B, C
  read(*,*) K
  
  do i = 1, K
     if(B<=A) then
        B=B*2
     else
        if(B>=C) then
           C=2*C
        end if
     end if
     if(B>A.and.C>B) then
        write(*,*) 'Yes'
        stop
     end if
  end do

  write(*,*) 'No'
  stop
 end program answer
        

Measured memory_bytes: 2856
#include <bits/stdc++.h>
using namespace std;
int main(){
 int a,b;
 cin >> a >> b;
 string s1="", s2 = "";
 for(int i =0; i < a; i++){
        s1+= to_string(b);
 }
 for(int i =0; i < b; i++){
        s2+= to_string(a);
 }
 
 
 if(s1 < s2){
        cout << s1 << endl;
        
 }
 
 else
 cout << s2 << endl;
 
}





Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<deque>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
	string s;cin >> s;bool n = false, S = false, w = false, e = false;
	rep(i, s.size()) {
		if (s[i] == 'N') n = true;
		else if (s[i] == 'S') S = true;
		else if (s[i] == 'W') w = true;
		else e = true;
	}
	if (n == S) n = true;
	else n = false;
	if (w == e) w = true;
	else w = false;
	if (n && w) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int main(){
 int k,ans=-1,i,a=0;
 cin >> k;
 for(i=1;i<=k;i++){
  a*=10;
  a+=7;
  if(a%k==0){
   ans=i;
   break;
  }
  a%=k;
 }
 cout << ans << endl;
 return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pll=pair<ll,ll>;
using plll=pair<ll,pll>;
using graph=vector<vector<int>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1){
      ret*=a;
    }
    a*=a;
    if(a>=p)a%=p;
    b=b>>1;
  }
  return ret;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modInv(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  int i;
  ll ret=1;
  for(i=0;i<n;i++){
    ret=ret*(i+1);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll binom(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1,fact=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    fact*=i+1;
    if(ret>=p)ret%=p;
    if(fact>=p)fact%=p;
  }
  return (ret*modInv(fact))%p;
}

void pushHeap(vector<int>& h,int n){
  int i=h.size();
  h.push_back(n);
  while(i!=0 && h[(i-1)/2]<h[i]){
    swap(h[i],h[(i-1)/2]);
    i=(i-1)/2;
  }
  h[i]=n;
}

int popHeap(vector<int>& h){
  int n=h.size()-1;
  if(n==-1)return 0;
  int i,ret=h[0];
  swap(h[0],h[n]);
  h.pop_back();
  for(i=0;i<n;){
    int j=2*i+1;
    if(j>=n)break;
    if(j!=n-1 && h[j]<h[j+1])j++;
    if(h[i]<h[j]){
      swap(h[i],h[j]);
    }
    i=j;
  }
  return ret;
}

vector<int> ver;
void dfs(const graph &g,int v){
  ver[v]=1;
  for(auto i:g[v]){
    if(ver[i]!=1)continue;
    dfs(g,i);
  }
}

int main(){
  int i,j,k,cnt=0;
  int n;
  cin>>n;
  vector<int> v,p;
  int d[55556];
  for(i=0;i<=55555;i++)d[i]=0;
  for(i=2;i<=55555;i++){
    if(i%10!=3)continue;
    cnt=1;
    int q=(int)round(sqrt(i));
    for(j=2;j<=q;j++){
      if(i%j==0){
        cnt=0;
        break;
      }
    }
    if(cnt==1)d[i]=1;
  }
  for(i=0;i<=55555;i++){
    if(n==0)return 0;
    if(d[i]==1){
      cout<<i<<endl;
      n--;
    }
  }
}

Measured memory_bytes: 512
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define mp make_pair

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

inline void scani(int& x){
	scanf("%d",&x);
}

//end of macro

bool dislike[10];
bool valid(int x){
    while(x){
        if(dislike[x%10])return false;
        x /= 10;
    }
    return true;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);
    
    int n,k;
    cin>>n>>k;
    REP(i,1,k){
        int x;
        cin>>x;
        dislike[x] = true;
    }
    
    while(!valid(n)){
        n++;
    }
    cout << n << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
const int maxn=3e5+5;
int a[maxn],n,m;
ll p[2*maxn],all=0; 
int max(int a,int b)
{
	return a>b?a:b;
}
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=1;i<n;i++)
	{
		
		int l=a[i],r=a[i+1];
		if(r<l)r+=m;
		all+=r-l;
		if(r-l>1)
		{
			p[l+2]+=1;
			p[r+1]-=r-l;
			p[r+2]+=r-l-1;
		}
	}
	for(int i=1;i<=2*m;i++) p[i]+=p[i-1];
	for(int i=1;i<=2*m;i++) p[i]+=p[i-1];
	ll ans=-1;
	for(int i=1;i<=m;i++)
	{
		ans=max(ans,p[i]+p[i+m]);
	}
	cout<<all-ans<<endl;
}

Measured memory_bytes: 2176
s = list(input())

max_num = min(len(s),100)

if len(s) == 2 and s[0] == s[1]:
    print(1,2)
    exit()

for k in range(3,max_num,2):
    l = [0]*26
    for kk in range(k):
        l[ord(s[kk])-97] += 1
    if max(l) == (k+1)//2:
        print(1,k)
        exit()

    for i in range(k,len(s)):
        l[ord(s[i-k])-97] -= 1
        l[ord(s[i])-97] += 1
        if max(l) == (k+1)//2:
            print(i-k+2,i+1)
            exit()

print(-1,-1)


Measured memory_bytes: 49648
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;

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


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::cout << std::ceil( (double)N/2 ) << std::endl;
  return 0;
}


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

using Weight = long long;

class Edge {
public:
  int src, dst;
  Weight w;
  Edge(): src(0), dst(0), w(0) {}
  Edge(int src, int dst, Weight w): src(src), dst(dst), w(w) {}
};

using Edges = vector < Edge >;
using Graph = vector < Edges >;

void addArc(Graph &g, int a, int b, Weight w = 1) {
  g[a].emplace_back(a, b, w);
}


void BellmanFord(const Graph&g, int s) {
  const Weight INF = numeric_limits<Weight>::max() / 4;
  Edges edges;
  for (auto& es: g) for (auto& e: es) edges.emplace_back(e);
  vector < Weight > dist(g.size(), -INF);
  dist[s] = 0;
    
  for (int i = 0; i <= 2 * g.size(); ++i) {
    for (auto& e: edges) {
      if (dist[e.src] != INF && dist[e.dst] < dist[e.src] + e.w) {
        if (i > g.size() && e.dst == g.size() - 1) {
          cout << "inf" << endl;
          return;
        }
        dist[e.dst] = dist[e.src] + e.w;
      }
    }
  }
  cout << dist[g.size() - 1] << endl;
}

int main() {
  int n, m;
  cin >> n >> m;
  Graph g(n);

  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    addArc(g, a, b, c);
  }
  BellmanFord(g, 0);
  return 0;
}


Measured memory_bytes: 504
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
using namespace std;
#define dbg(x) cerr << #x " = " << x <<endl;

string op;
char ans[1000];
int main()
{
	cin >> op;
	int  n = op.size();
	int cur = 0;
	for(int i = 0; i < n; i++)
	{
		if(op[i] == '0')
		{
			ans[cur++] = '0';
		}
		else if(op[i] == '1')
		{
			ans[cur++] = '1';
		}
		else if(op[i] == 'B')
		{
			if(cur > 0) cur--;
		}
	}
	for(int i = 0; i < cur; i++)
	{
		cout << ans[i];
	}
 } 

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

#define debug(args...) //fprintf (stderr, args)

typedef long long ll;
const int maxn = 1e5 + 10;

int n;
ll h[maxn], A, B;

bool ok (ll x)
{
	ll total = 0LL;

	for (int i = 1; i <= n; ++i)
	{
		ll a = h[i];

		a -= x * B;

		if (a <= 0)
			continue;

		total += (a / A) + (a % A != 0);

		if (total > x)
			return false;
	}

	return (total <= x);
}

ll solve ()
{
	ll ini = 0;
	ll fim = 1e9;

	A -= B;

	for (int k = 0; k < 100; ++k)
	{
		ll mid = (ini + fim) / 2LL;

		if (ok (mid))
			fim = mid;
		else
			ini = mid;
	}

	while (fim - 1 >= 0 && ok(fim - 1))
		--fim;

	return fim;
}

int main ()
{
	cin >> n >> A >> B;

	for (int i = 1; i <= n; ++i)
		cin >> h[i];

	cout << solve() << '\n';
	return 0;
}

Measured memory_bytes: 1024
a, b, c, x = [int(input()) for _ in range(4)]
count = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if i * 500 + j * 100 + k * 50 == x:
                count += 1
print(count)

Measured memory_bytes: 39536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll x,y;
    cin>>x>>y;
    if(x%y==0)
    {
        cout<<-1<<endl;
        return 0;
    }
    for(ll i=x;i<=1e18;i+=x)
    {
        if(i%y!=0)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 256
n = int(input())
ans = [0 for _ in range(10001)]
for i in range(1,100):
    for j in range(1,100):
        for k in range(1,100):
            v = i*i+j*j+k*k+i*j+j*k+k*i
            if v<=10000:
                ans[v]+=1
 
for i in range(n):
    print(ans[i+1])
    

Measured memory_bytes: 9200
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
bc = [x + y for y in c for x in b]
bc.sort(reverse=True)
ans = [x + y for y in a for x in bc[:k]]
ans.sort(reverse=True)
print(*ans[:k], sep="\n")


Measured memory_bytes: 147924
import math
from functools import lru_cache
from operator import mul
from functools import reduce


def cmb(n, r, mod):
    numerator = reduce(lambda x, y: x * y % mod, [n - r + k + 1 for k in range(r)])
    denominator = reduce(lambda x, y: x * y % mod, [k + 1 for k in range(r)])
    return numerator * pow(denominator, mod - 2, mod) % mod


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def my_factorial(n, mod):
    if n == 1:
        return 1
    return (n * my_factorial(n-1, mod)) % mod


@lru_cache(maxsize=None)
def for_factorial(n):
    val = 1
    for i in range(2, n + 1):
        val = (val * i)
    return val



x, y = map(int, input().split())
mod = 1000000007
cnt = (x + y) // 3
if (x + y) % 3 != 0:
    print(0)
    exit()
m = min(x, y)
num_2 = m - cnt
num_1 = cnt - num_2
ans = cmb(cnt, num_1, mod)
print(ans)



Measured memory_bytes: 102988
# coding: utf-8
n = int(input())
a = [n]
ans = 1
while True: 
    if n%2 == 0:
        n = n // 2
    else:
        n = 3 * n + 1
    if n in a:
        break
    a.append(n)
    ans+=1
print(ans+1)

Measured memory_bytes: 2940
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int K = sc.nextInt();
        if(A+B>=K) {
            System.out.println(Math.min(K, A));
            return;
        }
        System.out.println(A-(K-(A+B)));
    }
}


Measured memory_bytes: 35536
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long A = sc.nextLong();
    long B = sc.nextLong();
    long C = sc.nextLong();
    Long K = sc.nextLong();
    long total = 0;
    
    if(K<=A) {
      total = K;
    } else if(K<=A + B) {
      total = A;
    } else {
      total = A - (K - A - B);  
    }
    System.out.println(total);
  }
}

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

#define rep(i,M,N) for(int i=M;i<N;i++)

int main(){
    int  N,M;
    int sum = 0;
    cin>>N;
    vector<int> T(N);

    rep(i,0,N){
        cin>>T[i];
        sum+=T[i];
    }

    cin>>M;
    vector<pair<int,int>> PX;

    rep(i,0,M){
        int p,x;
        cin>>p>>x;
        PX.push_back(make_pair(p,x));
    }


    for(auto i : PX){
        cout<<sum - T[i.first-1] + i.second<<endl;
    }

}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int time = 0;
		
		for(int i = 0; i < 4; i++)
			time += sc.nextInt();
		
		System.out.println(time / 60);
		System.out.println(time % 60);
		
		sc.close();
	}
}

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

int main(){
  int n,m;
  cin >> n >> m;

  int ans = 0;
  for(int i=0;i<n;i++){
    cout << "lst " <<  i << endl;
    int k;
    cin >> k;
    vector<int> d(k);
    for(int j=0;j<k;j++) cin >> d[j];

    ans += k*(k-1);
  }

  cout << "ans " << ans << endl;
}

Measured memory_bytes: 3092
# -*- coding: utf-8 -*-
n = input() # 2 ~ 99
an = [int(x.strip()) for x in input().split(' ')]

count = 0
check = 0
for i in an:
  if i % 2 == 0:
    check += 1
    if i % 3 == 0 or i % 5 == 0:
      count += 1
if count == check or check == 0:
  print('APPROVED')
else:
  print('DENIED')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

signed main(){
	int n;
	cin >> n;

	int ans = 0;
	vector<int> a;
	for(int i = 1e9; i > 0; i /= 10){
		a.emplace_back(i);
	}

	for(int i = 3; i <= n; i++){
		for(int j = 1e9; j > 0; j /= 10){
			if(i >= j and  i / j % 2 == 0){
				i += j - 1;
				break;
			}
		}

		vector<bool> res(4, 0);
		for(int j = i; j > 0;){
			int a = j % 10;
			j /= 10;

			res[0] = res[0] or a == 3;
			res[1] = res[1] or a == 5;
			res[2] = res[2] or a == 7;
			res[3] = res[3] or (a != 3 and a != 5 and a != 7);
			if(res[3]) break;
		}
		if(res[0] and res[1] and res[2] and not res[3]) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
n, k = [int(x) for x in input().split()]
# ps = [int(x) for x in input().split()]

continuous_sum = (lambda n: (n + 1) * (n // 2) + (0 if n %2 == 0 else n // 2 + 1))
calc_expectedval = (lambda p: continuous_sum(p) / p)
expected_vals = [calc_expectedval(int(x)) for x in input().split()]

prevval = sum(expected_vals[0:0+k])
maxval = prevval
for i in range(n - k):
  candidate = prevval - expected_vals[i] + expected_vals[i + k]
  if candidate > maxval:
    maxval = candidate
  prevval = candidate

print(maxval)

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//template end

int mod=1e9+7;
struct Mint {
  int val;
  Mint inv() const{
    int tmp,a=val,b=mod,x=1,y=0;
    while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
    return Mint(x);
  }
public:
  Mint():val(0){}
  Mint(ll x):val(x>=0?x%mod:x%mod+mod){}
  Mint pow(ll t){Mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
  Mint& operator+=(const Mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
  Mint& operator-=(const Mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
  Mint& operator*=(const Mint& x){val=(ll)val*x.val%mod; return *this;}
  Mint& operator/=(const Mint& x){return *this*=x.inv();}
  bool operator==(const Mint& x) const{return val==x.val;}
  bool operator!=(const Mint& x) const{return val!=x.val;}
  bool operator<(const Mint& x) const{return val<x.val;}
  bool operator<=(const Mint& x) const{return val<=x.val;}
  bool operator>(const Mint& x) const{return val>x.val;}
  bool operator>=(const Mint& x) const{return val>=x.val;}
  Mint operator+(const Mint& x) const{return Mint(*this)+=x;}
  Mint operator-(const Mint& x) const{return Mint(*this)-=x;}
  Mint operator*(const Mint& x) const{return Mint(*this)*=x;}
  Mint operator/(const Mint& x) const{return Mint(*this)/=x;}
};
struct factorial {
  vector<Mint> Fact, Finv;
public:
  factorial(int maxx){
    Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1);
    Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i;
  }
  Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
  Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
  Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};

Mint dp[3010][3010];

int main(){
  int n; scanf("%d",&n);
  string s; cin>>s;
  rep(i,0,n)dp[0][i]=1;
  rep(i,0,n-1){
    Mint sum[3010]; sum[0]=dp[i][0];
    rep(j,1,n-i+1)sum[j]=sum[j-1]+dp[i][j];
    if(s[i]=='<')rep(j,0,n-i)dp[i+1][j]=sum[n-i-1]-sum[j];
    else rep(j,0,n-i+1)dp[i+1][j]=sum[j];
  }
  printf("%d\n",dp[n-1][0].val);
  return 0;
}

Measured memory_bytes: 35712
n=int(input())
ii=input().split(" ")
flower=[]
count=0
end=n

for i in ii:
  flower.append(int(i))

#print (flower)

while True:
  end=n
  if flower[0]==0:
    del flower[0]
    n=n-1
    if n==0:
      print(str(count))
      exit()
    else:
      continue
  for j in range(0,n):
    if flower[j]==0:
      end=j
      break
    
  for m in range (0,end):
    flower[m]=flower[m]-1
  #print(end)
  count=count+1
  #print(flower)
  continue

Measured memory_bytes: 3064
import math
a,b,C = map(float,input().split(' '))
S = a*b*math.sin(math.radians(C)) / 2.0
c = math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(C)))
h = 2*S/a
print(S)
print(a+b+c)
print(h)


Measured memory_bytes: 7780
log = console.log;

var stdin = require("fs").readFileSync("/dev/stdin", "UTF-8");
var lines = stdin.split("\n");
var N = Number(lines[0].split(" ")[0]);
var M = Number(lines[0].split(" ")[1]);
var XS = lines[1]
  .split(" ")
  .map(v => ~~v)
  .sort((a, b) => a - b);

if (N >= M) {
  log(0);
} else {
  LS = [];
  for (var i = 0; i < XS.length - 1; i++) {
    var L = XS[i + 1] - XS[i];
    LS.push(L);
  }

  LS.sort((a, b) => a - b);
  sum = LS.slice(0, M - N).reduce((a, c) => a + c);

  log(sum);
}

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

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0; i<n; i++){
    scanf("%d",&a[i]);
  }
  for(int j=(n-1); j>=0; j-=1){
    printf("%d",a[j]);
    if(j!=0){
      printf(" ");
    }
  }
    cout << endl;
}

Measured memory_bytes: 3180
/*input
4
1 4 6 3
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long lol;

int ans = 0, n, sml, big, now;

int main() {
    cin >> n >> big >> now;
    sml = min(big, now);
    big = max(big, now);
    ans = abs(big - now);

    for (int i = 3; i <= n; i++) {
        cin >> now;
        sml = min(sml, now);
        big = max(big, now);
        
        ans = max(ans, big - sml);
    }
    cout << ans << '\n';
    return 0;
}

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 210000;
vi e[maxn];
int d[maxn];
int n;
int D = 0;

void dfs(int v, int p) {
    int mx1 = 0, mx2 = 0;
    d[v] = 1;
    for (int u: e[v]) {
        if (u == p) continue;
        dfs(u, v);
        uax(d[v], d[u] + 1);
        int x = d[u];
        if (x > mx1) swap(x, mx1);
        if (x > mx2) swap(x, mx2);
    }
    uax(D, 1 + mx1 + mx2);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    cin >> n;
    forn(i, n - 1) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        e[u].pb(v);
        e[v].pb(u);
    }
    dfs(0, -1);
//    cerr << D << '\n';
    cout << (D % 3 == 2 ? "Second" : "First") << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


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

int main(int argc, char const* argv[])
{
  int N; cin >> N;
  vector<int> a(N); for (int i = 0; i < N; i++) cin >> a[i];
  vector<int> b(N + 1); for (int i = 0; i < N; i++) b[a[i]] = i;
  ll ans {};
  set<int> s { -1, N };
  for (int i = 1; i <= N; i++) {
    s.insert(b[i]);
    auto itr = s.find(b[i]);
    int l, r;
    itr--; l = *itr; itr++;
    itr++; r = *itr; itr--;
    ans += (ll)i * (*itr - l) * (r - *itr);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 11136
def fact(n):
    f = 1
    while n >= 1:
        f = f * n
        n = n - 1
    return f


def findSmallerInRight(st, low, high):
    countRight = 0
    i = low + 1
    while i <= high:
        if st[i] < st[low]:
            countRight = countRight + 1
        i = i + 1

    return countRight

def findRank(st):
    ln = len(st)
    mul = fact(ln)
    rank = 1
    i = 0

    while i < ln:
        mul = mul / (ln - i)
        countRight = findSmallerInRight(st, i, ln - 1)

        rank = rank + countRight * mul
        i = i + 1

    return int(rank)


n=int(input())
l1=list(map(int, input().split()))
l2=list(map(int, input().split()))

s1=""
s2=""

for x in l1:
    s1=s1+str(x)

for x in l2:
    s2=s2+str(x)


print(abs(findRank(s1) - findRank(s2)))

Measured memory_bytes: 3064
N=int(input())
list=[str(i) for i in [11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381]]
print(" ".join(list[:N]))

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

int main(){
  int N,M;
  map<int,int> D,T;
  cin>>N;
  for(int i=0;i<N;i++){
    int j;
    cin>>j;
    D[j]++;
  }
  cin>>M;
  for(int i=0;i<M;i++){
    int j;
    cin>>j;
    T[j]++;
  }
  for(pair<int,int> i:T)
    if(i.second>D[i.first]){
      cout<<"NO"<<endl;
      return 0;
    }
  cout<<"YES"<<endl;
}

Measured memory_bytes: 18944
package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	result := "No"
	if a == b {
		if a != c {
			result = "Yes"
		}
	}
	if a == c {
		if a != b {
			result = "Yes"
		}
	}
	if b == c {
		if a != b {
			result = "Yes"
		}
	}
	fmt.Println(result)

}


Measured memory_bytes: 512
x = int(input())

def prime(n):
    ans = "yes"
    for i in range(2,round(n**0.5)+1):
        if n%i == 0:
            ans = "no"
            break
        else:
            continue
    if ans == "yes":
        return n
    else:
        return prime(n+1)
    

if x == 2 or x == 3:
    print(x)
else:
    print(prime(x))


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod=1e9+7;
//const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    string s;
    cin>>s;
    int p=2019;
    map<int,ll> m;
    m[0]++;
    ll ans=0,sum=0,d=1;
    for(int i=s.length()-1;i>=0;i--){
        sum=(sum+d*(s[i]-'0')%p)%p;
        ans+=m[sum];
        m[sum]++;
        d=(d*10)%p;
    }
    cout<<ans;
    return 0;
}



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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define INF 2000000000000000000LL
#define EPS 1e-9
#define debug(a) cerr<<#a<<"="<<(a)<<"\n"
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL);

typedef long long ll;
typedef unsigned long long ull;
typedef complex<double> cd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll mod = 1e9+7;
const double PI = acos(-1);

int n,i,j,k,t;
ll c;
int h[200006];
ll dp[200006];

ostream& operator<<(ostream& out, pll x){
    out <<"("<<x.fi<<","<<x.se<<")";
    return out;
}

ll p2(ll val){
    return val*val;
}

ll f(pll curve, ll x){
    return p2(x - curve.fi) + curve.se;
}

double g(pll a, pll b){
    return 1.0*(p2(b.fi)+b.se-p2(a.fi)-a.se)/2/(b.fi-a.fi);
}

int main(){
    scanf("%d %lld", &n, &c);
    for(i=1;i<=n;++i)
        scanf("%d", h+i);
    deque<pll> curve;
    dp[1] = 0;
    curve.push_back({h[1], dp[1]+c});
    for(i=2;i<=n;++i){
        pll tmp = curve.front();
        curve.pop_front();
        while(!curve.empty()){
            // cout<<"hit 1"<<" "<<tmp<<" "<<curve.front()<<" "<<f(tmp, h[i])<<" "<<f(curve.front(), h[i])<<endl;
            if(f(tmp, h[i]) >= f(curve.front(), h[i])){
                tmp = curve.front();
                curve.pop_front();
            }
            else
                break;
        }
        // cout<<i<<" "<<h[i]<<" "<<tmp<<endl;
        dp[i] = f(tmp, h[i]);
        curve.push_front(tmp);
        tmp = {h[i], dp[i]+c};
        // cout<<"add "<<tmp<<endl;
        while(curve.size()>1){
            pll ttmp = curve.back();
            curve.pop_back();
            // cout<<"hit2 "<<curve.back()<<" "<<ttmp<<" "<<tmp<<" "<<g(curve.back(), ttmp)<<" "<<g(curve.back(), tmp)<<endl;
            if(g(curve.back(), ttmp) < g(curve.back(), tmp)){
                curve.push_back(ttmp);
                break;
            }
        }
        curve.push_back(tmp);
    }
    printf("%lld\n", dp[n]);
    return 0;
}

Measured memory_bytes: 4864
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    long sum = 0;
    for(int i = 0; i < m; i++){
        int b;
        cin >> b;
        sum += b;
    }
    long ans = 0;
    for(int i = 0; i < n; i++){
        ans += a[i]*sum;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3104
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

typedef pair<int,int> pii;
typedef pair<int,pii> pipii;

vector<pipii> vp;

int main() {
  while (true) {
    int n, m, a;
    scanf("%d %d %d", &n, &m, &a);
    if (n == 0 && m == 0 && a == 0) break;
    vp.clear();
    for (int i=0;i<m;i++) {
      int h, p, q;
      scanf("%d %d %d", &h, &p, &q);
      vp.push_back(pipii(-h,pii(p,q)));
      sort(vp.begin(), vp.end());
    }
    for (int i=0;i<vp.size();i++) {
      if (vp[i].second.first == a) a = vp[i].second.second;
      else if (vp[i].second.second == a) a = vp[i].second.first;

    }
    printf("%d\n", a);
  }
  return 0;
}

Measured memory_bytes: 2656
#include "bits/stdc++.h"
/* Properties of modulo:
	(a/b)%m ,where m is prime  = (a%m) * (b^(m-2))%m
*/
    /*ROLLING HASH
    Rabin-Karp algorithm for pattern matching in a string in O(n) time
    Calculating the number of different substrings of a string in O(n2logn)
    Calculating the number of palindromic substrings in a string.
    */
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define ll long long
#define pb push_back
#define nl cout<<"\n"
#define endl "\n"
#define all(c) (c).begin(),(c).end()
#define trav(a,x) for(auto a = x.begin() ; a != x.end() ; a++)
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
//template<typename T>
//#define o_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
// o_set(ll) name ; -- defining ordered set
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : counting from zero it returns the k-th largest or smallest element in the set - returns iterator
bool compare(ll a, ll b){
    return a > b;
}
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);}
ll power(ll x, ll ex ) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) ;
        ex >>= 1ll;
        x = (x * x) ;
    }
    return ans;
}
ll n , m , x;
vector<ll> c;
vector<ll> v[10001];
ll bit[12];
ll check(ll i){
    for(ll j = 0 ; j < 12 ;j++) bit[j] = 0;
    ll temp = i;
    for(ll j = 0 ; temp > 0 ; temp /= 2) bit[j++] = temp%2;
    ll sum[m] = {0};
    for(ll k = 0 ; k < 12 ; k++){
        if(bit[k] == 1){
            for(ll ii = 0 ; ii < m ; ii++){
                sum[ii] += v[ii][k];
            }
        }
    }
    bool flag = true;
    for(ll i = 0 ; i < m ; i++){
        if(sum[i] < x) flag = false;
    }
    if(flag){
        ll cost = 0;
        for(ll i = 0 ; i < 12 ; i++){
            if(bit[i] == 1) cost += c[i];
        }
        return cost;
    }
    else return 0;
}
void solve(){
    cin >> n >> m >> x;
    for(ll i = 0 ; i < n ; i++){
        ll a;
        cin >> a;
        c.pb(a);
        for(ll j = 0 ; j < m ; j++){
            ll b;
            cin >> b;
            v[j].pb(b);
        }
    }
    ll ans  = LLONG_MAX;
    ll len = power(2,n);
    for(ll i = 0 ; i < len ; i++){
        if(check(i)) ans = min(check(i) , ans);
    }
    if(ans != LLONG_MAX) cout << ans << endl;
    else cout << -1 << endl;
}
int main(){
    IOS;
    ll T=1;
    //cin>>T;
    ll t=0;
    while(t++<T){
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 4008
def main():
    n = int(input())
    xs = [input() for _ in range(n)]

    if judge(xs):
        print('Yes')
    else:
        print('No')

def judge(xs):
    s = set()

    for x, y in zip(xs, xs[1:]):
        s.add(x)
        if y in s:
            return False
        if x[-1] != y[0]:
            return False

    return True

main()


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    bool isTrue = false;
    for (int i = 0; 4 * i <= n; i++) {
        for (int j = 0; 4 * i + 7 * j <= n; j++){
            if (4 * i + 7 * j == n) isTrue = true;
        }
    }
    if (isTrue) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(abs(c-a)<=d){
        printf("Yes");
    }
    else if(abs(a-b)<=d && abs(b-c)<=d){
        printf("Yes");
    }
    else{
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

i64 I, O, T, J, L, S, Z;

i64 ljpair(i64 p)
{
	if (L < p || J < p || I < p) return 0LL;

	if (p < 0) return 0LL;
	i64 ret = p * 3;
	ret += (L - p) / 2 * 2;
	ret+= (J - p) / 2 * 2;
	ret += (I - p) / 2 * 2;
	return ret;
}

int main()
{
	scanf("%lld%lld%lld%lld%lld%lld%lld", &I, &O, &T, &J, &L, &S, &Z);
	i64 ret = 0;
	ret += O;
	ret += max(ljpair(0), ljpair(1));

	printf("%lld\n", ret);
	return 0;
}


Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
N , M = map(int,input().split())
divisors_list = make_divisors(M)
divisors_list.sort(reverse=True)
#print(divisors_list)
for val in divisors_list:
    if val * N <= M:
        break
print(val)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=520;
const ll inf=0x3f3f3f3f3f3f3f3f;

int n;
ll A[maxn][maxn];
ll B[maxn][maxn];

inline void init()
{
	n=read();
	REP(i,1,n)REP(j,1,n)
		if(i<j)A[i][j]=read();
		else if(i>j)B[j][i]=read();
	REP(i,1,n)REP(j,1,n)A[i][j]+=A[i-1][j];
	REP(i,1,n)REP(j,1,n)A[i][j]+=A[i][j-1];
	REP(i,1,n)REP(j,1,n)B[i][j]+=B[i-1][j];
	REP(i,1,n)REP(j,1,n)B[i][j]+=B[i][j-1];
	
}

ll f[maxn][maxn];

inline ll matrixA(int x1,int x2,int y1,int y2)
{
	if(x1>x2 || y1>y2)return 0;
	return A[x2][y2]-A[x1-1][y2]-A[x2][y1-1]+A[x1-1][y1-1];
}

inline ll matrixB(int x1,int x2,int y1,int y2)
{
	if(x1>x2 || y1>y2)return 0;
	return B[x2][y2]-B[x1-1][y2]-B[x2][y1-1]+B[x1-1][y1-1];
}

inline void doing()
{
	memset(f,inf,sizeof(f));
	f[0][0]=0;
	REP(i,0,n-1)REP(j,0,i)if(f[i][j]!=inf)
	{
		REP(k,i+1,n-1)
		{
			chkmin(f[k][i],f[i][j]+matrixA(i+1,k-1,i+1,k)+matrixB(1,j,i+1,k));
		}
	}
	ll ans=inf;
	REP(i,0,n-1)REP(j,0,i)if(f[i][j]!=inf)
	{
		chkmin(ans,f[i][j]+matrixA(i+1,n,i+1,n)+matrixB(1,j,i+1,n));
	}
	printf("%lld\n",ans);
}

int main()
{
	init();
	doing();
	return 0;
}


Measured memory_bytes: 6528