akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)
#include <vector>
#include <iostream>
using namespace std;

template <class T> struct Matrix {
  vector<vector<T>> value;
  T init;

  Matrix(vector<vector<T>> vec,T init_) :init(init_), value(vec) {}
  Matrix(int h, int w, T init_) : init(init_) , value(h, vector<T>(w,init_)) {}

  Matrix<T> operator*(Matrix<T>& left) {
      Matrix<T> res(value.size(),left[0].size(),init);
      for(int i = 0;i < value.size();i++){
          for(int k = 0;k < left.size();k++){
              for(int j = 0;j < left[0].size();j++){
                  res[i][j] = (res[i][j] + value[i][k] * left[k][j]);
              }
          }
      }
      return res;
  }

  Matrix<T> operator+(Matrix<T>& left){
      Matrix<T> res = *this;
      for(int i = 0;i < res.size();i++){
          for(int j = 0;j < res[0].size();j++){
              res[i][j] += left[i][j];
          }
      }
      return res;
  }

  Matrix<T> operator*(T c){
      Matrix<T> res = *this;
      for(int i = 0;i < res.size();i++){
          for(int j = 0;j < res[0].size();j++){
              res[i][j] *= c;
          }
      }
      return res;
  }

  vector<T>& operator[](int n){
      return value[n];
  }

  size_t size(){
      return value.size();
  }

  Matrix<T> operator^(long long n){
      Matrix<T> a = *this;
      Matrix<T> res(a.size(),a.size(),init);
      for(int i = 0;i < a.size();i++){
          res[i][i] = 1;
      }

      while(n > 0){
          if(n & 1) res = res * a;
          a = a * a;
          n >>= 1;
      }
      return res;
  }
};
template <i64 MOD> struct ModInt {
  i64 value;

  ModInt(i64 v = 0) { value = v % MOD; }

  operator i64() { return value; }
  ModInt<MOD> operator+(int v) { return (value + v) % MOD; }
  ModInt<MOD> operator+(i64 v) { return (value + v) % MOD; }

  ModInt<MOD> operator-(i64 v) {
    v %= MOD;
    return (MOD + value - v) % MOD;
  }

  ModInt<MOD> operator*(i64 v) { return (value * v) % MOD; }
};



i64 k;

int main(){
    cin >> k;
    i64 len;
    {
        i64 ok = 0;
        i64 ng = 1e10;
        while(ng - ok > 1){
            i64 mid = (ok + ng) / 2;
            i64 t = (mid / 2 - 1) * ((mid / 2));
            if(mid % 2 == 1) t += (mid - 1) / 2;
            if(t < k) ok = mid;
            else ng = mid;
        }
        len = ok;
    }
    i64 t = (len / 2 - 1) * ((len / 2));
    if (len % 2 == 1)
        t += (len - 1) / 2;
    k -= t + 1;


    i64 x = 0;
    i64 y = 0;
    i64 half = len / 4;

    if(k * 2 + 1 <= len / 2){
        x = k * 2 + 1;
        y = len - x;
    }
    else{
        k = len / 2 - k;
        x = 2 * k;
        y = len - x;
    }
    const i64 MOD = 1e9 + 7;
    using mint = ModInt<MOD>;

    auto mat = Matrix<mint>({{1,1},{1,0}},0);
    cout << (mat ^ (x + 1))[1][0] * (mat ^ (y + 1))[1][0] << endl;
}


Measured memory_bytes: 3100
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] a = new int[m];
    for(int i = 0; i < m; i++) {
      a[i] = sc.nextInt();
    }
    Arrays.sort(a);
    int[] hon = {2, 5, 5, 4, 5, 6, 3, 7, 6};
    int[] dp = new int[n + 1];
    int[] b = new int[m];
    for(int i = 0; i < m; i++) {
      b[i] = hon[a[i] - 1];
    }
    for(int i = 1; i < n + 1; i++) {
      dp[i] = -1000000; 
    }
    for(int i = 1; i < n + 1; i++) {
      for(int j = 0; j < m; j++) {
        if(b[j] <= i) {
          dp[i] = Math.max(dp[i], dp[i - b[j]] + 1);
        }
      }
    }
    String ans = "";
    int k = n;
    while(k > 0) {
      for(int j = m - 1; j >= 0; j--) {
        if((k >= b[j]) && (dp[k - b[j]] == (dp[k] - 1))) {
          k -= b[j];
          ans += String.valueOf(a[j]);
          break;
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 58580
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <limits>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

	cout << (a + (a * a) + (a * a * a)) << endl;

	return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
/* Data Structure */
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <stack>
#include <queue>

using namespace std;

#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3fLL
#define debug cerr << "======= GOT_HERE ======\n"
#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef map<int,int> mii;
typedef map<long long,long long> mll;
typedef set<int> si;
typedef set<long long> sll;

long long n,k;

int main()
{

	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n>>k;
	ll sum = 0;
	ll mx = 0;
	vector<ll> v(n);
	for(int i=0;i<n;++i)
	{
		cin>>v[i];
	}
	for(int i=0;i<k;++i)
	{
		sum+=v[i];
	}

	mx = sum;
	for(int i=k;i<n;++i)
	{
		sum-=v[i-k];
		sum+=v[i];
		mx = max(sum,mx);
	}
	cout << setprecision(10) << fixed << (mx+k)/(double)2 << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int x;
  cin>>x;
  for(int i=1;i<n;i++)
  {
    int y;
    cin>>y;
    x=__gcd(x,y);
  }
  cout<<x<<"\n";
}

Measured memory_bytes: 256
#include <stdio.h>


int main() {
	int n;
	char s[100];
	scanf("%d",&n);
	scanf("%s",s);
	int i, count = 0;
	for(i=0;i<n;i++){
		if(s[i] == 'R'){count++;}

	}
	if(2 * count > n){
		printf("Yes");
	}else{
		printf("No");
	}

	return 0;
}

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

void selectionSort(int a[], int N){
  bool flg =1;
  int count=0;
  for(int i=0;i<N;i++){
    int minj=i;
    for(int j=i;j<N;j++){
        if(a[j]<a[minj]){
          minj =j;
        }

    }
    swap(a[i],a[minj]);
    if(i!=minj) count++;
  }

  for(int k=0;k<N;k++){
      if(k==N-1) cout<<a[k]<<endl;
      else cout <<a[k]<<" ";
    }
    cout<<count<<endl;

}

int main() {
  int N;
  cin>>N;
  int a[N];
  for (int j = 0; j < N; j++) cin>>a[j];

  selectionSort(a,N);


}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define ls(x) (x)<<1
#define rs(x) (x)<<1|1
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ll rt<<1
#define rr rt<<1|1
#define PI acos(-1)
#define MM int m=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define Case(i,ans) cout<<"Case "<<i<<": "<<ans<<endl;
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) (x+mo_num)%mo_num
#define vc vector
#define vct vector<int>
#define fa(i,V) for(auto i:V)
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
#define P pair<int,int>
using namespace std;
const int INF=LLONG_MAX;
const int maxn=1e6+5;
const int mo_num=1e9+7;
int n,m,a[maxn],b[maxn],ans;
map<P,int>t;
set<P>T;
vc<P>H;
int32_t main()
{
    IOS
    cin>>n;
    fun(i)
    {
        int x,y;
        cin>>x>>y;
        t[{x,y}]=1;
        fa(j,H)
        {
            T.insert({j.fi-x,j.se-y});
        }
        H.pb({x,y});
    }
    if(n==1)return cout<<1,0;
    int num;
    ans=INF;
    fa(i,T)
    {
        int x=i.fi,y=i.se;
        num=n;
        fa(j,H)
        {
            if(t[{j.fi+x,j.se+y}])num--;
        }
        ans=min(ans,num);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
using ll = long long;
const ll mod = (ll)1e9 + 7;

ll powmod(ll a, ll k, ll m) {
  if (k == 0) return 1;
  ll t = powmod(a, k / 2, m);
  t = (t * t) % mod;
  if (k % 2 == 1) t = (t * a) % mod;
  return t;
}

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  if (n >= 2) {
    ll np = powmod(9, n, mod);
    ll npq = powmod(8, n, mod);
    ll np_nq = np * 2 - npq;
    while (np_nq < 0) np_nq += mod;
    np_nq %= mod;
    ans = powmod(10, n, mod) - np_nq;
    while (ans < 0) ans += mod;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  int ans = 0;
  for(int i = 0 ; i < n; i++){
    cin >> a[i];
  }
  for(int i = 0; i < n; i++){
    cin >> b[i];
  }
  for(int i = 0; i < n-1; i++){
    cin >> c[i];
  }
  for(int i = 1; i <= n; i++){
    ans += b[a[i-1]-1];
    if(a[i]-a[i-1]==1){
      ans += c[a[i-1]-1];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, k;
    cin >> n >> k;
    long long mod = 1e9 + 7;
    vector<long long>v(n + 5);
    for(int i = 1; i <= n; i++){
        cin >> v[i];
    }
    long long dp[n + 5][k + 5], cum[n + 5][k + 5];
    sort(v.begin() + 1, v.begin() + n + 1);
    dp[1][0] = 1, cum[1][0] = 1;
    for(int i = 1; i <= v[1]; i++){
        dp[1][i] = 1;
        cum[1][i] = (cum[1][i - 1] + dp[1][i]) % mod;
    }
    for(int i = v[1] + 1; i <= k; i++){
        dp[1][i] = 0;
        cum[1][i] = cum[1][i - 1];
    }
    for(int i = 2; i <= n; i++){
        for(int j = 0; j <= v[i]; j++){
            dp[i][j] = cum[i - 1][j];
            if(j == 0){
                cum[i][j] = dp[i][j];
            }
            else{
                cum[i][j] = (cum[i][j - 1] + dp[i][j])%mod;
            }
        }
        for(int j = v[i] + 1; j <= k; j++){
            dp[i][j] = (cum[i - 1][j] - cum[i - 1][j - v[i] - 1] + 2*mod) % mod;
            cum[i][j] = (cum[i][j - 1] + dp[i][j]) % mod;
        }
    }
    cout << dp[n][k];
    return 0;
}

Measured memory_bytes: 162176
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    bool poor = false;
    if (A == B && B != C || B == C &&  C != A || C == A && A != B)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define N 500000
int count;

struct node
{
  int key;
  int pare;
  int left;
  int right;
};

struct node bi[N];

void insert(int z)
{
  int x,y;
  int num=0;

  y=-1;
  x=bi[0].key;
//  printf("while start\n");
  while(1)
  {
    if(x==-1) break;
    y = num;
    if(z<x)
    {
      num = bi[num].left;
      if(num!=-1) x = bi[num].key;
      else
      {
        x=-1;
      }
    }
    else
    {
      num = bi[num].right;
      if(num!=-1) x = bi[num].key;
      else
      {
        x=-1;
      }
    }
  }
//  printf("while end\n");
  bi[count].pare=y;
  bi[count].key=z;

  if(y==-1)
  {
    bi[0].key=z;
  }
  else if(z<bi[y].key)
  {
    bi[y].left = count;
  }
  else
  {
    bi[y].right = count;
  }

  count++;
}

void pre(int now)
{
  printf(" %d",bi[now].key);
  if(bi[now].left!=-1)  pre(bi[now].left);
  if(bi[now].right!=-1)  pre(bi[now].right);
}

void in(int now)
{
  if(bi[now].left!=-1) in(bi[now].left);
  printf(" %d",bi[now].key);
  if(bi[now].right!=-1) in(bi[now].right);
}


void print()
{
  in(0);
  printf("\n");
  pre(0);
  printf("\n");
}

void find(int key)
{
  int i=0;
  while(1)
  {
    if(bi[i].key==key)
    {
      printf("yes\n");
      return;
    }
    if(bi[i].pare==-1) break;
    i = bi[i].pare;
  }
//  printf("start:%d num:%d\n",i,bi[i].key);
  while(1)
  {
    if(bi[i].key<key)
    {
      i=bi[i].right;
      if(i==-1)
      {
        printf("no\n");
        return;
      }
    }
    else
    {
      i=bi[i].left;
      if(i==-1)
      {
        printf("no\n");
        return;
      }
    }
    if(bi[i].key==key)
    {
      printf("yes\n");
      return;
    }
  }
}

int main(void)
{
  int n,i;
  int num;
  char comm[10];
  count=0;

  for(i=0;i<N;i++)
  {
    bi[i].key = -1;
    bi[i].pare = -1;
    bi[i].left = -1;
    bi[i].right = -1;
  }
//  printf("set ok\n");

  scanf("%d",&n);

  for(i=0;i<n;i++)
  {
//    printf("comm:");
    scanf("%s",comm);
//    printf("comm:%s\n",comm);
    if(strcmp(comm,"insert")==0)
    {
//      printf("scan:");
      scanf("%d",&num);
      insert(num);
    }
    else if(strcmp(comm,"find")==0)
    {
      scanf("%d",&num);
      find(num);
    }
    else
    {
//      printf("print\n");
      print();
    }
  }
  return 0;
}

Measured memory_bytes: 8424
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=200+10;
int n,p[N],q[N];

int main()
{
    cin>>n;
    int ls;
    for(int i=1;i<=n;i++)cin>>p[i];
    for(int i=1;i<=200;i++)
    {
        ls=0;
        for(int j=1;j<=n;j++)
            ls=ls+(p[j]-i)*(p[j]-i);
        q[i]=ls;
        //cout<<ls<<endl;
    }
    sort(q+1,q+201);
    cout<<q[1]<<endl;
    return 0;
}


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

//#define ulong unsigned long

int main(){
  long N;cin>>N;
  long S=1000000000000000000;
  vector<long> A(N);
  bool can=true;
  for(int i=0;i<N;i++){
    cin>>A.at(i);
    if(A.at(i)==0) can=false;
  }
  
  long ans=1;
  for(int i=0;i<N;i++){
    if(S/ans>=A.at(i)) ans*=A.at(i);
    else{
      ans=-1;
      break;
    }
  }
  if(!can) ans=0;
  cout<<ans<<endl;
}
    


Measured memory_bytes: 4052
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    string s, tmp;
    cin >> s;
    tmp = s;
    int q;
    cin >> q;

    int cnt = 0, cntr = 0, cntl = 0;
    deque<char> d;
    for (int i = 0; i < q; i++) {
        int t; 
        cin >> t;
        if (t == 1) {
            cnt++;
            swap(cntr, cntl);
        } else {
            int f;
            char c;
            cin >> f >> c;
            if (f == 1) {
                cntr++;
                if (cnt%2 == 0) d.push_front(c);
                else d.push_back(c);
            } else {
                cntl++;
                if (cnt%2 == 0) d.push_back(c);
                else d.push_front(c);
            }
        }
    }

    if (cnt%2 == 1) {
        reverse(s.begin(), s.end());
        reverse(d.begin(), d.end());
    }
    for (int i = 0; i < cntr; i++) cout << d[i];
    cout << s;
    for (int i = 0; i < cntl; i++) cout << d[cntr+i];
    cout << endl;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
 #define fi first
#define se second
 using namespace std;
 const int lim = 3e5 + 10;
 typedef pair<int,int > pii;
 pii Arr[lim]  = {};
 int main(){
  	int n;
	scanf("%d",&n);
	string A;
	cin >> A;
	for(int i = 0 ; i < A.size(); ++i ){
		if(A[i] == 'E') Arr[i+1].fi = 1;
		else Arr[i+1].se = 1;
	} 
	for(int i= 1 ; i <= n ; ++i){
		Arr[i].fi += Arr[i-1].fi;
		Arr[i].se += Arr[i-1].se;
		//printf("%d ",Arr[i]);
	}
	//printf("\n");
	int ans = 1e9 + 10;
	for(int i=1 ; i <= n ; ++i){
	//	if(i == 1)
	//	printf("%d %d\n" , (n-i)  ,  (Arr[n] - Arr[i]));
		ans = min(ans , abs((i-1) - Arr[i-1].fi) + abs((n-i) - (Arr[n].se-Arr[i].se)) ); 
	}
	printf("%d" ,ans);
 }


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

public class Main {

	public static void main(String[] args) {
		Scanner ob=new Scanner(System.in);
		int n=ob.nextInt();
		long a[]=new long[n];
		for (int i=0; i<a.length; i++) {
			a[i]=ob.nextLong();
		}
		long sum=0;
		for (int i=0; i<a.length-1; i++) {
			if(a[i]>a[i+1])
			{
			long d=a[i]-a[i+1];
			sum=sum+d;
			a[i+1]=a[i];
			}
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 51228
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;
 
  int sz;
  vector< Monoid > seg;
 
  const F f;
  const Monoid M1;
 
  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }
 
  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }
 
  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
 
  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
 
  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }
 
  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }
};


int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,K;cin >> N >> K;
  int ans = N-K+1;
  vector<int> v(N);
  SegmentTree< int > segmin(N, [](int a, int b) { return min(a,b); }, INT_MAX);
  SegmentTree< int> segmax(N, [](int a, int b) { return max(a,b); }, 0);
  rep(i,N){
    cin >> v[i];
    segmin.set(i, v[i]);
    segmax.set(i, v[i]);
  }
  segmin.build();
  segmax.build();
  int count = 1;
  int num = 0;
  rep(i,N-1){
    if(v[i] < v[i+1]){
      ++count;
      if(count == K) ++num;
    }else count = 1;
  }
  rep(i,N-K){
    int mi = segmin.query(i,i+K);
    int ma = segmax.query(i,i+K);
    if(v[i] == mi && v[i+K] > ma) --ans;
  }
  cout << ans-max(0,num-1) << endl;
  return 0;
}


Measured memory_bytes: 5248
#include <iostream>
#include <queue>
#include <string>

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

using namespace std;

struct Job {
    string name;
    int time;
};
Job job[100005];
int main() {
    int n, q;
    cin >> n >> q;
    rep(i, n) cin >> job[i].name >> job[i].time;
    queue<Job> que;
    rep(i, n) que.push(job[i]);
    int total = 0;
    while (!que.empty()) {
        Job t = que.front();
        que.pop();
        total += min(t.time, q);
        t.time -= q;
        if (t.time > 0) {
            que.push(t);
        } else {
            cout << t.name << " " << total << endl;
        }
    }
    return 0;
}

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

int main()
{
  int i,j,n;
  queue<pair<int,int>>q;
  cin>>n;
  if (n==3){
    cout<<2<<' '<<5<<' '<<63<<endl;
    return 0;
  }
  q.push({3,9});
  for (i=2;i<=30000;i+=6){
    q.push({i,i+2});
  }
  for (j=15;j<=30000;j+=12){
    q.push({j,j+6});
  }
  while (!q.empty()){
    if (n==1){
      cout<<6<<endl;
      return 0;
    }
    if (n==0)
      return 0;
    int x=q.front().first;
    int y=q.front().second;
    q.pop();
    cout<<x<<' '<<y<<' ';
    n-=2;
  }
  i=6;
  while (n!=0){
    cout<<i<<' ';
    i+=6;
    n--;
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <string.h>

#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
using namespace std;

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <string.h>

#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
using namespace std;
ll c[100005];
ll n,b,a,x;

bool f(ll y){
    ll all = y*b;
    for(ll i = n-1; i >= 0; i --){
        if(c[i] > all){
            y -= (c[i]-all)/a;
            if(c[i] - ((c[i]-all)/a)*a-all > 0){
                y --;
            }
            if(y < 0){
                return false;
            }
        }else{
            return true;
        }
    }
    return true;
}
int main(){

    sld(n) sld(a) sld(b)

    a -= b;
    for(ll i = 0; i < n; i ++){
        sld(c[i])
    }
    sort(c,c+n);
    //p(f(2));
    ll l = 0,r = 1000000000;
    ll mid;
    while(l < r){
        //p(mid) pn
        mid = (l+r)>>1;
        if(!f(mid)){
            l = mid+1;
        }else{
            r = mid;
        }
    }
    pld(l) pn
    //p(c[0]) pn
    return 0;
}


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e18;
const int MOD = 1e9 + 7;

signed main(){
    int N, ans = 0; cin >> N;
    vector<int> a( N ), b( N ), c( N - 1 );
    REP( i, N ){
        cin >> a[i];
    }
    REP( i, N ){
        cin >> b[i];
        ans += b[i];
    }
    REP( i, N - 1 ){
        cin >> c[i];
    }

    REP( i, N - 1 ){
        if( a[i] == a[i + 1] - 1 ){
            ans += c[a[i] - 1];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int h, w, n;
  cin >> h >> w >> n;
  vector<ll> ans(10, 0);
  ans.at(0) = (ll)(w-2)*(h-2);
  set<pair<int, int>> se;
  rep(i, n){
    int a, b;
    cin >> a >> b;
    a--; b--;
    se.insert({a, b});
    vector<vector<bool>> chk(5, vector<bool>(5, false));
    rep(j, 5){
      rep(k, 5){
        if(se.find({j+a-2, k+b-2}) != se.end()) chk.at(j).at(k) = true;
      }
    }
    // rep(j, 5){
    //   rep(k, 5) cerr << chk.at(j).at(k) << " ";
    //   cerr << endl;
    // }
    // cerr << "-----------------" << endl;
    rep(u, 3){
      rep(l, 3){
        // cerr << a+u-2 << " " << b+l-2 << endl;
        if(a+u-2 < 0 || h <= a+u || b+l-2 < 0 || w <= b+l) continue;
        int co = 0;
        rep2(k, u, u+3){
          rep2(j, l, l+3){
            if(chk.at(k).at(j) == true) co++;
          }
        }
        if(co != 0){
          // cerr << l << " " << u << endl;
          ans.at(co-1)--;
          ans.at(co)++;
        }
      }
    }
  }

  for(auto i : ans){
    cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 8240
import collections
n = int(input())
counts = []
for _ in range(n):
    s = list(input())
    s.sort()
    counts.append("".join(s))
ans = 0
c = collections.Counter(counts)
for key in c.keys():
    if c[key] >= 2:
        ans += (c[key]-1)*c[key]//2
print(ans)

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

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

const int INF = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-9;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    int ans = 0;
    rep(i, N) {
        while (i < N-1 && A[i] == A[i+1]) ++i;
        if (i < N-1) {
            if (A[i] < A[i+1])
                while (i < N-1 && A[i] <= A[i+1]) ++i;
            else if (A[i] > A[i+1])
                while (i < N-1 && A[i] >= A[i+1]) ++i;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
//31
#include<iostream>
#include<algorithm>
#include<utility>
#include<string>

using namespace std;

bool cmp(pair<string,int> a,pair<string,int> b){
  return a.second>b.second;
}

int main(){
  bool sec=false;
  for(int n;cin>>n,n;){
    pair<string,int> a[10];
    for(int i=0;i<n;i++){
      string s;
      int w,l,d;
      cin>>s>>w>>l>>d;
      a[i]=make_pair(s,w*3+d*1);
    }
    stable_sort(a,a+n,cmp);
    if(sec){
      cout<<endl;
    }
    sec=true;
    for(int i=0;i<n;i++){
      cout<<a[i].first<<','<<a[i].second<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
s=SI()
n=len(s)
for i in range(n-1):
    if s[i]==s[i+1]:
        print(i+1,i+2)
        sys.exit()
for i in range(n-2):
    if s[i]==s[i+2]:
        print(i+1,i+3)
        sys.exit()
print(-1,-1)
    

Measured memory_bytes: 73740
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>	
#include <cmath>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================

bool judge(ll x)
{
	string y = to_string(x);
	bool z = true;
	rep(i, sz(y) - 1)
	{
		if (abs(y[i] - y[i + 1]) > 1)
		{
			z = false; break;
		}
	}
	return z;
}

int a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;

int main()
{
	int n; cin >> n; vector<int> x; 
	for(int i=2;i*i<1000;i++)
	{
		a = i;
		while(a<1000)
		{
			a *= i;
			x.push_back(a);
		}
	}
	x.push_back(1);
	sort(all(x));
	x.push_back(INFINITY);
	rep(i, sz(x))
	{
		if (x[i] > n)
		{
			cout << x[i - 1] << endl; return 0;
		}
	}


	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

constexpr int MOD = 1000000007;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

constexpr LL INF = 1LL << 61;

int R, C;
int N;

vector<P> gr[100000];
vector<P> gc[100000];

LL valr[100000], valc[100000];
char chkr[100000], chkc[100000];

PLL dfs(int x) {
    LL min_r = valr[x], min_c = INF;
    for (const PLL& p: gr[x]) {
        LL v = p.first;
        LL a = p.second;

        if (chkc[v]) {
            if (valr[x] + valc[v] != a) {
                return PLL(-1, -1);
            }
            continue;
        }

        chkc[v] = true;
        valc[v] = a - valr[x];

        min_c = min(min_c, valc[v]);

        for (const PLL& q : gc[v]) {
            LL w = q.first;
            LL b = q.second;

            if (chkr[w]) {
                if (valc[v] + valr[w] != b) {
                    return PLL(-1, -1);
                }
                continue;
            }
            chkr[w] = true;
            valr[w] = b - valc[v];

            PLL tret = dfs(w);

            min_r = min(min_r, tret.first);
            min_c = min(min_c, tret.second);
        }
    }
    return PLL(min_r, min_c);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> R >> C >> N;
    for (int j = 0; j < N; ++j) {
        int r, c, a;
        cin >> r >> c >> a;
        --r; --c;

        gr[r].push_back(PLL(c, a));
        gc[c].push_back(PLL(r, a));
    }

    fill(chkr, chkr+R, false);
    fill(chkc, chkc+C, false);


    for (int j = 0; j < R; ++j) {
        if (!chkr[j]) {
            valr[0] = 0;
            chkr[0] = true;
            LL rmin, cmin;
            tie(rmin, cmin) = dfs(j);
            if (rmin + cmin < 0) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;

    return 0;
}


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

typedef long long int lli;
typedef long double lld;
typedef long long ll;
//Datatype
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define vvlli vector<vector<long long int>>
#define ppi pair<int, int>
#define rppi pair<int, pair<int, int>>
#define lppi pair<pair<int, int>, int>
#define vppi vector<pair<int, int>>
#define sppi stack<pair<int int>>
#define qppi queue<pair<int, int>>
//function
#define f first
#define s second
#define pb(x) push_back(x)
#define mkp(i, j) make_pair(i, j)
#define lmkp(i,j,k) make_pair(make_pair(i,j),k)
#define rmkp(i,j,k) make_pair(i,make_pair(j,k))
//loop
#define loop(i,n) for (i = 0; i < n; ++i)
#define loops(i,k,n) for (i = k; i <= n; ++i)
#define looprev(i,k,n) for (i = k; i >= n; --i)
//Const
#define inf (int)1e9
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
//Print
#define prd(n) printf("%d", n)
#define prl(n) printf("%lld", n)
#define prdn(n) printf("%d\n", n)
#define prln(n) printf("%lld\n", n)
#define prf(n) printf("%f", n)
//Scan
#define scd(n) scanf("%d", &n)
#define scd2(a, b) scanf("%d %d", &a, &b)
#define scd3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scl(n) scanf("%lld", &n)
#define scl2(a, b) scanf("%lld %lld", &a, &b)
#define scl3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define scf(n) scanf("%f", &n)

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli i, j, k, n;
    cin>>n>>k;
    vi A(n+1);
    loops(i, 1, n){
        cin>>A[i];
    }
    int dp[n+1][k+1];
    dp[0][0] = 1;
    loops(i, 1, k){
        dp[0][i] = 0;
    }
    loops(i, 1, n){
        vi sum(k+1);
        sum[0] = dp[i-1][0];
        loops(j, 1, k){
            sum[j] = (sum[j-1] + dp[i-1][j])%MOD;
        }
        loops(j, 0, k){
            if(j <= A[i]){
                dp[i][j] = sum[j];
            }
            else{
                int ne = j-A[i]-1;
                dp[i][j] = (sum[j]-sum[ne]+MOD)%MOD;
            }
        }
        sum.clear();
    }
    cout<<dp[n][k]<<endl;
  return 0;
}

Measured memory_bytes: 43496
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <ratio>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;
template<class T> using v = vector<T>;
template<class T, class U> using p = pair<T, U>;

#define REP(i, n) for(int i = 0; i < n; ++i)
#define REP1(i, n) for(int i = 1; i <= n; ++i)

template<class T> T read() { T x{}; cin >> x; return x; }
template<class T> v<T> read(int N){ v<T> x(N); REP(i, N) cin >> x[i]; return x; }

template<class T>
void write(const T &x){ cout << x << endl; }
void write(double x){ printf("%.15f\n", x); }

const ull MOD = 1000'000'007;

ll N;

int main(){
    string S, T, U;
    ll A, B;
    cin >> S >> T >> A >> B >> U;
    if(S == U){ --A; }
    if(T == U){ --B; }
    cout << A << " " << B << endl;
}



Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::io::Read;

const MOD: i64 = 1_000_000_007;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let k: usize = iter.next().unwrap().parse().unwrap();

    let mut s: usize = (n as f64).sqrt().floor() as usize;
    while (s + 1) * (s + 1) < n {
        s += 1;
    }

    let mut dp_a = vec![vec![0; s + 1 as usize]; k + 1];
    let mut dp_b = vec![vec![0; s + 1 as usize]; k + 1];
    //    dbg!(s);
    dp_a[0][1] = 1;

    for i in 0..k {
        let mut sum = 0;
        for j in 1..s + 1 {
            sum += dp_a[i][j];
            sum %= MOD;
        }
        dp_a[i + 1][s] = sum + dp_b[i][s];
        for j in 1..s {
            let idx = s - j;
            dp_a[i + 1][idx] = dp_a[i + 1][idx + 1] + dp_b[i][idx];
            dp_a[i + 1][idx] %= MOD;
        }
        let mut tmp_sum = 0;
        for j in 1..s + 1 {
            tmp_sum += dp_a[i][j];
            dp_b[i + 1][j] = tmp_sum * ((n / j) - std::cmp::max(n / (j + 1), s)) as i64;
            dp_b[i + 1][j] %= MOD;
        }
        //        dbg!(&dp_a);
        //        dbg!(&dp_b);
    }

    let mut res = 0;
    for i in 1..s + 1 {
        res += dp_a[k][i] + dp_b[k][i];
        res %= MOD;
    }
    println!("{}", res)
}


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

int main() {
    int cnt = 0;
    string str;
    bool flag = true;
    cin >> str;
    if(str.at(0) != 'A') flag = false;
    for(int i = 2; i < str.length() - 1; i++) if(str.at(i) == 'C') {
        str.at(i) = 'c';
        cnt++;
    }
    if(cnt != 1) flag = false;
    rep(i, str.length() - 1) {
        if(str.at(i + 1) < 'a' || 'z' < str.at(i + 1)) flag = false;
    }
    if(flag) cout << "AC" << endl;
    else cout << "WA" << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define fst first
#define scd second
int par[100001], size[100001];
void init(int n)
{
	for(int i = 0; i < n; ++i)
	{
		par[i] = i;
		size[i] = 1;
	}
}
int root(int x)
{
	if(par[x] == x)
	{
		return x;
	}
	else
	{
		return par[x] = root(par[x]);
	}
}
bool issame(int x, int y)
{
	return root(x) == root(y);	
}
void unite(int x, int y)
{
	x = root(x);
	y = root(y);
	if(x == y)
		return;
	if(size[x] > size[y])
	{
		par[y] = x;
		size[x] += size[y];
	}
	else
	{
		par[x] = y;
		size[y] += size[x];
	}
}

int main()
{
	int n, m, k;
	scanf("%d%d%d", &n, &m, &k);
	vector<vector<int> > f(n, vector<int>(0)), b(n, vector<int>(0));
	for(int i = 0, j, l; i < m; ++i)
	{
		scanf("%d%d", &j, &l);
		f[j - 1].push_back(l - 1);
		f[l - 1].push_back(j - 1);
	}
	for(int i = 0, j, l; i < k; ++i)
	{
		scanf("%d%d", &j, &l);
		b[j - 1].push_back(l - 1);
		b[l - 1].push_back(j - 1);
	}
	vector<bool> isarr(n, false);
	init(n);
	for(int i = 0; i < n; ++i)
	{
		stack<int> s;
		s.push(i);
		for(int t; !s.empty(); )
		{
			t = s.top();
			if(isarr[t])
			{
				break;
			}
			isarr[t] = true;
			for(int j = 0; j < f[t].size(); ++j)
			{
				unite(t, f[t][j]);
				s.push(f[t][j]);
			}
		}
	}
	for(int i = 0, ans = 0; i < n; ++i, ans = 0)
	{
		ans = size[root(i)] - 1 - f[i].size();
		for(int j = 0; j < b[i].size(); ++j)
		{
			ans -= issame(i, b[i][j]);
		}
		printf("%d ", ans);
	}
	printf("\n");
}

Measured memory_bytes: 12760
using System;
class Program{
  static void Main(string[] args){
    int n = int.Parse(Console.ReadLine());
    int ans = 0;
    string s = Console.ReadLine();
    while (s.Length > 0) {
      if (s.Length > 2) {
        if (s.StartsWith("ABC")) {
          s = s.Substring(3);
          ans++;
        } else {
          s = s.Substring(1);
        }
      } else {
        s = "";
      }
    }
    Console.WriteLine(ans);
  }
}


Measured memory_bytes: 13280
#include <iostream>

using namespace std;

int main() {
    int a, b, c, d;
    int cost = 0;

    cin >> a >> b >> c >> d;

    if (a < b) {
        cost += a;
    } else {
        cost += b;
    }

    if (c < d) {
        cost += c;
    } else {
        cost += d;
    }

    cout << cost << endl;

    return 0;
}

Measured memory_bytes: 256
D, G = map(int, input().split())
pc = [(0, 0)]*D
for i in range(D):
    p, c = map(int, input().split())
    pc[i] = (p, c)

ans = 10**10
for i in range(2**D):
    s = 0
    num = 0
    rest_max = -1
    for j in range(D):
        if (i >> j) & 1:
            s += 100*(j+1) * pc[j][0] + pc[j][1]
            num += pc[j][0]
        else:
            rest_max = j
    if s < G:
        s1 = 100 * (rest_max + 1)
        need = (G - s + s1 - 1) // s1
        if need >= pc[rest_max][0]:
            continue
        num += need
    ans = min(ans, num)
print(ans)


Measured memory_bytes: 3064
import copy
import time

t1 = time.time()

def calc(T):
    res = 0
    L = [0]*26
    for i in range(D):
        res += S[i][T[i]-1]
        L[T[i]-1] = i+1
        for j in range(26):
            res -= C[j]*(i+1-L[j])
    return res
    
D = int(input())
C = [int(c) for c in input().split()]
S = [[int(s) for s in input().split()] for _ in range(D)]

T = [0]*D
for i in range(D):
    temp = -1
    for j in range(26):
        if temp < S[i][j]:
            temp = S[i][j]
            idx = j+1
    T[i] = idx

T2 = [0]*D
L = [0]*26
for i in range(D):
    p = -10**12
    for j in range(26):
        d = S[i][j]
        for k in range(26):
            if k == j:
                continue
            d -= C[k]*(i+1-L[k])
        if p < d:
            p = d
            idx = j+1
    T2[i] = idx
    
p1 = calc(T)
p2 = calc(T2)
if p2 > p1:
    T = copy.deepcopy(T2)

i = 0
next = 1
while time.time()-t1 < 1.9:
    for j in range(26):
        temp = copy.deepcopy(T)
        temp[i] = j+1
        newp = calc(temp)
        if p < newp:
            T[i] = j+1
            p = newp
    i += next
    if i == -1:
        i = 1
        next = 1
    elif i == D:
        i = D-2
        next = -1

for t in T:
    print(t)

Measured memory_bytes: 75376
#include <iostream>

using namespace std;

int w, h;
int m[50][50];
void paint(int x, int y) {
	if (x < 0 || x >= w || y < 0 || y >= h) return;
	if (m[y][x] == 0) return;
	m[y][x] = 0;
	for (int dx = -1; dx <= 1; ++dx) for (int dy = -1; dy <= 1; ++dy) {
		paint(x+dx, y+dy);
	}
}
int main() {
	while ( cin >> w >> h, w || h ) {
		for (int y = 0; y < h; ++y) {
			for (int x = 0; x < w; ++x) {
				cin >> m[y][x];
			}
		}
		int ans = 0;
		for (int y = 0; y < h; ++y) {
			for (int x = 0; x < w; ++x) {
				if (m[y][x]) {
					paint(x, y);
					++ans;
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1312
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)

int main() {
	ll n, m,l,r,cnt=0;
	in(n);
	in(m);
	ll s = -1,e=n;
	rep(i, 0, m) {
		in(l);
		in(r);
		if (s < l) {
			s = l;
		}
		if (e > r) {
			e = r;
		}

	}

	cnt = e - s + 1;
	if (cnt < 0) {
		cnt = 0;
	}

	outn(cnt);


}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int y = in.nextInt();
        while(x != 0 || y != 0){
            if(x > y) {
                System.out.println(y + " " +x);
            } else {
                System.out.println(x + " " + y);
            }
            x = in.nextInt();
            y = in.nextInt();
        }
        in.close();
    }
}


Measured memory_bytes: 35424
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int k; cin >> k;
    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << a[k-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;

    int n,sum=0;
    n=s.length();

    for(int i = 0 ; i<n ; i++)
    {
        if(s[i]!=t[i]) {
            sum=1;
            break;
        }
    }

    if(sum==1) cout<<"No";
            else cout<<"Yes";
}


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

int main() {
  int n, l;
  cin >> n >> l;
  
  vector<string> s(n);
  string S;
  for(int i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  sort(s.begin(), s.end());
  for(int i = 0; i < n; i++) {
    S += s.at(i);
  }
  cout << S << endl;
}
  

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

int main(){
    int n;
    cin >> n;
    int x[n];
    for (int i=0; i<n; i++){
        cin >> x[i];
    }
    int max = x[0];

    for (int i=1; i<n; i++){
        if (x[i] > max){
            max = x[i];
        }
    }
    int min = x[0];

    for (int i=1; i<n; i++){
        if (x[i] < min){
            min = x[i];
        }
    }
    long int sum = x[0];

    for (int i=1; i<n; i++){
        sum += x[i];
    }
    cout << min << ' ' << max << ' ' << sum << endl;

    return 0;
}


Measured memory_bytes: 3132
//============================================================================
// Name        : competitive_programing.cpp
// Author      : .Data_Nerd.
// Description : problem solving training
//============================================================================

#include <bits/stdc++.h>
#define Data_Nerd ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define files freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define MOD 1000000007
#define OO 0x3f3f3f3f
#define NIL -1
using namespace std;
typedef long long ll;
typedef long double ld;

int n;

ld ans = 0;

int main() {
    Data_Nerd

	scanf("%d", &n);

    for(int i = 0; i < n; ++i) {
    	ld x; cin >> x;
    	ans += (1 / x);
    }

    cout << 1 / ans;

    return 0;
}


Measured memory_bytes: 256