akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i = 0; i < (n); i++)
typedef pair<int, int> P;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

const ll INF = 1001001001;

vector<ll> to[2505];
vector<ll> rto[2505];
bool reachableFrom1[2505];
bool reachableToN[2505];
bool ok[2505];

ll V,E,p;

struct edge{
    int from;
    int to;
    int c;
};

void dfs(int v) {
  if (reachableFrom1[v]) return;
  reachableFrom1[v] = true;
  for (int u : to[v]) {
    dfs(u);
  }
}

void rdfs(int v) {
  if (reachableToN[v]) return;
  reachableToN[v] = true;
  for (int u : rto[v]) {
    rdfs(u);
  }
}

bool bellman_ford(const ll &s,const ll &V,const ll &E,const vector<edge> &ed, vector<ll> &d){

    // s=スタート, Vが頂点数，Eが辺の数, ed=どのようなパスを持つか, 
    //d=答えを保持するvector．今は１つの経路が欲しいので参照して書き換えているが全ての経路について必要になった場合にはdをreturnするように改造する

    // 初期化
    for(ll i = 0; i < V; i++){
        d[i] = INF;
    }
    ll num = 0;
    d[s] = 0;
    while(true){
        if(num>V){
            return true;
        }
        //updateが更新されなくなるまでこの操作を繰り返す
        bool update = false;
        for(ll i = 0; i < E; i ++){
            edge e = ed[i];
            if(!ok[e.to])continue;
            if(!ok[e.from])continue; // 接続していないところは考えない．
            // cout << e.to << " " << e.from << endl;
            if(d[e.from]!=INF && d[e.to]>d[e.from]+e.c){
                d[e.to] = d[e.from]+e.c;
                update = true;
            }
        }
        if(!update){
            break;
        }
        num ++;
    }
    return false;
}




int main(){

     cin >> V >> E >> p;
    vector<edge> ed(E);
    rep(i,E){
        cin >> ed[i].from >> ed[i].to >> ed[i].c;
        ed[i].c = p - ed[i].c;
        to[ed[i].from].push_back(ed[i].to);
        rto[ed[i].to].push_back(ed[i].from);
    }
    vector<ll> d(V+5); // スタートの頂点番号を0ではなく１としたいので余分に作ってd[0]は使わない
    dfs(1);
    rdfs(V);
    rep(i,V) ok[i+1] = reachableFrom1[i+1]&reachableToN[i+1];
    bool loop = bellman_ford(1, V, E, ed, d);
    // rep(i,V){
    //     if(ok[i+1]){
    //         cout << i+1 << " true" << endl;
    //     }else{
    //         cout << i+1 << " false" << endl;
    //     }
    // }

    if(loop){
        cout << "-1" << endl;
    }else{
        ll ans = -d[V];
        ans = max((ll)0, ans);
        cout << ans << endl;
    }
    

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,l;
    cin>>n>>l;
    string s[n];
    for(int i=0;i<n;i++) cin>>s[i];
    sort(s,s+n);
    for(int i=0;i<n;i++) cout<<s[i];
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char c[20];
  int tmp=-1;
  long int n;
  scanf("%ld", &n);
  while(n){
    int r=(n-1)%26;
    c[++tmp]='a'+r;
    n=(n-1)/26;
  }
  for(int i=tmp;i>=0;i--){
    printf("%c", c[i]);
  }
  return 0;
}


Measured memory_bytes: 1660
#include <iostream>
#include <cstdio>
#include <cmath>
#include <list>
#include <algorithm>

using namespace std;

int main(void) {
  list<int> L;
  list<int>::iterator it = L.end();

  int n;
  cin >> n;
  for(int i = 0; i < n; i++) {
    int command, ins;
    cin >> command;
    switch(command) {
      case 0:
        cin >> ins;
        it = L.insert(it, ins);
        break;
      case 1:
        int move;
        cin >> move;
        if(move > 0)
          for(int j = 0; j < move; j++) it++;
        else
          for(int j = 0; j < -move; j++) it--;
        break;
      case 2:
        it = L.erase(it);
        break;
    }
  }

  for(list<int>::iterator itr = L.begin(); itr != L.end(); itr++) {
    cout << *itr << endl;
  }
}


Measured memory_bytes: 18644
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
const long MOD = 1000000007;
#define all(a) a.begin(), a.end()
#define eall(a) a.begin()+1, a.end()
#define show(ans)  cout << ans << endl;


long N, M;
int main(){
cin >> N >> M;
vector<long> L(M+2);
vector<long> R(M+2);
erep(i, M) cin >> L[i] >> R[i];
vector<long> x(N+2);
erep(i, M){
    x[L[i]]++;
    x[R[i]+1]--;
}
for(long i = 2; i <= N; i++){
    x[i] = x[i-1]+x[i];
}
// erep(i, N) show(x[i]);
long cnt = 0;
erep(i, N){
    if(x[i] == M) cnt++;
}
show(cnt);

return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
const int mod=998244353;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int n,k,fac[N],inv[N],ifac[N];
int C(int n,int m) {
    if(n<0||m<0||n<m) return 0;
    return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int calc(int n,int m,int b) {
    if(m-n>=b||b<=0) return 0;
    return (C(n+m,n)-C(n+m,n+b)+mod)%mod;
}
int main() {
    n=gi(),k=gi();
    fac[0]=1;for(int i=1;i<=k;i++) fac[i]=1ll*fac[i-1]*i%mod;
    inv[1]=1;for(int i=2;i<=k;i++) inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
    ifac[0]=1;for(int i=1;i<=k;i++) ifac[i]=1ll*ifac[i-1]*inv[i]%mod;
    int ans=0;
    for(int r=k,b=0;r>=(b=k-r);r--) {
        if(r==b) ans=(ans+calc(r,b-1,r-n+1))%mod;
        else ans=(ans+calc(r,b,r-n+1))%mod;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 10368
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;

// Required random number generators

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    READV(N);
    READV(M);
    vector<bool> visited(N+1,false);
    visited[1]=true;
    vector<ll> balls(N+1,1);
    FORI(i,0,M)
    {
        READV(u);
        READV(v);
        if(visited[u])
        {
            visited[v]=true;
        }
        balls[v]++;
        balls[u]--;
        if(balls[u]==0)
        {
            visited[u]=false;
        }
    }
    ll ans=0;
    FORI(i,1,N+1)
    {
        ans+=visited[i];
    }
    cout<<ans<<endl;


//-----------------------------------------------------------------------------------------------------------//


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

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

class Dice{
private:
  int num[6];
public:
  Dice(int,int,int,int,int,int);
  
  void e_roll(){
  int tmp;
  tmp = num[5];
  num[5] = num[2];
  num[2] = num[0];
  num[0] = num[3];
  num[3] = tmp;
}
  void w_roll(){
  int tmp;
  tmp = num[5];
  num[5] = num[3];
  num[3] = num[0];
  num[0] = num[2];
  num[2] = tmp;
}
  void n_roll(){
  int tmp;
  tmp = num[5];
  num[5] = num[4];
  num[4] = num[0];
  num[0] = num[1];
  num[1] = tmp;
}
  void s_roll(){
  int tmp;
  tmp = num[5];
  num[5] = num[1];
  num[1] = num[0];
  num[0] = num[4];
  num[4] = tmp;
}
  int gettop(){return num[0];};
};

  Dice::Dice(int a,int b,int c,int d,int e,int f){
  num[0] = a;
  num[1] = b;
  num[2] = c;
  num[3] = d;
  num[4] = e;
  num[5] = f;
}


int main(){
  int num[6];
  string order;
  for(int i = 0;i < 6;i++){
    cin >> num[i];
  }
  cin >> order;

  Dice dice(num[0],num[1],num[2],num[3],num[4],num[5]);

  for(int i = 0;i < order.size();i++){
    if(order[i] == 'E'){
      dice.e_roll();
    }else if(order[i] == 'W'){
      dice.w_roll();
    }else if(order[i] == 'N'){
      dice.n_roll();
    }else if(order[i] == 'S'){
      dice.s_roll();
    }
  }

  cout << dice.gettop() << endl;

    return 0;
}

Measured memory_bytes: 3196
import java.util.Scanner;

public class Main {
    static long x, ans;

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        x = in.nextLong();
        int n = 0;
        for (long i = 100; i < x;) {
            long a = i / 100;
            i += a;
            n++;
        }
        System.out.println(n);
    }
}


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


int main()
{
    string a,b;
    cin>>a>>b;
    ll i,na=a.size(),nb=b.size();
    if(na+1==nb)
    {
        for(i=0;i<na;i++)
        {
            if(a[i]!=b[i])
            {
                cout<<"No";
                return 0;
            }
        }
        cout<<"Yes";
        return 0;
    }
    else
    {
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 3632
N=int(input())
h=list(map(int,input().split()))

count=1
judge=False
answer=0

while count<=max(h):
    judge=False
    for i in h:
        if i>=count:
            judge=True
        elif i<count and judge==True:
            answer+=1
            judge=False
    if judge==True:
        answer+=1
    count+=1

print(answer)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <tuple>
#include <cmath>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,m) for(int i=n;i<m;i++)
int main()
{
    int A, B, C, D; cin >> A >> B >> C >> D;
    if (A + B > C + D) cout << "Left" << endl;
    if (A + B == C + D) cout << "Balanced" << endl;
    if (A + B < C + D) cout << "Right" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
     int a,b,i;
    char op;
    for(i=1;i>0;i++){
        scanf("%d %c %d",&a,&op,&b);
        if(op=='+')
        {printf("%d\n",a+b);
        }
        else if(op=='-')
        {printf("%d\n",a-b);
        }
        else if(op=='*')
        {printf("%d\n",a*b);
        }
        else if(op=='/'){
            printf("%d\n",a/b);
        }else{
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 2096
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,A,B;
  cin>>N>>A>>B;
  if(B>N*A){
    cout<<N*A<<endl;
  }
  if(B==N*A){
    cout<<B<<endl;
  }
  if(B<N*A){
    cout<<B<<endl;
  }
}
    
  

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

int main() {
    int i, n;
    cin >> n;
    int a[n];
    int minval = 1000001, maxval = -1000001;
    long int sumval = 0;

    for(i=0; i<n; ++i) {
        cin >> a[i];
        minval = min(minval, a[i]);
        maxval = max(maxval, a[i]);
        sumval += a[i];
    }
    cout << minval << ' ' << maxval << ' ' << sumval << endl;

    return 0;
}

Measured memory_bytes: 3100
from sys import stdin
rs = lambda : stdin.readline().strip()
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))

def main():
    N, H, W = ril()
    ans = 0
    for i in range(N):
        a, b = ril()
        if H <= a and W <= b:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()


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

int main() {
  double n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;

  int x = ceil(n / a);
  int y = ceil(n / c);
  int ans = min(x * b, y * d);

  cout << ans << endl;
}



Measured memory_bytes: 3228
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int main(){
    int n,m;
    int i,j,k;
    int a,b,c;
    string sa,sb;
    cin>>sa>>sb;
    n=sa.size(),m=sb.size();
    b=n;
    for(i=0;i<=n-m;i++){
        a=0;
        for(j=0;j<m;j++){
            if(sa[i+j]!=sb[j])a++;
        }
        b=min(a,b);
    }
    cout<<b<<endl;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>

int selectionSort(int *,int);

int main()
{
  int n,*m,i,c,j;
  
  scanf("%d",&n);

  m = (int *)malloc(n * sizeof(int));

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

  c = selectionSort(m,n);

  for(j=0;j<n;j++){
    printf("%d",m[j]);
    if(j<n-1) printf(" ");
    else printf("\n");
  }
  printf("%d\n",c);

  free(m);

  return 0;
}

int selectionSort(int *m,int n)
{
  int i,j,minj,t,c=0;
  
  for(i=0;i<n;i++){
    minj = i;
    for(j=i;j<n;j++){
      if(m[j]<m[minj]){
	minj = j;
      }
    }
    if(i!=minj) c++;
    t = m[i];
    m[i] = m[minj];
    m[minj] = t;
  }

  return c;
}


    
      
      
  
  



Measured memory_bytes: 2108
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#define pb push_back
#define mp make_pair
using namespace std;

int n;
string a, b, c;

int ans;
int cnt[30];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    cin >> n;
    cin >> a >> b >> c;

    for(int i = 0; i < n; i++)
    {
        memset(cnt, 0, sizeof(cnt));
        cnt[a[i] - 'a']++;
        cnt[b[i] - 'a']++;
        cnt[c[i] - 'a']++;

        int diff = 0;
        for(int j = 0; j < 26; j++)
            if(cnt[j])
                diff++;
        ans += (diff - 1);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
using System;

    class NIKKEIC
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            long[] a = new long[n];
            long[] b = new long[n];

            for (int i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                a[i] = long.Parse(input[0]);
                b[i] = long.Parse(input[1]);
            }

            long[] c = new long[n];

            for(int i = 0; i < n; i++)
            {
                c[i] = a[i] + b[i];
            }

            QuickSort(c,a,0,n-1);
            
            long taka = 0;
            long aoki = 0;

            for (int i = n-1; i > 0; i -= 2)
            {
                taka += a[i];
                aoki += c[i-1] - a[i-1];
            }
            if (n % 2 != 0)
                taka += a[0];

            Console.WriteLine(taka - aoki);
            
        }

        public static void QuickSort<T>(T[] array, T[] srray, int left, int right) where T : IComparable<T>
        {
            if (left < right)
            {
                // ピボット決定（配列の先頭、真ん中、末尾の3つの値の中央値とする）
                T pivot = Median(array[left], array[(left + (right - left) / 2)], array[right]);

                int l = left;
                int r = right;

                // ピボットを中心に、分ける
                while (true)
                {
                    // ピボットより小さいデータのインデックスを見つける
                    while (array[l].CompareTo(pivot) < 0) l++;
                    // ピボットより大きいデータのインデックスを見つける
                    while (array[r].CompareTo(pivot) > 0) r--;
                    // 見つかったインデックスの大小が逆転していれば、終了
                    if (l >= r) break;

                    // 見つかった要素を交換
                    Swap(ref array[l], ref array[r], ref srray[l], ref srray[r]);

                    l++; r--;
                }
                // 左右に分けた配列を再帰的にソート
                QuickSort(array,srray, left, l - 1);
                QuickSort(array,srray, r + 1, right);
            }
        }

        // 3値の中から中央値を返す
        public static T Median<T>(T x, T y, T z) where T : IComparable<T>
        {
            if (x.CompareTo(y) < 0)
            {
                return x.CompareTo(z) < 0 ? (y.CompareTo(z) < 0 ? y : z) : x;
            }
            else
            {
                return y.CompareTo(z) < 0 ? (x.CompareTo(z) < 0 ? x : z) : y;
            }
        }

        public static void Swap<T>(ref T a, ref T b , ref T c, ref T d)
        {
            var tmp = a;
            var temp = c;
            a = b;
            b = tmp;
            c = d;
            d = temp;
        }
    }


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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;
}

ll cnt = 0;
ll N;
void dfs(ll v, bool flg3, bool flg5, bool flg7){
    if(v > N) return;
    if(flg3 && flg5 && flg7) cnt++;
    dfs(v*10 + 3, true, flg5, flg7);
    dfs(v*10 + 5, flg3, true, flg7);
    dfs(v*10 + 7, flg3, flg5, true);
}

int main(){

    cin >> N;
    dfs(0, false, false, false);
    cout << cnt << endl;

    
    return 0;
}

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

int main()
{

    string S;
    int n = 0;
    cin >> S;

    for (int i = 0; i < 3; i++)
    {
        n += (S[i] == 'o' ? 1 : 0);
    }

    cout << 700 + (100 * n);

    return 0;
}

Measured memory_bytes: 256
//Name: A Traveler
//Level: 2
//Category: シミュレーション
//Note:

/*
 * 宿場町1から各宿場町までの距離を累積和として求めておくと，任意の宿場町間の距離がO(1)で出せる．
 * あとはシミュレーションするだけ．
 */
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int N, M;
    cin >> N >> M;
    vector<int> distance(N-1); // distance of town_i between town_{i+1}
    vector<int> accum(N-1, 0);
    for(int i = 0; i < N-1; ++i) {
        cin >> distance[i];
        if(i > 0) accum[i] = accum[i-1];
        accum[i] += distance[i];
    }
    int ans = 0;
    int cur = 0;
    for(int i = 0; i < M; ++i) {
        int d;
        cin >> d;
        int next = cur+d;
        if(d > 0) {
            int cur_acc = cur==0 ? 0 : accum[cur-1];
            ans += accum[next-1] - cur_acc;
        }
        else {
            int next_acc = next==0 ? 0 : accum[next-1];
            ans += accum[cur-1] - next_acc;
        }
        ans %= 100000;
        cur = next;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1676
from itertools import product

h,w,k=map(int,input().split())
lst=[input() for _ in range(h)]

count=0
for x in product((0,1),repeat=h):
    for y in product((0,1),repeat=w):
        sm=0
        for i in range(h):
            if x[i]==0 : continue
            for j in range(w):
                if y[j]==0 : continue
                if lst[i][j]=="#" : sm+=1
        if sm==k : count+=1

print(count)

Measured memory_bytes: 9140
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <ctime>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <vector>
#include <iostream>
#include <cstring>
#include <set>
#include <map>
#include <string>
 
namespace fastinput
{
	/** Interface */
 
	inline int readChar();
	template <class T = int> inline T readInt();
	template <class T> inline void writeInt(T x, char end = 0);
	inline void writeChar(int x);
	inline void writeWord(const char *s);
 
	/** Read */
 
	static const int buf_size = 16384;
 
	inline int getChar() {
		static char buf[buf_size];
		static int len = 0, pos = 0;
		if (pos == len)
			pos = 0, len = fread(buf, 1, buf_size, stdin);
		if (pos == len)
			return -1;
		return buf[pos++];
	}
 
	inline int readChar() {
		int c = getChar();
		while (c <= 32)
			c = getChar();
		return c;
	}
 
	template <class T>
	inline T readInt() {
		int s = 1, c = readChar();
		T x = 0;
		if (c == '-')
			s = -1, c = getChar();
		while ('0' <= c && c <= '9')
			x = x * 10 + c - '0', c = getChar();
		return s == 1 ? x : -x;
	}
 
	/** Write */
 
	static int write_pos = 0;
	static char write_buf[buf_size];
 
	inline void writeChar(int x) {
		if (write_pos == buf_size)
			fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
		write_buf[write_pos++] = x;
	}
 
	template <class T>
	inline void writeInt(T x, char end) {
		if (x < 0)
			writeChar('-'), x = -x;
 
		char s[24];
		int n = 0;
		while (x || !n)
			s[n++] = '0' + x % 10, x /= 10;
		while (n--)
			writeChar(s[n]);
		if (end)
			writeChar(end);
	}
 
	inline void writeWord(const char *s) {
		while (*s)
			writeChar(*s++);
	}
 
	struct Flusher {
		~Flusher() {
			if (write_pos)
				fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
		}
	} flusher;
}
 
using namespace fastinput;
using namespace std;
 
int main()
{
	::ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	vector <int> v(n);
	for (int i = 0; i < n; ++i)
		cin >> v[i];
	int res = 2e9;
	for (int x = -100; x <= 100; ++x)
	{
		int cur = 0;
		for (int i = 0; i < n; ++i)
		{
			cur += abs(v[i] - x) * abs(v[i] - x);
		}
		res = min(res, cur);
	}
	cout << res << endl;
 
 
	return 0;
}

Measured memory_bytes: 256
N = int(input())
As = list(map(int, input().split()))
d = [0]*(N**2)
for i in range(N):
    for j in range(N-i):
        span = i*N+j
        if i == 0:
            d[span] = As[j]
        else:
            d[span] = max(As[j]-d[span-N+1], As[j+i]-d[span-N])
print(d[span])

Measured memory_bytes: 111852
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REPF(i, a, n) for (int i = a; i < (n); i++)
#define REP(i, n) REPF(i, 0, n)
#define FORE(x, s) for (auto& x : s)
#define ALL(x) begin(x),end(x)

signed main() {
    int N;
    cin >> N;
    vector<vector<int>> g(N);
    REP(i, N) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<bool> oncycle(N, false), vis(N, false);
    vector<int> parent(N, -1), depth(N, 0);
    int x, y;
    function<void(int, int)> dfs = [&](int v, int p) {
        vis[v] = true;
        parent[v] = p;
        if (p != -1) depth[v] = depth[p] + 1;
        FORE(w, g[v]) {
            if (w == p) continue;
            if (vis[w]) {
                x = v, y = w;
                return;
            } else {
                dfs(w, v);
            }
        }
    };
    dfs(0, -1);
    
    {
        oncycle[x] = oncycle[y] = true;
        while (depth[x] > depth[y]) {
            x = parent[x];
            oncycle[x] = true;
        }
        while (depth[x] < depth[y]) {
            y = parent[y];
            oncycle[y] = true;
        }
        while (x != y) {
            x = parent[x];
            y = parent[y];
            oncycle[x] = oncycle[y] = true;
        }
    }

    int Q;
    cin >> Q;
    while (Q--) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        if (oncycle[a] && oncycle[b]) {
            cout << 2 << endl;
        } else {
            cout << 1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 17668
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> li;
    for(int i = 0; i<n; i++){
        int x;
        cin >> x;
        for(int j = -1; j<=1; j++){
            li.push_back(x+j);
        }
    }
    int ans = 0;
    int last = -5;
    int co = 0;
    sort(li.begin(),li.end());
    for(int i = 0; i<li.size(); i++){
        if(li[i]!=last){
            co = 0;
        }
        last = li[i];
        co++;
        ans = max(ans,co);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2420
main=do
 [n,k]<-map read.words<$>getLine
 d<-words<$>getLine
 print(f n d)
  where f n d = if (g (show n) d) then (f (n+1) d) else n
        g n d = foldr (||) False (map (\c->elem [c] d) n)

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main(){int i,n,k=0;
string s;
cin>>s;n=s.size();
if(n%2){k=1;}
n/=2;
for(i=0;i<n;i++){if(s[2*i]!='h'||s[2*i+1]!='i'){k++;}}
if(k){cout<<"No";}
else{cout<<"Yes";}
    return 0;}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
#define int long long int
struct action
{
	int a;
	int b;
	int c;
};
int bottom(action axn[], int n)
{
	int dp[n + 1][3] = {0};
	dp[0][0] = axn[0].a;
	dp[0][1] = axn[0].b;
	dp[0][2] = axn[0].c;
	for (int i = 1; i < n; i++)
	{
		dp[i][0] = axn[i].a + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = axn[i].b + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = axn[i].c + max(dp[i - 1][0], dp[i - 1][1]);
	}
	return max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
}
int32_t main()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int n;
	cin >> n;
	action axn[n];
	for (int i = 0; i < n; i++)
	{
		cin >> axn[i].a;
		cin >> axn[i].b;
		cin >> axn[i].c;
	}
	cout << bottom(axn, n);
}
// 7
// 6 7 8
// 8 8 3
// 2 5 2
// 7 8 6
// 4 6 8
// 2 3 4
// 7 5 1

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mxe max_element
#define mne min_element
#define bg begin()
#define nd end()
 
void swap(int &a,int &b)
{
    int t=a;
    a=b;
    b=t;
    return ;
}





int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll t,n;
    ll k;
    cin>>n>>k;
    
    vector<ll> v(n);
    for(auto &x:v)cin>>x;
    sort(v.begin(),v.end());
    ll res=accumulate(v.begin(),v.begin()+k,0);
    cout<<res<<"\n";
    
    return 0;
}








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

int main() {
  int n;
  cin>>n;
  int cnt=0;
  for(int i=1;i<=n;i++) {
    int a;
    cin>>a;

    if(i%2==1&&a%2==1) {
      cnt++;
    }
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void puts_all(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void puts_all(const T &value, const Args&... args){std::cout << value << " ";puts_all(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int h,a;
  while(cin >> h >> a){
    cout << (h + a - 1) / a << endl;
  }


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  int count = 0;
  for(int i = 0; i < S.size() / 2; i++){
    if(S.at(i) != S.at(S.size() - 1 - i))count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)

apple = []
apple.extend(p[:x])
apple.extend(q[:y])
apple.extend(r)

apple.sort(reverse=True)
print(sum(apple[:x+y]))


Measured memory_bytes: 23328
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define lowbit(x) ((x)&(-x))
#define inf 0x3f3f3f3f
#define endl "\n"
#define MP(x,y) (make_pair(x,y))
#define pll pair<int,int>
#define pi 3.1415926535
using namespace std;
int n,k,c;
char s[200005];
int z[200005],y[200005],lst[200005];
int main(){
    scanf("%d%d%d",&n,&k,&c);
    scanf("%s",s);
    int l = 0;
    while(s[l]=='x') l++;
    int r=n-1;
    while(s[r]=='x') r--;
    if(r<l) return 0;
    for(int i=l;i<=r;i++){
        if(s[i] == 'x'){
            z[i] = 0;
            lst[i] = lst[i-1];
        }else{
            lst[i] = i;
            int x = i;
            if(i-l>c){
                x = lst[x-c-1];
                z[i] = z[x]+1;
            }else{
                z[i] = 1;
            }
        }
    }
    for(int i=r;i>=l;i--){
        if(s[i]=='x'){
            y[i] = 0;
            lst[i] = lst[i+1];
        }else{
            lst[i] = i;
            int x=i;
            if(r-i>c){
                x = lst[x+c+1];
                y[i] = y[x]+1;
            }else{
                y[i] = 0;
            }
        }
    }
    vector<int> a,b;
    a.pb(-inf);
    for(int i=l;i<=r;i++){
        if(z[i]+y[i]>=k) a.pb(i);
        //cout<<i<<' ';}
    }
    a.pb(inf);
    for(int i=1;i<a.size()-1;i++){
        if(a[i]-a[i-1]>c && a[i+1]-a[i]>c){
            b.pb(a[i]+1);
        }
    }
    if(b.size()<=k){
        for(int i=0;i<b.size();i++){
            printf("%d\n",b[i]);
        }
    }
}


Measured memory_bytes: 5748
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
string S;

void solve(){
	int s = S.size();
	while(true){
		s -= 2;
		bool b = true;
		rep(i, s / 2){
			if(S[i] != S[i + s / 2]) {
				b = false;
				break;
			}
		}
		if(b){
			cout << s << endl;
			break;
		}
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> S;
		solve();
	return 0;
}


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 10e-10;

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n, k;
    cin >> n >> k;
    ll a[n];
    for(int i=0;i<n;i++) cin >> a[i];

    vector<ll> v;
    for(int i=0;i<n;i++) {
        ll total = a[i];
        v.push_back(total);
        for(int j=i+1;j<n;j++) {
            total += a[j];
            v.push_back(total);
        }
    }

    ll ans = 0LL;
    for(int i=50;i>=0;i--) {
        ll tmpans = ans + (1LL << i);
        int count = 0;
        for(int j=0;j<n*(n+1)/2;j++) {
            if((tmpans & v[j]) == tmpans) {
                count++;
            }
        }
        if(count >= k) ans = tmpans;
    }
    cout << ans << endl;

}


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

typedef long long ll;
typedef double ld;
typedef pair <ll, ll> pll;

#define pb push_back
#define mp make_pair
#define all(_c) _c.begin(), _c.end()

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    int h[n], v[n];
    for (int i = 0; i < n; i++)
        cin >> h[i], v[i] = 0;
    
    int cnt = 0;
    bool f = 0;
    while (!f) {
        for (int i = 0; i < n; ) {
            int j = i, mn = INT_MAX;
            while (j < n and v[j] != h[j]) {
                mn = min(mn, h[j] - v[j]);
                j++;
            }
            if (mn != INT_MAX) {
                cnt += mn;
                for (int k = i; k < j; k++)
                    v[k] += mn;
            }
            if (i == j) i++;
            else i = j;
        }
        f = 1;
        for (int i = 0; i < n; i++) 
            if (v[i] != h[i])
                f = 0;
    }

    cout << cnt << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int read() {
	int x=0, f=1; char ch=' ';
	while(!isdigit(ch)) {ch=getchar(); if(ch=='-') f=-1;}
	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48), ch=getchar();
	return x*f;
}
int a, b, c, d, e; 
int main() {
	cin>>a>>b>>c>>d>>e;
	if(!a) cout<<1;
	else if(!b) cout<<2;
	else if(!c) cout<<3;
	else if(!d) cout<<4;
	else if(!e) cout<<5;
}


Measured memory_bytes: 3636
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void printvv(vector<vector<int>> V){
	int h = V.size();
  	int w = V[0].size();
  	rep(i,h){
    	rep(j,w){
  			cout << V[i][j] << " ";
        }
      	cout << endl;
    }
  	cout << endl;
  	return;
}

void Main()
{
	int H, W;
  	cin >> H >> W;
  	vector<string> S(H);
  	rep(i,H) cin >> S[i];
  
  	// S[i][j], 0<=i<H, 0<=j<W
  	vector<vector<int>> L(H, vector<int>(W,0));
  	vector<vector<int>> R(H, vector<int>(W,0));
  	vector<vector<int>> U(H, vector<int>(W,0));
  	vector<vector<int>> D(H, vector<int>(W,0));
  	
  	rep(i,H){
    	rep(j,W){
        	if(S[i][j] == '#'){
            	L[i][j] = 0;
            }
        	else{
            	if(j==0){L[i][j] = 1;}
              	else{L[i][j] = L[i][j-1] + 1;}
            }
        }
    }
  
  	rep(i,H){
    	rep3rev(j,W-1,0){
        	if(S[i][j] == '#'){
	           	R[i][j] = 0;
            }
        	else{
            	if(j==W-1){R[i][j] = 1;}
              	else{R[i][j] = R[i][j+1] + 1;}
            }
        }
    }
  
	rep(j,W){
    	rep(i,H){
        	if(S[i][j] == '#'){
            	U[i][j] = 0;
            }
        	else{
            	if(i==0){U[i][j] = 1;}
              	else{U[i][j] = U[i-1][j] + 1;}
            }
        }
    }  
              	
	rep(j,W){
    	rep3rev(i,H-1,0){
        	if(S[i][j] == '#'){
            	D[i][j] = 0;
            }
        	else{
            	if(i==H-1){D[i][j] = 1;}
              	else{D[i][j] = D[i+1][j] + 1;}
            }
        }
    }  
  	/*
    printvv(U);			           
	printvv(D);
  	printvv(L);
  	printvv(R);  	
	*/
  	
  	int temp = 0;
  	rep(i,H){
		rep(j,W){
			temp = max(temp, U[i][j]+D[i][j]+L[i][j]+R[i][j]-3);
        }
    }
  	cout << temp << endl;
  	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 67328
#include <stdio.h>

double outerproduct(double xa, double ya, double xb, double yb){
	return xa*yb-xb*ya;
}

int main() {
	double x[4], y[4], op1, op2, op3, op4;
	while( EOF!=scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",
			&x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3])) {
		op1 = outerproduct( x[2]-x[0], y[2]-y[0], x[1]-x[0], y[1]-y[0]);
		op2 = outerproduct( x[3]-x[1], y[3]-y[1], x[2]-x[1], y[2]-y[1]);
		op3 = outerproduct( x[0]-x[2], y[0]-y[2], x[3]-x[2], y[3]-y[2]);
		op4 = outerproduct( x[1]-x[3], y[1]-y[3], x[0]-x[3], y[0]-y[3]);
		if ( ( (op1>0.0)&&(op2>0.0)&&(op3>0.0)&&(op4>0.0) )||
		( (op1<0.0)&&(op2<0.0)&&(op3<0.0)&&(op4<0.0) ) ) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); 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 REPS(i, n) for (int i = 1; i <= (n); i++)
#define RREPS(i, n) for (int i = (n); i > 0; i--)
#define mp make_pair
#define pb(a) push_back(a)
typedef long long ll;

int main() {
  int N;
  ll C;
  cin >> N >> C;
  vector<ll> x(N);
  vector<ll> v(N);
  REP(i, N) cin >> x[i] >> v[i];
  ll ans = 0;
  vector<ll> S(N);
  vector<ll> RS(N);
  S[0] = v[0];
  REPS(i, N - 1) S[i] = S[i - 1] + v[i];
  RS[N - 1] = v[N - 1];
  RREP(i, N - 1) RS[i] = RS[i + 1] + v[i];

  REP(i, N) S[i] -= x[i];
  REP(i, N) RS[i] -= C - x[i];
  REPS(i, N - 1) {
    S[i] = max(S[i], S[i - 1]);
  }
  RREP(i, N - 1) {
    RS[i] = max(RS[i], RS[i + 1]);
  }
  ans = max(S[N - 1], RS[0]);
  REP(i, N - 1) {
    ans = max(ans, S[i] - x[i] + RS[i + 1]);
  }
  RREPS(i, N - 1) {
    ans = max(ans, RS[i] + S[i - 1] - (C - x[i]));
  }
  cout << max((ll)0, ans) << endl;
  return 0;
}


Measured memory_bytes: 3328
def main():
    S = {'AC':0, 'WA':0, 'TLE':0, 'RE':0}
    N = int(input())
    for i in range(N):
        s = input()
        S[s] += 1

    for i in ['AC', 'WA', 'TLE', 'RE']:
        print('{} x {}'.format(i, S[i]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9120
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
void solve(); int main() { solve(); return 0; }

void solve() {
  ll n,k;
  cin >> n >> k;
  vector<int> A(n), F(n);
  loop(i,0,n) cin >> A[i];
  loop(i,0,n) cin >> F[i];
  sort(A.begin(), A.end());
  sort(F.rbegin(), F.rend());
  
  auto ok = [&](ll x, ll y) {
    ll total = 0;
    loop(i,0,n) {
      total += max(A[i]-x/F[i], 0LL);
    }
    return total <= y;
  };
  
  ll x,l=-1, r=1000000000000; // (10^6)^2+α
  while (l+1<r) {
    x = (l+r)/2;
    if (ok(x, k)) r=x;
    else l=x;
  }
  
  cout << r << endl;
}


Measured memory_bytes: 4848
def solve(N,X,M):
    Loop = [X]
    Loop_set = set(Loop)

    for i in range(N):
        X = X**2 % M
        if X not in Loop_set:
            Loop.append(X)
            Loop_set.add(X)
        else:
            break

    loop_st = 0
    for i in range(len(Loop)):
        if Loop[i] == (Loop[-1]**2 % M):
            loop_st = i
            break

    loop_len = len(Loop) - loop_st
    ans = sum(Loop[:loop_st])
    N -= loop_st
    ans += (sum(Loop[loop_st:]) * (N // loop_len) + sum(Loop[loop_st:loop_st + (N % loop_len)]))
    return ans

def main():
    N,X,M = map(int,input().split())

    print(solve(N,X,M))

if __name__ == "__main__":
    main()


Measured memory_bytes: 77352
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;

const int maxn=2e5+50;

int n,k,N,r[maxn];
ll ans,a[maxn],sum[maxn];

inline int read(int x=0,char c=getchar()) {
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x;
}

ll c[maxn];

inline void add(int x,int v){for(;x<=N;x+=x&-x)c[x]+=v;}
inline int ask(int x){int y=0;for(;x;x-=x&-x)y+=c[x];return y;}

int main() {
	n=read();k=read();
	for(register int i=1;i<=n;++i) a[i]=read()-k; //转换为区间和大于等于0 
	for(register int i=1;i<=n;++i) if((sum[i]=(a[i]+=a[i-1]))>=0) ++ans;
	//处理前缀和的同时把区间左端点为1的情况直接算了 
	sort(sum+1,sum+1+n); N=unique(sum+1,sum+1+n)-sum-1; //不同前缀和的个数 
	for(register int i=1;i<=n;++i) r[i]=lower_bound(sum+1,sum+1+N,a[i])-sum; //离散化 
	for(register int i=1;i<=n;++i) ans+=ask(r[i]),add(r[i],1);
	//枚举右端点 看有多少个左端点满足要求 
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define min(...) minn(__VA_ARGS__)
#define max(...) maxx(__VA_ARGS__)
#define stringio() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
char _;
typedef long long ll;
typedef pair<int,int> pii;
template<typename t>constexpr const t minn(const t x,const t y){return x<y?x:y;}
template<typename t,typename ...r>constexpr const t minn(const t x,const r ...xs){return minn(x,minn(xs...));}
template<typename t>constexpr const t maxx(const t x,const t y){return x>y?x:y;}
template<typename t,typename ...r>constexpr const t maxx(const t x,const r ...xs){return maxx(x,maxx(xs...));}
template <typename t> void scan (t& x) {do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0);}
template <typename t, typename ...r> void scan (t& x, r&... xs) {scan(x); scan(xs...);}
const int MAXN = 100005;
int main() {
    int r;
    scan(r);
    printf ("%d\n",3*r*r);
    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h, w, k = map(int, readline().split())
dp = [[0] * w for _ in range(h + 1)]
dp[0][0] = 1
mod = 10 ** 9 + 7
for i in range(h):
    for b in range(1 << (w - 1)):
        if '11' in bin(b):
            continue
        for j in range(w):
            if j and b & (1 << (j - 1)):
                dp[i + 1][j - 1] += dp[i][j]
            elif b & (1 << j):
                dp[i + 1][j + 1] += dp[i][j]
            else:
                dp[i + 1][j] += dp[i][j]
print(dp[-1][k - 1] % mod)


Measured memory_bytes: 3188
#!/usr/bin/env python3

t = list(str(input()))

t_new = []
for i in t:
    if i == "?":
        t_new.append("D")
    else:
        t_new.append(i)

for i in t_new:
    print(i, end="")
# ans = 0
# for i in range(n):
#     if t_new[i] == D:
#         ans += 1

# for i in range(1, n):
#     if t_new[i-1] == P and t_new[i] == D:
#         ans += 1
# print(ans)


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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        int n = in.ni(), m = in.ni();
        long k = in.nl();
        long[] a = in.nl(n);
        long[] b = in.nl(m);
        long[] sum_a = new long[n+1];
        long[] sum_b = new long[m+1];
        sum_a[0] = 0;
        for (int i = 1; i <= n; i++) {
            sum_a[i] = sum_a[i-1]+a[i-1];
        }
        sum_b[0] = 0;
        for (int i = 1; i <= m; i++) {
            sum_b[i] = sum_b[i-1]+b[i-1];
        }
        int r = m;
        while(r>=0&&sum_b[r]>k) r--;
        int ans = r;
        for (int i = 0; i <= n; i++) {
            while(r>=0&&sum_b[r]+sum_a[i]>k) r--;
            if(r==-1) break;
            ans = Math.max(r+i,ans);
        }
        out.println(ans);

    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 63152
#include<iostream>
#include<vector>
using namespace std;
long long int inf = 1e10;
int main(){
    long long int n,w,i,j,ans;
    cin>>n>>w;
    long long int wt[n],val[n],sum_val = 0;
    for(i=0; i<n; i++){
        cin>>wt[i]>>val[i];
        sum_val += val[i];
    }
    long long int dp[n+1][sum_val+1];
    for(i=0; i<=n; i++){
        for(j=0; j<=sum_val; j++){
            dp[i][j] = inf;
            if(j==0)
                dp[i][j] = 0;
            if(i==0)
                continue;
            else if(j>=val[i-1])
                dp[i][j] = min(dp[i-1][j] , wt[i-1] + dp[i-1][j-val[i-1]]);
            else
                dp[i][j] = dp[i-1][j];
        }
    }
    for(i=0; i<=sum_val; i++){
        if(dp[n][i]<=w)
            ans = i;
    }
    cout<<ans;
}

Measured memory_bytes: 79104