akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
const ll MAXN=2e5+51;
struct Node{
    ll x,y;
    inline bool operator <(const Node &rhs)const
    {
        return this->x<rhs.x;
    }
};
struct Segment{
    ll l,r,id;
};
struct Edge{
    ll to,prev,id;
};
Node nd[MAXN];
Segment seg[MAXN];
Edge ed[MAXN<<1];
ll n,m,tot,cnt,l,r,lx,rx,flg,rr;
ll last[MAXN],res[MAXN],w[MAXN],c[MAXN],diff[MAXN],vis[MAXN];
inline ll read()
{
    register ll num=0,neg=1;
    register char ch=getchar();
    while(!isdigit(ch)&&ch!='-')
    {
        ch=getchar();
    }
    if(ch=='-')
    {
        neg=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        num=(num<<3)+(num<<1)+(ch-'0');
        ch=getchar();
    }
    return num*neg;
} 
inline void addEdge(ll from,ll to,ll id)
{
    ed[++tot].prev=last[from];
    ed[tot].to=to;
    ed[tot].id=id;
    last[from]=tot;
}
inline ll discrete(ll x)
{
    ll l=1,r=n+1,res=0,mid;
    while(l<=r)
    {
        mid=(l+r)>>1;
        w[mid]>=x?res=mid,r=mid-1:l=mid+1;
    }
    return res;
}
inline ll discrete2(ll x)
{
    ll l=1,r=n,res=0,mid;
    while(l<=r)
    {
        mid=(l+r)>>1;
        w[mid]<=x?res=mid,l=mid+1:r=mid-1;
    }
    return res;
}
inline ll dfs(ll node,ll fa,ll x)
{
    ll t=0;
    vis[node]=1;
    for(register int i=last[node];i;i=ed[i].prev)
    {
        if(!vis[ed[i].to])
        {
            t^=dfs(ed[i].to,node,i);
        }
    }
    if(node==fa)
    {
        return t;
    }
    if(diff[node]^t)
    {
        res[++rr]=ed[x].id;
        return 1;
    }
    return 0;
}
int main()
{
    n=read(),m=read();
    for(register int i=1;i<=n;i++)
    {
        nd[i].x=read(),nd[i].y=read();
    }
    sort(nd+1,nd+n+1);
    for(register int i=1;i<=n;i++)
    {
        c[i]=nd[i].y,w[i]=nd[i].x;
    }
    for(register int i=1;i<=m;i++)
    {
        l=discrete(lx=read()),r=discrete2(rx=read());
        if(rx<lx)
        {
            continue;
        }
        seg[++cnt]=(Segment){l,r,i};
    }
    for(register int i=1;i<=n;i++)
    {
        diff[i]=c[i]^c[i-1];
    }
    for(register int i=1;i<=cnt;i++)
    {
        addEdge(seg[i].l,seg[i].r+1,seg[i].id);
        addEdge(seg[i].r+1,seg[i].l,seg[i].id);
    }
    dfs(n+1,n+1,0);
    for(register int i=1;i<=n;i++)
    {
        if(vis[i])
        {
            continue;
        }
        if(dfs(i,i,0)!=diff[i])
        {
            return puts("-1"),0;
        }
    }
    printf("%d\n",rr),sort(res+1,res+rr+1);
    for(register int i=1;i<=rr;i++)
    {
        printf("%d ",res[i]);
    }
}

Measured memory_bytes: 14080
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = a; i < n; i++)
#define Repr(i, n, a) for (int i = n; i >= a; i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int n;
vector<int> b;

int solve(int num)
{
    int l = 0, r = n + 2;
    while (r - l > 1)
    {
        int mid = (l + r) / 2;
        if (b[mid] < num)
            l = mid;
        else
            r = mid;
    }
    return l;
}

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

    cin >> n;
    vector<int> a(n);
    b.resize(n + 2);
    b[0] = -INF;
    b[n + 1] = INF;
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i + 1];
    int ans = 0;
    rep(i, 30)
    {
        int num = 1LL << i, cnt = 0;
        vector<int> c = b;
        rep(j, n) b[j + 1] %= (2 * num);
        sort(all(b));
        rep(j, n)
        {
            int tmp = a[j] % (2 * num);
            cnt += solve(2 * num - tmp) - solve(num - tmp) + solve(4 * num - tmp) - solve(3 * num - tmp);
        }
        if (cnt % 2 == 1)
            ans += num;
        b = c;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#define int long long
using namespace std;

signed main() {
	int a;
	while (cin >> a,a) {
		multimap<int, int>s;
		multimap<int, int>o;
		for (int b = 0; b < a; b++) {
			string c;
			cin >> c;
			int e =(c[0]-48) * 36000 + (c[1] - 48) * 3600 + (c[3] - 48) * 600 + (c[4] - 48) * 60 + (c[6] - 48)*10+ (c[7] - 48);
			s.insert(pair<int, int>(e, 1));
			cin >> c;
			e = (c[0] - 48) * 36000 + (c[1] - 48) * 3600 + (c[3] - 48) * 600 + (c[4] - 48) * 60 + (c[6] - 48)*10 + (c[7] - 48);
			o.insert(pair<int, int>(e, -1));
		}
		for (auto w = s.begin(); w != s.end(); w++) {
			o.insert(pair<int, int>((*w).first, (*w).second));
		}
		int p = 0, q = 0;
		for (auto g = o.begin(); g != o.end(); g++) {
			q += (*g).second;
			p = max(p, q);
		}
		cout << p << endl;
	}
}

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

int N, D[1 << 18], cnt[1 << 18];

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> D[i]; cnt[D[i]]++;
	}
	for (int i = 1; i <= 100000; i++) cnt[i] += cnt[i - 1];

	int ans = 0;
	for (int i = 1; i <= 100000; i++) {
		if (cnt[i] * 2 == N) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll Xor,A[2],Ans;
inline void pre(){
    ll N,Tmp;
    cin>>N>>A[0]>>A[1];
    for(int i=3;i<=N;i++)
        cin>>Tmp,Xor^=Tmp;
}
inline bool alw(){
    if(A[0]+A[1]-Xor<0||(A[0]+A[1]-Xor&1))
        return 0;
    ll B[2]={ A[0]+A[1]-Xor>>1 , A[0]+A[1]-Xor>>1 };
    for(ll Bit=40;Bit>=0;Bit--)
        if( (Xor>>Bit)&1 ){
            if((B[0]|1ll<<Bit)<=A[0])
                B[0]|=1ll<<Bit;
            else B[1]|=1ll<<Bit;
        }
    Ans=A[0]-B[0];
    return Ans>=0&&Ans<A[0]&&(B[0]^B[1]^Xor)==0&&B[0]+B[1]==A[0]+A[1];
}
int main(){
    pre();
    if( alw() )
        cout<<Ans;
    else cout<<-1;
    return 0;
}

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

using namespace std;

int main(void) {
	int a[3] = { 0 }, n[3], i;
	for (i = 0; i < 3; i++)
		cin >> n[i];
	if (n[0] == n[1] && n[1] == n[2]) {
		if (n[0] & 1)
			printf("0\n");
		else
			printf("-1\n");
	}
	else {
		for (i = 0; i < 3; i++) {
			while ((n[i] & 1) == 0) {
				a[i]++;
				n[i] >>= 1;
			}
		}
		i = min(min(a[0], a[1]), a[2]);
		if (a[0] == a[1] && a[1] == a[2])
			i++;
		printf("%d\n", i);
	}
	return 0;
}

Measured memory_bytes: 384
#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>;

const int N = 200000;

int h, w, n, sr, sc;
char s[N + 1], t[N + 1];

int dp[N + 1][4];

int main() {
  scanf("%d%d%d%d%d%s%s", &h, &w, &n, &sr, &sc, s, t);
  dp[n][0] = 1;
  dp[n][1] = w;
  dp[n][2] = 1;
  dp[n][3] = h;
  for (int i = n - 1; i >= 0; i--) {
    rep(j, 4) dp[i][j] = dp[i + 1][j];

    if (t[i] == 'L' && dp[i][1] < w) dp[i][1]++;
    if (t[i] == 'R' && dp[i][0] > 1) dp[i][0]--;
    if (t[i] == 'U' && dp[i][3] < h) dp[i][3]++;
    if (t[i] == 'D' && dp[i][2] > 1) dp[i][2]--;

    if (s[i] == 'L') dp[i][0]++;
    if (s[i] == 'R') dp[i][1]--;
    if (s[i] == 'U') dp[i][2]++;
    if (s[i] == 'D') dp[i][3]--;

    if (dp[i][1] < dp[i][0] || dp[i][3] < dp[i][2]) {
      cout << "NO" << endl;
      return 0;
    } 
  }
  if (sc >= dp[0][0] && sc <= dp[0][1] && 
      sr >= dp[0][2] && sr <= dp[0][3]) cout << "YES" << endl;
  else cout << "NO" << endl;
  // rep(i, n + 1) {
  //   rep(j, 4) printf("%d ", dp[i][j]);
  //   printf("\n");
  // }
  return 0;
}

Measured memory_bytes: 7136
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
const int mod = 1e9+7;
const int INF = 1e9;
const int MAX = 1e6;
// const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// struct edge {int to, cost;};
// vector<edge> graph[MAX];
// bool visited[MAX];
// int dist[MAX];

int main() {
    // input
    int a, b;
    cin >> a >> b;
    // solve
    bool flag = false;
    for (int i = 0; ; i++) {
        int x = (int)(i * 0.08);
        int y = (int)(i * 0.1);
        if (x > 100 or y > 100) break;
        if (x == a and y == b) {
            flag = true;
            cout << i << endl;
            break;
        }
    }
    // output
    if (not flag) cout << -1 << endl;
}

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


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int               long long
#define endl              '\n'
#define ff                first
#define ss                second
#define mp                make_pair
#define pb                push_back
#define vii               vector<int> 
#define mii                          map< int, int >
#define msi                          map< string, int > 
#define mib                          map< int, bool > 
#define pii               pair<int,int>
#define vpii              vector< pii >
#define all(v)            v.begin(),v.end()
#define loop(i,s,e)       for(int i=s;i<e;i++)
#define rloop(i,e,s)      for(int i=e;i>=s;i--)
#define mset(a,f)              memset(a,f,sizeof(a))
#define M                 1000000007
#define fastio            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define prvec(v)          loop(i_u_j,0,v.size())cout << v[i_u_j] <<" "; cout << endl;
#define prarr(arr,n)      loop(i_u_j,0,n)cout << arr[i_u_j] << " "; cout << endl;
#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)


template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //
const int N = 1e5 + 7;
string str;
int n, D;
int arr[N], dp[N][2][101];
int getans(int idx, int f, int rem)
{     
      int &mafia = dp[idx][f][rem];
      if( mafia != -1 ) return mafia;
      if( idx == n )   return (rem == 0);
      
      int mxd = str[idx] - '0';
      if(f) mxd = 9;

      int ans = 0;
      for(int i = 0; i <= mxd; i += 1)
      {
            int nf = f;
            if( i < mxd ) nf = 1;
            ans += getans( idx+1, nf, (rem + i)%D );
            ans %= M;
      }
      return mafia = ans;
}

void solve()
{
     cin >> str >> D;
     n = str.length();
     mset(dp,-1);
     int ans = getans(0,0,0) - 1;
     if( ans == -1 ) ans = M - 1;
     cout << ans;

}

int32_t main() {
    fastio;

  


  int t = 1; 
  //cin>>t;
  
  while(t--) solve();
  
  


}


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //















Measured memory_bytes: 158848
N = int(input())
SPI = []
for i in range(N):
    S, P = input().split()
    P = int(P)
    SPI.append((S, P, i + 1))
SPI.sort(key=lambda spi: (spi[0], -spi[1]))
for _, _, i in SPI:
    print(i)

Measured memory_bytes: 38640
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

static const int MAX = 500000;
static const int NIL = -1;

class Node { //????????¨????????±
public:
	int location;
	int l, r;
	Node(){}
};

class Point { //??§?¨?????????±
public:
	int id, x, y;
	Point(){}
	Point(int id, int x, int y): id(id), x(x), y(y) {}
	bool operator < (const Point &p) const {
		return id < p.id; //this?????\
	}

	void print() {
		printf("%d\n", id);
	}
};

int n;
Point P[MAX];
Node T[MAX];
int np;

bool lessX(const Point &p1, const Point &p2) {
	return p1.x < p2.x;
}

bool lessY(const Point &p1, const Point &p2) {
	return p1.y < p2.y;
}

int makeKDTree(int l, int r, int depth) { //??¨???????????¨?????????????????????????????????id???T.l??????inorder?????¨????§???????t??????preorder
	if (!(l < r)) return NIL;
	int mid = (l + r) / 2;
	int t = np++; //??¨????§????????????°?????????
	if (depth % 2 == 0) {
		sort(P + l, P + r, lessX); //????????¨?????????????¨?????????????????????\??????Point?????????
	} else {
		sort(P + l, P + r, lessY);
	}
	T[t].location = mid;
	T[t].l = makeKDTree(l, mid, depth + 1);
	T[t].r = makeKDTree(mid + 1, r, depth + 1);

	return t;
}

void find(int v, int sx, int tx, int sy, int ty, int depth, vector<Point> &ans) {
	int x = P[T[v].location].x;
	int y = P[T[v].location].y;

	if (sx <= x && x <= tx && sy <= y && y <=ty) {
		ans.push_back(P[T[v].location]);
	}

	if (depth % 2 == 0) {
		if (T[v].l != NIL && sx <= x) {
			find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
		} 
		if (T[v].r != NIL && x <= tx) {
			find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
		}
	} else {
		if (T[v].l != NIL && sy <= y) {
			find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
		}  
		if (T[v].r != NIL && y <= ty) {
			find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
		}
	}
	
}

int main() {
	int q;
	scanf("%d", &n);
	int x, y;
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &x, &y);
		P[i] = Point(i, x, y);
		T[i].l = T[i].r = NIL; 
	}

	np = 0;

	int root = makeKDTree(0, n, 0);

	scanf("%d", &q);
	int sx, tx, sy, ty;
	vector<Point> ans;
	for (int i = 0; i < q; i++) {
		scanf("%d%d%d%d", &sx, &tx, &sy, &ty);
		ans.clear();
		find(root, sx, tx, sy, ty, 0, ans);
		sort(ans.begin(), ans.end());
		for (int j = 0; j < ans.size(); j++) {
			ans[j].print();
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 12580
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;


typedef long long int lli;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<float, float> ff;
typedef vector<ii> vii; 
typedef vector<ff> vff;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vi ab(n);
    int sec_max = -1;
    int k=-1,ind=-1,count = 0;
    for (int i = 0; i < n; i++)
    {
        cin>>ab[i];
        if(ab[i]>k){
            ind = i;
            k  = ab[i];
        }
    }
    for (int i = 0; i < n; i++)
    {
        if(ab[i]==k){count++;}
        if(ab[i]!=k){sec_max = max(ab[i],sec_max);}
    }
    if(count>1){
        for (int i = 0; i < n; i++)
        {
            cout<<k<<endl;
        }
        
    }else{
        for (int i = 0; i < n; i++)
        {
            if(ab[i]!=k){
                cout<<k<<endl;
            }else{
                cout<<sec_max<<endl;
            }
        }
        
    }
    return 0;
}

Measured memory_bytes: 2432
# https://atcoder.jp/contests/abc051/tasks/abc051_c

sx, sy, tx, ty = gets.split.map(&:to_i)

res = ""

dx = tx - sx
dy = ty - sy

res << "L" + "U" * (dy + 1) + "R" * (dx + 1) + "D"

res << "L" * dx + "D" * dy

res << "R" * dx + "U" * dy

res << "R" + "D" * (dy + 1) + "L" * (dx + 1) + "U"

puts res

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <functional>
#include <cmath>
#include <cstdint>
#include <mutex>
#include <thread>
#include <bitset>


using namespace std;


int main()
{
	int a, b;
	cin >> a >> b;
	if (a > b)
	{
		for (int i = 0; i < a; i++)
			cout << b;
	}
	else
	{
		for (int i = 0; i < b; i++)
			cout << a;
	}
	return 0;
}


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

int main() {
  int input;
  cin >>input;
  
  string str;
  cin >>str;

  string result;
  if(input >= str.size()){
    result = str;
  }else{
    result = str.substr(0,input) + "...";
  }
  cout << result<< endl;

  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
const ll INF = ll(1e18);
const ll mod = ll(1e9+7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
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; }
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}

//modの値の確認をすること
int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    rep0(i, n)cin >> a[i];
    rep0(i, k){
        vector<ll> b(n + 1,0);
        rep0(j, n){
            ++b[max(j - a[j],0ll)];
            --b[min(j + a[j] + 1,n)];
        }
        rep1(j, n)b[j] += b[j - 1];
        b.pop_back();
        a = b;
        bool f = true;
        rep0(j, n)if(a[j] != n){f = false;break;}
        if(f) break;
    }
    cout << a[0];
    rep1(i, n - 1)cout << " " << a[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 6376
#include<stdio.h>
#include<string.h>

int main(void)
{
	
	int i,j,len,count=0,tmp=0;
	char s[100001];
	
	scanf("%s",s);
	
	len = strlen(s);
	
	
	for(i=0; i < len; i++){
		if( s[i] != s[i+1] ) count++;
	}
	
	count--;
	printf("%d\n",count);
	
	return 0;
	
}
				

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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	if(s[0]!='A') {
		cout << "WA" << endl;
		return 0;
	}
	s[0]=' ';
	int n=s.size();
	bool C=false;
	for (int i=2; i<n-1; i++)
		if(s[i]=='C') {
			s[i]=' ';
			C=true;
			break;
		}
	if(!C) {
		cout << "WA" << endl;
		return 0;
	}
	for (auto ch : s)
		if(ch!=' '&&isupper(ch)) {
			cout << "WA" << endl;
			return 0;
		}
	cout << "AC" << endl;
	return 0;
}


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

using namespace std;

int main() {

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

  vector<long> AA(N);
  for (int i = 0; i < N; ++i) {
    AA[i] = A[i] - i + 1;
  }
  sort(AA.begin(), AA.end());

  long b = AA[(N-1)/2];
  long ans = 0;
  for (int i = 0; i < N; ++i) {
    ans += abs(AA[i] - b);
  }

  cout << ans << endl;

}


Measured memory_bytes: 3328
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    cin >> a;
    cin >> b;
    if(a>b){
        cout << ("a > b");
    }else if(a<b){
        cout << ("a < b");
    }else{
        cout << ("a == b");}
    cout << endl;
}



Measured memory_bytes: 3076
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
total = a[0]
index = 1
cnt = 0
for i in range(N - 2):
    if cnt == 2:
        index += 1
        cnt = 0
    total += a[index]
    cnt += 1

print(total)

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

int main() {
    int N;
    cin >> N;
    vector<string> s(N);
    for (int i=0; i<N; i++) cin >> s.at(i);
    int M;
    cin >> M;
    vector<string> t(M);
    for (int i=0; i<M; i++) cin >> t.at(i);

    int output = 0;
    for (int i=0; i<N; i++){
        int count = 0;
        for (int j=0; j<N; j++){
            if (s.at(i) == s.at(j)) count += 1;
        }
        for (int j=0; j<M; j++){
            if (s.at(i) == t.at(j)) count -= 1;
        }
        output = max(output, count);
    }

    if (output<0) output=0;
    cout << output << endl;
    return 0;
}


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

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}

// 空のベクトルを二つ渡す。N (>=2) 以下の素数を primes に順番に入れる。
void prime_vectors(int N, vector<int>& primes, vector<bool>& is_prime){
    primes = {};
    is_prime = {};
    for(int i=0; i<=N; i++){
        is_prime.push_back(true);
    }

    primes.push_back(2);
    for(int j=4; j<=N; j+=2){
        is_prime[j] = false;
    }

    int i;
    for(i=3; i*i<=N; i+=2){
        if(!is_prime[i]) continue;
        primes.push_back(i);
        for(int j=2*i; j<=N; j+=i){
            is_prime[j] = false;
        }
    }

    for(; i<=N; i+=2){
        if(is_prime[i]){
            primes.push_back(i);
        }
    }
}

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n, m;
    cin >> n >> m;

    vector<int> c(m);
    for(int i=0; i<m; i++){
        cin >> c[i];
    }

    vector<int> dp(n+1);
    for(int i=0; i<=n; i++){
        dp[i] = i;
    }

    for(int i=0; i<m; i++){
        for(int j=c[i]; j<=n; j++){
            int new_num = dp[j-c[i]] + 1;
            if(dp[j] > new_num){
                dp[j] = new_num;
            }
        }
    }
    cout << dp[n] << endl;

    return 0;
}


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

int main(void)
{
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  int smax = a[1] - a[0];
  int smin = a[0];
  for(int i = 1; i < n; i++)
  {
    smax = max(smax,(a[i] - smin));
    smin = min(smin, a[i]);
  }
  cout << smax << endl;
}


Measured memory_bytes: 3588
#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 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(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  string s;
  cin >> s;
  s.pop_back();
  s.pop_back();
  while(1){
    string sr = s.substr(s.size()/2);
    string sf = s.substr(0, s.size()/2);
    if(sr == sf){
      cout << s.size() << endl;
      return 0;
    }
    s.pop_back();
    s.pop_back();
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int gcd(int a, int b){
    if(a==0) return b;
	return gcd(b%a, a);
}

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

    int N;
    int A[100005];
    int MAX = -1;
    int lis[2][100005];

    cin >> N;

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

    lis[0][0] = A[0];
    lis[1][N-1] = A[N-1];
    for (int i = 0;i < N;i++){
        lis[0][i+1] = gcd(lis[0][i],A[i+1]);
    }
    for (int i = N-2;i >= 0;i--){
        lis[1][i] = gcd(lis[1][i+1],A[i]);
    }

    int ans = -1;
    ans = max(ans,lis[0][N-2]);
    ans = max(ans,lis[1][1]);

    for (int i = 1;i < N-1;i++){
        ans = max(ans,gcd(lis[0][i-1],lis[1][i+1]));
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 1408
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n, m;
  cin >> n >> m;
  int a[n];
  for(int i = 0; i < n; i++) cin >> a[i];
  int b[m], c[m];
  for(int i = 0; i < m; i++) cin >> b[i] >> c[i];

  vector< pii > cb(m);
  for(int i = 0; i < m; i++){
    cb[i] = make_pair(c[i], b[i]);
  }
  sort(cb.begin(), cb.end());

  priority_queue< int, vector< int >, greater< int > > pq;
  for(int i = 0; i < n; i++){
    pq.push(a[i]);
  }

  for(int i = m - 1; i >= 0; i--){
    for(int j = 0; j < cb[i].second && pq.top() < cb[i].first; j++){
      pq.pop();
      pq.push(cb[i].first);
    }
  }

  ll sum = 0;
  while(!pq.empty()){
    sum += pq.top();
    pq.pop();
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 2812
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    map<ll, ll> cnt;
    rep(i, 4){
        ll n; cin >> n;
        cnt[n]++;
    }
    (cnt[1] == 1 && cnt[9] == 1 && cnt[7] == 1 && cnt[4] == 1) ? YES() : NO();
}

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

int main() {
  int N,M;
  cin >> N >> M;
  int count[60] = {};
  for(int i=0; i<M; i++) {
    int a,b;
    cin >> a >> b;
    count[a-1]++;
    count[b-1]++;
  }
  for(int i=0; i<N; i++) {
    cout << count[i] << endl;
  }
}

Measured memory_bytes: 3628
use proconio::{input,fastout};

#[fastout]
fn main() {
  input! {
    n: usize,
    k: usize,
    a: [u64;n],
  }
  
  for i in k..n {
    if a[i] > a[i-k] {
      println!("Yes");
    }
    else {
      println!("No");
    }
  }
}

Measured memory_bytes: 5624
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();
		int c = sc.nextInt();
		// 文字列の入力
		//String s = sc.next();
		// 出力
		//System.out.println((a+b+c) + " " + s);
	

	    int tmp=0;
	        if(a<=b&&b<c)
	             tmp=a+b;
	        if(c<=b&&b<a)
	            tmp=c+b;
	        if(b<=a&&a<c) 
	            tmp=a+b;
	        if(c<=a&&a<b)
	            tmp=c+a;
	        if(a<=c&&c<b)
	            tmp=a+c;
	        if(b<=c&&c<a)
	            tmp=c+b;
	        if(a==b&&b==c)
	        tmp=a+b;
	        System.out.println(tmp);
	       
	    
	    
	}
}


Measured memory_bytes: 21716
#include <stdio.h>

#define STACKSIZE 100

int stack[STACKSIZE];

int n=0;

void push(int x)
{
        if ( n >= STACKSIZE){
                fprintf(stderr, "stack overflow\n");
                n=0;
        }
        n++;
        stack[n]=x;
}

int pop(void){
  n=n-1;
  return stack[n+1];
}

main()
{
        int c;
        long x, a, b;

        while ((c=getchar())!=EOF){
                if (isdigit(c)){
                        ungetc(c, stdin);
                        scanf("%d", &x);
                        push(x);
                }
                else {
                        switch(c) {
                        case '+':
                                b=pop();
                                a=pop();
                                push(a+b);
                                break;
                        case '-':
                                b=pop();
                                a=pop();
                                push(a-b);
                                break;
                        case '*':
                                b=pop();
                                a=pop();
                                push(a*b);
                                break;
                        case '/':
                                b=pop();
                                a=pop();
                                push(a/b);
                                break;
                        case '\n':
                                if (n==1){
                                        printf("%d\n", pop());
                                }
                                else {
                                        printf("Invalid expression.\n");
                                        n=0;
                                }
                        case ' ':
                                break;
                        case '\t':
                                break;
                        default:
                                printf("Invalid input.\n");
                                n=0;
                                break;
                        }
                }
        }
}




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

int main()
{
    long long int t;
        double a,b,c,d,z;
        cin>>a>>b>>c>>d;
        z=abs(5.5*d-30*c);
        if(z>180) z=360-z;
        z=(3.141592653589793*z)/180;
        cout<<setprecision(15);
        cout<<sqrt(a*a+b*b-2*a*b*cos(z));

    return 0;
}


Measured memory_bytes: 4152
S=input()
x=int(S[0:2])
y=int(S[2:])
if 1<=x<=12:
    if 1<=y<=12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 1<=y<=12:
        print("YYMM")
    else:
        print("NA")
    
        

Measured memory_bytes: 2940
#include <bits/stdc++.h>
//#include "Local_Debug.h"
using namespace std;
#define Endl endl
#define debug(x) cout << #x << " = " << (x) << endl;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)2e5 + 5;
string s, t;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	while (cin >> s >> t)
	{
		ll ans = 0;
		for (ll i = 0; i < 3; ++i)
			if (s[i] == t[i])
				ans++;
		cout << ans << endl;
	}
}
/*
CSS
CSR

SSR
SSR

RRR
SSS
*/

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
string s;
int cx=0x7fffffff;
int main()
{
	cin>>s;
	int len=s.length();
	for(int i=0;i<len;i++)
		if(s[i]=='C')
		{
			cx=i;
			break;
		}
	for(int i=len-1;i>=0;i--)
		if(s[i]=='F'&&i>cx)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
		else if(s[i]=='F'&&i<cx)
		{
			cout<<"No"<<endl;
			return 0;
		}
	cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
using namespace std;


int N, K;
int memo[16][2048];
vector<int> costs[16];


int rec(int i, int used)
{
  if(memo[i][used] != -1) return memo[i][used];

  if(i == 10) return 0;

  int best = 0;
  for(int t = 0; t < costs[i].size() && used + t <= K; t++) {
    best = max(best, rec(i+1, used + t) + costs[i][t] + (t-1) * t);
  }

  return memo[i][used] = best;
}


int main()
{
  // memoを全て-1で初期化 この関数は-1以外では0でしか初期化出来ないので注意
  memset(memo, -1, sizeof memo);

  cin >> N >> K;

  vector<vector<int> > books(10);
  for(int i = 0; i < N; i++) {
    int C, G;
    cin >> C >> G;
    books[G-1].push_back(C);
  }

  for(int i = 0; i < 10; i++) {
    sort(books[i].begin(), books[i].end(), greater<int>());

    costs[i].push_back(0);
    for(int j = 0; j < books[i].size(); j++) {
      costs[i].push_back(costs[i][j] + books[i][j]);
    }
  }

  cout << rec(0, 0) << endl;
}

Measured memory_bytes: 1380
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
l = LI()
if l.count(5) == 2 and l.count(7) == 1:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 74616
H, W = map(int, input().split())

a = [input() for w in range(H)]

for i in range(H)[::-1]:
    if '#' not in a[i]:
        del a[i]
        H -= 1

n = []

for j in range(W)[::-1]:
    m = [''.join(t[j] for t in a)]
    if '#' in m[0]:
        n += m

for k in range(H):
    print(''.join(u[k] for u in n[::-1]))

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

using namespace std;

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int dx = tx - sx;
  int dy = ty - sy;
  cout << string(dy, 'U') << string(dx, 'R');
  cout << string(dy, 'D') << string(dx, 'L');
  cout << 'L' << string(dy + 1, 'U') << string(dx + 1, 'R') << 'D';
  cout << 'R' << string(dy + 1, 'D') << string(dx + 1, 'L') << 'U';
  cout << endl;
  return 0;
}



Measured memory_bytes: 256
using System;

namespace あっとコーダー
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');

            int n = int.Parse(s[0]);
            int a = int.Parse(s[1]);
            int b = int.Parse(s[2]);

            if (n * a >= b)
            {
                Console.WriteLine("{0}", b);
            }
            else
            {
                Console.WriteLine("{0}", n * a);
            }


        }
    }
}

Measured memory_bytes: 13140
#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() {
  string s, t;
  cin >> s >> t;
  
  
  int cntmax = 0;
  for(int i = 0; i < int(t.length()); i++){
  	for(int j = i; j <= int(s.length()) - int(t.length()) + i; j++){
      int cnt = 0;
      if(t.at(i) == s.at(j)){
        cnt = 1;
        for(int k = 1; k < int(t.length()) - i; k++){
          if(t.at(i+k) == s.at(j+k)) cnt++;
        }
      }
      cntmax = max(cntmax, cnt);
    }
  }
  
  cout << int(t.length())-cntmax << endl;
  return 0;
}



Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
/*
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <random>
#include <bits/stdc++.h>
*/

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
//typedef vector<ll> vec;
//typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll MAX_N=100010,MAX_K=1010;

ll N,K;
ll x,y,rect[4*MAX_K][4*MAX_K];
char c;

ll sum_rect(ll x_bottom,ll y_bottom,ll h,ll w){
  return rect[x_bottom+h][y_bottom+w]-rect[x_bottom][y_bottom+w]
            -rect[x_bottom+h][y_bottom]+rect[x_bottom][y_bottom];
}

int main(){
  cin>>N>>K;
  for(ll i=0;i<N;i++){
    cin>>x>>y>>c;
    if(c=='W'){
      x+=K;
    }
    rect[x%(2*K)][y%(2*K)]++;
  }
/*
  for(ll i=0;i<2*K;i++){
    for(ll j=0;j<2*K;j++){
      rect[i+1][j+1]=B[i][j];
    }
  }
*/
  for(ll i=0;i<2*K;i++){
    for(ll j=0;j<2*K;j++){
      rect[i+2*K][j+2*K]=rect[i][j];
      rect[i+2*K][j]=rect[i][j];
      rect[i][j+2*K]=rect[i][j];
    }
  }
  /*
  for(ll j=0;j<4*K;j++){
    for(ll i=0;i<4*K;i++){
          cout<<rect[i][j]<<" ";
    }
    cout<<endl;
  }
*/

  for(ll i=0;i<4*K;i++){
    for(ll j=1;j<4*K;j++){
      rect[i][j]+=rect[i][j-1];
    }
  }

  for(ll i=1;i<4*K;i++){
    for(ll j=0;j<4*K;j++){
      rect[i][j]+=rect[i-1][j];
    }
  }
/*
  for(ll j=0;j<4*K;j++){
  for(ll i=0;i<4*K;i++){
          cout<<rect[i][j]<<" ";
      }
      cout<<endl;
  }
*/

  ll ans=0;
  ll tmp;
  for(ll i=0;i<2*K;i++){
    for(ll j=0;j<2*K;j++){
      tmp=0;
      tmp+=sum_rect(i+K,j+K,K,K);
      tmp+=sum_rect(i,j,K,K);
      ans=max(tmp,ans);
    }
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 127232
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main() {
	cin >> a >> b;
	if(a <= 0 && b >= 0) puts("Zero");
	else if(a > 0) puts("Positive");
	else if(b > 0 && -a % 2 == 0) puts("Positive");
	else if(b > 0) puts("Negative");
	else if((b - a) % 2 == 1) puts("Positive");
	else puts("Negative");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> p;
typedef unsigned long long int ull;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};

int main(){
    ll X,Y,A,B,C;
    cin>>X>>Y>>A>>B>>C;
    vector<ll> r(A),b(B),g(C),s(X+Y);
    for(int i=0;i<A;i++) cin>>r[i];
    for(int i=0;i<B;i++) cin>>b[i];
    for(int i=0;i<C;i++) cin>>g[i];
    sort(r.begin(),r.end(),greater<ll>());
    sort(b.begin(),b.end(),greater<ll>());
    sort(g.begin(),g.end(),greater<ll>());
    ll ans=0;
    for(int i=0;i<X;i++){
      ans+=r[i];
      s[i]=r[i];
    }
    for(int i=0;i<Y;i++){
      ans+=b[i];
      s[X+i]=b[i];
    }
    sort(s.begin(),s.end());
    for(int i=0;i<C;i++){
        if(g[i]<=s[i]||i>=X+Y) break;
        ans+=g[i]-s[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6884
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


ll all(int n) {
    int i;
    ll res = 1;
    for (i = 0; i <= n; i++) {
        res *= 2;
    }
    return res - 1;
}

ll solve(int n, ll x, ll b) {
    ll nb = (b + 3) / 2 - 3;
    if (n == 0) return 1;
    if (x <= 1) return 0;
    if (x < nb + 1) {
        return solve(n - 1, x - 1, nb);
    }
    if (x == nb + 1) {
        return all(n - 1);
    }
    if (x == nb + 2) {
        return all(n - 1) + 1;
    }
    return all(n - 1) + 1 + solve(n - 1, x - nb - 2, nb);
}

int main(void) {
    int n;
    ll x, b;

    cin >> n >> x;

    b = 1;
    for (int i = 0; i < n + 2; i++) {
        b *= 2;
    }

    cout << solve(n, x, b - 3) << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

long long Euclid(long long A, long long B){
  if(A<B) return Euclid(B, A);
  while(B!=0){
    long long R = A%B;
    A = B; B = R;
  }
  return A;
}

int main(){
  long long N;
  std::cin >> N;
  std::vector<long long> A(N);
  std::copy_n(std::istream_iterator<long long>(std::cin), N ,A.begin());

  long long GCD = A[0];

  for(int i = 1 ; i < (int)A.size() ; i++ ){
    GCD = Euclid(A[i],GCD);
  }
  std::cout<<GCD<<std::endl;
  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>//min/max/sort(rand-access it)/merge
#include <bitset>
#include <climits>//INT_MAX/INT_MIN/ULLONG_MAX
#include <cmath>//fmin/fmax/fabs/sin(h)/cos(h)/tan(h)/exp/log/pow/sqrt/cbrt/ceil/floor/round/trunc
#include <cstdlib>//abs/atof/atoi/atol/atoll/strtod/strtof/..., srand/rand, calloc/malloc, exit, qsort
#include <iomanip>//setfill/setw
#include <iostream>//cin/cout/wcin/wcout/left/right/internal/dec/hex/oct/fixed/scientific
#include <iterator>
#include <list>
#include <queue>
#include <string>//stoi/stol/stoul/stoll/stoull/stof/stod/stold/to_string/getline
#include <tuple>
#include <utility>//pair
#include <valarray>
#include <vector>

#define PRIME 1000000007

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<ull, int> puli;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pllll;
typedef pair<ull, ull> pulul;
typedef pair<double, double> pdd;
typedef tuple<int, int, int> ti3;
typedef tuple<int, int, int, int> ti4;

const bool debug = false;

int main(void) {
	ui n;
	cin >> n;
	if (n==1)
	{
		ui a;
		cin >> a;
		cout << (a/2) << endl;
		return 0;
	}
	ui prev, now;
	ull total = 0UL;
	cin >> prev;
	total += (ull)(prev/2);
	prev %= 2;
	now = prev;
	for (int i = 0; i < n-1; ++i)
	{
		prev = now;
		cin >> now;
		if (prev && now)
		{
			++total;
			--now;
			--prev;
		}
		total += (ull)(now/2);
		now %= 2;
	}
	cout << total << endl;
	return 0;
}

Measured memory_bytes: 256
N,K = gets.split.map(&:to_i)
A = Array.new(N + 1, 0)
gets.split.map(&:to_i).each_with_index do |a,i|
  A[i + 1] = a
end

ord = Array.new(N + 1)
ord[1] = 0
i = 1
until ord[A[i]] || ord[i] == K
  ord[A[i]] = ord[i] + 1
  i = A[i]
end
if ord[i] == K
  puts i
else
  d = (K - ord[A[i]]) % (ord[i] - ord[A[i]] + 1)
  puts ord.index(ord[A[i]] + d)
end


Measured memory_bytes: 30560
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
using ld = long double;
 
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())
 
#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))
 
#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed
 
bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }
 
#define N_MAX 1000000
#define N_MAX_SQRT 1000
 
ll fact[N_MAX];
 
void init_fact() {
  std::vector<ll> prime_vec;
 
  fact[1 - 1] = 1;
  for (size_t i = 2; i <= N_MAX; i++) {
    bool is_prime = true;
    for (auto &&p : prime_vec) {
      if (i % p == 0) {
        fact[i - 1] = p;
        is_prime = false;
        break;
      }
      if (p * p > i) {
        break;
      }
    }
 
    if (is_prime) {
      fact[i - 1] = i;
      prime_vec.push_back(i);
    }
  }
}
 
unordered_map<ll, ll> factorize(ll n) {
  unordered_map<ll, ll> retv;
  while (n > 1) {
    ll f = fact[n - 1];
    retv[f]++;
    n /= f;
  }
 
  return retv;
}
 
ll count_divider(ll n) {
  unordered_map<ll, ll> factor_dict = factorize(n);
  ll retv = 1;
  for (auto &&p : factor_dict) {
    retv *= p.second + 1;
  }
  return retv;
}
 
ll solve(ll N) {
  init_fact();
  ll ans = 1;
  for (ll i = 2; i < N; i++) {
    ans += count_divider(i);
  }
 
  return ans;
}
 
int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  ll N;
  cin >> N;
  // main procedure
  ll ans = solve(N);
 
  // output
  cout << ans << endl;
 
  return 0;
}

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

#define rep( i, n ) for( int i = 0; i < ( n ); i++ )
#define PI 3.14159265
typedef long long ll;

struct Dice {
    int  num[ 6 ];
    void roll( char c ) {
        int t;
        if( c == 'E' ) {
            t        = num[ 0 ];
            num[ 0 ] = num[ 3 ];
            num[ 3 ] = num[ 5 ];
            num[ 5 ] = num[ 2 ];
            num[ 2 ] = t;
        } else if( c == 'W' ) {
            t        = num[ 0 ];
            num[ 0 ] = num[ 2 ];
            num[ 2 ] = num[ 5 ];
            num[ 5 ] = num[ 3 ];
            num[ 3 ] = t;
        } else if( c == 'N' ) {
            t        = num[ 0 ];
            num[ 0 ] = num[ 1 ];
            num[ 1 ] = num[ 5 ];
            num[ 5 ] = num[ 4 ];
            num[ 4 ] = t;
        } else if( c == 'S' ) {
            t        = num[ 0 ];
            num[ 0 ] = num[ 4 ];
            num[ 4 ] = num[ 5 ];
            num[ 5 ] = num[ 1 ];
            num[ 1 ] = t;
        }
    }
    int top() { return num[ 0 ]; }
};

int main( void ) {

    Dice d;
    rep( i, 6 ) cin >> d.num[ i ];
    string s;
    cin >> s;
    rep( i, s.length() )d.roll( s.at( i ) );
    cout << d.top() << endl;
    return 0;
}



Measured memory_bytes: 3192
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int N,L;
	cin>>N>>L;
	vecs(S)
	fx(N){
		vecps(S)
	}
	sorts(S)
	fx(N){
		cout<<S.at(x);
	}
	cout<<endl;
	
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

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

int main(){
  constexpr int mod = 1000000007;
  int n; cin >> n;
  ll ans = 1;
  for(int i = 1; i <= n; ++i){
    ans = (ans*i)%mod;
  }
  cout << ans << endl;
}



Measured memory_bytes: 3636
#include <cstdio>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
const int INF = 1000000000;

int main()
{
    int n, m;
    int d[512];
    vector<int> f[512];

    while (scanf("%d %d", &n, &m), n != 0){
        for (int i = 1; i <= n; i++) f[i].clear();
        for (int i = 0; i < m; i++){
            int a, b;
            scanf("%d %d", &a, &b);
            f[a].push_back(b);
            f[b].push_back(a);
        }

        fill(d + 1, d + n + 1, INF);
        priority_queue<P, vector<P>, greater<P> > q;
        q.push(P(0, 1));
        d[1] = 0;
        while (!q.empty()){
            P p = q.top();
            q.pop();

            if (d[p.second] < p.first) continue;
            for (int i = 0; i < f[p.second].size(); i++){
                int v = f[p.second][i];
                if (d[v] > d[p.second] + 1){
                    d[v] = d[p.second] + 1;
                    q.push(P(d[v], v));
                }
            }
        }

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

    return 0;
}

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

using namespace std;
inline void y()
{
  cout<<"YES\n";
}
inline void n()
{
  cout<<"NO\n";
}
int a,b,c;
string s;
int main()
{
  cin>>a>>b>>c;
  if((b*10+c)%4==0)y();
  else n();
  return 0;
}



Measured memory_bytes: 256