akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, X;
    cin >> N >> X;
    int min_m = 1001;
    for(int i = 0; i < N; i++) {
        int m;
        cin >> m;
        min_m = min(min_m, m);
        X -= m;
    }
    cout << N + X/min_m << endl;
}


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

using namespace std;

int main() {
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    for (int i = 0; i < m; i++) {
        cin >> b.at(i);
    }
    vector<vector<int>> a(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a.at(i).at(j);
        }
    }

    int count = 0;
    for (int i = 0; i < n; i++) {
        int ans = 0;
        for (int j = 0; j < m; j++) {
            ans += a.at(i).at(j) * b.at(j);
        }
        if (ans + c > 0) {
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 3604
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<iostream>
using namespace std;
#define N 100001
vector<int>ljb[N];
typedef vector<int>::iterator ITER;
typedef long long ll;
queue<int>q;
int n,anss[N];
ll ans;
int fa[N],dep[N],top[N],son[N],siz[N];
void dfs(int U)
{
    siz[U]=1;
    for(ITER it=ljb[U].begin();it!=ljb[U].end();++it)
      {
        dep[*it]=dep[U]+1;
        dfs(*it);
        siz[U]+=siz[*it];
        if(siz[*it]>siz[son[U]])
          son[U]=(*it);
      }
}
void df2(int U)
{
    if(son[U])
      {
        top[son[U]]=top[U];
        df2(son[U]);
      }
    for(ITER it=ljb[U].begin();it!=ljb[U].end();++it)
      if((*it)!=son[U])
        {
          top[*it]=(*it);
          df2(*it);
        }
}
int lca(int U,int V)
{
    while(top[U]!=top[V])
      {
        if(dep[top[U]]<dep[top[V]])
          swap(U,V);
        U=fa[top[U]];
      }
    if(dep[U]>dep[V])
      swap(U,V);
    return U;
}
int calc(int U,int V)
{
    return dep[U]+dep[V]-(dep[lca(U,V)]<<1);
}
int main()
{
	//freopen("g.in","r",stdin);
	int x;
	scanf("%d",&n);
	for(int i=2;i<=n;++i)
	  {
	  	scanf("%d",&x);
	  	fa[i]=x;
	  	ljb[x].push_back(i);
	  }
	top[1]=1;
    dfs(1);
    df2(1);
	q.push(1);
	while(!q.empty())
	  {
	  	int U=q.front();
	  	for(ITER it=ljb[U].begin();it!=ljb[U].end();++it)
	  	  {
	  	  	anss[*it]=calc(q.back(),*it);
	  	  	q.push(*it);
	  	  }
	  	q.pop();
	  }
	for(int i=2;i<=n;++i)
	  ans+=(ll)anss[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 12164
#coding:utf-8


if __name__ == "__main__":
    S = raw_input()
    T = raw_input()
    q = int(raw_input())

    S_sum = [0] * (len(S) + 1)
    T_sum = [0] * (len(T) + 1)

    for i, char in enumerate(S):
        if char == "A":
            S_sum[i+1] = S_sum[i] + 1
        elif char == "B":
            S_sum[i+1] = S_sum[i] + 2

    for i, char in enumerate(T):
        if char == "A":
            T_sum[i+1] = T_sum[i] + 1
        elif char == "B":
            T_sum[i+1] = T_sum[i] + 2

    for query in range(q):
        a, b, c, d = map(int, raw_input().split(" "))

        S_mod = (S_sum[b] - S_sum[a-1]) % 3
        T_mod = (T_sum[d] - T_sum[c-1]) % 3

        if S_mod == T_mod:
            print "YES"
        else:
            print "NO"



Measured memory_bytes: 12676
import sys
C11,C12,C13 = map(int, input().split())
C21,C22,C23 = map(int, input().split())
C31,C32,C33 = map(int, input().split())





if (C11+C22==C12+C21) and (C12+C23==C13+C22) and (C21+C32==C22+C31) and (C22+C33==C23+C32):
    print('Yes')
    sys.exit()


print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3+5;
int n, m;
vector<int> g[N];
int vis[N];
vector<int> tmp, ans;
void dfs(int u) {
    tmp.push_back(u);
    vis[u] = 1;
    for(int v : g[u]) {
        if(v == tmp[0]) {
            if(tmp.size() < ans.size() || ans.empty()) {
                ans = tmp;
            }
        } else if(!vis[v]) {
            dfs(v);
        }
    }
    tmp.pop_back();
}

int main() {
    cin >> n >> m;
    for(int i = 0, u, v; i < m; i++) {
        cin >> u >> v;
        g[u].push_back(v);
    }
    for(int i = 1; i <= n; i++) {
        memset(vis, 0, sizeof vis);
        tmp.clear();
        dfs(i);
    }
    if(ans.size() == 0) cout << -1 << endl;
    else {
        cout << ans.size() << '\n';
        for(int x : ans) {
            cout << x << '\n';
        }
    }
    return 0;
}

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

bool ok1(vector<int> v, int x) {
  if (v.size() == 0) return x == 0;
  map<int,bool> mp[v.size()];
  mp[0][v[0]] = 1;
  for (int i = 1; i < v.size(); i++) {
    int d = v[i];
    for (auto p:mp[i - 1]) {
      mp[i][p.first + d] = 1;
      mp[i][p.first - d] = 1;
    }
  }
  return mp[v.size() - 1][x];
}

bool ok2(vector<int> v, int x) {
  if (v.size() == 0) return x == 0;
  map<int,bool> mp[v.size()];
  mp[0][v[0]] = 1;
  for (int i = 1; i < v.size(); i++) {
    int d = v[i];
    for (auto p:mp[i - 1]) {
      mp[i][p.first + d] = 1;
      mp[i][p.first - d] = 1;
    }
  }
  return mp[v.size() - 1][x] || mp[v.size() - 1][-x];
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  int x, y;
  cin >> s >> x >> y;
  int cnt = 0;
  int f = 1;
  vector<int> vec1, vec2;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'F') cnt++;
    else {
      if (f == 1) {
        vec1.push_back(cnt);
        cnt = 0;
        f = 2;
      } else {
        vec2.push_back(cnt);
        cnt = 0;
        f = 1;
      }
    }
  }
  if (f == 1) {
    vec1.push_back(cnt);
  } else {
    vec2.push_back(cnt);
  }
  cout << (ok1(vec1,x) && ok2(vec2,y) ? "Yes":"No") << endl;
  return 0;
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

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

// x^n
int POW(int x, int n) {
  int ret = 1;
  rep(i, 0, n) {
    ret *= x;
  }
  return ret;
};

struct Puzzle {
  int panel[8];
  int x, y; // 0のx, y
};

int calc_state(Puzzle p) {
  int ret = 0;
  rep(i, 0, 8) {
    ret += p.panel[i] * POW(8, i);
  }
  return ret;
};



// state, distance
map<int, int> T;
map<int, bool> visited;

int dx[4] = { 0, 0, 1, -1 }; // u, d, r, l
int dy[4] = { -1, 1, 0, 0 }; // u, d, r, l

void bfs() {
  Puzzle init_p = { 0, 1, 2, 3, 4, 5, 6, 7, 0, 0 };
  queue<Puzzle> q;
  q.push(init_p);
  T[calc_state(init_p)] = 0;
  Puzzle p;
  int x, y;
  int x2, y2;
  while(!q.empty()) {
    p = q.front(); q.pop();
    int p_state = calc_state(p);
    if (Find(visited, p_state)) continue;
    visited.emplace(p_state, true);
    x = p.x;
    y = p.y;
    // 0の動かし先
    rep(i, 0, 4) {
      x2 = x + dx[i];
      y2 = y + dy[i];
      if (0 <= x2 && x2 < 4 && 0 <= y2 && y2 < 2) {
        Puzzle tmp = p;
        swap(tmp.panel[y * 4 + x], tmp.panel[y2 * 4 + x2]); // 交換
        // 0の位置を更新
        tmp.x = x2;
        tmp.y = y2;
        int tmp_state = calc_state(tmp);
        if (!(Find(visited, tmp_state))) { // 探索済み出ない
          if (Find(T, tmp_state)) {
            T[tmp_state] = min(T[tmp_state], T[p_state] + 1);
          } else {
            T[tmp_state] = T[p_state] + 1;
          }
          q.emplace(tmp);
        }
      }
    }
  }
};

int main() {
  bfs();

  int n;
  Puzzle p;
  while (true) {
    rep(i, 0, 8) {
      if (!(cin >> n)) return 0;
      p.panel[i] = n;
      if (n == 0) {
        p.x = i % 4;
        p.y = i / 4;
      }
    }
    int p_state = calc_state(p);
    cout << T[p_state] << endl;
  }
};



Measured memory_bytes: 5092
#include <iostream>
#include <math.h>
//#include <numeric>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
#define n_max 100000

#define rep(i,n) for(int i = 0; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;

int main()
{
    int n, k;
    string s, t;
    cin >> n >> k;
    cin >> s;
    t = s;
    transform(s.begin(), s.end(), s.begin(), ::tolower);
    t[k-1] = s[k-1];

    cout << t << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>n>>y;
    rep(i,n+1){
        rep(j,n+1){
            ll k=n-i-j;
            if(k<0)continue;
            ans=i*1000+j*5000+k*10000;
            if(ans==y){
                cout<<k<<" "<<j<<" "<<i<<"\n";
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>

#define SPACE string(" ")
using namespace std;

int main(void) {
	string str;
	getline(cin, str);

	string::size_type pos = 0;
	pos = str.find(SPACE, pos);
	int a = atoi(str.substr(0, pos).c_str());
	pos += SPACE.length();
	int b = atoi(str.substr(pos).c_str());

	cout << a * b << SPACE << 2 * a + 2 * b << endl;

	int c;
	cin >> c;

	return 0;
}

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

using namespace std;

typedef long long ll;

int main()
{
    int n,c;
    scanf("%d%d",&n,&c);
    const int m=1e5+1,inf=1e9+1;
    vector<ll> x(m,inf);
    x[0]=0;
    while(n--)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        for(int i=m-1;i>=b;--i)
            x[i]=min(x[i],x[i-b]+a);
    }
    ll res=0;
    for(int i=0;i<m;++i)
        res=x[i]<=c?i:res;
    printf("%lld\n",res);
}


Measured memory_bytes: 1024
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #n,m,k=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    #n=int(readline())
    ss=readline().rstrip()

    if ss=="ABC":
        print("ARC")
    else:
        print("ABC")

    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 16156
S = list(input())
N = len(S)

m = N//2 +1
l = S[:m-1]
r = S[m:]

def chk(str_):
	leng = len(str_)
	if leng == 1:
		return True
	elif leng%2 == 2:
		ll = str_[:leng//2]
		rr = str_[leng//2:]
	else:
		ll = str_[:leng//2]
		rr = str_[leng//2:]
	for a, b in zip(ll, reversed(rr)):
		if a != b:
			return False
	return True

if chk(S) and chk(l) and chk(r):
	print("Yes")
else:
	print("No")

Measured memory_bytes: 3064
using System;

namespace AtCoder_1223_1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);
            int d = int.Parse(input[3]);

            if (a + b < c + d)
            {
                Console.WriteLine("Right");
            }else if(a + b == c + d){
                Console.WriteLine("Balanced");
            }else{
                Console.WriteLine("Left");
            }
        }
    }
}


Measured memory_bytes: 13140
// #include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
// #include <deque>
// #include <queue>
// #include <array>
// #include <ctime>
// #include <list>
#include <map>
#include <set>
// #include <cassert>
// #include <complex>
// #include <sstream>
// #include <forward_list>
// #include <unordered_set>
// #include <unordered_map>

using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define scani(n) scanf("%d",&n);
#define EPS 1e-9
#define FOR(i,n) for(int i=0; i<n; i++)
#define X first
#define Y second
#define arrinput for(int i=0; i<n; i++) cin>>arr[i];
#define arrsum for(int i=0; i<n; i++) sum+=arr[i];
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define forr(i,n) for(int i=n-1; i>=0; i--)
#define sz(a) (int)(a.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

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

const int MOD = 1e9+7;
const int n_ = 1e5+1000;
const long double PI = acos(-1.0);

ll gcd (ll a, ll b) {return ( a ? gcd(b%a, a) : b );}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}

bool vowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') return true;
    else return false;
}

// Union-Find Disjoint Sets Library written in OOP manner, using both path compression and union by rank heuristics
class UnionFind {                                              // OOP style
private:
    vi p, rank, setSize;                       // remember: vi is vector<int>
    int numSets;
public:
    UnionFind(int N) {
        setSize.assign(N, 1); numSets = N; rank.assign(N, 0);
        p.assign(N, 0); for (int i = 0; i < N; i++) p[i] = i; }
    int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
    bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
    void unionSet(int i, int j) { 
        if (!isSameSet(i, j)) { numSets--; 
        int x = findSet(i), y = findSet(j);
        // rank is used to keep the tree short
        if (rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; }
        else                   { p[x] = y; setSize[y] += setSize[x];
                                 if (rank[x] == rank[y]) rank[y]++; } } }
    int numDisjointSets() { return numSets; }
    int sizeOfSet(int i) { return setSize[findSet(i)]; }
};

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

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n, x;
    cin>>n>>x;
    int arr[n];
    arrinput;
    int ans = 0;
    if(arr[0] > x) {
        ans += (arr[0] - x);
        arr[0] = x;
    }
    for1(i,n-1) {
        if(arr[i-1]+arr[i] > x) {
            ans += (arr[i] + arr[i-1] - x);
            arr[i] = x - arr[i-1];
        }
    }
    cout<<ans;

    return 0;
}   

Measured memory_bytes: 1024
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = 0
for i in range(n):
    f = min(a[i],b[i])
    if i == 0:
        c += f
        c += min(a[i+1],b[i]- f)
        a[i+1] -= min(a[i+1],b[i]-f)
    else:
        c += f
        c += min(a[i+1],b[i] - f)
        a[i+1] -= min(a[i+1],b[i]-f)
print(c)

Measured memory_bytes: 18752
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e5 + 10;

int main() {
    string s;
    cin >> s;
    int n = s.length();
    if(s[0] == s[n-1]) {
        cout << (!(n & 1) ? "First" : "Second") << endl;
    } else {
        cout << ((n & 1) ? "First" : "Second") << endl;
    }
    return 0;
}

Measured memory_bytes: 512
class NullNode():
    def __init__(self):
        self.id = -1

class Node():
    def __init__(self, id):
        self.id = id
        self.parent = NullNode()
        self.left = NullNode()
        self.right = NullNode()

def preorder(node, out_list=[]):
    if node.id != -1:
        out_list.append(str(node.id))
        out_list = preorder(node.left, out_list)
        out_list = preorder(node.right, out_list)
    return out_list

def inorder(node, out_list=[]):
    if node.id != -1:
        out_list = inorder(node.left, out_list)
        out_list.append(str(node.id))
        out_list = inorder(node.right, out_list)
    return out_list

def postorder(node, out_list=[]):
    if node.id != -1:
        out_list = postorder(node.left, out_list)
        out_list = postorder(node.right, out_list)
        out_list.append(str(node.id))
    return out_list

n = int(input())
node_list = [Node(id) for id in range(n)]
for i in range(n):
    [id, left, right] = [int(j) for j in input().split()]
    i_node = node_list[id]
    if left != -1:
        i_node.left = node_list[left]
        node_list[left].parent = node_list[id]
    if right != -1:
        i_node.right = node_list[right]
        node_list[right].parent = node_list[id]

for node in node_list:
    if node.parent.id == -1:
        root = node

print('Preorder')
out_list = preorder(root)
print(' ' + ' '.join(out_list))

print('Inorder')
out_list = inorder(root)
print(' ' + ' '.join(out_list))

print('Postorder')
out_list = postorder(root)
print(' ' + ' '.join(out_list))



Measured memory_bytes: 5616
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES cout<<"YES"<<'\n'
#define NO cout<<"NO"<<'\n'
#define Yes cout<<"Yes"<<'\n'
#define No cout<<"No"<<'\n'
#define yes cout<<"yes"<<'\n'
#define no cout<<"no"<<'\n'
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    string s; cin >> s;
    REP(i,s.size()) if(!(i&1)) cout << s[i];
    cout << endl;

    return 0;
}

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

int main(){
    int A, B, C, X, ans = 0;
    cin >> A >> B >> C >> X;
    for(int i = 0; i <= A; i++){
        for(int j = 0; j <= B; j++){
            for(int k = 0; k <= C; k++){
                if(500 * i + 100 * j + 50 * k == X){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int a, b, x;
  cin >> a >> b;
  
  if(a + b == 3) x = 3;
  else if(a + b == 4) x = 2;
  else if(a + b == 5) x = 1;
  
  cout << x << endl;
}

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

#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,k; cin >> n >> k;
    vector<pair<ll,ll>> a(n);
    rep(i,0,n) cin >> a[i].first >> a[i].second;
    sort(all(a));
    ll cnt=0;
    ll memo=a[0].first;
    int i=0;
    while(cnt<k && i<n){
        cnt += a[i].second;
        memo = a[i].first;
        i++;
    }
    cout << memo << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main
{

    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        int m = scan.nextInt();
        int t;

        while (n != 0 && m != 0) {
            int f = 0;
            int best = 0;
            int k = 0;
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = scan.nextInt();
            }
            for (int l = 0; l < n; l++) {
                for (int r = l+1; r < n; r++) {
                    t = a[l] + a[r];
                    if (t <= m) {
                        if (t >= k) {
                            best = t;
                            k = t;
                            f++;
                        }
                    }
                }
            }
            if (f > 0) {
                System.out.println(best);
            } else {
                System.out.println("NONE");
            }
            n = scan.nextInt();
            m = scan.nextInt();

        }
    }
}



Measured memory_bytes: 47656
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int n;
  cin>>n;
  set<long long int> all;
  vector<long long int> hoge;
  map<long long int,long long int> dic;
  long long int count=2;
  long long int maxsize=0;
  while(count<=sqrt(n)){
    long long int allsize=all.size();
    if(n%count==0){
      all.insert(count);
      dic[count]++;
      maxsize=max(maxsize,dic[count]);
      long long int nowsize=all.size();
      if(nowsize!=allsize) hoge.push_back(count);
      n/=count;
      continue;
    }else{
      if(count==2){
        count++;
      }else{
        count+=2;
      }
    }
  }
  if(n!=1){
    long long int allsize=all.size();
    all.insert(n);
    dic[n]++;
    long long int nowsize=all.size();
    maxsize=max(maxsize,dic[n]);
    if(nowsize!=allsize) hoge.push_back(n);
  }
  long long int x=maxsize+1;
  long long int rui[x];
  rui[0]=0;
  for(long long int i=1; i<x; i++){
    rui[i]=rui[i-1]+i;
  }
  long long int ans=0;
  long long int allsize=all.size();
  for(long long int i=0; i<allsize; i++){
    long long int high=x;
    long long int low=0;
    long long int mid;
    while(high>=low){
      mid=(high+low)/2;
      if(rui[mid]>dic[hoge.at(i)]){
        high=mid-1;
      }else if(rui[mid]<dic[hoge.at(i)]){
        low=mid+1;
      }else{
        break;
      }
    }
    if(rui[mid]>dic[hoge.at(i)]){
      mid--;
    }
    ans+=mid;
  }
  cout<<ans<<endl;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

ll N, K;
vector<ll> L;

signed main()
{
    cin >> N >> K;
    REP(i, N) {
        ll tmp;
        cin >> tmp;
        L.push_back(tmp);
    }
    sort(L.begin(), L.end(), greater<ll>());
    ll ans = 0;
    REP(i, K) { ans += L[i]; }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const int MOD = 1e9+7;
//}}}

ll A[200000];
ll sumA[200001];
int main(){
	int N;
	cin >> N;
	rep(i, N) cin >> A[i];
	sumA[0] = A[0];
	rep(i, 1, N){
		sumA[i] = sumA[i - 1] + A[i];
	}
	map<ll, int> m;
	rep(i, N + 1) m[sumA[i]]++;
	ll count = 0;
	for(auto &x: m){
		ll y = x.second;
		count += y * (y - 1) / 2;
	}
	cout << (count) << endl;
	return 0;
}


Measured memory_bytes: 15872
import java.util.Scanner;

public class Main {
    // void call(int n){
    //   int i = 1;
    //  CHECK_NUM:
    //   int x = i;
    //   if ( x % 3 == 0 ){
    //     cout << " " << i;
    //     goto END_CHECK_NUM;
    //   }
    //  INCLUDE3:
    //   if ( x % 10 == 3 ){
    //     cout << " " << i;
    //     goto END_CHECK_NUM;
    //   }
    //   x /= 10;
    //   if ( x ) goto INCLUDE3;
    //  END_CHECK_NUM:
    //   if ( ++i <= n ) goto CHECK_NUM;

    //   cout << endl;
    // }
    public static void main(String []args){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	// int n = 350;
	for(int i = 1;i<= n;++i){
	    if(i % 3 == 0){
	    	System.out.print(" " + i);
	    	continue;
	    }
	    int x = i;
	    while(true){

		if(x % 10 == 3){
		    System.out.print(" " + i);
		    break;
		}
		x /= 10;
		if(x == 0)break;
	    }
	}
	System.out.println("");

    }
}

Measured memory_bytes: 28768
#include<bits/stdc++.h>
//using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb emplace_back
#define mp std::make_pair
#define endl "\n"
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
constexpr ll MOD=1e9+7;
//constexpr ll MOD=998244353;
//constexpr ll MOD=100000;
constexpr ll MAX=1e7;
constexpr ll INF=(1ll<<60);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
struct Binary_indexed_tree{
    int N;
    vi bit;
    Binary_indexed_tree(int n):N(n){
        bit.resize(N+1,0);
    }
    void add(int x,int a){
        for(x;x<=N;x+=(x&-x)) bit[x]+=a;
    }
    ll sum(int x){
        ll ret=0;
        for(x;x>0;x-=(x&-x)) ret+=bit[x];
        return ret;
    }
    ll lower_bound(ll X){
        if(sum(N)<X||X<=0) return -1;
        ll ret=0,memo=1,sum=0;
        while(memo*2<=N) memo*=2;
        while(memo>0){
            if(memo+ret<=N&&sum+bit[memo+ret]<X){
                sum+=bit[memo+ret];
                ret+=memo;
            }
            memo/=2;
        }
        return ret+1;
    }
};
struct Union_Find{
    ll N;
    vi par;
    vi siz;
    Union_Find(int n):N(n){
        par.resize(N);
        siz.resize(N,1);
        rep(i,0,N) par[i]=i;
    }
    ll root(ll X){
        if(par[X]==X) return X;
        return par[X]=root(par[X]);
    }
    bool same(ll X,ll Y){
        return root(X)==root(Y);
    }
    void unite(ll X,ll Y){
        X=root(X);
        Y=root(Y);
        if(X==Y) return;
        par[X]=Y;
        siz[Y]+=siz[X];
        siz[X]=0;
    }
    ll size(ll X){
        return siz[root(X)];
    }
};
ll modpow(ll X,ll Y,ll mod){
    ll sum=X,cnt=1;
    vi A;
    while(cnt<=Y){
        A.pb(sum);
        sum*=sum;
        sum%=mod;
        cnt*=2;
    }
    int M=A.size();
    ll ret=1;
    REP(i,1,M){
        if(Y>=(1ll<<M-i)){
            Y-=(1ll<<M-i);
            ret*=A[M-i];
            ret%=mod;
        }
    }
    return ret;
}
ll fac[MAX],finv[MAX],inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n,ll r){
    if(n<r||n<0||r<0) return 0;
    return fac[n]*finv[r]%MOD*finv[n-r]%MOD;
}
signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll A,B,C,D; cin>>A>>B>>C>>D;
    ll X=A*60+B,Y=C*60+D;
    ll K; cin>>K;
    cout<<Y-X-K<<endl;
}


Measured memory_bytes: 3656
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

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

int main() {
    int x, y, z;
    x = read(); y = read(); z = read();
    cout << z << " " << x << " " << y << endl;
    return 0;
}

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

const int N = 10;

char F[N][N];

int main() {
    int h, w;
    scanf("%d %d", &h, &w);
    for (int i = 0; i < h; i++) {
        scanf("%s", F[i]);
    }
    assert(F[0][0] == '#');
    int y = 0, x = 0;

    while (true) {
        F[y][x] = '.';
        if (y + 1 < h && F[y + 1][x] == '#') {
            y++;
        } else if (x + 1 < w && F[y][x + 1] == '#') {
            x++;
        } else {
            break;
        }
    }
    bool any = false;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            any |= F[i][j] == '#';
        }
    }
    puts(any ? "Impossible" : "Possible");
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;

class D
{
	static void Main()
	{
		var M = 1000000007;
		var r64 = Enumerable.Range(0, 64);
		var s3s = new List<string>();
		Make3s(s3s, "");
		var id = r64.ToDictionary(i => s3s[i]);
		var bl = new HashSet<string> { "AGC", "GAC", "ACG", "AGGC", "ATGC", "AGTC" };

		var n = int.Parse(Console.ReadLine());

		var dp = new long[n + 1, 64];
		dp[0, 63] = 1;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < 64; j++)
				foreach (var c in "ACGT")
				{
					var s4 = s3s[j] + c;
					var s3 = s4.Substring(1);
					if (bl.Contains(s3) || bl.Contains(s4)) continue;
					dp[i + 1, id[s3]] += dp[i, j];
					dp[i + 1, id[s3]] %= M;
				}
		Console.WriteLine(r64.Sum(i => dp[n, i]) % M);
	}

	static void Make3s(List<string> l, string s)
	{
		if (s.Length == 3) l.Add(s);
		else foreach (var c in "ACGT") Make3s(l, s + c);
	}
}


Measured memory_bytes: 15584
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;


int findSumOfDigits(int n)
{
	int sum = 0;
	while (n > 0)
	{
		sum += n % 10;
		n /= 10;
	}

	return sum;
}

int main()
{
	int N,A,B;
	cin >>N;
	int X = findSumOfDigits(N);

	if (N % X == 0)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

}


Measured memory_bytes: 256
N, q = gets.split.map(&:to_i)
S = "<#{gets.chomp}>"
l,r = [1, N]

def move(pos, op)
  label = op[0]
  dir = op[2]
  S[pos] != label ? pos : (dir == 'L' ? pos - 1 : pos + 1)
end
$<.reverse_each do |op|
  l = (l - 1 .. l + 1).find do |pos| 
    move(pos, op) >= l
  end
  r = (r - 1 .. r + 1).reverse_each.find do |pos| 
    move(pos, op) <= r
  end
  break if r < l
end

puts r < l ? 0 : r - l + 1


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

int main() {
    int L, R;
    cin >> L >> R;
    if ((R-L) >= 2019) {
        int ans = 0;
        cout << ans << "\n";
        return 0;
    } else {
        int ans = 10000;
        for (int i = L; i <= R - 1; ++i) {
            for (int j = i + 1; j <= R; ++j) {
                int res = ((i % 2019) * (j % 2019)) % 2019;
                if (res < ans) {
                    ans = res;
                    if (ans == 0) {
                        cout << ans << "\n";
                        return 0;
                    }
                }
            }
        }
        cout << ans << "\n";
        return 0;
    }
}


Measured memory_bytes: 256
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"3
3 1 2"# => r#"11"#,

r#"7
5 0 7 8 3 3 2"# => r#"312"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: usize,
        d: [u64; n],
    }
    let mut ans = 0;

    for i in 0..n {
        for j in i + 1..n {
            ans +=  d[i] * d[j];
        }
    }
    ans.to_string()
}

Measured memory_bytes: 4352
N = int(input())
a = []
for i in range(N):
    a.append(int(input())-1)
index = 0
#indexが1になったら（２ボタンを押したら）おしまい
flag = False 
count = 0
for i in range(N):
    count+=1
    index=a[index]
    if(index == 1):
        flag = True
        break
if(flag):
    print(count)
else:
    print(-1)
    

Measured memory_bytes: 7084
#include<stdio.h>
#include<string.h>
int main(){
    char a[20],b[20],c[20];
    scanf("%s",a);
    scanf("%s",b);
    scanf("%s",c);

    if(a[strlen(a)-1]==b[0] && b[strlen(b)-1]==c[0])
        printf("YES\n");
    else
        printf("NO\n");}


Measured memory_bytes: 1664
Imports System

Module Program
    Sub Main(args As String())
        Dim tmpA As String() = Split(Console.ReadLine(), " ")
        Dim tmpB As String() = Split(Console.ReadLine(), " ")

        Dim H As Long = CLng(tmpA(0))
        Dim N As Long = CLng(tmpA(1))

        Dim attack As Long = 0
        Dim i As Integer = 1
        For i = 1 To N
            attack += CLng(tmpB(i - 1))
        Next

        If H <= attack Then
            Console.WriteLine("Yes")
        Else
            Console.WriteLine("No")
        End If

    End Sub
End Module


Measured memory_bytes: 20704
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

	int res = 0;
	string s; cin >> s;
	string c = "CODEFESTIVAL2016";
	for (int i = 0; i < (int)c.length(); i++) {
		if (s[i] != c[i]) res++;
	}
	cout << res << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();

        if (a>b){
            if(a<c) {System.out.println(b + " " + a + " " + c);
            } else {
                if (b>c) {System.out.println(c + " " + b + " " + a);
                } else { System.out.println(b + " " + c  + " " + a);
                }
            }
        }
        else {
            if (c>b) { System.out.println(a + " " + b + " " + c);
            } else {
                if (a>c) { System.out.println(c + " " + a  + " " + b);
                } else { System.out.println(a + " " + c + " " + b);
                }
            }
        }
    }
}


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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, x = 0, i = 0;
    cin >> n;
    while (x < n)
    {
        x++;
        i = x;
        if (x % 3 == 0)
        {
            cout << " " << x;
        }
        else
        {
            while (i)
            {
                if (i % 10 == 3)
                {
                    cout << " " << x;
                    break;
                }
                i /= 10;
            }
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3204
#include<iostream>
int n,q;
int A[20],T[200];
bool dfs(int i,int tgt){
	if(i==n)return tgt==0;
	else if(dfs(i+1,tgt))return true;
	else if(dfs(i+1,tgt-A[i]))return true;
}
int main(){
	std::cin>>n;
	for(int k=0;k<n;k++){
		std::cin>>A[k];
	}
	std::cin>>q;
	for(int j=0;j<q;j++){
		std::cin>>T[j];
		if(dfs(0,T[j])){
			std::cout<<"yes\n";
		}
		else std::cout<<"no\n"; 
	}
	return 0;
}

Measured memory_bytes: 3072
/*
  AOJ 2209
  Title:UTF-8
  @kankichi573
  2014/3/8 TLE
*/
#include <stdio.h>

int n;
char dat[1000][8];
int  memo[1001];
int  flag[1001];

int count_c(char dat[],char c,int from,int to)
{
  int i,ret;

  ret=0;
  for(i=from;i<=to;i++)
    ret += (dat[i]==c)?1:0;
  return(ret);
}
int match_1byte(char dat[])
{
  int ret;

  if(dat[0]=='1')
    return(0);
  ret=1<<count_c(&dat[0],'x',1,7);
  return(ret);
}
my_match(char c1,char c2)
{
  return((c1==c2)||(c1=='x'));
}
mystrncmp(char s1[],char s2[],int n)
{
  int i;
  for(i=0;i<n;i++)
    if(!my_match(s1[i],s2[i]))
      return(0);
  return(-1);
}
int match_2byte(char dat[])
{
  int ret,ret0,retx,ret1,ret2,ret3;

  if(mystrncmp(&dat[0],"110",3) && mystrncmp(&dat[8],"10",2))
    {
      retx=count_c(&dat[0],'x',3,6);
      if(ret1=count_c(&dat[0],'1',3,6))
	ret0=(1<<retx);
      else
	ret0=(1<<retx)-1;

      ret2=count_c(&dat[0],'x',7,7);
      ret3=count_c(&dat[8],'x',2,7);
      ret=ret0*(1<<(ret2+ret3));
      return(ret);
    }
  else
    return(0);
}
int match_3byte(char dat[])
{
  int ret,ret0,retx,ret1,ret2;

  if(mystrncmp(&dat[0],"1110",4) && mystrncmp(&dat[8],"10",2) && 
     mystrncmp(&dat[16],"10",2))
    {
      retx=count_c(&dat[0],'x',4,7)+count_c(&dat[8],'x',2,2);
      if(ret1=count_c(&dat[0],'1',4,7)+count_c(&dat[8],'1',2,2))
	ret0=(1<<retx);
      else
	ret0=(1<<retx)-1;

      ret2 =  count_c(&dat[8],'x',3,7);
      ret2 += count_c(&dat[16],'x',2,7);
      ret=ret0*(1<<ret2);
      return(ret);
    }
  else
    return(0);
}
int match_4byte(char dat[])
{  int ret,ret0,retx,ret1,ret2;

  if(mystrncmp(&dat[0],"11110",5) && mystrncmp(&dat[8],"10",2) && 
     mystrncmp(&dat[16],"10",2)   && mystrncmp(&dat[24],"10",2))
    {
      retx=count_c(&dat[0],'x',5,7)+count_c(&dat[8],'x',2,3);
      if(ret1=count_c(&dat[0],'1',5,7)+count_c(&dat[8],'1',2,3))
	ret0=(1<<retx);
      else
	ret0=(1<<retx)-1;

      ret2 =  count_c(&dat[8] ,'x',4,7);
      ret2 += count_c(&dat[16],'x',2,7);
      ret2 += count_c(&dat[24],'x',2,7);
      ret=ret0*(1<<ret2);
      return(ret);
    }
  else
    return(0);
}


int match(int p)
{
  unsigned long long ret,ret1;
  
  if(flag[p])
    return(memo[p]);

  if(p==n)
    return(1);
  ret1  = match_1byte(&dat[p][0]);

  if(ret1)
      ret=ret1*match(p+1);
  else
    ret=0;

  if(n-p>=2)
  {
    ret1 = match_2byte(&dat[p][0]); 
    if(ret1)
      ret += ret1*match(p+2); 
  }
  if(n-p>=3)
    {
       ret1 = match_3byte(&dat[p][0]); 
      if(ret1)
	ret += ret1*match(p+3); 
    }
  if(n-p>=4)
    {
       ret1 = match_4byte(&dat[p][0]); 
      if(ret1)
	ret += ret1*match(p+4); 
    }
  ret %= 1000000;
  memo[p]=ret;
  flag[p]=1;
  return(ret);
}

void init_memo ()
{
  int i;
  for(i=0;i<1000;i++)
    flag[i]=0;
}

main()
{
  int i;

  while(scanf("%d" ,&n) && n)
    {
      init_memo();

      for(i=0;i<n;i++)
	scanf("%s",&dat[i][0]);
  
      printf("%d\n",match(0));
    }
  return(0);
}

Measured memory_bytes: 680
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
using namespace std;
typedef long long ll;
typedef pair<int, int>pii;
const int maxn=3e5+100;
int n, pref[maxn], suf[maxn];
string s;
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin>>n>>s;
    for(int i=0; i<n; i++)
    pref[i+1]=pref[i]+(s[i]=='W');
    for(int i=n-1; i>=0; i--)
    suf[i+1]=suf[i+2]+(s[i]=='E');
    int ans=INT_MAX;
    for(int i=1; i<=n; i++)
    ans=min(ans, pref[i-1]+suf[i+1]);
    cout<<ans<<"\n";
    return 0;
}

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

using namespace std;

#define long long long
#define INF ((long) 1e18)
#define MOD ((long) 1e9 + 7)
#define mll map<long, long>
#define pll pair<long, long>
#define pb push_back
#define FOR(i, a, b) \
  for (long i = (a); i < (long) (b); i++)
#define PRINTV(v) \
  FOR (_i, 0, v.size()) \
    cout << v[_i] << " "; \
  cout << "\n";

long a[1000][1000], d[1000][1000];

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

  long n, c;
  cin >> n >> c;

  FOR (i, 1, c+1) {
    FOR (j, 1, c+1) {
      cin >> d[i][j];
    }
  }
  FOR (i, 0, n) {
    FOR (j, 0, n) {
      cin >> a[i][j];
    }
  }
  map<long, set<pll>> f;
  FOR (k, 0, 3) {
    FOR (cor, 1, c+1) {
      long aux = 0;
      FOR (i, 0, n) {
        FOR (j, 0, n) {
          if ((i + j) % 3 == k) {
            aux += d[a[i][j]][cor];
          }
        }
      }
      f[k].insert({aux, cor});
    }
  }
  long minimo = INF;
  for (auto &x : f[0]) {
    for (auto &y : f[1]) {
      for (auto &z : f[2]) {
        if (x.second == y.second) continue;
        if (x.second == z.second) continue;
        if (z.second == y.second) continue;
        long total = x.first + y.first + z.first;
        minimo = min(minimo, total);
      }
    }
  }
  printf("%lld\n", minimo);
}


Measured memory_bytes: 6528
import java.util.*;

class Main {

    private static int A, B, C, D, E, F;
    private static int ansSugarAmount, ansWaterAmount;
    private static double maxDensity = 0.0;
    private static int[][] cache = new int[F][F];

    private static void dfs(int sugarAmount, int waterAmount) {
        if (sugarAmount + waterAmount > F || cache[sugarAmount][waterAmount] == 1) {
            return;
        }

        double density = densityPercent(sugarAmount, waterAmount);
        double densityLimit = ((double) E / ((double)E + 100.0)) * 100.0;
        if (maxDensity <= density && density <= densityLimit) {
            maxDensity = density;
            ansSugarAmount = sugarAmount;
            ansWaterAmount = waterAmount;
        }

        cache[sugarAmount][waterAmount] = 1;

        // add A
        dfs(sugarAmount, waterAmount + A);
        // add B
        dfs(sugarAmount, waterAmount + B);
        // add C
        dfs(sugarAmount + C, waterAmount);
        // add D
        dfs(sugarAmount + D, waterAmount);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        A = sc.nextInt() * 100; // 水
        B = sc.nextInt() * 100; // 水
        C = sc.nextInt(); // 砂糖
        D = sc.nextInt(); // 砂糖
        E = sc.nextInt(); //100g煮溶ける
        F = sc.nextInt(); //ビーカーの最大容量

        cache = new int[F+1][F+1];

        dfs(0, 0);
        System.out.println((ansSugarAmount + ansWaterAmount) + " " + ansSugarAmount);
    }

    private static double densityPercent(int sugarAmount, int waterAmount) {
        double sum = (double)sugarAmount + (double)waterAmount;
        double sugar = (double)sugarAmount;
        return ((sugar / sum) * 100.0);
    }
}

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

using ll = long long;

#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll N, std::vector<std::string> S) {
  int cnt_ac = 0;
  int cnt_wa = 0;
  int cnt_tle = 0;
  int cnt_re = 0;

  rep(i, N) {
    if (S.at(i) == "AC") {
      cnt_ac++;
    } else if (S.at(i) == "WA") {
      cnt_wa++;
    } else if (S.at(i) == "TLE") {
      cnt_tle++;
    } else if (S.at(i) == "RE") {
      cnt_re++;
    }
  }

  cout << "AC x " << cnt_ac << endl;
  cout << "WA x " << cnt_wa << endl;
  cout << "TLE x " << cnt_tle << endl;
  cout << "RE x " << cnt_re << endl;
}

int main() {
  ll N;
  scanf("%lld", &N);
  std::vector<std::string> S(N);
  for (int i = 0; i < N; i++) {
    string s;
    std::cin >> s;
    S.at(i) = s;
  }
  solve(N, std::move(S));
  return 0;
}


Measured memory_bytes: 6436
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main(){
	string s;
	cin >> s;

	vector<int> n(30,-100);

	for(int i=0; i<(int)s.size(); i++){
		int si;
		si=(char)s[i]-'a';
		if(n[si]+2<i) n[si]=i;
		else if(n[si]+1==i || n[si]+2==i) {
			cout << n[si]+1 << " " << i+1 << endl;
			return 0;
		}
	}
	cout << "-1 -1" << endl;

	return 0;

}




Measured memory_bytes: 512
#include<stdio.h>
int main()
{
	int s=0,n=0,i;
	char a[3];
	scanf("%s",a);
	for(i=0;i<3;i++)
	{
		if(a[i]=='R')
		s++;
		else
		{
			if(s>n)
			n=s;
			s=0;
		}
	}
	if(s>n)
	n=s;
	printf("%d",n); 
}


Measured memory_bytes: 1696