akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define int long long
#define inf (int)1e18+7
#define mod 1000000007


const int nmax = 22;
int n;
int rel[nmax][nmax];
int dp[(1 << 21)];


int solve(int womanmask) {
    
    int man_id = __builtin_popcount(womanmask);
    if (man_id == n) return 1;
    if (dp[womanmask] != -1) return dp[womanmask];

    int ans = 0;
    for (int i = 0; i < n; i ++) {
        if (rel[man_id][i] == 1) {
            if ( (womanmask & (1 << i)) == 0) {
               ans += solve(womanmask | (1 << i));        
                ans %= mod;
            }
        }
    }
    return dp[womanmask] = ans;

}



signed main() {
     
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i ++) {
        for (int j = 0; j < n; j ++) {
            cin >> rel[i][j];
        }
    }

    memset(dp, -1, sizeof dp);

    int res = solve(0);
    cout << res << endl;


    return 0;
}

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

using namespace std;

int main(){
  int a,b,c,d;
  cin >> a>> b>> c>> d;
  if (a+b==c+d) cout << "Balanced" << endl;
  else if (a+b>c+d) cout << "Left" << endl;
  else cout << "Right" << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"---------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
						For(_x,L,R)cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> vi;
typedef long double LD;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=100005;
int n,S;
LL x[N],p[N];
vector <int> ans;
int main(){
	n=read(),S=read();
	For(i,1,n)
		x[i]=read(),p[i]=read();
	int L=1,R=n;
	while (L<R&&x[L]<S&&x[R]>S){
		if (p[L]>=p[R]){
			p[L]+=p[R];
			ans.pb(x[R]);
			R--;
		}
		else {
			p[R]+=p[L];
			ans.pb(x[L]);
			L++;
		}
	}
	LL tot=0;
	if (x[L]<S)
		ans.pb(x[L]);
	else
		ans.pb(x[R]);
	while (!ans.empty()){
		tot+=abs(S-ans.back());
		S=ans.back();
		ans.pop_back();
	}
	cout<<tot<<endl;
	return 0;
}

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

using namespace std;

int main() {
    string s;
    cin >> s;
    int currentlen = 0, maxlen = 0;
    for (char i : s) {
        if (i == 'A' || i == 'C' || i == 'G' || i == 'T') {
            ++currentlen;
            if (maxlen < currentlen) maxlen = currentlen;
        } else currentlen = 0;
    }
    cout << maxlen << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main()
{
    int n, m;
    int tgt[100];
    int pt[100] = {0};
    int nomi[100][100];

    scanf("%d", &n);
    scanf("%d", &m);

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

    for (int i = 0; i < m; i++){
        int tmp = 0;
        for (int j = 0; j < n; j++){
            scanf("%d", &nomi[i][j]);
            if (tgt[i] == nomi[i][j]){
                //printf("tgt[%d] = %d, nomi[%d][%d] = %d\n", i, tgt[i], i, j, nomi[i][j]);
                pt[j]++;
                tmp++;
            }
        }
        pt[tgt[i] - 1] += n - tmp;
    }

    for (int i = 0; i < n; i++){
        printf("%d\n", pt[i]);
    }

    return (0);
}

Measured memory_bytes: 1064
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    ll n, k, s; cin >> n >> k >> s;
    rep(i, n){
        if(i < k){
            if(i != n - 1)cout << s << " ";
            else cout << s;
        }else{
            if(s != 1e9){
            if(i != n - 1)cout << s + 1 << " ";
            else cout << s + 1;
            }else{
                if(i != n - 1)cout << s - 1 << " ";
            else cout << s - 1;
            }

        }
    }
    cout << endl;
}


Measured memory_bytes: 1280
import sys
input = sys.stdin.readline
N = int(input())
a = [tuple(map(int, input().split())) for _ in range(N)]
for i in range(N - 2):
  if a[i][0] == a[i][1] and (a[i + 1][0] == a[i + 1][1]) and (a[i + 2][0] == a[i + 2][1]):
    print("Yes")
    break
else: print("No")

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

int main(){
    int a,b,d,r;
    double f;
    cin >> a >> b;

    d = a/b;
    r = a%b;
    f = (double)a/b;

    cout << d << " " << r << " " << fixed << setprecision(5) << f << endl;

}


Measured memory_bytes: 3280
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <functional>
#include <climits>
using namespace std;

const int MAX_V = 100000;
const int MAX_E = 500000;
const int INF = INT_MAX;

struct E
{
  int to, cost;
  E(int t, int c) : to(t), cost(c) {};
};
typedef pair<int, int> pii;

int v;
vector<E> g[MAX_V];
int d[MAX_V];

void dijkstra(int s)
{
  fill(d, d + v, INF);
  d[s] = 0;
  priority_queue<pii, vector<pii>, greater<pii> > q;
  q.push(pii(0, s));
  
  while(!q.empty()){
    pii p = q.top();
    q.pop();
    int from = p.second;
    if(d[from] < p.first) continue;
    
    for(int i = 0; i < g[from].size(); ++i){
      int to = g[from][i].to;
      int cost = g[from][i].cost;
      
      if(d[to] > d[from] + cost){
        d[to] = d[from] + cost;
        q.push(pii(d[to], to));
      }
    }
  }
}

int main()
{
  int gv, ge, gr;
  cin >> gv >> ge >> gr;
  v = gv;
  for(int i = 0; i < ge; ++i){
    int gs, gt, gd;
    cin >> gs >> gt >> gd;
    g[gs].push_back(E(gt, gd));
  }
  
  dijkstra(gr);
  
  for(int i = 0; i < v; ++i){
    if(d[i] != INF)
      cout << d[i] << endl;
    else
      cout << "INF" <<endl;
  }
}

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

int main(){
   int n,m;
  cin>>n>>m;
  int a1,b1,a2,b2;
  cin>>a1>>b1>>a2>>b2;
  a1-=1,b1-=1,a2-=1,b2-=1;
  vector<pair<int,int>> adj[n*m];
  vector<string> v(n);
  for(int i=0;i<n;i++)
     cin>>v[i];
  
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      if(v[i][j]=='.'){
        if(i+1<n && v[i+1][j]=='.'){
          adj[i*m+j].push_back(make_pair(0,i*m+m+j));
          adj[i*m+m+j].push_back(make_pair(0,i*m+j));
        }
        if(j+1<m && v[i][j+1]=='.'){
          adj[i*m+j].push_back(make_pair(0,i*m+j+1));
          adj[i*m+j+1].push_back(make_pair(0,i*m+j));
        }
        for(int k=-2;k<=2;k++){
          for(int q=-2;q<=2;q++){
            if(i+k>=0 && j+q>=0 && i+k<n && j+q<m && v[i+k][j+q]=='.'){
              adj[i*m+j].push_back(make_pair(1,(i+k)*m+j+q));
          	  adj[(i+k)*m+j+q].push_back(make_pair(1,i*m+j));
            }
          }
        }
      }
    }
  }
  priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>> > pq;
  pq.push(make_pair(0,a1*m+b1));
  int d[n*m+1];
  for(int i=0;i<=n*m;i++)
     d[i]=INT_MAX;
     
  d[a1*m+b1]=0;
  while(!pq.empty()){
    int v=pq.top().second;
     int dv=pq.top().first;
    pq.pop();
    if(d[v]!=dv)
       continue;
   for(auto u:adj[v]){
     int to=u.second;
     int l=u.first;
     if(d[v]+l<d[to]){
        d[to]=d[v]+l;
        pq.push(make_pair(d[to],to));
	}	
   }
  }
  if(d[a2*m+b2]==INT_MAX)
     cout<<-1;
  else
     cout<<d[a2*m+b2];
}
    


Measured memory_bytes: 189668
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int a,b,c;
  int cnta=0,cntb=0;
  while(scanf("%d,%d,%d",&a,&b,&c)!=EOF){
    if(a*a+b*b==c*c)cnta++;
    else if(a==b)cntb++;
  }
  cout<<cnta<<endl<<cntb<<endl;
}

Measured memory_bytes: 1208
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int main() {
  ll n;
  scanf("%lld", &n);
  ll lhs = 0;
  ll rhs = (ll)1e15;
  while(lhs != rhs) {
    ll mid = (lhs+rhs)/2;
    ll amt = 0;
    if(mid%2 == 0) {
      amt += 11 * (mid/2);
    }
    else {
      amt += 11 * (mid/2) + 6;
    }
    if(amt >= n) {
      rhs = mid;
    }
    else {
      lhs = mid+1;
    }
  }
  printf("%lld\n", lhs);
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

string S,T;
ll nxt[200010][26];

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

  cin>>S>>T;
  ll N=S.size();
  ll M=T.size();
  S="$"+S+S;

  memset(nxt,-1,sizeof(nxt));
  for(ll i=2*N-2;i>=0;i--){
    rep(j,26){
      if(S[i+1]-'a'==j){
        nxt[i][j]=i+1;
      }else{
        nxt[i][j]=nxt[i+1][j];
      }
    }
  }

  ll crt=0,res=0;
  rep(i,M){
    if(nxt[crt][T[i]-'a']==-1){
      cout<<-1<<endl;
      return 0;
    }
    res+=nxt[crt][T[i]-'a']-crt;
    crt=nxt[crt][T[i]-'a']%N;
  }
  cout<<res<<endl;

  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<vector<pair<int, int>>> a(n);
  for (auto& e : a) {
    int m;
    cin >> m;
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      e.push_back({x - 1, y});
    }
  }

  int r = 0;
  for (int b = 0; b < (1 << n); b++) {
    bool valid = true;
    for (int i = 0; i < n; i++) {
      if (!((b >> i) & 1)) continue;
      for (auto e : a[i]) valid = valid && ((b >> e.first) & 1) == e.second;
    }
    if (valid) {
      bitset<16> bs(b);
      r = max(r, (int)bs.count());
    }
  }
  cout << r << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define ull unsigned long long
#define for_list(a) for(auto i:a)
#define f(s,a) for(int i=0;i<s;i++) cin>>a[i];

int count = 0;
void show(int a[201][201]){
    for (int i = 0; i < 201; ++i)
    {
        for (int j = 0; j < 201; ++j)
        {
            cout << a[i][j] << " ";
        }
        cout << endl;
    }

}
 
template<typename T>
vector<int> maxmin_list(T a){
    int l = INT_MIN,p = INT_MAX;
    for_list(a){
        l = max(l,i);
        p = min(i,p);
    }
    vector<int> v = {l,p};
    return v;
}
ll power(ll a,ll b){
    ll s;
    if(b == 0)
        return 1;
    if(b == 1)
        return a;
    if(b%2 == 0){
        s = power(a,b/2);
        return s*s;
    }
    else{
        s = power(a,(b-1)/2);
        return a*s*s;
    }
}
int randomize(){
    return (rand()%10000);
}
int b[100000];
int main()
{
    srand(time(NULL));
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // #ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    // cout <<fixed;
    // cout << setprecision(2);
    int k;cin >> k;
    int m;cin >> m;
    ll l[k+m+1];
    ll a[k];
    for (int i = 0; i < k; ++i)
    {
        cin >> a[i];
        l[i] = INT_MAX;
    }
    for (int i = 0; i < m+k; ++i)
    {
        l[i] = INT_MAX;
    }
    l[0] = 0;
    l[1] = abs(a[0] - a[1]);
    for (int i = 1; i < k; ++i)
    {
        for (int j = i-m > 0 ? i-m :0 ; j < i; ++j)
        {
            l[i] = min(abs(a[i] - a[j])+l[j],l[i]);
        }
    }
    // for (int i = 0; i < k; ++i)
    // {
    //     cout << l[i] << " ";
    // }
    // cout << endl;
    cout << l[k-1] << endl;
}

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

int main() {
    // 配列の用意
    int array[32] = {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};
    int input;
    cin >> input;
    cout << array[input-1] << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
using Graph = vector<vector<int> >;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define int long long

void solve() {
	string s; ll k; cin >> s >> k;
    string u = s + s;
    int n = s.size();
    int cnt = 0, cnt1 = 0;
    bool saigo = false;
    char x = s[0]; 
    bool onazi = true; 
    rep1(i, n - 1) {
        if(x != s[i]) {
            onazi = false;
        }
        if(s[i] == s[i - 1]) {
            s[i] = '0';
            cnt ++;
            if(i == n  - 1) saigo = true; 
        }
    }
    rep1(i, 2 * n - 1) {
        if(u[i] == u[i - 1]) {
            u[i] = '0';
            cnt1 ++;
        }
    }
    ll ans;
    if(onazi) {ans = (n * k) / 2;}
    else ans = (cnt1 - cnt) * (k - 1) + cnt;;
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
nums = [int(i) for i in input().split()]
sorted_nums = sorted(nums)
median_idx = n // 2
low = sorted_nums[median_idx-1]
high = sorted_nums[median_idx]
tmp = (low + high) / 2

for num in nums:
    if num < tmp:
        print(high)
    else:
        print(low)


Measured memory_bytes: 25620
N, K = [int(v) for v in input().split()]

S = [0] * N

for _ in range(K):
    snack = int(input())
    snukes = [int(v) for v in input().split()]
    for snuke in snukes:
        S[snuke-1] = 1

print(sum(x == 0 for x in S))


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

int main(){
	int N;
	cin >> N;
	if(N==1)cout << N << endl;
	else if(N<4)cout << "2" << endl;
	else if(N<8)cout << "4" << endl;	
	else if(N<16)cout << "8" << endl;
	else if(N<32)cout << "16" << endl;
	else if(N<64)cout << "32" << endl;
	else cout << "64" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int A[300000];
int a[25][300000];
int b[20] = {};
long long int ans = 0;
int main()
{
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> A[n];
        for(int j = 0; j < 20; j++)
        {
            int p = pow(2, j);
            a[j][i] = (A[n]/p) % 2;
        }
    }
    
    int dame = 0;
    for(int i = 0; i < n; i++)
    {
        int c = 0;
        if(i != 0)
        {
            for(int j = 0; j < 20; j++)
            {
                b[j] = b[j] - a[j][i-1] - a[j][dame];
            }
        }
        for(int j = dame; j < n; j++)
        {
            for(int k = 0; k < 20; k++)
            {
                b[k] = b[k] + a[k][j];
                if(b[k] > 1)
                {
                    c = 1;
                }
            }
            if(c == 1)
            {
                ans = ans + j - i;
                dame = j;
                break;
            }
        }
        if(c == 0)
        {
            ans = ans + n - i;
            dame = n-1;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 24320
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, ans;
  int N, marker;
  marker = 0;
  cin >> S;
  N = S.size();
  for (int i; i < N; i++){
    if (i % 2 == 0) {
      if (S.at(i) == 'L') {
        ans = "No";
        marker = 1;
        break;
      }
    }
    else {
      if (S.at(i) == 'R') {
        ans = "No";
        marker = 1;
        break;
      }
    }
    if (marker == 1) {
      break;
    }
    else {
      ans = "Yes";
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  string s;
  int a, b;
  
  cin >> a >> b >> s;
  
  if(s.at(b-1)=='A') s.at(b-1)='a';
  if(s.at(b-1)=='B') s.at(b-1)='b';
  if(s.at(b-1)=='C') s.at(b-1)='c';
  
  co(s);
}


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

int main() {
    int N;
    cin >> N;
    vector<ll> T(N);
    rep(i,N) cin >> T.at(i);
    ll ans = 1;
    rep(i,N) ans = lcm(ans, T.at(i));
    cout << ans << endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    int r,x,d;
    cin >> r >> d >> x;
    for(int i = 0; i < 10; i++){
        x = r*x-d;
        cout << x << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
    int N;
    cin >> N;

    int A[110];
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }

    int v;
    int j;

    for (int i = 0; i < N; i++)
    {
        v = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > v)
        {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        for (int i = 0; i < N; i++)
        {
            cout << A[i];
            if(i != N-1) cout << " ";
        }
        cout << "" << endl;
     }
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

static const ll INF = 1e15;

const ll mod = 1000000007;

int v, e;
vector<vector<ll>> g;
vector<vector<ll>> dp;

ll dfs(ll state, ll current, ll start) {
	state |= (1LL << current);
	if (dp[state][current] != -1) {
		return dp[state][current];
	}
	if (state == (1LL << v) - 1) {
		dp[state][current] = g[current][start];
		return g[current][start];
	}
	ll dist = INF;	
	for (int i = 0; i < v; i++) {
		if (g[current][i] == INF) continue;
		if (state & (1LL << i)) continue;
		ll d = g[current][i] + dfs(state, i, start);
		dist = min(dist, d);
	}
	dp[state][current] = dist;
	return dist;
}

int main(void)
{
	cin >> v >> e;
	g.resize(v, vector<ll>(v, INF));
	rep(i, e) {
		int s, t, d;
		cin >> s >> t >> d;
		g[s][t] = d;
	}	
	ll dist = INF;
	for (int i = 0; i < v; i++) {
		dp.assign(1LL << v, vector<ll>(v, -1));
		ll d = dfs((1LL << i), i, i);
		dist = min(d, dist);
	}
	if (dist == INF) {
		cout << -1 << endl;
	}
	else {
		cout << dist << endl;
	}
	return 0;
}



Measured memory_bytes: 7636
#include<bits/stdc++.h>
using namespace std;
int dp[3001][3001];
string s,t,ans;
int main()
{
	cin>>s>>t;
	for(int i=0;i<=s.length();i++)
	{
		for(int j=0;j<=t.length();j++)
		{
			if(i==0||j==0)dp[i][j]=0;
			else if(s[i-1]==t[j-1])dp[i][j]=dp[i-1][j-1]+1;
			else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	int i=s.length(),j=t.length();
	while(dp[i][j]!=0)
	{
		if(s[i-1]==t[j-1])
		{
			ans+=s[i-1];
			i--;j--;
		}
		else if(dp[i-1][j]>=dp[i][j-1])i--;
		else j--;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int N, M, a, b;
  cin >> N >> M;
  vector<int> R(N);

  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    R.at(a - 1)++;
    R.at(b - 1)++;
  }

  for (int i = 0; i < N; i++) cout << R.at(i) << endl;
}

Measured memory_bytes: 3604
#include<stdio.h>
#include<assert.h>

long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}

int main(){
  long long i,j,x,y,fx=1,fy=1,fs=0,ph=1,l,k,w,v,n;
  long long rx[262144],ry[262144],c=0;
  scanf("%lld%lld%lld",&k,&x,&y);
  if(x<0){x*=-1;fx=-1;}
  if(y<0){y*=-1;fy=-1;}
  if(x>y){l=x;x=y;y=l;fs=1;}
  if((x+y)%2==1 && k%2==0){printf("-1\n");return 0;}
  rx[c]=x;
  ry[c]=y;
  c++;
  if((x+y)<k && (x+y)%2==1){
    v=(k+y-x)/2;
    y+=v;
    x-=(k-v);
    rx[c]=x;
    ry[c]=y;
    c++;
  }
  w=(k-(x+y)%k)%k;
  if((x+y)<k && (x+y)%2==0){n=2;}
  else if(w%2==0){n=llceil(x+y,k);}
  else{n=llceil(x+y,k)+1;}
  w=(k*n-y-x)/2;
  while(x!=0 || y!=0){
    l=k;
    if(ph==1){
      x-=l;
      l=0;
      if(x<-w){
        l=-w-x;
        x=-w;
      }
      if(x==-w){
        ph=2;
      }
    }
    if(ph==2){
      y-=l;
      l=0;
      if(y<0){
        l=-y;
        y=0;
      }
      if(y==0){
        ph=3;
      }
    }
    if(ph==3){
      x+=l;
      l=0;
    }
    rx[c]=x;
    ry[c]=y;
    c++;
  }
  for(i=0;i<c-1;i++){
    assert(llzt(rx[i],rx[i+1])+llzt(ry[i],ry[i+1])==k);
  }
  printf("%lld\n",c-1);
  for(i=c-2;i>=0;i--){
    if(fs==1){l=rx[i];rx[i]=ry[i];ry[i]=l;}
    rx[i]*=fx;
    ry[i]*=fy;
    printf("%lld %lld\n",rx[i],ry[i]);
  }
  return 0;
}


Measured memory_bytes: 5760
# AGC013A - Sorted Arrays
def main():
    n = int(input())
    A = tuple(map(int, input().split()))
    ans, cur = 0, A[0]
    flg = 0  # unknown (0), increasing (1), decreasing (2)
    for i in A:
        if (flg == 1 and i < cur) or (flg == 2 and i > cur):  # end of trend
            ans += 1
            flg = 0
        elif not flg and cur < i:  # new increasing trend
            flg = 1
        elif not flg and cur > i:  # new decreasing trend
            flg = 2
        cur = i
    print(ans + 1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14352
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

int main() {
	int i, j, k;
	int x, a, b;

	cin >> x >> a >> b;

	x = x - a;

	for (i = 0; i*b <= x; i++) {

	}
	i--;

	x = x - (i*b);

	cout << x << endl;







	getchar();
	getchar();
	return 0;
}

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

using namespace std;

#define INF (1ll << 62)
#define pb push_back
#define ii pair<int,int>
#define OK cerr <<"OK"<< endl
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define endl '\n'

int dp[200000][3];
int mat[200000][3];


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

  int n;

  cin >> n;

  for(int i = 1; i <= n; i++) {
  	for(int j = 0; j < 3; j++) {
  		cin >> mat[i][j];
  		for(int k = 0; k < 3; k++) {
  			if(j == k)
  				continue;
  			dp[i][j] = max(dp[i][j], mat[i][j] + dp[i - 1][k]);
  		}
  	}
  }

  cout << *max_element(dp[n], dp[n] + 3) << endl;
}

Measured memory_bytes: 8448
T = int(input())
for i in range(T):
    n, A, B, C, D = map(int, input().split())
    memo = {}

    def herasu(N):
        if N == 0:
            return 0
        if N == 1:
            return D
        if N in memo:
            return memo[N]
        m = 100000000000000000000000
        if N % 2 == 0:
            m = min([m, A + herasu(N//2)])
        else:
            m = min([m, A + herasu(N//2) + D])
            m = min([m, A + herasu(N//2 + 1) + D])
        if N % 3 == 0:
            m = min(m, B + herasu(N//3))
        else:
            m = min([m, B + herasu(N//3) + (N%3) * D])
            m = min([m, B + herasu(N//3 + 1) + (3-(N%3)) * D])
        if N % 5 == 0:
            m = min(m, C + herasu(N // 5))
        else:
            m = min([m, C + herasu(N//5) + (N%5) * D])
            m = min([m, C + herasu(N//5 + 1) + (5-(N%5)) * D])
        m = min([m, D * N])
        memo[N] = m
        return m

    print(herasu(n))


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

#define REP(i,n) for(int i = 0;i < n;++i)
#define PB(s) push_back(s)
#define ST(n) sort(n.begin(),n.end())

const double PI  = acos(-1.0);

using namespace std;
typedef long long ll;

int EDSum(ll);//各桁の和
vector<int> SOE(int,int);//素数 (Min,Max)
int MinCM(int,int);//最小公倍数(num1,num2)
ll MaxCD(ll,ll);//最大公約数(num1,num2)
vector<int> igets(int);//cin * N
ll nPr(ll,ll); //(n,r)
ll nE(ll); //(n)
ll nCr(ll,ll); //(n,r)

void solve(){
    ll N,X,sum;
    cin>>N>>X;
    ll box[N];
    for(int i=0;i<N;i++){
      cin>>box[i];
      box[i]=abs(X-box[i]);
    }
    sum=box[0];
    for(int i=1;i<N;i++)sum=MaxCD(sum,box[i]);
    cout<<sum<<endl;
}

int main(void){cin.tie(0);ios::sync_with_stdio(false);solve();}
int EDSum(ll number) {
  int ans = 0;
  while (1) {
    ans += number % 10;
    number /= 10;
    if (number == 0) break;
  }
  return ans;
}

vector < int > SOE(int mini, int maxx) {
  vector < int > int_array;
  for (int i = 2; i <= maxx; i++) int_array.push_back(i);
  vector < int > sosu;
  double stop = sqrt(maxx);
  while (true) {
    sosu.push_back(int_array.front());
    int_array.erase(int_array.begin());
    if (stop < (double)(sosu.back())) break;
    for (int i = 0; i < (int) int_array.size(); i++) {
      if (int_array[i] % sosu.back() == 0)
        int_array.erase(int_array.begin() + i);
    }
  }
  sosu.insert(sosu.end(), int_array.begin(), int_array.end());
  while(true)if(mini<=sosu[0])break;else sosu.erase(sosu.begin());
  return sosu;
}

int MinCM(int a, int b) {
  int c = a * b;
  if (a < b) swap(a, b);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return c / b;
}

ll MaxCD(ll a, ll b) {
  if (a < b) swap(a, b);
  ll r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
vector < int > igets(int N) {
  vector < int > A;
  int temp;
  for (int i = 0; i < N; ++i) {
    cin >> temp;
    A.push_back(temp);
  }
  return A;
}

ll nPr(ll n, ll r) {
  ll ans = 1;
  r = n - r;
  while (n != r) {
    ans *= n;
    --n;
  }
  return ans;
}

ll nE(ll n) {return nPr(n, n);}

ll nCr(ll n, ll r) {
  if (0 != n - r && n - r < r) r = n - r;
  return nPr(n, r) / nE(r);
}








Measured memory_bytes: 1024
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.StreamTokenizer
import java.util.*

class A

fun main( args: Array<String> ) {
    val st = StreamTokenizer( BufferedReader( InputStreamReader( System.`in` ) ) )
    val n = st.nextInt()
    val k = st.nextInt()
    val a = IntArray( n, { st.nextInt() } )
    a.sort()
    val s = ArrayList<Int>( n )
    run {
        var l = 0
        for ( i in 0 .. a.size ) {
            if ( i == a.size || a[i] != a[l] ) {
                s.add( i - l )
                l = i
            }
        }
    }
    s.sort()
    var r = 0
    for ( i in 0 until s.size - k ) {
        r += s[i]
    }
    println( r )
}

private fun StreamTokenizer.nextInt(): Int {
    nextToken()
    return nval.toInt()
}


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

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m, l;
    cin>>n>>m>>l;
    
    int a[n][m];
    int b[m][l];
    
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin>>a[i][j];
        }
    }
    for(int i=0; i<m; i++){
        for(int j=0; j<l; j++){
            cin>>b[i][j];
        }
    }
    
    long long int c[n][l];
    
    for(int i=0; i<n; i++){
        for(int j=0; j<l; j++){
            long long int sum = 0;
            for(int k=0; k<m; k++){
                sum += a[i][k]*b[k][j];
            }
            c[i][j] = sum;
            if(j!=l-1) cout<<c[i][j]<<" ";
            else cout<<c[i][j]<<endl;
        }
    }
    
    
    
    return 0;
    
}


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

int main() {
  string S;
  cin >> S;
  int counter = 0;
  for (int i=0; i<3; i++) {
    if (S.at(i) == 'o') {
      counter++;
    }
  }
  int y = 700+counter*100;
  cout << y << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int ans = 1e9;
int n, m, s;
int a[100];
int cost[100];
int maze[100][100];
int res[1000];
bool check(){
	rep(i, 1, m + 1){
		if(a[i] < s) return false;
	}
	return true;
}
void dfs(int i, int sum){
	if(check()) {
		ans = min(ans, sum);
		return ;
	}
	if(i == n + 1) return ;
	rep(j, i + 1, n + 1){
		rep(k, 1, m + 1) a[k] += maze[j][k];
		sum += cost[j];
		dfs(j, sum);
		sum -= cost[j];
		rep(k, 1, m + 1) a[k] -= maze[j][k];
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin >> n >> m >> s;
	rep(i, 1, n + 1){
		cin >> cost[i];
		rep(j, 1, m + 1) {
			cin >> maze[i][j];
			res[j] += maze[i][j];
		}
	}
	rep(i, 1, m + 1){
		if(res[i] < s ) {
			cout << "-1" <<endl;
			return 0;
		}
	}
	dfs(0, 0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3668
#include<stdio.h>
int main()
{
  char s1,s2,s3;
  int a=0;
  scanf("%c%c%c",&s1,&s2,&s3);
  if(s1=='1')
    a++;
  if(s2=='1')
    a++;
  if(s3=='1')
    a++;
  printf("%d\n",a);
  return 0;
}

Measured memory_bytes: 128
// https://arc087.contest.atcoder.jp/tasks/arc087_a
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
typedef pair<int,int> PI;
typedef vector<PI> VT ;
#define ll long long int
#define print(arr) for(auto x:arr) cout<<x<<" "; cout<<endl
using namespace std;

int main()
{
	int n;
	cin>>n;
	vector<int> v(n);
	unordered_map<int,int> mp;
	for(int i=0;i<n;i++){
		cin>>v[i];
		mp[v[i]]++;
	}
	int ans = 0;
	for(auto i : mp){
		if(i.first<i.second){
			ans+=i.second-i.first;
		}
		else if(i.first>i.second){
			ans+=i.second;
		}
	}
	cout<<ans<<"\n";
	return 0;
}

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

using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define fill(a, x) memset(a, x, sizeof(a))
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
long long MOD=1e9+7;

int main()
{	
	ios_base:: sync_with_stdio(0);
	cin.tie(0);
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	ll a,b,c,d,i,j,maxi=0,n,add=1,ans=0;
	cin>>n;
	vi art(n);
	vi num(1000001);
	for(i=0;i<n;i++){
		cin>>art[i];
		num[art[i]]++;
	}
	for(i=0;i<n;i++){
		add=1;
		num[art[i]]--;
		for(j=1;j*j<=art[i];j++){
			if(art[i]%j) continue;
			if(num[j]){
				add = 0;
				//cout<<j<<" ";
				break;
			}
			if(num[art[i]/j]){
				add = 0;
				//cout<<j<<" ";
				break;
			}
		}
		num[art[i]]++;
		ans+=add;
	   }
	   cout<<ans;
	}




Measured memory_bytes: 7932
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
typedef long long int ll;
#define REP(i,n) for (int i = 1; i <= n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define lli long long int
#define INF 1000000000
const double pi = 3.14159265358979323846;


int main() {
    fast
    //test
    {
        ll i,j,n,m=0,a,b,k,c;
        cin>>a>>b>>c>>k;
		if(k>a)
		{
		    k-=a;
		    m=a;
		    if(k>b)
		    {
		        k-=b;
		        cout<<m-k;
		        
		    }
		    else cout<<m;
		}
		else cout<<k;
		      
    }
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

int main(void){
	string s;
	cin>>s;
	int si = s.size()-1;
	ll ans = 0;
	ll count = 0;
	while(true){
		if(si < 0) break;
		if(si-1 >= 0 && s[si] == 'C' && s[si-1] == 'B'){
			count++;
			si--;si--;
		}else if(s[si] == 'A'){
			ans += count;
			si--;
		}else{
			count = 0;
			si--;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using LL = int64_t;
const int maxn=1e5+5;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const LL LLINF=1e14;
const double pi=acos(-1.0);


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    LL a,b,c,k;
    cin>>a>>b>>c>>k;
    cout<<max((a<<k)+b+c,max(a+(b<<k)+c,a+b+(c<<k)));
    return 0;
}


Measured memory_bytes: 256
a, b = map(int, input().split())
# x = (a * 100) // 8
y = (b * 100) // 10

for i in range(y, y + 10):
  if (i * 10) // 100 == b and (i * 8) // 100 == a:
    print(i)
    exit()
print(-1)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
vector<int>adj[1000000];
int dis[1000000],indegree[10000000];
bool vis[1000000];
void dfs(int u){
	vis[u]=true;
	for(auto i:adj[u]){
		dis[i]=max(dis[i],dis[u]+1);
		--indegree[i];
		if(indegree[i]==0)
			dfs(i);
	}
}		
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
		++indegree[y];
	}
	for(int i=1;i<=n;i++){
		if(!vis[i] && indegree[i]==0)
			dfs(i);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		ans=max(ans,dis[i]);
	cout<<ans<<endl;
	return 0;
}


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


void solve(long long A, long double B){
    cout << (long long)(A * B) << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long double B;
    scanf("%Lf",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 3836
using System;
using System.Linq;

namespace AtCoder20190615
{
	class ProgramA
	{
		static void Main(string[] args)
		{
			var array = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
			int N = array[0];
			int K = array[1];
			A(N, K);
		}
		static void A(int N, int K)
		{
			int result;
			if (K == 1)
			{
				result = 0;
			}
			else
			{
				int max = 1 + (N - K);
				int min = 1;
				result = max - min;
			}
			Console.WriteLine(result);
		}
	}
}

Measured memory_bytes: 13268
package main

import (
	"fmt"
)

func main() {

	var n, x int

	var in [][]int

	for {
		fmt.Scanf("%d%d", &n, &x)
		if n == 0 && x == 0 {
			break
		}

		in = append(in, []int{n, x})
	}

	for _, v := range in {

		var hit int

		for i := 1; i <= v[0]; i++ {
			for j := i; j <= v[0]; j++ {
				for k := j; k <= v[0]; k++ {
					if i == j || i == k || j == k {
						continue
					}
					if i+j+k == v[1] {
						hit++
					}
				}
			}
		}

		fmt.Printf("%d\n", hit)
	}

}



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

int main() {
	int N;
	cin >> N;
	vector<int> vec(N);
	for (int i = 0; i < N; i++) {
		cin >> vec.at(i);
	}
	int A = 0;
	for (int i = 0; i < N; i++) {
		if (vec.at(i) == 0) {
			A++;
			break;
		}
	}
	int B = 0;
	for (int i = 0; i < N; i++) {
		if (vec.at(i) < 0) {
			B++;
		}
	}
	if (A == 0 && B % 2 == 1) {
		int mini = 1000000000;
		for (int i = 0; i < N; i++) {
			if (vec.at(i) < 0) {
				vec.at(i) = -vec.at(i);
			}
			mini = min(mini, vec.at(i));
		}
		long sum = 0;
		for (int i = 0; i < N; i++) {
			sum += vec.at(i);
        }
      cout << sum - 2 * mini << endl;
	}
	else {
		long sum = 0;
		for (int i = 0; i < N; i++) {
			if (vec.at(i) >= 0) {
				sum += vec.at(i);
			}
			else {
				sum -= vec.at(i);
			}
		}
		cout << sum << endl;
	}
}


Measured memory_bytes: 640
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;
const char ENDL = '\n';

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int n;
    cin >> n;
    VI a(n);
    REP(i, n) {
        cin >> a[i];
    }

    int ans = a[0] / 2;
    a[0] = a[0] % 2;
    FOR(i, 1, n) {
        if (a[i - 1] == 1) {
            if (a[i] > 0) {
                ans++;
                a[i - 1]--;
                a[i]--;
            }
        }
        ans += a[i] / 2;
        a[i] = a[i] % 2;
    }

    cout << ans << ENDL;

    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;

template<class T, class F, ll LOG=60>
struct doubling {
    vector<vector<T>> nxt;
    doubling(vector<T> xs, F f) : nxt(LOG, vector<T>(xs.size())) {
        REP(i, xs.size()) nxt[0][i] = f(xs[i]);
        FOR(k, 1, LOG) REP(j, xs.size()) nxt[k][j] = nxt[k-1][nxt[k-1][j]];
    }
    // xs[x]にk回適用
    T query(ll x, ll k) {
        for(ll i=LOG-1; i>=0; --i) if(k&1LL<<i) x = nxt[i][x];
        return x;
    }
};

int main(void) {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for(auto &i: a) cin >> i, i--;

    vector<ll> xs(n);
    iota(xs.begin(), xs.end(), 0);
    doubling dbl(xs, [&](ll now){ return a[now]; });
    cout << dbl.query(0, k)+1 << endl;

    return 0;
}

Measured memory_bytes: 103220
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>

using namespace std;

typedef long long ll;

#ifdef ONPC
    mt19937 rnd(228);
#else
    mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector <int> a(n), b(m);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < m; i++)
    {
        cin >> b[i];
    }
    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if (a[i] == a[j])
            {
                cout << 0 << '\n';
                return 0;
            }
        }
    }
    for (int i = 0; i < m; i++)
    {
        for (int j = i + 1; j < m; j++)
        {
            if (b[i] == b[j])
            {
                cout << 0 << '\n';
                return 0;
            }
        }
    }
    int i = 0;
    int j = 0;
    int ok = 0;
    int mod = 1e9 + 7;
    ll ret = 1;
    for (int x = n * m; x >= 1; x--)
    {
        while (i < n && a[i] >= x)
        {
            i++;
        }
        while (j < m && b[j] >= x)
        {
            j++;
        }
        if (a[i - 1] != x && b[j - 1] != x)
        {
            (ret *= (i * (ll) j - ok)) %= mod;
        }
        else
        {
            if (a[i - 1] != x)
            {
                (ret *= i) %= mod;
            }
            else if (b[j - 1] != x)
            {
                (ret *= j) %= mod;
            }
        }
        ok++;
    }
    cout << ret << '\n';
}


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

#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)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

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

void Main()
{
	int n;
	cin >> n;
	string s;
	string head = "MARCH";
	vll cnt(5,0);
	rep(i,n){
		cin >> s;
		rep(j,5) if(s[0] == head[j]) cnt[j]++;
	}
	// rep(j,5) cout << head[j] << ": " << cnt[j] << endl;
	ll ans = 0;
	rep(i,3){
		rep3(j,i+1,3){
			rep3(k,j+1,4){
				// cout << i << "," << j << "," << k << endl;
				ans += cnt[i]*cnt[j]*cnt[k];
			}
		}
	}
	cout << ans << endl;
	return;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
double pi = 3.14159265359;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    string s, t;
    cin >> s >> t;
    int dp[s.size() + 1][t.size() + 1];
    rep (i, 0, s.size() + 1) rep (j, 0, t.size() + 1) dp[i][j] = 0;
    rep (i, 0, s.size()) {
        rep (j, 0, t.size()) {
            if (s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
            else
                dp[i + 1][j + 1] = max ({dp[i + 1][j], dp[i][j + 1], dp[i][j]});
        }
    }
    // cout << dp[s.size()][t.size()] << "\n";
    string ans = {};
    int i = s.size(), j = t.size();
    while (i > 0 && j > 0) {
        if (dp[i][j] == dp[i - 1][j]) i--;
        else if (dp[i][j] == dp[i][j - 1])
            j--;
        else {
            ans = s[i - 1] + ans;
            i--, j--;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 35456
# -*- coding: utf-8 -*-

s = list(input())
n = len(s)

#回文かどうかチェック
isKaibun = True
for i in range((n-1)//2):
    if s[i] != s[-(i+1)]:
        isKaibun = False
if isKaibun:
    pass
else:
    print("No")
    exit()

s = s[:((n-1)//2)]

#回文かどうかチェック
isKaibun = True
for i in range((n-1)//2):
    if s[i] != s[-(i+1)]:
        isKaibun = False
if isKaibun:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

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

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vll a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    ll a0 = a[0], a1 = a[1], a2 = 0, a01 = a[0] + a[1];
    for (int i = 2; i < n; i++) a2 ^= a[i];

    // dp[i][j][k]: i 桁目について、繰り上がり(j) と a 以下か(k)で場合分け
    V<vvll> dp(44, vvll(2, vll(2, -1)));
    dp[0][0][0] = 0;
    for (int i = 0; i < 43; i++) {
        for (int pjk = 0; pjk < 4; pjk++) {
            int pj = pjk >> 1, pk = pjk & 1;
            if (dp[i][pj][pk] == -1) continue;
            for (int abit = 0; abit < 2; abit++) {
                // xor が a2 と一致するはずなので
                int bbit = ((a2 >> i) & 1) ^ abit;
                int bsum = abit + bbit + pj;
                // 和が一致しない
                if ((bsum & 1) ^ ((a01 >> i) & 1)) continue;
                int nk;
                if (abit < ((a0 >> i) & 1)) nk = 0;
                else if (abit > ((a0 >> i) & 1)) nk = 1;
                else nk = pk;
                chmax(dp[i + 1][bsum >> 1][nk], dp[i][pj][pk] + ((ll)(abit & 1) << i));
            }
        }
    }

    ll ans = dp[43][0][0];
    if (ans <= 0) cout << -1 << '\n';
    else cout << a[0] - ans << '\n';
    return 0;
}


Measured memory_bytes: 3664