akhauriyash/Code-Regression huggingface dataset:
package main


import (
  "fmt"
)


var ans = 0


func dfs(nodeID int, graph [][]int, visited []bool) {

  var _ans = true
  for i := 0; i < len(visited); i++ {
    if (!visited[i]) {
      _ans = false
    }
  }
  if (_ans) {
    ans++
  }

  for nextNodeID := 0; nextNodeID < len(graph[nodeID]); nextNodeID++ {

    if graph[nodeID][nextNodeID] == 0 {
      continue
    }

    if visited[nextNodeID] {
      continue
    }

		visited[nextNodeID] = true
    dfs(nextNodeID, graph, visited)
    visited[nextNodeID] = false
  }
}


func main () {
  var n, m int
  fmt.Scanf("%d %d", &n, &m)

  graph := make([][]int, n)
  for i := 0; i < n; i++ {
    graph[i] = make([]int, n)
  }

  var s, t int
  for i := 0; i < m; i++ {
    fmt.Scanf("%d %d", &s, &t)
    s--; t--
    graph[s][t] = 1
    graph[t][s] = 1
  }

  visited := make([]bool, n)
  visited[0] = true

  dfs(0, graph, visited)
  fmt.Println(ans)
}


Measured memory_bytes: 512
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    l = [int(input()) for _ in range(N)]

    if sum(l)%2==1:
        print('first')
    else:
        ret = 'second'
        for i in l:
            if i%2!=0:
                ret = 'first'
                break
        print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 12928
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long int ll;

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


Measured memory_bytes: 4056
/*2019/08/25 */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
#define MIN 999999999
#define MAX -999999999
typedef long long int ll;
typedef unsigned long long int ull;
void llswap(ll *x,ll *y){ll temp;temp=*x;*x=*y;*y=temp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){return *(int*)a-*(int*)b;}
int desc(const void *a,const void *b){return *(int*)b-*(int*)a;}
int llasc(const void *a,const void *b){return *(ll*)a-*(ll*)b;}
int lldesc(const void *a,const void *b){return *(ll*)b-*(ll*)a;}
/*
int asc_t(const void *a,const void *b){return ((struct_t*)a)->member - ((struct_t*)b)->member;}
int desc_t(const void *a,const void *b){return ((struct_t*)b)->member - ((struct_t*)a)->member;}
*/

int main(){
    int t,n,s,f;
    int hour=0;
    while(1){
        hour=0;

        scanf("%d",&t);
        if(t==0)break;
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf("%d %d",&s,&f);
            hour+=f-s;
        }
        if(hour>=t){
            printf("OK\n");
        }else{
            printf("%d\n",t-hour);
        }

    }
    return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define ill(_x)  ll _x;scanf("%lld",&_x);
#define idb(_x)  double _x;scanf("%lf",&_x);
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x, a, b)((x)>=a && (x)<=b    )
#define in1(x, a, b)((x)>a && (x)<b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const double pi = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int X10=1024,X11=2048,X12=4096,X13=8196,X14=16392,X15=32786,X16=65536,X17=131072,X18=262144,X19=524288,X20=1048576;


int A[26];
void _(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout <<((abs(c-a)<=d || (abs(a-b)<=d && abs(b-c)<=d))?"Yes":"No");
}






int main() {
#ifdef Debug
    freopen("/home/joduskame/Desktop/cpp/IO/Input.txt", "r", stdin);
    freopen("/home/joduskame/Desktop/cpp/IO/Output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    _();
    return 0;

}







Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vint x(N);
    REP(i,N) cin>>x[i];

    vint y=x;
    sort(ALL(y));

    REP(i,N){
        int idx=lower_bound(ALL(y),x[i])-y.begin();
        if(idx<N/2)
            cout<<y[N/2]<<endl;
        else
            cout<<y[N/2-1]<<endl;
    }

}


Measured memory_bytes: 5376
$n=<>;
@a=glob<>;

for($i=0;$i<$n;$i+=2){
    $e{$a[$i]}++;
    $o{$a[$i+1]}++;
}

@ee=sort {$e{$b} <=> $e{$a}} keys %e;
@oo=sort {$o{$b} <=> $o{$a}} keys %o;

if($ee[0]!=$oo[0]){
    print $n-$e{$ee[0]}-$o{$oo[0]};
} else{
    $x=$e{$ee[1]}+$o{$oo[0]};
    $y=$e{$ee[0]}+$o{$oo[1]};
    $z=($x>$y)?$x:$y;
    print $n-$z;
}

Measured memory_bytes: 29704
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#define MAX_N 100001
using namespace std;
//struct edge{int to;ll cost;};
vector<int> tree[MAX_N];
int mark[MAX_N];
int n,a,b;
int path[MAX_N];
int p;
int route[MAX_N];
int r;
int black;
int white;
void dfs(int now,int last,int end){
    if(now == end){
        r = p;
        for(int i = 0;i<p;i++)route[i]=path[i]; 
    }
    path[p++] = now;
    for(auto &e:tree[now]){
        if(e==last)continue;
        dfs(e,now,end); 
    }
    path[--p] = 0;
}
void color(int now,int last,int c)
{
    mark[now] = c;
    for(auto &e:tree[now]){
        if(e==last)continue;
        if(mark[e]!=0 && mark[e]!=c)continue;
        color(e,now,c);
    }
}
void solve()
{
    dfs(1,0,n);
    for(int i = 0;i<=r/2;i++){
        mark[route[i]] = 1; 
    }
    for(int i = r/2+1;i<r;i++){
        mark[route[i]] = 2;
    }
    mark[n] = 2;
    color(1,0,1);
    color(n,0,2);
    for(int i = 1;i<=n;i++){
        if(mark[i]==1)black++;
        if(mark[i]==2)white++;
    }
    if(black<=white)cout<<"Snuke"<<endl;
    else cout<<"Fennec"<<endl;
}
int main()
{
    cin>>n;
    for(int i = 1;i<=n-1;i++){
        cin>>a>>b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    solve();
    return 0;
}


Measured memory_bytes: 11520
n = int(input())
ary = list(map(int,input().split()))

flag = True
cnt=0

for j in range(n):
  flag = True
  while flag:
    flag = False
    i = n #5
    #print(ary) #5 3 2 4 1
    while i > 1:
      i -= 1
      if(ary[i-1] > ary[i]):
        ary[i], ary[i-1] = ary[i-1], ary[i]
        cnt += 1
print(' '.join(map(str,ary)))
print(cnt)



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

using namespace std;

int n, at = 1;
long long tot;
vector< int > v;

int main() {
	scanf("%d", &n);
	if (n == 3) {
		printf("2 5 63\n");
		return 0;
	}
	while (n) {
		// printf("%d %d\n", n, at);
		while ((at % 2 && at % 3) || (n == 1 && (tot + at) % 6) || (n == 2 && ((tot + at) % 6 == 1 || (tot + at) % 6 == 5)))
			at++;
		// printf("%d %d\n", n, at);
		tot += at;
		v.push_back(at);
		n--;
		at++;
	}
	for (int i = 0; i < v.size(); i++)
		printf("%d%c", v[i], i == v.size() - 1 ? '\n' : ' ');
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)

int sum(int b,int len)
{
	int ret=0;
	rep(i,len)ret+=b+i;
	return ret;
}

int main(){
	int n;
	while(cin>>n,n)
	{
		int ans=0;
		for(int len=2;len<=n;len++)
		for(int b=1;b<=n;b++)
		{
			int s=sum(b,len);
			if(s==n)ans++;
			if(s>n)break;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<cmath>

using namespace std;

string s;
long long store[15][15];
long long dp[15];

void solve(){
    for(int i=0;i<s.length();i++){
        for(int j=i;j<s.length();j++){
            store[i][j]=stoll(s.substr(i, j-i+1));
        }
    }
    for(int i=0;i<s.length();i++){
        for(int j=0;j<=i;j++){
            if(j==0){
                dp[i] += store[0][i];
            }
            else{
                dp[i] += store[j][i]*pow(2, j-1) + dp[j-1];
            }
        }
    }
    cout << dp[s.length()-1] << endl;
}


int main(){
    cin >> s;
    solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll n,C,x[200000],v[200000];

ll c[2][200000];
int main(){
	cin >> n >> C;
	REP(i,n) {
		cin >> x[i] >> v[i];
	}

	c[0][0] = c[1][0] = 0;

	REP(i,n) {
		c[0][i + 1] = v[i]; 
	}
	
	REP(i,n) {
		c[1][i + 1] = v[n - i - 1];
	}

	REP(i,2) {
		REP(j,n) {
			c[i][j + 1] += c[i][j];
		}
	}
	REP(i,n) {
		c[0][i + 1] -= x[i];
	}
	REP(i,n) {
		c[1][i + 1] -= C - x[n - i - 1];
	}

	ll ans = 0;

	REP(i,2) {
		REP(j,n + 1) {
			ans = max(ans,c[i][j]);
		}
	}

	REP(i,2) {
		REP(j,n) {
			c[i][j + 1] = max(c[i][j + 1],c[i][j]);
		}
	}
	/*REP(i,2) {
		REP(j,n + 1) {
			cout << c[i][j] << " ";
		}
		cout << endl;
	}*/

	REP(i,n - 1) {
		//printf("a%lld %lld %lld  %lld\n",c[0][i + 1],x[i],c[1][n - i- 1],c[0][i + 1] - x[i] + c[1][n - i - 1]);
		ans = max(ans,c[0][i + 1] - x[i] + c[1][n - i - 1]);
	}
	REP(i,n - 1) {
		//printf("b%lld %lld %lld  %lld\n",c[1][i + 1],(C - x[n - i - 1]),c[0][n - i - 1],c[1][i + 1] - C + x[n - i - 1] + c[0][n - i - 1]);
		ans = max(ans,c[1][i + 1] - (C - x[n - i - 1]) + c[0][n - i - 1]);
	}
	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

map<ll, ll> prime_factorization(ll n) {
    map<ll, ll> m;
    ll x = n;
    ll d = 2;
    while (x > 1 && d * d <= n) {
        if (x % d == 0) {
            m[d]++;
            x /= d;
        } else {
            d++;
        }
    }
    if (x != 1) m[x]++;
    return m;
}

void solve() {
    ll n, p;
    cin >> n >> p;
    auto m = prime_factorization(p);
    ll ans = 1;
    for (auto q : m) {
        if (q.second >= n) ans *= (ll)pow(q.first, q.second / n);
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define mod 1000000007
#define PI 3.1415926535
using namespace std;
ll power(ll x, ll y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return power(x, y / 2) * power(x, y / 2);
    else
        return x * power(x, y / 2) * power(x, y / 2);
}
ll modExpo(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return modExpo((x*x)%mod,n/2);
    else                            
        return (x*modExpo((x*x)%mod,(n-1)/2))%mod;
 
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    auto start_time = clock();
    cerr << setprecision(3) << fixed;
#endif
    ll n,w;
    cin>>n>>w;
    ll wt[n],v[n];
    for(ll i=0;i<n;i++)
        cin>>wt[i]>>v[i];
    
    ll dp[n+1][w+1];
    for(ll i=0;i<=n;i++)
    {
        for(ll j=0;j<=w;j++)
        {
            if(i==0 || j==0)
                dp[i][j]=0;
            else if(wt[i-1]<=j)
                dp[i][j]=max(dp[i-1][j],v[i-1]+dp[i-1][j-wt[i-1]]);
            else
                dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][w];
#ifdef LOCAL
    auto end_time = clock();
    cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms\n";
#endif
}

Measured memory_bytes: 82504
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a%b, y, x);
	y -= a / b * x;
	return d;
}

bool check(pair < llint, llint> a, pair<llint, llint> b) {
	if (a.first == b.first) {
		return a.second < b.second;
	}
	return a.first > b.first;
}

int main() {
	llint n, h;
	cin >> n >> h;
	vpllint a(n);
	vpllint b(n);
	rep(i, n) {
		cin >> a[i].first >> a[i].second;
		b[i].first = a[i].second;
		b[i].second = a[i].first;
	}
	sort(a.begin(), a.end(), check);
	sort(b.begin(), b.end(), check);
	llint cnt = 0;
	llint ans = 0;
	for (int i = 0;i < n&&cnt < h&&a[0].first < b[i].first;i++) {
		cnt += b[i].first;
		ans++;
	}
	if (cnt > h) {
		cout << ans << endl;
		return 0;
	}
	ans += (h - cnt + a[0].first - 1) / a[0].first;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3456
def is_prime(a):
    import math
    if a == 1:
        return False
    for i in range(2,int(math.sqrt(a))+1):
        if a%i == 0:
            return False
    return True

X = int(input())
while is_prime(X) == False:
    X = X+1
print(X)

Measured memory_bytes: 2940
class Array
  def scan_left(init = 0)
    reduce([init]) { |a, n| a << yield(a.last, n) }
  end
end

n = gets.to_i
ns1 = gets.split.map(&:to_i)
ns2 = gets.split.map(&:to_i)

a1 = ns1.scan_left(&:+)
a2 = ns2.scan_left(&:+)

b2 = Array.new(n) { |i| a2.last - a2[i] }
p a1.drop(1).zip(b2).map { |(a, b)| a + b }.max


Measured memory_bytes: 1788
n=input()

calc=[]
calc.append(int(n[0])+int(n[1])+int(n[2])+int(n[3]))
calc.append(int(n[0])+int(n[1])+int(n[2])-int(n[3]))
calc.append(int(n[0])+int(n[1])-int(n[2])+int(n[3]))
calc.append(int(n[0])+int(n[1])-int(n[2])-int(n[3]))
calc.append(int(n[0])-int(n[1])+int(n[2])+int(n[3]))
calc.append(int(n[0])-int(n[1])+int(n[2])-int(n[3]))
calc.append(int(n[0])-int(n[1])-int(n[2])+int(n[3]))
calc.append(int(n[0])-int(n[1])-int(n[2])-int(n[3]))

if 7 in calc:
    idx=calc.index(7)
if idx==0:
    print(n[0]+"+"+n[1]+"+"+n[2]+"+"+n[3]+"=7")
elif idx==1:
    print(n[0]+"+"+n[1]+"+"+n[2]+"-"+n[3]+"=7")
elif idx==2:
    print(n[0]+"+"+n[1]+"-"+n[2]+"+"+n[3]+"=7")
elif idx==3:
    print(n[0]+"+"+n[1]+"-"+n[2]+"-"+n[3]+"=7")
elif idx==4:
    print(n[0]+"-"+n[1]+"+"+n[2]+"+"+n[3]+"=7")
elif idx==5:
    print(n[0]+"-"+n[1]+"+"+n[2]+"-"+n[3]+"=7")
elif idx==6:
    print(n[0]+"-"+n[1]+"-"+n[2]+"+"+n[3]+"=7")
else:
    print(n[0]+"-"+n[1]+"-"+n[2]+"-"+n[3]+"=7")


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

int main() {
	long long n,m;
	cin>>n>>m;
	string s,t;
	cin>>s>>t;
	long long ans = (n*m)/__gcd(n,m);
	int stepn = n/__gcd(n,m);
	int stepm = m/__gcd(n,m);
	int i=0,j=0;
	while(i<n && j<m) {
		if(s[i] != t[j]) {
			cout<<-1;
			return 0;
		}
		i += stepn;
		j += stepm;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;string s;int q;
    cin>>n;cin>>s;cin>>q;
    while(q--)
    {
        int k;
        scanf("%d",&k);
        ll d=0,dm=0,dmc=0,mc=0,c=0,m=0;
        int i;
        ll ans=0;
        for(i=0;i<k;i++)
        {
            if(s[i]=='D'){
                d++;
            }else if(s[i]=='M'){
                dm+=d;m++;
            }else if(s[i]=='C'){
                dmc+=dm;c++;
            }
        }
        ans+=dmc;
        for(;i<n;i++){
            switch(s[i-k]){
                case 'D':dmc-=mc;dm-=m;d--;break;
                case 'M':mc-=c;m--;break;
                case 'C':c--;break;
            }
            if(s[i]=='D'){
                d++;
            }else if(s[i]=='M'){
                dm+=d;m++;
            }else if(s[i]=='C'){
                dmc+=dm;mc+=m;c++;ans+=dm;
            }
        }
        printf("%lld\n",ans);
    }
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    i64 n, m, v, p;
    std::cin >> n >> m >> v >> p;
    std::vector<i64> a(n);
    for (auto &e : a) std::cin >> e;
    std::sort(a.begin(), a.end());

    int l = -1, r = n - p;
    while (r - l > 1) {
        int k = (l + r) / 2;
        auto b(a);
        b[k] += m;
        i64 rem = (v - 1) * m, t = b[k];
        for (int i = 0; rem && i < n; i++) {
            if (i == k) continue;
            i64 d = std::min({ rem, m, std::max(0ll, t - a[i])});
            b[i] += d;
            rem -= d;
        }
        for (int i = n - 1; rem && i >= 0; i--) {
            i64 d = std::min({ m, rem, a[i] + m - b[i] });
            b[i] += d;
            rem -= d;
        }
        std::nth_element(b.begin(), b.begin() + (n - p), b.end());
        if (b[n - p] <= t) r = k;
        else l = k;
    }

    std::cout << n - r << std::endl;

    return 0;
}


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

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) cin >> A[i];
  vector<bool> check(N);
  ll now = 0;
  ll kitentesuu = 0;
  while (1) {
    if (check[now]) break;
    check[now] = true;
    now = A[now] - 1;
    kitentesuu++;
  }
  ll loopkiten = now;
  ll looptesuu = 0;
  while (1) {
    now = A[now] - 1;
    looptesuu++;
    if (now == loopkiten) break;
  }
  kitentesuu -= looptesuu;
  if (K < kitentesuu) {
    now = 0;
    rep(i, K) now = A[now] - 1;
  } else {
    K -= kitentesuu;
    K %= looptesuu;
    now = loopkiten;
    rep(i, K) now = A[now] - 1;
  }
  cout << now + 1 << endl;

  return 0;
}

Measured memory_bytes: 4848
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define prin(ans) cout << ans << endl
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 105
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PA;
typedef priority_queue<ll> PQ;
typedef pair<double, double> doup;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef map<ll, ll> Map;

ll N, M;
Map mp;
ll fact[100101];
ll rfact[100101];


ll modPow(ll x, ll n) {
    ll res=1;
    while(n>0) {
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

void pdiv(ll n) {
    for(ll i=2; i<=n; i++) {
        while(n%i==0) {
            mp[i]++;
            n/=i;
        }
    }
}


int main(void) {
    cin >> N >> M;
    pdiv(M);
    ll ans=1;
    ll i;
    
    fact[0]=rfact[0]=1;
    for(i=1; i<=100100; i++) {
        fact[i]=i*fact[i-1]%MOD;
        rfact[i]=modPow(fact[i], MOD-2);
    }
    
    
    for(auto it=mp.begin(); it!=mp.end(); it++) {
        ans*=fact[N+it->second-1]*rfact[N-1]%MOD*rfact[it->second]%MOD;
        ans%=MOD;
    }
    
    prin(ans);
}


Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#define N 200010
#define ll long long
using namespace std;

ll a[N];
ll tmp[N],c[N];
int n,mxd;
ll k;

int lowbit(int x){
  return x&(-x);
}

ll query(int x){
  ll ret=0;
  for(int i=x;i>=1;i-=lowbit(i)){
    ret+=c[i];
  }
  return ret;
}

void modify(int x){
  for(int i=x;i<=mxd;i+=lowbit(i)){
    c[i]++;
  }
}

int main(){
  scanf("%d%lld",&n,&k);
  for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
  for(int i=1;i<=n;i++) a[i]-=k;
  for(int i=1;i<=n;i++) a[i]+=a[i-1];
  for(int i=1;i<=n;i++) tmp[i]=a[i];
  sort(tmp+1,tmp+1+n);
  mxd=unique(tmp+1,tmp+1+n)-tmp-1;
  for(int i=1;i<=n;i++) a[i]=lower_bound(tmp+1,tmp+1+mxd,a[i])-tmp;
  ll ans=0;
  for(int i=1;i<=n;i++){
    ans+=query(a[i]);
    if(tmp[a[i]]>=0) ans++;
    modify(a[i]);
  }
  printf("%lld\n",ans);
  return 0;
}

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

int main(){
    string s;
    string t;
    int i;
    cin >> s >> t;
    i = t.size();
    t = t.erase(i-1);
    // cout << t;
    if (s==t){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 3092
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int length = scanner.nextInt();
		int chosen = scanner.nextInt();
		int[] numbers = new int[length];
		for(int i = 0; i < length; i++) 
			numbers[i] = scanner.nextInt();
		
		Arrays.sort(numbers);
		
		long result = 0l;
		for(int i = 0; i < chosen; i++) 
			result += numbers[i];
		System.out.print(result);
	}
}


Measured memory_bytes: 30040
#include <stdio.h>

double pow2(double x){
	return x*x;
}

int main(){
	int n,i,ans;
	double xa,ya,ra,xb,yb,rb,length;

	scanf("%d",&n);

	for(i = 0;i < n;i++){
		scanf("%lf %lf %lf %lf %lf %lf",&xa,&ya,&ra,&xb,&yb,&rb);

		length = pow2(ya-yb)+pow2(xa-xb);

		ans = 1;

		if(length > pow2(ra+rb)){
			ans = 0;
		}else if(length < pow2(ra-rb)){
			if(ra < rb){
				ans = -2;
			}else{
				ans = 2;
			}
		}

		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
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 RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << -1 << endl;return 0
#define Endl endl


signed main(void){
    int N,L;
    int a[114514];
    cin >> N >> L;
    REP(i,N){
        cin >> a[i];
    }
    int maxi=0,maxl=0;
    REP(i,N-1){
        if(maxl<a[i]+a[i+1]){
            maxl=a[i]+a[i+1];
            maxi=i+1;
        }
    }
    if(maxl<L){
        cout << "Impossible" << endl;
        return 0;
    }
    cout << "Possible" << endl;
    for(int i=1;i<maxi;i++){
        cout << i << endl;
    }
    for(int i=N-1;i>maxi;i--){
        cout << i << endl;
    }
    cout << maxi << endl;
    
    return 0;
}



Measured memory_bytes: 1664
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }

long mod = pow(10, 9) + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto S = RD;

	auto dp = new long[][](S.length+1, 4);
	dp[0][0] = 1;
	foreach (i, c; S)
	{
		dp[i+1][] = dp[i][];
		if (c == '?')
		{
			dp[i+1][0].moda(dp[i][0]);
			dp[i+1][0].moda(dp[i][0]);
			foreach (j; 0..3)
			{
				dp[i+1][j+1].moda(dp[i][j]);
				dp[i+1][j+1].moda(dp[i][j+1]);
				dp[i+1][j+1].moda(dp[i][j+1]);
			}
		}
		else
		{
			auto j = c - 'A';
			dp[i+1][j+1].moda(dp[i][j]);
		}
	}

	//stderr.writeln(dp);
	writeln(dp[S.length][$-1]);
	stdout.flush();
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gya[200010];
ll kai[200010];
ll beki(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k%2==1){
            ret*=now;
            ret%=mod;
        }
        now*=now;
        now%=mod;
        k/=2;
    }
    return ret;
}
ll gyaku(ll n){
    return beki(n,mod-2);
}
void nckinit(ll n){
    kai[0]=1;
    kai[1]=1;
    for(int i=2;i<=n;i++){
        kai[i]=kai[i-1]*i;
        kai[i]%=mod;
    }
    gya[n]=gyaku(kai[n]);
    for(int i=n-1;i>=1;i--){
        gya[i]=gya[i+1]*(i+1);
        gya[i]%=mod;
    }
    gya[0]=1;
}
ll nck(ll n,ll k){
    if(k<0)return 0;
    if(k==0||n==k)return 1;
    ll ret=kai[n];
    ret*=gya[n-k];
    ret%=mod;
    ret*=gya[k];
    ret%=mod;
    return ret;
}
ll npk(ll n,ll k){
    if(k<0)return 0;
    if(k==0)return 1;
    ll ret=kai[n];
    ret*=gya[n-k];
    ret%=mod;
    return ret;
}
int main(){
    int n,a,b,c,d;cin>>n>>a>>b>>c>>d;
    a--;b--;c--;d--;
    string s;cin>>s;
    if(d>c){
        rep(i,a+1,c){
            if(s[i]=='#'&&s[i-1]=='#'){
                cout<<"No"<<endl;
                return 0;
            }
        }
        rep(i,b+1,d){
            if(s[i]=='#'&&s[i-1]=='#'){
                cout<<"No"<<endl;
                return 0;
            }
        
        }
        cout<<"Yes"<<endl;
    }
    else{
        int e=0;
        rep(i,a+1,c){
            if(s[i]=='#'&&s[i-1]=='#'){
                cout<<"No"<<endl;
                return 0;
            }
        }
        rep(i,b,d+1){
            if(i==n)break;
            if(s[i-1]=='.'&&s[i]=='.'&&s[i+1]=='.'){
                e=1;
                break;
            }
        }
        if(e)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	ll N, K; cin >> N >> K;
	vvll doubling(70, vll(N));
	cin >> doubling[0];
	for (int i = 0; i < N; i++) {
		doubling[0][i]--;
	}

	int now = 0;
	if (K & 1) now = doubling[0][now];
	K >>= 1;
	for (int i = 1; i < 70; i++) {
		for (int j = 0; j < N; j++) {
			doubling[i][j] = doubling[i-1][doubling[i-1][j]];
		}
		if (K & 1) now = doubling[i][now];
		K >>= 1;
	}
	cout << now+1 << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 114340
N,X = map(int,input().split())
L = list(map(int,input().split()))
a = 0
b = 0
c = [0]
d = []
for val in L:
  a += 1
  b += val
  c.append(b)
for i in c:
  if i <= X:
    d.append(i)
print(len(d))

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

int main(){
    int N,X,a,b,c,d,e;
    int min=0,kari;
    int ans;
    long long sum=0;
    


    cin>>N;
    cin>>X;
    vector<int> okasi(N);

    for(auto&x : okasi){
        cin>>x;
        sum+=x;
    }

    ans=N;
    kari=X-sum;

    sort(okasi.begin(),okasi.end());

    ans=ans+(kari/okasi[0]);

    cout<<ans<<endl;


}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include<string>
#include<string.h>
using namespace std;

int main() {

	string s, t;
  cin >> s >> t;

  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) != t.at(i)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int N, K;
    cin >> N >> K;
    vector<int> l(N);
    for(int i = 0; i < N; i++)
        cin >> l[i];
    
    sort(l.begin(), l.end());
    reverse(l.begin(), l.end());
    
    int ans = 0;
    for(int i = 0; i < K; i++){
        ans += l[i];
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string s1,s2;
int main()
{
	getline(cin,s1);
	getline(cin,s2);
	sort(s1.begin(),s1.end());
	sort(s2.begin(),s2.end(),greater<char>());
	if(s1 < s2) cout<<"Yes";
	else cout<<"No";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  
 int a,b,c,i,j;
  int d = 0, e = 0;
  scanf("%d %d %d",&a,&b,&c);
 int str[102];
  
  for (i == 0;i < b;++i){
    scanf("%d",&str[i]);
  }

for (j == 0; j < b; ++j){
  if (c - str[j] > 0) {
    d = d + 1;
  } else {
    e = e + 1;
  }
}
  
if (d - e >= 0) {
  printf("%d",e);
} else {
  printf("%d",d);
}
  
  return 0;
}

Measured memory_bytes: 128
package main
 
import (
	"bufio"
	"fmt"

	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
 
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
 
func main() {
	sc.Split(bufio.ScanWords)
	k := nextInt()
	x := nextInt()
	if 500 * k >= x{
		fmt.Print("Yes\n")
		os.Exit(0)
	}
	fmt.Print("No\n");
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main() {
	int A, B, ans = 0;
	cin >> A >> B;

	for (int i = A; i <= B; i++) {
		int tmp = i;
		int w[5];
		for (int j = 0; j < 5; j++) {
			w[j] = tmp % 10;
			tmp /= 10;
		}
		if (w[0] == w[4] && w[1] == w[3])
			ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

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

  std::vector<std::pair<int, int> > war;

  int temp1, temp2;
  for (int i=0; i<M; i++){
    scanf("%d", &temp1);
    scanf("%d", &temp2);
    temp1--; temp2--;
    war.push_back(std::make_pair(temp2, temp1));
  }
  sort(war.begin(), war.end());
  
  int bridge_right = war[0].first;
  int ans = 1;
  int i = 0;
  while(i<war.size()){
    if (war[i].second >= bridge_right){
      bridge_right = war[i].first;
      ans++;
    }
    i++;
  }
  printf("%d\n", ans);
  return 0;
}


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

int main(){
	int a, b, result;
	cin >> a >> b;
	if(a >= b + 1) result = a * 2 - 1;
	else if(b >= a + 1) result = b * 2 - 1;
	else result = a + b;
	cout << result << endl;
	return 0;
}

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

int main(){
	int N;
	cin >> N;
	vector<ll> A(N);
	rep(i,N){
		cin >> A[i];
	}
	sort(A.begin(),A.end());
	vector<ll> B(N);
	rep(i,N){
		B[i] = A[i];
	}
	
	REP(i,N-1){
		A[i] += A[i-1];
	}
	
	int id = -1;
	rep(i,N-1){
		if(A[i]*2 < B[i+1]){
			id = i;
		}
	}
	
	cout << N - 1 - id << endl;
	
	return 0;
}



Measured memory_bytes: 1792
//09
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  for(int n,w,d;cin>>n>>w>>d,n|w|d;){
    vector<pair<int,int> > v(1);
    v[0]=make_pair(w,d);
    while(n--){
      int p,s;
      cin>>p>>s;
      pair<int,int> c=v[p-1];
      v.erase(v.begin()+p-1);
      if(s%(c.first+c.second)<c.first){
	int wl=s%(c.first+c.second);
	int wh=c.first-wl;
	if(wh<wl){
	  swap(wh,wl);
	}
	v.push_back(make_pair(wl,c.second));
	v.push_back(make_pair(wh,c.second));
      }else{
	int dl=c.first+c.second-s%(c.first+c.second);
	int dh=c.second-dl;
	if(dh<dl){
	  swap(dh,dl);
	}
	v.push_back(make_pair(c.first,dl));
	v.push_back(make_pair(c.first,dh));
      }
    }
    vector<int> va(v.size());
    for(int i=0;i<v.size();i++){
      va[i]=v[i].first*v[i].second;
    }
    sort(va.begin(),va.end());
    for(int i=0;i<v.size();i++){
      cout<<va[i]<<((i==v.size()-1)?'\n':' ');
    }
  }
  return 0;
}

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

using namespace std;
typedef long long LL;
typedef vector<LL> V;
typedef vector<V> VV;
const LL MOD=1e9+7;

LL comb[500][500];
struct INIT{
    INIT(){
	comb[0][0]=1;
	for(int i=0;i<400;i++){
	    comb[i+1][0]=0;
	    for(int j=0;j<=i;j++){
		comb[i+1][j]+=comb[i][j];
		comb[i+1][j+1]=comb[i][j];
	    }
	}
    }
}init;

int main(){
    int N,W;
    cin>>N>>W;
    map<int,int> w,z;
    for(int i=0;i<N;i++){
	int t;cin>>t;w[t]++;
	z[t]=0;
    }
    N=0;
    for(auto &it:z)it.second=N++;
    V zz(N+1,114514);
    for(auto &it:z)zz[it.second]=it.first;
    VV dp(W+1,V(N+1,0));
    dp[0][0]=1;
    for(auto &it:w){
	int num=it.first;
	int cnt=it.second;
	int id=z[it.first];
	VV nxt(W+1,V(N+1,0));
	for(int i=0;i<cnt;i++){
	    for(int j=0;j+num*i<=W;j++)
		for(int k=0;k<N;k++){
		    (nxt[j+num*i][min(k,id)]+=dp[j][k]*comb[cnt][i]%MOD)%=MOD;
		}
	}
	for(int j=0;j+num*cnt<=W;j++){
	    for(int k=0;k<id;k++){
		(nxt[j+num*cnt][k]+=dp[j][k])%=MOD;
	    }
	    (nxt[j+num*cnt][id+1]+=dp[j][id])%=MOD;
	}
	swap(dp,nxt);
    }
    LL res=0;
    for(int i=0;i<=W;i++)
	for(int j=0;j<=N;j++)
	    if(W-i<zz[j]){
		//cout<<i<<" "<<j<<" " <<dp[i][j]<<endl;
		(res+=dp[i][j])%=MOD;
	    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 32432
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <stack>
using namespace std;
int last(int n)
{
    return n%10;
}
int f[6];
bool com(int a,int b)
{
  //  if(a%10==0)
  //      return a<b;
    return a%10>b%10;
}
int main()
{
    for(int i=0;i<5;i++)
        cin >> f[i];
    sort(f,f+5,com);
    int s=0;
    int q=0;
    for(int i=0;i<5;i++){
        if(f[i]%10==0){
            q++;
            s+=f[i];
        }
    }

    for(int i=0;i<4-q;i++){
        if(f[i]%10==0)
            s+=f[i];
        else
            s+=f[i]+10-last(f[i]);
    //    cout << s << " ";
    }
    cout << s+f[4-q];


    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();

        long c = n / (a+b);
        long d = n % (a+b);
        if(c < 1) {
            System.out.println(Math.min(a, n));
        } else {
            long e = n % (a+b);
            long f = Math.min(e, a);
            System.out.println(c * a + f);
        }
    }
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

class UF {

  vector<int> par; // 親
  vector<int> rank; // 深さ

public:

  void init(int n) { // n個で初期化
    for(int i=0;i<n;i++) {
      par.push_back(i);
      rank.push_back(0);
    }
  }

  UF(int n) {
    for(int i=0;i<n;i++) {
      par.push_back(i);
      rank.push_back(0);
    }
  }

  int find(int x) { // 木の中のxの親を返す
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
  }

  void unite(int x, int y) { // xとyを統合する
    x = find(x);
    y = find(y);
    if (x == y) return;

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

  bool same(int x, int y) { // xとyが等しいかどうか判定する
    return find(x) == find(y);
  }
};


int main () {
  cin.tie(0);
  cout << setprecision(10);

  vi dh = {1, -1, 0, 0};
  vi dw = {0, 0, 1, -1};

  int h, w; cin >> h >> w;
  UF uf(h*(w+1));
  vector<string> s(h);
  REP(i, h) {
    cin >> s[i];
  }

  REP(i, h) {
    REP(j, w) {
      REP(k, 4) {
        if(0 <= i + dh[k] && i + dh[k] < h &&
        0 <= j + dw[k] && j + dw[k] < w &&
        s[i][j] != s[i+dh[k]][j+dw[k]]) {
          uf.unite(i*w+j, (i+dh[k])*w+(j+dw[k]));
        }
      }
    }
  }

  map<int, pair<ll, ll>> m;
  REP(i, h) {
    REP(j, w) {
      if(s[i][j] == '.') m[uf.find(i*w+j)].fi++;
      else m[uf.find(i*w+j)].se++;
    }
  }

  ll ans = 0;
  MFOR(i, m) {
    ans += i->se.fi * i->se.se;
  }
  cout << ans << endl;
}


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

char s[5000][5000];
int dp[5000][2][2];
int n,m;

int solve(int x,int y){
	memset(dp,0,sizeof(dp));
	for(int i=y;i<m;i++){
		int j=x-(i-y);
		if(j<0)break;
		rep(k,2)rep(l,2){
			if(j+2<n&&s[j][i]=='R'&&s[j+1][i]=='G'&&s[j+2][i]=='W'&&!k&&!l){
				dp[i+1][0][0]=max(dp[i+1][0][0],dp[i][k][l]+1);
			}
			if(i+2<m&&s[j][i]=='R'&&s[j][i+1]=='G'&&s[j][i+2]=='W'){
				dp[i+1][l][1]=max(dp[i+1][l][1],dp[i][k][l]+1);
			}
			dp[i+1][l][0]=max(dp[i+1][l][0],dp[i][k][l]);
		}
	}
	int Max=0;
	rep(i,m+1)rep(j,2)rep(k,2)Max=max(Max,dp[i][j][k]);
	return Max;
}
int main(){
	scanf("%d%d",&n,&m);
	rep(i,n)scanf("%s",s[i]);
	int ans=0;
	rep(i,n-1)ans+=solve(i,0);
	rep(i,m)ans+=solve(n-1,i);
	cout<<ans<<endl;
}


Measured memory_bytes: 17972
from collections import defaultdict

N, M = map(int, input().split(' '))
H = tuple(map(int, input().split(' ')))
edges = defaultdict(set)

for _ in range(M):
    a, b = map(int, input().split(' '))
    a -= 1
    b -= 1
    edges[a].add(b)
    edges[b].add(a)

count = 0
for i in range(N):
    hi = H[i]
    for j in edges[i]:
        if hi <= H[j]:
            break
    else:
        count += 1

print(count)


Measured memory_bytes: 51384
#include<bits/stdc++.h>
using namespace std;
 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define in() ( { int a ; scanf("%d",&a); a; } )
 
const int N = 3e5 + 9;
const int mod = 1e9 + 7;
//int dx[]={1,0,-1,0,1,-1,-1,1};
//int dy[]={0,1,0,-1,1,1,-1,-1};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    ll n, i, tot = 0;
    cin >> n;
    ll ar[n] = {};
    for(i = 0; i < n; i++){
        cin >> ar[i];
    }
    sort(ar, ar+n, greater<ll>());
    tot += ar[0];
    ll cnt = 1;
    i = 1;
    while(1){
        if(cnt == n-1) break;
        if(1 == (n-1-cnt)){
            tot += ar[i];
            cnt++;
        }
        else{
            tot += (2*ar[i]);
            cnt += 2;
        }
        i++;
        //cout << tot << nl;
    }
    cout << tot << nl;
}

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

int main() {
    int n;
    cin >> n;
    vector <int> p(n);
    for (int i=0; i<n; i++) cin >> p.at(i);
    int ans=0;
    for (int i=1; i<n-1; i++) {
        vector <int> t{p.at(i-1),p.at(i),p.at(i+1)};
        sort(t.begin(), t.end());
        if (t.at(1)==p.at(i)) ans++;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long 
#define mod 1000000007
using namespace std;
int n;
int dp[100001][2];
vector<int>adj[100001];
int solve(int u ,int par ,int c)
{
     if(dp[u][c]!= -1)
      return dp[u][c];
     int ans  = 0;
     
     bool leaf = true;
      
      int w1 = 1;int w2 =1;
     for(auto child : adj[u])
     {
         if(child!= par)
         {
            leaf = false;

            w1 = (w1*solve(child,u,0))%mod;

            if(!c)
              {
                  w2 = (w2*solve(child,u,1))%mod;
              }
         }
     }

     if(leaf)
     {
        if(c == 1)
          return 1;
        else
          return 2;
     }
       ans = w1;
       if(!c)
        ans = (ans+w2)%mod;

      return dp[u][c] = ans;

}
signed main(void)
{
    memset(dp , -1 ,sizeof dp);
    cin>>n;
    int a,b;
    for(int  i = 0;i<(n-1);i++)
    {
      cin>>a>>b;
      adj[a].push_back(b);
      adj[b].push_back(a);
    }

    cout<<solve(1,-1,0)<<endl;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int N, M; cin >> N >> M;
    vector<ll> S;
    ll A[N]; rep(i, N) cin >> A[i];
    ll ruiseki[N+1]; ruiseki[0] = 0; rep(i, N) ruiseki[i+1] = ruiseki[i] + A[i];
    for(int i = 0; i < N; i++){
        for(int j = i+1; j <= N; j++){
            S.push_back(ruiseki[j]-ruiseki[i]);
        }
    }
    int bit_cnt = 0;
    ll ans = 0;
    rep(i, 41){
        bit_cnt = 0;
        ll val = (1ll << (40-i));
        rep(j, S.size()){
            if((val & S[j]) == val) bit_cnt++;
        }
        if(bit_cnt >= M){
            ans += val;
            rep(j, S.size()){
                if((val & S[j]) != val) S[j] = 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

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

Measured memory_bytes: 3896
#include<stdio.h>

void compare(int A[]){
    int a,b,c;
    a = A[0] + A[1];
    b = A[0] - A[1];
    c = A[0] * A[1];

        if(a >= b && a >= c) {
            printf("%d", a);
        }else if(a <= b && b >= c) {
            printf("%d", b);
        }else if(b <= c && a <= c)  {
            printf("%d", c);
        }
}

int main(){
    int i;
    int A[3];
    for(i=0; i<2; i++) scanf("%d", &A[i]);


    compare(A);
    return 0;
}

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

#define X first
#define Y second
#define mp make_pair
#define sz(v) (int) v.size()
#define all(v) v.begin(), v.end()

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

/*#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
                         tree_order_statistics_node_update>;*/

void solve() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << c << " " << a << " " << b << "\n";
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int tt = 1;
	// cin >> tt;
	while (tt--) solve();
	return 0;
}


Measured memory_bytes: 256