akhauriyash/Code-Regression huggingface dataset:
/*


*/
#include <cstdio>
#include <cctype>
#include <algorithm>
//#define gc() getchar()
#define MAXIN 400000
#define gc() (SS==TT&&(TT=(SS=IN)+fread(IN,1,MAXIN,stdin),SS==TT)?EOF:*SS++)
typedef long long LL;
const int N=1e5+5,INF=1<<30;

int Ans,Enum,H[N],nxt[N<<1],to[N<<1],len[N<<1],A[N],Min,root,sz[N],cnt1,cnt2;
bool vis[N];
char IN[MAXIN],*SS=IN,*TT=IN;
struct Node
{
	int s,dep,bel;
	bool operator <(const Node &x)const
	{
		return s<x.s;//按s排序啊（我怎么按dep了mdzz）
	}
}f[N],g[N];

inline int read()
{
	int now=0;register char c=gc();
	for(;!isdigit(c);c=gc());
	for(;isdigit(c);now=now*10+c-48,c=gc());
	return now;
}
inline void AE(int w,int u,int v)
{
	to[++Enum]=v, nxt[Enum]=H[u], H[u]=Enum, len[Enum]=w;
	to[++Enum]=u, nxt[Enum]=H[v], H[v]=Enum, len[Enum]=w;
}
void FindRoot(int x,int fa,int tot)
{
	int mx=0; sz[x]=1;
	for(int i=H[x],v; i; i=nxt[i])
		if(!vis[v=to[i]]&&v!=fa) FindRoot(v,x,tot), sz[x]+=sz[v], mx=std::max(mx,sz[v]);
	mx=std::max(mx,tot-sz[x]);
	if(mx<Min) Min=mx, root=x;
}
void DFS(int x,int fa,int need,int need2,int sum,int dep,int anc)
{//need:v->x当前点至少需要要有多少油量 rest:v->x会剩下多少油量 need2:x->v最少需要多少起始油量 sum:x->v一共多少油量 rest=A[root]+sum
	g[++cnt2]=(Node){need2,dep,anc}, sum+=A[x];
	if(A[x]>=need) f[++cnt1]=(Node){sum,dep+1,anc};
	for(int i=H[x],v,w; i; i=nxt[i])
		if(!vis[v=to[i]]&&v!=fa)
			w=len[i], DFS(v,x,w+std::max(0,need-A[x]),std::max(need2,w-sum),sum-w,dep+1,anc);
}
void Solve(int x)
{
	vis[x]=1, cnt1=cnt2=1, f[1]=(Node){0,1,0}, g[1]=(Node){0,0,0};
	for(int i=H[x],v; i; i=nxt[i])
		if(!vis[v=to[i]]) DFS(v,x,len[i],len[i],-len[i],1,v);
	for(int i=1,a=A[x]; i<=cnt1; ++i) f[i].s+=a;
	std::sort(f+1,f+1+cnt1), std::sort(g+1,g+1+cnt2);
	Node a=(Node){0,0,0},b=a;
	int res=0; g[cnt2+1].s=INF;
	for(int i=1,j=1; i<=cnt1; ++i)
	{
		while(g[j].s<=f[i].s)
		{
			if(g[j].dep>a.dep)
				if(g[j].bel!=a.bel) b=a, a=g[j];
				else a=g[j];
			else if(g[j].dep>b.dep && g[j].bel!=a.bel) b=g[j];
			++j;
		}
		if(f[i].bel!=a.bel) res=std::max(res,f[i].dep+a.dep);
		else res=std::max(res,f[i].dep+b.dep);
	}
	Ans=std::max(Ans,res);
	for(int i=H[x],v; i; i=nxt[i])
		if(!vis[v=to[i]]) Min=N, FindRoot(v,x,sz[v]), Solve(root);
}

int main()
{
	int n=read();
	for(int i=1; i<=n; ++i) A[i]=read();
	for(int i=1; i<n; ++i) AE(read(),read(),read());
	Ans=1, Min=N, FindRoot(1,1,n), Solve(root), printf("%d\n",Ans);

	return 0;
}


Measured memory_bytes: 16900
#include <iostream>
#include <algorithm>
#include<string>
#include<cmath>
#include<stack>
#include <vector>
#include<queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
using namespace std;

int main() {
	int a[3],k;
	cin >> a[0] >> a[1] >> a[2]>>k;
	sort(a, a + 3);
	for (int i = 0; i < k; i++) {
		a[2] = a[2] * 2;
	}
	cout << a[0] + a[1] + a[2] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for(ll i=b-1;i>=a;i--)
const ll maxn=1e5+5, mod=1e9+7;
ll n,dp[maxn][2],u,v;
vector<ll> ady[maxn];
void dfs(ll n, ll p) {
    dp[n][0]=dp[n][1]=1;
    for(ll to: ady[n]) if(to!=p) {
        dfs(to, n);
        dp[n][1]=(dp[n][1]*dp[to][0])%mod;
        dp[n][0]=(dp[n][0]*(dp[to][0]+dp[to][1]))%mod;
    }
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n;
    rep(i,0,n-1) {
        cin>>u>>v;
        ady[u].push_back(v);
        ady[v].push_back(u);
    }
    dfs(1,0);
    cout<<(dp[1][0]+dp[1][1])%mod<<"\n";
}


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

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

ll dp[101010];
ll N, M;
map<int, bool> flag;
ll mod = 1e9 + 7;

int main() {
    cin >> N >> M;
    rep(i, M) {
        int a;
        cin >> a;
        flag[a] = true;
    }

    dp[0] = 1;
    int cur = 0;
    for (int i=0; i<=N; ++i) {
        if (!flag[i+1]) {
            dp[i+1] += dp[i];
            dp[i+1] %= mod;
        }
        if (!flag[i+2]) {
            dp[i+2] += dp[i];
            dp[i+2] %= mod;
        }
    }

    cout << dp[N]%mod << endl;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


void solve(){
    int N, M;
    cin >> N >> M;
    int a = 1, b = N - 1, c = N / 2, d = N / 2 + 1;
    REP(i,M){
        if(i & 1) cout << a++ << " " << b-- << endl;
        else cout << c-- << " " << d++ << endl;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> l(m);
    vector<int> r(m);
    for (int i = 0; i < m; ++i) {
        cin >> l.at(i) >> r.at(i);
    }
    sort(l.rbegin(), l.rend());
    int left = l.at(0);
    sort(r.begin(), r.end());
    int right = r.at(0);
    int p = right - left + 1;
    cout << (p > 0 ? p : 0) << endl;
}


Measured memory_bytes: 1024
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
from collections import deque
#======================================================#
def main():
    n = II()
    graph = [[] for _ in range(n)]
    for i in range(n-1):
        u,v,w = MII()
        graph[u-1].append((w, v-1))
        graph[v-1].append((w, u-1))
    dq = deque()
    color = [-1]*n
    dist = [-1]*n
    dq.append((0,0))
    color[0] = 0
    dist[0] = 0
    while dq:
        prev_cost, src = dq.popleft()
        for cost, dst in graph[src]:
            if dist[dst] != -1:
                continue
            if prev_cost%2 == cost%2:
                color[dst] = 0
            else:
                color[dst] = 1
            dist[dst] = dist[src] + cost
            dq.append((dist[dst], dst))
    print(*color, sep='\n')

if __name__ == '__main__':
    main()

Measured memory_bytes: 49288
#include <algorithm>
#include <sstream>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <string>
#include <queue>
#include <vector>
using namespace std;

long long int factorial(int n) {
	if (n == 1) return n;

	return n * factorial(n - 1);
}

int main()
{
	int n;
	cin >> n;
	cout << factorial(n) << endl;
}



Measured memory_bytes: 3076
#include <iostream>
using namespace std;
int main(void){
    int m, f, b, debt;
    cin >> m >> f >> b;
    
    if(m>=b){
        cout << 0 << endl;
    }
    
    else{
        debt = b-m;
        if(f>=debt){
            cout << debt << endl;
        }
        else cout << "NA" << endl;
    }
    return 0;
}



Measured memory_bytes: 3108
#include<iostream>
using namespace std;
int main() {
  int a, c;
  char b;
  while(cin>>a>>b>>c && b !='?') {
    if(b == '+') cout << a + c << endl;
    else if(b == '-') cout << a - c << endl;
    else if(b == '*') cout << a * c << endl;
    else if(b == '/') cout << a / c << endl;
  }
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=103,INF=1<<30;
typedef pair<int,int> P;

struct edge{int to,cap,cost,rev;};

int V;
vector<edge> G[MAX];
int h[MAX];
int dist[MAX];
int prevv[MAX],preve[MAX];

void add_edge(int from,int to,int cap,int cost){
    G[from].push_back((edge){to,cap,cost,int(G[to].size())});
    G[to].push_back((edge){from,0,-cost,int(G[from].size()-1)});
}

int min_cost_flow(int s,int t,int f){
    int res=0;
    fill(h,h+V,0);
    
    while(f>0){
        priority_queue<P,vector<P>,greater<P>> que;
        fill(dist,dist+V,INF);
        dist[s]=0;
        que.push(P(0,s));
        while(!que.empty()){
            P p=que.top();que.pop();
            int v=p.second;
            if(dist[v]<p.first) continue;
            for(int i=0;i<G[v].size();i++){
                edge &e=G[v][i];
                if(e.cap>0&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
                    dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
                    prevv[e.to]=v;
                    preve[e.to]=i;
                    que.push(P(dist[e.to],e.to));
                }
            }
        }
        
        if(dist[t]==INF){
            return -1;
        }
        for(int v=0;v<V;v++){
            h[v]+=dist[v];
        }
        
        int d=f;
        for(int v=t;v!=s;v=prevv[v]){
            d=min(d,G[prevv[v]][preve[v]].cap);
        }
        f-=d;
        res+=d*h[t];
        for(int v=t;v!=s;v=prevv[v]){
            edge &e=G[prevv[v]][preve[v]];
            e.cap-=d;
            G[v][e.rev].cap+=d;
        }
    }
    return res;
}//sからtへの流量fの最小費用流、流せない場合は-1

int main(){

    int E,F;cin>>V>>E>>F;
    for(int i=0;i<E;i++){
        int a,b,c,d;cin>>a>>b>>c>>d;
        add_edge(a,b,c,d);
    }
    
    int ans=min_cost_flow(0,V-1,F);
    
    cout<<ans<<endl;
}




Measured memory_bytes: 3220
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define int long long
#define endre getchar();getchar();return 0
#define INF 1000000007
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return (y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int n) {
	if (n == 0)return 1;
	return (kai(n - 1)*n) % INF;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int mystoi(string s) {
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		cnt += (int)(s[i] - '0') * pow(10, s.size() - i - 1);
	}
	return cnt;
}
int x;
signed main() {
	cin >> x;
	if (x % 11 == 0)cout << x / 11 * 2 << endl;
	else if (x % 11 <= 6)cout << x / 11 * 2 + 1 << endl;
	else cout << x / 11 * 2 + 2 << endl;
	endre;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int maxVal = pow(2, 31) - 1;
class RMQ {
public:
    RMQ(int n, int v) {
        int i = 1;
        while(i < n){
            i *= 2;
        }
        tree = vector<int>(i*2-1, v);
        st_idx = i-1;
        s = i*2-1;
    };
    void update(int x, int v){
        int idx = x + st_idx;
        tree[idx] = v;
        while(idx){
            int p = (idx-1)/2;
            int sb = idx%2 ? idx+1 : idx-1;
            tree[p] = min(tree[idx], tree[sb]);
            idx = p;
        }
    }
    int findMin(int l, int r){
        return findMin(l+st_idx, r+st_idx, maxVal);
    }
    void print(){
        for(int x : tree){
            cout << x << ' ';
        }
        cout << endl;
    }
private:
    vector<int> tree;
    int s;
    int st_idx;
    int findMin(int l, int r, int v){
        //cout << l  << ' ' << r << endl;
        if(l > r){
            return  v;
        }
        if(l == r){
            return min(v, tree[l]);
        }
        int minVal = v;
        if(l%2 == 0){
            minVal = min(minVal, tree[l]);
            l /= 2;
        } else {
            l = (l-1)/2;
        }
        if(r%2 == 1){
            minVal = min(minVal, tree[r]);
            r = (r-2)/2;
        } else {
            r = (r-1)/2;
        }
        return findMin(l, r, minVal);
    }
};

int main(){
    ios_base::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    RMQ rmq = RMQ(n, maxVal);
    int com, x, y;
    for(int i = 0; i < q; ++i){
        cin >> com >> x >> y;
        if(com){
            int v = rmq.findMin(x, y);
            cout << v << endl;
        } else {
            rmq.update(x, y);
            //rmq.print();
        }
    }
}

Measured memory_bytes: 2052
N, M, K = map(int, input().split())

mod = 998244353

ans = 0

class Combination:
    def __init__(self, n):
        self.facts = [1 for i in range(N+1)]
        self.invs = [1 for i in range(N+1)]
        
        for i in range(1, N+1):
            self.facts[i] = self.facts[i-1] * i % mod
            self.invs[i] = pow(self.facts[i], mod-2, mod)

    def ncr(self, n, r):
        return self.facts[n] * self.invs[r] * self.invs[n-r] % mod

    def nhr(self, n, r): 
        return self.ncr(n+r-1, n-1)

comb = Combination(N)

for i in range(K+1):
    d = M * pow(M-1, N-i-1, mod) * comb.ncr(N-1, i)
    ans = (ans + d % mod) % mod

print(ans)


Measured memory_bytes: 94568
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
signed main(){
  int a;
  cin>>a;
  vector<int> b(a),c(a,0);
  fo(i,a)
    cin>>b[i];
  for(int i=0;i<2*a;i+=2)
    c[(i+2)%a]=c[i%a]+(b[(i+1)%a]-b[i%a])*2;
  fo(i,a){
    cout<<c[i]+(b[0]*2-c[0]-c[1])/2;
    if(i!=a-1)
      cout<<' ';
    else
      cout<<endl;
  }
}

Measured memory_bytes: 2944
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]

ab=[[a[i],b[i]] for i in range(n)]
ab.sort(key=lambda x:x[1])

a=[ab[i][0] for i  in range(n)]
b=[ab[i][1] for i  in range(n)]

ai=[[a[i],i] for i in range(n)]
ai.sort(key=lambda x:x[0])

flag1=True
for i in range(n):
  if ai[i][0]>b[i]:
    flag1=False
    break
    
idx=ai[0][1]
cnt=0
while idx!=0:
  idx=ai[idx][1]
  cnt+=1

if cnt==n-1:
  flag2=False
  for i in range(n-1):
    if b[i]>=ai[i+1][0]:
      flag2=True
      break
else:
  flag2=True
  
if flag1 and flag2:
  ans='Yes'
else:
  ans='No'
print(ans)
  



Measured memory_bytes: 35788
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <map>
#include <tuple>
using namespace std;

int S, A[1000009]; bool used[1000009];

int main() {
	cin >> S; A[0] = S; used[A[0]] = true;
	for (int i = 1; i <= 1000000; i++) {
		if (A[i - 1] % 2 == 1) A[i] = A[i - 1] * 3 + 1;
		else A[i] = A[i - 1] / 2;
		if (used[A[i]] == true) {
			cout << i + 1 << endl;
			return 0;
		}
		else used[A[i]] = true;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){

        Scanner scan = new Scanner(System.in);
        String S = scan.next();
        String T = scan.next();

        if (S.contains(T.substring(0, S.length())) && T.length() == S.length() + 1 && S.length() <= 10 &&
                S.length() >= 1) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35728
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		if(n == 3 || n == 5 || n == 7) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 22612
#include <stdio.h>
#include <string.h>
#include <queue>
#include <utility>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, a, b, c, n, m, h, w, d[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}, ans = 0;
  scanf("%lld%lld", &h, &w);
  char s[h + 2][w + 10];
  for(i = 0; i < w + 2; ++i) s[0][i] = '0', s[h + 1][i] = '0';
  for(i = 0; i < h; ++i) s[i + 1][0] = '0', scanf("%s", s[i + 1] + 1), s[i + 1][w + 1] = '0';
  bool flg[h + 2][w + 2][4], flg2[h + 2][w + 2];
  for(i = 0; i < h + 2; i++) for(j = 0; j < w + 2; ++j) {
    for(k = 0; k < 4; ++k) flg[i][j][k] = false;
    flg2[i][j] = false;
  }
  for(i = 1; i <= h; i++) {
    for(j = 1; j <= w; ++j) {
      flg2[i][j] = true;
      for(k = 0; k < 4; ++k) if(s[i + d[k][0]][j + d[k][1]] != '0' && s[i + d[k][0]][j + d[k][1]] != s[i][j]) flg[i][j][k] = true;
    }
  }
  queue< pair<ll, ll> > q;
  for(i = 1; i <= h; ++i) for(j = 1; j <= w; ++j) if(flg2[i][j]) {
    ll cnt[2] = {0, 0};
    q.push(make_pair(i, j));
    flg2[i][j] = false;
    if(s[i][j] == '#') cnt[0]++;
    else cnt[1]++;
    while(q.size()) {
      pair<ll, ll> p = q.front();
      q.pop();
      for(k = 0; k < 4; ++k) if(flg[p.first][p.second][k] && flg2[p.first + d[k][0]][p.second + d[k][1]]) {
        flg2[p.first + d[k][0]][p.second + d[k][1]] = false;
        if(s[p.first + d[k][0]][p.second + d[k][1]] == '#') cnt[0]++;
        else cnt[1]++;
        q.push(make_pair(p.first + d[k][0], p.second + d[k][1]));
      }
    }
    ans += cnt[0] * cnt[1];
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 1152
n = int(input())
s = input()
l = 0
r = n-1
ans = 0
while l < r:
    # print(l, r)
    if s[l] == 'W':
        if s[r] == 'W':
            r -= 1
        elif s[r] == 'R':
            r -= 1
            l += 1
            ans += 1
    elif s[l] == 'R':
        if s[r] == 'W':
            r -= 1
            l += 1
        elif s[r] == 'R':
            l += 1
print(ans)


Measured memory_bytes: 9488
n,m = gets.chomp.split(" ").map(&:to_i)
route = Array.new(200000){Array.new}
m.times do |i|
  a,b = gets.chomp.split(" ").map(&:to_i)
  route[a-1].push(b)
end
route[0].each do |from|
  route[from-1].each do |to|
    if to == n
      puts "POSSIBLE"
      exit
    end
  end
end
puts "IMPOSSIBLE"

Measured memory_bytes: 31416
#include <iostream>
#define llint long long 
#define mod 1000000007

using namespace std;

llint N, C;
llint A[405], B[405];
llint p[405][405];
llint f[405][405];
llint dp[405][405];

int main(void)
{
	cin >> N >> C;
	for(int i = 1; i <= N; i++) cin >> A[i];
	for(int i = 1; i <= N; i++) cin >> B[i];
	
	for(int i = 1; i <= 400; i++){
		llint pro = 1;
		for(int j = 0; j <= 400; j++){
			p[i][j] = pro;
			pro *= i;
			pro %= mod;
		}
	}
	
	for(int i = 1; i <= 400; i++){
		for(int j = 0; j <= 400; j++){
			llint sum = 0;
			for(int k = A[i]; k <= B[i]; k++){
				sum += p[k][j];
				sum %= mod;
			}
			f[i][j] = sum;
		}
	}
	
	dp[0][0] = 1;
	for(int i = 1; i <= N; i++){
		for(int j = 0; j <= C; j++){
			for(int k = 0; k <= j; k++){
				dp[i][j] += dp[i-1][k] * f[i][j-k];
				dp[i][j] %= mod;
			}
		}
	}
	
	cout << dp[N][C] << endl;
	return 0;
}

Measured memory_bytes: 4096
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] S = sc.nextLine().toCharArray();
        int n = S.length;

        for (int i = 0; i < (1 << n - 1); i++) {
            long sum = (S[0] - '0');
            String res = "" + S[0];
            for (int j = 0; j < n - 1; j++) {
                if ((i & (1 << j)) != 0) {
                    sum += S[j + 1] - '0';
                    res += "+";
                } else {
                    sum -= S[j + 1] - '0';
                    res += "-";
                }
                res += S[j + 1];
            }

            if (sum == 7) {
                System.out.print(res + "=7");
                return;
            }
        }
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
const int INF = 1e9;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
//setprecision(15)

int main() {
	ll N, A, B; cin >> N >> A >> B;
	ll T = B - A;
	if (T < 0) {
		cout << "0" << endl;
	} else if (T == 0) {
		cout << "1" << endl;
	} else if (N == 1) {
		cout << "0" << endl;
	} else if (N == 2) {
		cout << "1" << endl;
	} else {
		ull ans = 1 + (N - 2) * T;
		cout << ans << endl;
	}
}


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

struct Card{
  char pic; int val;
};

void bubbleSort(Card A[], int n){
  for(int i = 0; i < n - 1; i++){
    for(int j = n - 1; j > i; j--){
      if(A[j].val < A[j-1].val){
        swap(A[j], A[j-1]);
      }
    }
  }
}

void selectionSort(Card B[], int n){
  for(int i = 0; i < n; i++){
    int min = i;
    for(int j = i; j < n; j++){
      if(B[j].val < B[min].val) min = j;
    }
    swap(B[i], B[min]);
  }
}

int main(void){
  int n;
  Card A[36], B[36];

  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> A[i].pic >> A[i].val;
    B[i].pic = A[i].pic; B[i].val = A[i].val;
  }

  bubbleSort(A, n);
  selectionSort(B, n);

  for(int i = 0; i < n; i++){
    cout << A[i].pic << A[i].val;
    if(i < n - 1) cout << " ";
  }
  cout << "\nStable" << endl;

  bool flag = true;
  for(int i = 0; i < n; i++){
    cout << B[i].pic << B[i].val;
    if(i < n - 1) cout << " ";
    if(B[i].pic != A[i].pic) flag = false;
  }
  if(flag){
    cout << "\nStable" << endl;
  }else{
    cout << "\nNot stable" << endl;
  }

  return 0;
}

Measured memory_bytes: 1164
k = int(input())
import math
l = []
ans = 0
e = 0
d = 0
for a in range(1,k+1):
    for b in range(a,k+1):
        e = math.gcd(a,b)
        for c in range(b,k+1):
            d = math.gcd(e,c)
            if a != b and b!= c and a!= c:
                ans+= d*6
            elif (a==b and a!=c) or (a==c and a!= b) or (b == c and a!= b):
                ans+= d*3
            else:
                ans+= d
print(ans)


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

int main() {
	int a, b, out;
	cin >> a >> b;

	if(a > b) {
		out = a + a - 1;
	} else if(a == b) {
		out = a + b;
	} else {
		out = b + b - 1;
	}

	cout << out << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int MAX = 1e5+5;
int A, B, Q; ll s[MAX], t[MAX], x;
int main() {
  scanf("%d %d %d", &A, &B, &Q);
  for(int i = 1; i <= A; ++i) scanf("%ld", &s[i]);
  for(int i = 1; i <= B; ++i) scanf("%ld", &t[i]);
  s[0] = t[0] = -INF, s[A+1] = t[B+1] = INF;
  for(int i = 1; i <= Q; ++i) {
    scanf("%ld", &x);
    auto sitr = lower_bound(s+1, s+A+1, x);
    ll sv[2] = {*(sitr-1), *sitr};
    auto titr = lower_bound(t+1, t+B+1, x);
    ll tv[2] = {*(titr-1), *titr};
    ll ans = INF;
    for(int j = 0; j < 2; ++j) {
      for(int k = 0; k < 2; ++k) {
        ans = min(ans, abs(sv[j]-x)+abs(sv[j]-tv[k]));
      }
    }
    for(int j = 0; j < 2; ++j) {
      for(int k = 0; k < 2; ++k) {
        ans = min(ans, abs(tv[j]-x)+abs(tv[j]-sv[k]));
      }
    }
    printf("%ld\n", ans);
  }
}

Measured memory_bytes: 2816
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void){
	int n,m;
	int x;
	int sum,MIN,cnt;
	int i;
	scanf("%d%d",&n,&m);
	MIN=1001;
	sum=0;
	cnt=n;
	for(i=0;i<n;i++){
		scanf("%d",&x);
		sum+=x;
		if(MIN>x)	MIN=x;
	}
	m-=sum;
	cnt+=m/MIN;
	printf("%d\n",cnt);
	return 0;
}
	

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main(){
    string s;
    int ct=0;
    getline(cin,s);
    int len = s.length();
    for(int i=0;i<(int)len/2;i++){
        if(s[i] != s[len-1-i]) {
            s[i] = s[len-i];
            ct = ct + 1;
        }
    }
    cout<<ct;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int ans[1 << 17];
void solve(int a, int b, int l, int r, int n){
	if(l + 2 == r){
		assert(__builtin_popcount(a ^ b) == 1);
		ans[l] = a;
		ans[l + 1] = b;
		return;
	}
	b ^= a;
	
	vi ord(n, -1);
	int sortedb = 0, k = n, m = (l + r) / 2;
	
	for(int i = n - 1;i >= 0; i--){
		if(b >> i & 1){
			ord[i] = --k;
			sortedb |= 1 << k;
		}
	}
	for(int i = n - 1;i >= 0; i--){
		if(!(b >> i & 1)) ord[i] = --k;
	}
	
	assert(sortedb >> n - 1 & 1);
	sortedb ^= 1 << n - 1;
	
	solve(0, 1, l, m, n - 1);
	solve(1, sortedb, m, r, n - 1);
	
	for(int i = l; i < r; i++){
		if(i >= m) ans[i] ^= 1 << n - 1;
		int t = 0;
		rep(j, n) t |= (ans[i] >> ord[j] & 1) << j;
		ans[i] = t ^ a;
	}
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n, a, b; cin >> n >> a >> b;
	if(!__builtin_parity(a ^ b)){
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES" << endl;
	solve(a, b, 0, 1 << n, n);
	rep(i, 1 << n) cout << ans[i] << (i+1==1<<n?"\n":" ");
	
	return 0;
}

Measured memory_bytes: 1536
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import math

MOD = 1000000007



def fact(n):
  ans = {0}
  for i in range(1,math.ceil(n**0.5)+1):
      ans.add(i)
      ans.add(n//i)
  return sorted(list(ans))

def main():
  N,K = map(int, input().split())
  dp = [{} for _ in range(K+1)]
  keys = fact(N)
  dp[1] = {f:f for f in keys}

  for i in range(1,K):
    j_prev = 0
    dp[i+1][0] = 0
    for j in keys[1:]:
      dp[i+1][j] = (dp[i+1][j_prev] + (j-j_prev)*dp[i][N//j]) % MOD
      j_prev = j
  print(dp[K][N])


if __name__ == "__main__":
  main()

Measured memory_bytes: 436636
s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0]*(m+1) for _ in range(n+1)]
for i in range(1,n+1):
  for j in range(1,m+1):
    if s[i-1]==t[j-1]:
      dp[i][j]=dp[i-1][j-1]+1
    else:
      dp[i][j]=max(dp[i-1][j],dp[i][j-1])
x=dp[-1][-1]
i=n
j=m
ans=""
while x!=0:
  if dp[i][j]==dp[i][j-1]:
    j-=1
  elif dp[i][j]==dp[i-1][j]:
    i-=1
  else:
    ans+=s[i-1]
    i-=1
    j-=1
    x-=1
print(ans[::-1])


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

using namespace std;

int main()
{
	string s;
	cin >> s;
	for (int i = 0; i < s.length() - 1; i++) {
		if (s[i] == s[i + 1]) {
			printf("%d %d\n", i + 1, i + 2);
			return 0;
		}
	}
	for (int i = 0; i < s.length() - 2; i++) {
		if (s[i] == s[i + 2]) {
			printf("%d %d\n", i + 1, i + 3);
			return 0;
		}
	}
	cout << "-1 -1" << endl;

	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;


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

  vector <int> pow1 = {1};
  vector <int> pow6(0);
  vector <int> pow9(0);
  int a=6;int b=9;
  for(int i=1;i<12;i++){
  

    pow6.push_back(a);
    pow9.push_back(b);

     a  = 6*a;
    b = b* 9;

  }

  vector <int> dp = {0}; // 0

  for(int i=1;i<=N;i++){

    int pre=99999999;

    pre = min(pre,dp[i-1]);

    for(int j=0;j<11;j++){
      if(i-pow6[j]<0) break;
      pre = min(pre,dp[i-pow6[j]]);
    }

    for(int j=0;j<11;j++){
      if(i-pow9[j]<0) break;
      pre = min(pre,dp[i-pow9[j]]);
    }

  dp.push_back(pre + 1);
  }
  
cout<<dp.back()<<endl;

  return 0;
}
  

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

#define rep(i, s, n) for (Int i = s; i < (Int)(n); i++)
#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
double EPS = 1e-10;
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    string s;
    cin >> s;
    string t[4] = {"dream", "dreamer", "erase", "eraser"};
    bool update = true;
    while (update) {
        update = false;
        rep(i, 0, 4) {
            if (s.size() >= t[i].size() and s.substr(s.size() - t[i].size()) == t[i]) {
                rep(j, 0, t[i].size()) s.pop_back();
                update = true;
                break;
            }
        }
    }
    dump(s.empty() ? "YES" : "NO");
    return 0;
}

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

  int main(){

while (1){
int a,b;
string op;
cin>>a>>op>>b;

if(op == "?") break;

int x;
if ( op =="+") x = a + b;
if ( op =="-") x = a - b;
if ( op =="*") x = a * b;
if ( op =="/") x = a / b;

cout<<x<<endl;
}
return 0;
}


Measured memory_bytes: 3116
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, char) => {
        read_value!($next, String).chars().collect::<Vec<char>>()[0]
     };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
    ($next:expr, isize1) => {
        read_value!($next, isize) - 1
    };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}
macro_rules! printvec {
    ( $item:expr ) => {
        for &i in &$item {
            print!("{} ", i);
        }
        println!("");
    }
}
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);
impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}
impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}
#[derive(PartialEq, PartialOrd, Clone, Debug)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}
#[allow(dead_code)]
const MOD: usize = 1000000007;


fn main() {
    input!{
        X: usize, Y: usize,
    }
    let x = match X {
        1 => 300000,
        2 => 200000,
        3 => 100000,
        _ => 0,
    };
    let y = match Y {
        1 => 300000,
        2 => 200000,
        3 => 100000,
        _ => 0,
    };
    if X == 1 && Y == 1 {
        println!("{}",x+y+400000);
    } else {
        println!("{}",x+y);
    };
}

Measured memory_bytes: 4476
#include<stdio.h>

int main(void){
        int h[10];
        int i,j,l;
        int k;


        for(i=0; i<10; i++){
                scanf("%d",&h[i]);
        }
        //配列の数が小さいほど、中身の数は大きい。ランキング
        for(l=9; l>0; l--){
                for(j=0; j<l; j++){
                        if(h[j] < h[j+1]){
                                int num = h[j];
                                h[j] = h[j+1];
                                h[j+1] = num;
                        }
                }
        }

        for(k=0; k<3 ; k++){
                printf("%d\n",h[k]);
        }

        return 0;
}                                                                   

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

int main(){
    int N,A;
    cin >> N >> A;
    int amari;
    while (true)
    {
     amari = N % 500;
     N /= 500;
    if(N < 500)break;
    }
    if (A>=amari)cout << "Yes" <<endl;
    else cout << "No" <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
#define set multiset
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

int pow(int x, int n){
  if(n == 0)return 1;
  if(n % 2 == 0)return pow(x * x % MOD, n/2);
  else return x * pow(x, n-1) % MOD;
}


int n;int a[210000];
signed main(){
  cin>>n;rep(i,n){
    cin>>a[i];
    a[i] *= -1;
  }
  set<int> st;
  rep(i,n){
    auto itr = st.upper_bound(a[i]);
    if(itr != st.end())st.erase(itr);
    st.insert(a[i]);
  }
  cout << st.size() << endl;
}


Measured memory_bytes: 5760
#include<iostream>

using namespace std;
int ans = 0;
void swap(int* x, int* y){
    *x += *y;
    *y = *x - *y;
    *x = *x - *y;
}
int insertion_sort(int A[], int n){
    int ans = 0;
    int min_A;
    for (int i = 0; i < n-1; i++)
    {
        min_A = i;
        for (int j = i+1; j < n; j++)
        {
            min_A = ((A[min_A] <= A[j]) ? min_A : j);
        }
        if(min_A!=i){
        swap(&A[min_A], &A[i]);
        ans++;
        }
    }
    return ans;
}

void trace(int A[], int n){
    cout << A[0];
    for (int i = 1; i < n; i++)
    {
        cout << " " << A[i];
    }
    cout << endl;
}

int main(){
    int n; cin >> n;
    int A[105];
    for (int i=0; i < n; i++)
        cin >> A[i];
    int ans = insertion_sort(A, n);
    trace(A, n);
    cout << ans << endl;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
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 pair<int,int> P;

int main(){
  int n,k;
  cin >> n >> k;
  int p[n];
  rep(i,n)cin >> p[i];
  int s[n+1];
  s[0]=0;
  rep(i,n)s[i+1] = s[i]+p[i];
  int t=0;
  rep(i,n-k+1){
    chmax(t,s[i+k]-s[i]);
  }
  double ans = (t+k)/2.0;
  printf("%.10f\n", ans);
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<climits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
const int NMAX=1<<17;
int a,b,c;
int main(){
  cin>>a>>b>>c;
  if(a==b){
    prin(c);
  }
  else if(b==c){
    prin(a);
  }
  else{
    prin(b);
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n,w;
int a[110],b[110];
int dp[100010];
signed main(){
	cin>>n>>w;
	for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
	for(int i=1;i<=n;i++)
		for(int j=w;j>=a[i];j--){
			dp[j]=max(dp[j],dp[j-a[i]]+b[i]);
		}
	cout<<dp[w]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <bitset>

int main(){
  int N, A, B;
  scanf("%d %d %d", &N, &A, &B);
  printf("%d %d\n", std::min(A, B), std::max(0, A + B - N));
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    int a,b,c,x,y;cin>>a>>b>>c>>x>>y;
    int ans1 = a*x+b*y;
    int ans2 = 2*c*max(x,y);
    int ans3 = (x>=y)?(2*c*y+a*(x-y)):(2*c*x+b*(y-x));
    co(min(ans1, min(ans2, ans3)));
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100001

int partition(int A[],int p,int r){
  int x,i,j,temp;
  x = A[r];
  i=p-1;
  for(j=p; j<r; j++){
    if(A[j] <= x){
      i++;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }
  temp = A[i+1];
  A[i+1] = A[r];
  A[r] = temp;
  return i+1;
}


int main(){
  int i,j,key,n;
  int A[MAX];

  scanf("%d",&n);
  for(i=0; i<n; i++)scanf("%d",&A[i]);
  key = partition(A,0,n-1);
  
  for(i=0; i<key; i++){
    if(i >=1)printf(" ");
    printf("%d",A[i]);
  }
  printf(" ");
  printf("[%d]",A[key]);
  
  for(j=key+1; j<n; j++){
    if(j>key)printf(" ");
    printf("%d",A[j]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2120
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main()
{int n;
 cin >> n ;
 
 int count = 0;
 
 if (n >= 105) count++;
 if (n >= 135) count++;
 if (n >= 165) count++;
 if (n >= 3*5*13) count++;
 if (n >= 189) count++;
 
 cout << count << endl;
  
  
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

for k in range(N - 1):
    print(A[k], end = ' ')
print(A[N - 1])

for i in range(1, N):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j + 1] = A[j]
        j -= 1
    A[j + 1] = v
    for k in range(N - 1):
        print(A[k], end = ' ')
    print(A[N - 1])


Measured memory_bytes: 5980
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<int,int>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double eps=1e-5;
const ll MOD=1e9+7;
int main(){
    int n,i;cin>>n>>i;
    cout<<n-i+1<<endl;
}   


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
int main() {
    int n; cin >> n;
    int bt = 0, bx = 0, by = 0;
    rep(i, n) {
        int t, x, y; cin >> t >> x >> y;
        bool a = abs(x - bx) + abs(y - by) <= t - bt;
        bool b = (abs(x - bx) + abs(y - by)) % 2 == (t - bt) % 2;
        //cout << a << " " << b << endl;
        if (!(a && b)) {
            cout << "No" << endl;
            return 0;
        }
        bt = t; bx = x; by = y;
    }
    cout << "Yes" << endl;
    return 0;
    
}


Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
S = input()

n = 1
ans = 0
for i in range(N):
    s = S[i:i + n]
    while s in S[i + n:]:
        n += 1
        s = S[i:i + n]
        ans += 1

print(ans)

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

int n, k;
ll p[MAX];

int main()
{
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        scanf("%lld", &p[i]);
    }
    double s = 0, ans = 0;
    for(int i = 1; i <= k; i++){
        s += 1.0*(p[i]+1)/2;
    }
    ans = max(ans, s);
    for(int i = k+1; i <= n; i++){
        s -= 1.0*(p[i-k]+1)/2;
        s += 1.0*(p[i]+1)/2;
        ans = max(ans, s);
    }
    printf("%.7lf", ans);

    return 0;
}


Measured memory_bytes: 1792
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int n;
V< P<int, int> > x;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    x.resize(n);
    
    V<int> ans(n * n, -1);
    for (int i = 0; i < n; i++) {
        int tmpx; cin >> tmpx;
        tmpx--;
        x[i] = make_pair(tmpx, i + 1);
        ans[tmpx] = i + 1;
    }

    sort(ALL(x));

    int left = 0, right = n * n - 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < x[i].second - 1; j++) {
            while (ans[left] != -1) left++;
            if (left > x[i].first) {
                cout << "No\n";
                return 0;
            }
            ans[left] = x[i].second;
        }
    }

    reverse(ALL(x));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n - x[i].second; j++) {
            while (ans[right] != -1) right--;
            if (right < x[i].first) {
                cout << "No\n";
                return 0;
            }
            ans[right] = x[i].second;
        }
    }

    cout << "Yes\n";
    for (int i = 0; i < n * n; i++) cout << ans[i] << (i == n * n - 1 ? '\n' : ' ');
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i=0; i<N; i++) cin >> a[i];
  map<int, int> mp;
  for (int i=0; i<N; i++) mp[a[i]]++;
  auto iterf = mp.begin();
  auto itere = mp.end();
  itere--;
  int amax = itere->first;
  int amin = iterf->first;
  int maxcnt = itere->second;
  int mincnt = iterf->second;
  if (amax-amin>=2) {
    cout << "No" << endl;
    return 0;
  }
  // cout << "amax: " << amax << endl << "maxcnt: " << maxcnt << endl << "mincnt: " << mincnt << endl;
  if (((mp.size()==1) && ((mincnt==amax+1)||((maxcnt/2>=amax)&&(1<=amax))))
   || ((mp.size()==2) && (mincnt+1<=amax) && (amax<=mincnt+(maxcnt/2)))){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}


Measured memory_bytes: 5376
#include <stdio.h>
int main()
{
    int n;
    
    scanf("%d",&n);
    int t1,t2,t3,t4;
    
    t1=n%10 , n=n/10;
    t2=n%10 , n=n/10;
    t3=n%10 , n=n/10;
    t4=n%10 , n=n/10;
    
    if((t1==t2)||(t2==t3)||(t3==t4))
    printf("Bad\n");
    else
    printf("Good\n");
    
    

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

bool is_integer( double x ){
  return floor(x)==x;
}

int main(void){
    // input
    int N, M, K;
    cin >> N >> M >> K;

    // col : 行ボタンを押した回数
    // row : 列ボタンを押した回数
    // col を押して黒くなった目の個数 = (N - row) * col
    // row を押して黒くなった目の個数 = (M - col) * row

    for (int col = 0; col < M+1; ++col) {
        for (int row = 0; row < N+1; ++row) {
            int n = (N - row) * col + (M - col) * row;
            if (n == K) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from fractions import gcd
import bisect
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

k, s = na()
ans = 0
for x in range(k+1):
        for y in range(k+1):
                z = s - x - y
                if z <= k and z >= 0:
                        ans += 1
print(ans)




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

bool is_prime(int N) {
    if (N == 1) return false;
    for (int i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}
int main() {
    int n;cin>>n;
    int x;
    int ans=0;
    for(int i=0;i<n;i++){
        cin>>x;
        if(is_prime(x)){
            ans++;
        }
    }
    cout<<ans<<endl;
}


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


int main() {
    int N,M,C;
    cin >> N >> M >> C;
    vector<int> B(M);
    rep(i,M) {
        cin >> B[i];
    }
    vector<vector<int>> A(N,vector<int>(M));
    rep(j,N) {
        rep(k,M) {
            cin >> A[j][k];
        }
    }
    int ans = 0;
    rep(l,N) {
        int sum = C;
        rep(m,M) {
            sum += B[m]*A[l][m];
        }
        if (sum > 0) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628