akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int c[][] = new int[3][3];
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                    c[i][j] = Integer.parseInt(in.next());
                }
            }
            int rows[][] = new int[3][2];
            int cols[][] = new int[3][2];

            for (int i = 0; i < 3; i++) {
                rows[i][0] = c[i][0] - c[i][1];
                rows[i][1] = c[i][1] - c[i][2];
            }
            for (int i = 0; i < 3; i++) {
                cols[i][0] = c[0][i] - c[1][i];
                cols[i][1] = c[1][i] - c[2][i];
            }

            boolean ok = false;

            if (rows[0][0] == rows[1][0] && rows[1][0] == rows[2][0] &&
                    rows[0][1] == rows[1][1] && rows[1][1] == rows[2][1] &&
                    cols[0][0] == cols[1][0] && cols[1][0] == cols[2][0] &&
                    cols[0][1] == cols[1][1] && cols[1][1] == cols[2][1]) {
                ok = true;
            }
            out.println(ok ? "Yes" : "No");

        }

    }
}



Measured memory_bytes: 21844
list= input().split(" ")
X=int(list[0])
Y=int(list[1])

for w in range(X+1):
    z = X-w#crane_num
    w_leg_num = int(w)*2#turtle_leg_num
    z_leg_num = int(z)*4
    total_leg_num =w_leg_num+z_leg_num
    if total_leg_num == Y:
        print("Yes")
        break
    elif w==X:
        print("No")

Measured memory_bytes: 9128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) {
  v = vector<T>(n, x);
}
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n) {
  v = vector<T>(n); for (lli i=0; i<n; ++i) cin >> v[i];
}
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n, m;
vector<pair<lli, lli>> e;
vector<lli> v;
vector<lli> len;

lli dfs(lli node) {
  if (len[node] < 0) {
    lli l = 0;
    for (lli i=v[node]; 0<=i && e[i].first==node; ++i) {
      l = max(l, 1 + dfs(e[i].second));
    }
    return len[node] = l;
  } else {
    return len[node];
  }
}

int main() {
  cin >> n >> m;
  init_n(e, m);
  for (lli i=0; i<m; ++i) cin >> e[i].first >> e[i].second;
  sort(begin(e), end(e));
  init_n(v, n+1, -1);
  for (lli i=0, prev=-1; i<m; ++i) {
    if (e[i].first != prev) {
      v[e[i].first] = i;
      prev = e[i].first;
    }
  }
  init_n(len, n+1, -1);
  lli l = 0;
  for (lli node = 0; node <= n; ++node) {
    l = max(l, dfs(node));
  }
  cout << l << endl;
  return 0;
}


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

int main(){
  int N,W,answer=0;
  cin>>N;
  vector <string> Nvec(N);
  for(int i=0; i<N; i++)
    cin>>Nvec.at(i);
  cin>>W;
  vector <string> Wvec(W);
  for(int i=0;i<W;i++){
    cin>>Wvec.at(i);
  }
  vector <int> ans(100);
  for(int i=0; i<N; i++){
    int pl=0,mi=0;
    for(int j=0; j<W; j++){
      if(Nvec.at(i)==Wvec.at(j))
        mi--;
    }
    for(int j=0; j<N; j++){
      if(Nvec.at(i)==Nvec.at(j))
        pl++;
    }
    pl+=mi;
    ans.at(i)=pl;
  }
  for(int k=0; k<99; k++){
    if(answer<ans.at(k))
      answer=ans.at(k);
  }
  cout<<answer<<endl;
}

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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  auto solve = [&]() -> ll {
    ll X; cin >> X;
    if (X < 600) return 8;
    if (X < 800) return 7;
    if (X < 1000) return 6;
    if (X < 1200) return 5;
    if (X < 1400) return 4;
    if (X < 1600) return 3;
    if (X < 1800) return 2;
    return 1;
  };
  cout << solve() << endl;

  return 0;
}



Measured memory_bytes: 3644
# AOJ 0195 What is the Most Popular Shop in Tokaich
# Python3 2018.6.20 bal4u

import sys
while True:
	tbl = {}
	for i in range(5):
		s = sum(list(map(int, input().split())))
		if i == 0 and s == 0: sys.exit()
		tbl[chr(ord('A')+i)] = s
	ans = sorted(tbl.items(), key=lambda x: x[1], reverse = True)
	print(*ans[0])



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

int main(){
  string n;
  cin >> n;
  for (int i = 0; i < n.length(); i++) {
    if(n[i]=='1'){
      n[i]='9';
    } 
    else if (n[i]=='9'){
      n[i]='1';
    }
  }
  cout << n << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

template <class T>
struct Edge
{
    int src, dest;
    T cost;

    explicit Edge(int src, int dest, T cost) : src(src), dest(dest), cost(cost) {}

    bool operator<(const Edge<T> &other) const
    {
        return cost < other.cost;
    }
};

template <class T>
using Graph = std::vector<std::vector<Edge<T>>>;
template <class T>
using Edges = std::vector<Edge<T>>;

template <class T>
Graph<T> make_graph(int V, int E, int one_indexed = 1,
                    bool digraph = 0, bool weighted = 0)
{
    Graph<T> graph(V);
    int u, v;
    T c = 1;
    for (int i = 0; i < E; ++i)
    {
        std::cin >> u >> v;
        if (weighted)
            std::cin >> c;
        graph[u - one_indexed].emplace_back(u - one_indexed, v - one_indexed, c);
        if (!digraph)
            graph[v - one_indexed].emplace_back(v - one_indexed, u - one_indexed, c);
    }
    return graph;
}

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int n, m;
    cin >> n >> m;
    auto g = make_graph<int>(n, m);
    vector<bool> visited(n);
    ll ans = 0;
    REP(i, 0, n)
    {
        if (visited[i])
            continue;
        vector<int> stack = {i};
        visited[i] = 1;
        ans++;

        while (!stack.empty())
        {
            auto v = stack.back();
            stack.pop_back();
            for (auto &e : g[v])
                if (!visited[e.dest])
                {
                    visited[e.dest] = 1;
                    stack.emplace_back(e.dest);
                }
        }
    }

    cout << ans - 1 << endl;
}

Measured memory_bytes: 9940
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <set>

using namespace std;

int main(int argc, char* argv[]) {
	set<string> s;
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		string x;
		cin >> x;
		s.emplace(x);
	}
	cout << s.size() << endl;
	return 0;
}


Measured memory_bytes: 19180
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<long double, long double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int MOD = 1000000007;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main(){
    int n, m; cin >> n >> m;
    vector<vector<int>> ar(n, vector<int>(n,10000));
    vector<P> eg(m);
    int ans = 0;
    rep(i,n){
        ar[i][i] = 0;
    }
    rep(i,m){
        int a, b; cin >> a >> b;
        a--; b--;
        ar[a][b] = 1;
        ar[b][a] = 1;
        eg[i].first = a;
        eg[i].second = b;
    }
    rep(i,m){
        bool t = true;
        auto cost = ar;
        cost[eg[i].first][eg[i].second] = 10000;
        cost[eg[i].second][eg[i].first] = 10000;
        rep(k,n){
            rep(l,n){
                rep(j,n){
                    cost[l][j] = min(cost[l][j], cost[l][k] + cost[k][j]);
                }
            }
        }
        //printvvec(cost);
        rep(j,n-1){
            repp(k,n,j+1){
                if (cost[j][k] >= 100){
                    t = false;
                    break;
                }
            }
            if (!t) break;
        }
        if (!t) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
#define endl '\n'
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//二項係数 mod p
ll modinv(ll n, ll &p) {
  ll a = p, u = 1, v = 0;
  while (a) {
    ll t = n / a;
    n -= t * a;
    swap(n, a);
    u -= t * v;
    swap(u, v);
  }
  u %= p;
  if (u < 0) u += p;
  return u;
}

int main() {
  ll n, k, p = 1e9 + 7;
  cin >> n >> k;

  vll a(n);
  for (ll i = 0; i < n; i++) cin >> a[i];
  sort(all(a));

  ll ans = 0;
  ll subans = 1;
  ans += a[k - 1] - a[n - k];
  while (ans < 0) ans += p;
  ans %= p;
  for (ll i = k; i < n; i++) {
    subans *= i;
    subans %= p;
    subans *= modinv(i - k + 1, p);
    subans %= p;
    ll x = a[i] - a[n - 1 - i];
    while (x < 0) x += p;
    x %= p;
    x *= subans;
    x %= p;
    ans += x;
    ans %= p;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
h,w=map(int,input().split())
S= [[j for j in input()] for i in range(h)]
for i in range(h):
  for j in range(w):
    a=0
    if S[i][j]==".":
      for p in range(-1,2):
        for k in range(-1,2):
          if 0<=i+p<h and 0<=j+k<w:
            if S[i+p][j+k]=="#":
              a+=1
      S[i][j]=str(a)

for i in S:
  print("".join(i))


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

typedef long long ll;
#define loop(x) for(int i = 0;i<(x);i++)

int c(int x){
    if(x==1){
        return 0;
    }
    return (x*(x-1))/2;
}
int main(){
    int n,m;
    cin>>n>>m;
    cout<<(c(n)+c(m));
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

dp = [[0]*(N+1) for _ in range(N+1)]

for n in range(1, N+1):
    for l in range(0, N-n+1):
        r = l + n
        if (N-n)%2==0:
            dp[l][r] = max(dp[l+1][r] + A[l], dp[l][r-1] + A[r-1])
        else:
            dp[l][r] = min(dp[l+1][r] - A[l], dp[l][r-1] - A[r-1])
print(dp[0][N])

Measured memory_bytes: 144720
N = int(input())
a = 'abcdefghijklmn'
ans = []


def rec(d, now, kind):
    if d == N:
        print(now)
        return
    for i in range(kind):
        rec(d + 1, now + a[i], kind)
    rec(d + 1, now + a[kind], kind + 1)

rec(1, 'a', 1)


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

const int inf = INT_MAX, mx=100005;
vector<int> v[mx];
int in[mx], max_len,height[mx];

void dfs(int x,int prnt,int level)
{
    if(height[x]!=-1)
    {
        max_len = max(max_len,level+height[x]);
        return ;
    }
    else
    {
        max_len = max(max_len,level);
    }
    for(int i=0;i<v[x].size();i++)
    {
        if(v[x][i]!=prnt)
        {
            dfs(v[x][i],x,level+1);
            height[x] = max(height[x],height[v[x][i]]+1);
        }
    }
    if(v[x].size()==0) height[x] = 0;
}
 
main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
        in[y]++;
    }
    int ans = 0;
    memset(height,-1,sizeof height);
    for(int i=1;i<=n;i++)
    {
        if(in[i]==0)
        {
            max_len = 0;
            dfs(i,-1,0);
            ans = max(max_len,ans);
        }
    }
    cout<<ans;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
#define db(x) cout << #x << " = " << (x) << "\n";
using ll = long long;
using ld = long double;
ll nodes, edges;
ll lmt = 100'001;
vector<ll> dist(lmt), visited(lmt), in_degree(lmt);
vector<vector<ll>> v(lmt);
void topological_sort()
{
    vector<bool> visited(nodes + 1, false);
    queue<ll> q;
    for (ll i = 1; i <= nodes; i++)
    {
        if (!in_degree[i])
        {
            q.push(i);
            visited[i] = true;
        }
    }
    while (!q.empty())
    {
        ll vertex = q.front();
        q.pop();
        for (ll i : v[vertex])
        {
            dist[i] = max(dist[i], dist[vertex] + 1);
            if (!visited[i])
            {
                in_degree[i]--;
                if (!in_degree[i])
                {
                    q.push(i);
                    visited[i] = true;
                }
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cin >> nodes >> edges;
    ll from, to;
    for (ll i = 0; i < edges; i++)
    {
        cin >> from >> to;
        v[from].push_back(to);
        ++in_degree[to];
    }
    topological_sort();
    cout << *max_element(dist.begin(), dist.begin() + nodes + 1);
    return 0;
}


Measured memory_bytes: 8064
import java.util.Scanner;

public class Main {

    static int N;
    static int W;
    // @formatter:off
    static int[][] NEIGHBOR_GRID =
        { { -1, -1 }, {  0, -1 },  {  1, -1 },
          { -1,  0 },              {  1,  0 },
          { -1,  1 }, {  0,  1 },  {  1,  1 } };
    // @formatter:on


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

        String[] NW = sc.nextLine().split(" ");
        N = Integer.parseInt(NW[0]);
        W = Integer.parseInt(NW[1]);

        int[][] out = new int[N][W];
        String[][] ans = new String[N][W];

        // 数値をいったん埋める
        for (int i = 0; i < N; i++) {
            char[] row = sc.nextLine().toCharArray();
            for (int j = 0; j < W; j++) {

                if (row[j] == '#') {
                    fill8NeighborhoodsGrid(out, i, j);
                    ans[i][j] = "#";
                }
            }
        }

        // 埋めた場所を文字列化する
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < W; j++) {

                if (ans[i][j] == null) {
                    ans[i][j] = String.valueOf(out[i][j]);
                }
            }
        }

        // 出力
        for (String[] row : ans) {
            for (String column : row) {
                System.out.print(column);
            }
            System.out.println();
        }
    }

    private static void fill8NeighborhoodsGrid(int[][] out, int i, int j) {
        for (int[] site : NEIGHBOR_GRID) {
            int x = site[0];
            int y = site[1];

            // 8近傍を埋める
            fill(out, i + x, j + y);
        }
    }

    private static void fill(int[][] out, int i, int j) {
        if (i < 0 || j < 0 || N <= i || W <= j) {
            // 枠外の場合は終わり
            return;
        }

        out[i][j]++;
    }
}



Measured memory_bytes: 22228
#include<bits/stdc++.h>
#define rep(i,a,b) for(register int i=a;i<=b;++i)
#define rpd(i,a,b) for(register int i=a;i>=b;--i)
#define rep1(i,x) for(register int i=head[x];i;i=nxt[i])
typedef long long ll;
const int N=1e5+5;
using namespace std;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,L,now;int a[N];
int main(){
	n=read();L=read();rep(i,1,n)a[i]=read();
	rep(i,1,n-1)if(a[i]+a[i+1]>=L){now=i;break;}
	if(!now)return puts("Impossible"),0;puts("Possible");
	rpd(i,n-1,now+1)printf("%d\n",i);rep(i,1,now)printf("%d\n",i);
	return 0;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

typedef int64_t ll;
using namespace std;

int main() {
    // freopen("output.txt", "w", stdout);

    string s;
    cin >> s;
    int num = 0;
    for (auto c: s) {
        num += c - '0';
    }
    if (num%9 == 0)
        cout << "Yes";
    else
        cout << "No";
    cout << endl;
    return 0;
}

Measured memory_bytes: 3700
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

def solve():
    n, k = list(map(int, input().strip().split()))
    a = list(map(int, input().strip().split()))

    m = a[0]
    maxx = a[0]
    for i in range(1, n):
        m = gcd(m, a[i])
        if a[i] > maxx:
            maxx = a[i]

    if k % m == 0 and k <= maxx:
        return "POSSIBLE"
    else:
        return "IMPOSSIBLE"

print(solve())

Measured memory_bytes: 14224
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
char an[100100];
char bn[100100];
int da[100100];
int db[100100];
int main(){
    scanf("%s%s",&an,&bn);
    int len=strlen(an);
    for(int i=0;i<len ;i++){
        if(an[i]=='A') da[i+1]=(da[i]+1);
        else da[i+1]=(da[i]+2);
    }
    len=strlen(bn);
    for(int i=0;i<len ;i++){
        if(bn[i]=='A') db[i+1]=(db[i]+1);
        else db[i+1]=(db[i]+2);
    }
    int q;
    scanf("%d",&q);
    for(int i=1;i<=q;i++){
        int a1,a2,b1,b2;
        scanf("%d%d%d%d",&a1,&a2,&b1,&b2);
        int ansa=da[a2]-da[a1-1];
        ansa%=3;
        int ansb=db[b2]-db[b1-1];
        ansb%=3;
        if(ansa==ansb)printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 1408
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;

ll bit[2200000];
ll n;

void set_val(ll i,ll x){
    i++;
    while(i<=n){
        bit[i]=max(bit[i],x);
        i += i & -i;
    }
    return;
}

ll max_val(ll i){
    i++;
    ll res=0;
    while(i>0){
        res=max(res,bit[i]);
        i -= i & -i;
    }
    return res;
}

int main()
{
    
    cin >> n;
    vector<pll> h(n);
    vector<ll> a(n);
    rep(i,n){
        ll len;
        cin >> len;
        h[i].fi=len-1;
        h[i].se=i;
    }
    sort(h.begin(),h.end());
    vector<ll> dp(n);
    rep(i,n){
        cin >> a[i];
    }
    for(auto x:h){
        dp[x.fi]=max_val(x.se-1)+a[x.se];
        set_val(x.se,dp[x.fi]);
    }
    ll ans=0;
    rep(i,n){
        ans=max(ans,dp[i]);
    }
    cout  << ans << endl;
    return 0;
} 

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,ll>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 2*1e5;
const int mod = 1e9+7;

int main() {
    string a, b, c; cin >> a >> b >> c;
    if (a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) {
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    string S;
    cin >> S;
    
    reverse(S.begin(), S.end());
    int cnt = 0;
    while (true) {
        if (cnt == S.size()) {
            cout << "YES" << endl;
            return 0;
        }
        if (cnt > S.size() - 5) {
            cout << "NO" << endl;
            return 0;
        }
        if (S.substr(cnt, 5) == "maerd" || S.substr(cnt, 5) == "esare") {
            cnt += 5;
            continue;
        }
        if (cnt > S.size() - 6) {
            cout << "NO" << endl;
            return 0;
        }
        if (S.substr(cnt, 6) == "resare") {
            cnt += 6;
            continue;
        }
        if (cnt > S.size() - 7) {
            cout << "NO" << endl;
            return 0;
        }
        if (S.substr(cnt, 7) == "remaerd") {
            cnt += 7;
            continue;
        }
        cout << "NO" << endl;
        return 0;
    }
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;
const int MOD = 1e9 + 7;

int main(){
  int N;
  cin >> N;
  vector<int> T(N), A(N);
  REP(i,N) cin >> T[i];
  REP(i,N) cin >> A[i];

  vector<int> lb(N, 1), ub(N, INF);
  lb[0] = ub[0] = T[0];
  for(int i = 1; i < N; ++i) {
    if(T[i] > T[i - 1]) {
      lb[i] = ub[i] = T[i];
    }else{
      ub[i] = ub[i - 1];
    }
  }

  ll res = 1LL;
  if(!(A[N - 1] >= lb[N - 1] && A[N - 1] <= ub[N - 1])) res = 0LL;
  lb[N - 1] = ub[N - 1] = A[N - 1];
  for(int i = N - 2; i >= 0; --i) {
    if(A[i] > A[i + 1]) {
      if(!(A[i] >= lb[i] && A[i] <= ub[i])) res = 0LL;
      lb[i] = ub[i] = A[i];
    }else{
      if(A[i] < lb[i]) res = 0LL;
      ub[i] = min(ub[i], A[i]);
    }
  }
  REP(i,N) {
    ll tmp = ub[i] - lb[i] + 1;
    res = (res * tmp) % MOD;
  }
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 1792
class Stack
  def initialize
    @arr = []
    @top = 0
  end

  def push(x)
    @arr[@top] = x
    @top = @top + 1
  end

  def pop
    x = @arr[@top - 1]
    @top = @top - 1
    x
  end
end

def poland(arr)
  stack = Stack.new
  for s in arr
    if s == '+' then
      b = stack.pop
      a = stack.pop
      c = a + b
      stack.push(c)
    elsif s == '-' then
      b = stack.pop
      a = stack.pop
      c = a - b
      stack.push(c)
    elsif s == '*' then
      b = stack.pop
      a = stack.pop
      c = a * b
      stack.push(c)
    else
      stack.push(s.to_i)
    end
  end
  puts stack.pop
end

arr = STDIN.gets.split(' ')
poland(arr)

Measured memory_bytes: 8720
#include <cstdio>
#include <vector>
#define rep(i,l,n) for(int i = l; i < (n); i++)
using namespace std;
using ll = long long;
bool binary_search(vector<int> a, int t) {
    int left = 0,right = a.size();
    while(left < right) {
        int m = (right+left)/2;
        if(a.at(m) == t) return true;
        else if(a.at(m) < t) left = m+1;
        else right = m;
    }
    return false;
}
int main() {
    int n,q,t,ans = 0;
    scanf("%d",&n);
    vector<int> s(n);
    rep(i,0,n) scanf("%d",&s[i]);
    scanf("%d",&q);
    rep(i,0,q) {
        scanf("%d",&t);
        if(binary_search(s,t)) ans++;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int exist[50000];
    for(int i = 0; i < 50000; i++)exist[i] = i + 1;
    int N;
    cin >> N;
    for(int i = 0; i < 50000; i++){
        if((int)((float)exist[i]*1.08) == N){
            cout << exist[i];
            return 0;
        }
    }
    cout << ":(";
    return 0;
}



Measured memory_bytes: 384
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

N, M, A, B = map(int, raw_input().split())

ans = [['.'] * M for i in range(N)]

if M % 2 == 1:
    for i in range(0, N - 1, 2):
        if B > 0:
            B -= 1
            ans[i][M - 1], ans[i + 1][M - 1] = "^", "v"

if N % 2 == 1:
    for i in range(M - 2, -1, -2):
        if A > 0:
            A -= 1
            ans[N - 1][i], ans[N - 1][i + 1] = "<", ">"

flag = False
if 2 * (A + B) == (N / 2) * (M / 2) * 4 and (N % 2) == (M % 2) == (A % 2) == 1:
    flag = True
    A += 1

for i in range(N - 2 - N % 2, -1, -2):
    for j in range(0, M - 1, 2):
        if A == 1:
            A -= 2
            ans[i][j], ans[i + 1][j], ans[i][j + 1], ans[i + 1][j + 1] = "<", ".", ">", "."
        elif A >= 2:
            A -= 2
            ans[i][j], ans[i + 1][j], ans[i][j + 1], ans[i + 1][j + 1] = "<", "<", ">", ">"
        elif B == 1:
            B -= 2
            ans[i][j], ans[i + 1][j], ans[i][j + 1], ans[i + 1][j + 1] = "^", "v", ".", "."
        elif B >= 2:
            B -= 2
            ans[i][j], ans[i + 1][j], ans[i][j + 1], ans[i + 1][j + 1] = "^", "v", "^", "v"

if flag:
    ans[N - 2][0], ans[N - 2][1], ans[N - 1][0] = "^", ".", "v"
    B = 0

if A > 0 or B > 0:
    print "NO"
    exit()

print "YES"
for i in range(N):
    print "".join(ans[i])


Measured memory_bytes: 11768
n = gets.chomp
x = gets.chomp.split.map(&:to_f)
y = gets.chomp.split.map(&:to_f)

xy = x.zip(y)

(1..3).each do |d|
  puts xy.inject(0){|total, v| total += (v[0] - v[1]).abs ** d } ** (1/d.to_f)
end

puts xy.map{|v| (v[0] - v[1]).abs }.max

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

using namespace std;

int main()
{
	string w;
	cin >> w;
	map<char, int> m;
	for (int i = 0; i < w.size(); i++)
		m[w[i]]++;
	bool ok = true;
	for (int i = 0; i < 26; i++)
		if (m['a' + i] % 2 != 0)
			ok = false;
	if (ok)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


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

//#define USING_LONG_LONG
#ifdef USING_LONG_LONG
    #define int long long
    const int INF=1001001001001001001ll;
#else
    const int INF=1001001001;
#endif

#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREP(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define clr(a) memset((a),0,sizeof(a))
#define CLR(a) memset((a),-1,sizeof(a))
#define each(i,v) for(__typeof((v).begin()) i=(v).begin();i!=(v).end();i++)
#define minv(a,b) (a)=min((a),(b))
#define maxv(a,b) (a)=max((a),(b))
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<string>vs;
typedef pair<int,int>pii;
#define fi first
#define se second

const int SQ=400;
int N,Q;
struct latte{
    vi v;
    int s;
    latte(){v.clear();s=0;}
};

vector<latte>li;

signed main(){
    scanf("%d%d",&N,&Q);
    latte now;
    rep(i,N){
        now.v.pb(0);
        if(i%SQ==SQ-1){li.pb(now);now=latte();}
    }
    if(now.v.size())li.pb(now);

    while(Q--){
        int type,x,y;scanf("%d%d%d",&type,&x,&y);
        if(type==0){
            x--;
            int cur=0;
            rep(i,li.size()){
                if(cur<=x&&x<cur+li[i].v.size()){
                    li[i].v[x-cur]+=y;
                    li[i].s+=y;
                    break;
                }
                cur+=li[i].v.size();
            }
        }
        else{
            x--;y--;
            int ret=0,cur=0;
            rep(i,li.size()){
                if(x<=cur&&cur+li[i].v.size()<=y+1)ret+=li[i].s;
                else if(!(y<cur||cur+li[i].v.size()<x+1)){
                    rep(j,li[i].v.size()){
                        if(x<=cur+j&&cur+j<=y)ret+=li[i].v[j];
                    }
                }
                cur+=li[i].v.size();
            }
            printf("%d\n",ret);
        }
    }
    return 0;
}

Measured memory_bytes: 1540
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
ll MOD = 998244353;
int main() {
    ll n,k,c,ans,s;
    ans = 0;
    cin >> n >> k;
    vector<ll>v(n+1);
    vector<ll>l(k),r(k);
    rep(i, k) {
        cin >> l[i] >>r[i];
    }
    vector<ll>sum(k,0);
    vector<ll>dp(n+1,0);
    dp[1] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j<k; j++) {
            if (i - l[j] > 0) {
                sum[j] += dp[i-l[j]];
                sum[j] %= MOD;
            }
            if (i - r[j] - 1 > 0) {
                sum[j] -= dp[i - r[j] - 1];
                sum[j] %= MOD;
                if (sum[j] < 0) {
                    sum[j] += MOD;
                }
            }
            dp[i] += sum[j];
            dp[i] %= MOD;
        }
    }
    cout << dp[n] << endl;
    return 0;
}



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

int main(void)
{
	int a[4],b[4];

	while(cin >> a[0] >> a[1] >> a[2] >> a[3], !cin.eof()){
		cin >> b[0] >> b[1] >> b[2] >> b[3];

		int hit = 0, blow = 0;
		int num[10] = {};

		for(int i = 0; i < 4; i++){
			if(a[i] == b[i]){
				hit++;
				b[i] = 0;
			}
			num[a[i]]++;
		}
		for(int i = 0; i < 4; i++)
			if(num[b[i]] > 0)
				blow++;
		

		cout << hit << ' ' << blow << endl;
	}



	return 0;
}

Measured memory_bytes: 1160
#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(){
	int n, k;
	cin >> n >> k;
	map<int, int> m;
	rep(i, n){
		int in;
		cin >> in;
		m[in]++;
	}
	vector<pair<int, int>> vp;
	for(auto p : m){
		vp.push_back(make_pair(p.second, p.first));
	}
	sort(vp.begin(), vp.end(), greater<pair<int, int>>());
	int ans = 0;
	rep(i, vp.size()){
		// cerr << vp.at(i).first << " " << vp.at(i).second << endl;
		if(i >= k){
			ans += vp.at(i).first;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11768
#include "bits/stdc++.h"
using namespace std;
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}

const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

const int N=1e5+5;

int f[N];

void solve(){
	int n;
	cin>>n;
	
	rep(x,1,101){
		rep(y,1,101){
			rep(z,1,101){
				f[x*x + y*y + z*z + x*y + y*z + z*x]++;
			}
		}
	}
	
	rep(i,1,n+1){
		cout<<f[i]<<"\n";
	}
	
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SIEVE
		sieve();
	#endif
	#ifdef NCR
		init();
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


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

const double PI = acos(-1);
const double EPS = 1e-10;
int d, n, b;
int p[10], h[10];

bool check(double theta, double L) {
    double v = sqrt(L / sin(2 * theta));
    double vx = v * cos(theta);
    double vy = v * sin(theta);
    REP(i, n) {
        double x = fmod(p[i], L);
        double y = vy * x / vx - x * x / (2 * vx * vx);
        if (y + EPS < h[i]) return false;
    }
    return true;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);

    cin >> d >> n >> b;
    REP(i, n) cin >> p[i] >> h[i];
    double ans = 1e9;
    REP(k, b + 1) {
        double L = 1.0 * d / (k + 1);
        double ng = PI / 4, ok = PI / 2;
        REP(i, 100) {
            double m = (ng + ok) / 2;
            if (check(m, L)) ok = m;
            else ng = m;
        }
        ans = min(ans, sqrt(L / sin(2 * ok)));
    }
    cout << ans << endl;
}


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

int main() {
  string s;
  cin >> s;
  vector<int> v(s.size());
  for (int i = 0; i < s.size(); i++) v[i] = s[i] - '0';

  ll ans = 0;
  for (int i = 0; i < (1 << (v.size()) - 1); i++) {  // 全ての+のパターン
    ll d = 0;
    for (int j = 0; j < v.size(); j++) { // それぞれの+があるかないかを見分ける
      d += v[j];
      if (i & (1 << j) || j == v.size() - 1) {  // +があるor端に来た
        ans += d;
        d = 0;
      } else {
        d *= 10;  // 次の為に1桁ずらす
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
int main(){
 ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int t;
   t=1;
   while(t--){
   	int n;
   	cin>>n;
   	string s;
   	cin>>s;
   	
	int count=0;
   	for(int i=0;i<s.size();i++){
   		if(s[i]=='1')
   		count++;
	}
	if(count==0){
		for(int i=0;i<s.size();i++){
			cout<<"1\n";
		}
		continue;
	}
	int f=count-1;
	int g=count+1;
   	vector<int> po(s.size());
   	vector<int> sm(s.size());
   	long long int ans1=0,ans2=0;
   	long long int h=1;
   	long long int k=1;
   	for(int i=s.size()-1;i>=0;i--){
   		if(count!=1)
   		po[i]=h%f;
   		sm[i]=k%g;
   		if(count!=1)
   		ans1=((ans1%f)+((s[i]-'0')%f)*(h%f))%f;
   		ans2=((ans2%g)+((s[i]-'0')%g)*(k%g))%g;
   		if(count!=1)
   		h=((h%f)*(2%f))%f;
   		k=((k%g)*(2%g))%g;
    }
	for(int i=0;i<s.size();i++){
		long long int ans=1;
		if(s[i]=='0'){
			int j;
			j=(ans2+sm[i])%g;
			while(j>0){
				ans++;
				j=j% __builtin_popcount(j);
			}
		}
		else{
			if(count==1){
				cout<<"0\n";
				continue;
			}
			int j=ans1%f;
			j=((j-po[i])%f+f)%f;
			while(j>0){
				ans++;
				j=j% __builtin_popcount(j);
			}
		}
		cout<<ans<<"\n";
	 }
   }
   return 0;
}

Measured memory_bytes: 5188
def x(m,n):
    H = 0
    B = 0
    for i in range(4):
        if m[i] == n[i]:
            H += 1
        else:
            if m[i] in n:
                B += 1
    return(H, B)

while True:
    try:
        a = list(map(int, input().split()))
        b = list(map(int, input().split()))
        print(*x(a, b))
    except:
        break


Measured memory_bytes: 5592
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const int INF=1000100010;
int main(){
int a,b;cin>>a>>b;
int ans=0;
bool ok=false;
rep(i,1250){
    if(a<=i*0.08&&i*0.08<a+1&&b<=i*0.10&&i*0.10<b+1){
        ans=i;
        ok=true;
        break;
    }
}
if(ok)cout<<ans<<endl;
else cout<<-1<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
int main(){
    int a;
    std::vector<int> data;
    std::vector<int> d;
    for(int i=0;i<10;i++){
        std::cin>>a;
    data.push_back(a);
    }
    for(int i=0;i<10;i++){
        std::cin>>a;
    d.push_back(a);
    }
    std::sort(data.begin(),data.end(),std::greater<int>());
    std::sort(d.begin(),d.end(),std::greater<int>());
    std::cout<<data[0]+data[1]+data[2]<<" "<<d[0]+d[1]+d[2]<<std::endl;
    return 0;
}


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

using namespace std;

int main(){
  string a, b;
  cin >> a;
  cout << " ";
  cin >> b;
  
  int num = stoi(a + b);
  int i = 1;
  bool flag = false;
  while((i-1)*(i-1) < num){
    if(i*i == num){
      flag = true;
    }
    i++;
  }
  
  if(flag){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

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

int main() {
	int a, b, c;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	
	if (a-b == b-c)
	{
		printf("YES");
	}
	else
	{
		printf("NO");
	}
}

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

int main() {
    int n;
    cin>>n;
  long long  int dp[1000001]={0};
   for(int i=1;i<=1000000;i++)
   {
   	for(int j=i;j<=1000000;j+=i)
   	{
   		dp[j]++;
   	}
   }
   
   long long int sum=0;
   for(int i=1;i<=n-1;i++)
   {
   	sum+=dp[n-i];
   }
   cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 11436
n = int(input())
cnt = [0]*n
for i in range(n):
    a = int(input())
    cnt[i] += a

ans = 0
for i, j in zip(range(n-1), range(1, n)):
    x, y = cnt[i], cnt[j]
    z = x//2
    cnt[i] -= 2*z
    ans += z
    if cnt[i] == 0:
        continue
    if 0 < y:
        ans += 1
        cnt[i] -= 1
        cnt[j] -= 1
else:
    ans += cnt[-1]//2

print(ans)

Measured memory_bytes: 7028
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<n;++i)
#define FOR(i,s) for(int i=s;i>=0;--i)

using ll = long long;
using namespace std;

const ll INF = 1010101010;
const ll MOD = 1000000007;

int main() {
	ll n, m, a, b, c, ans = 0, A[10101];
	cin >> n;
	if (n < 1200) cout << "ABC" << endl;
	else if (n < 2800) cout << "ARC" << endl;
	else cout << "AGC" << endl;

	return 0;
}


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

int main(){
	int n;
	long b = 0,c = 0;
  	cin >> n;
  	vector<long> a(n);
	for(int i = 0; i<n;i++) {
		cin >> a[i];
		c += a[i];
	}
	int min = 1E9 * 3;
  	for(int i = 0; i<n-1;i++) {
		b += a[i];
		c -= a[i];
  		if(min > abs(b-c))
	  		min = abs(b-c);
	}
	cout << min << endl;
	
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define CLR(a) memset((a), 0 ,sizeof(a))

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



int main(void){
  string s, S[3];
  cin >> s; S[0] = s;
  cin >> s; S[1] = s;
  cin >> s; S[2] = s;

  map<char, int> mp;
  mp['a'] = 0;
  mp['b'] = 1;
  mp['c'] = 2;

  int now = 0, next;

  while(true){
    if(S[now].size() == 0) break;
    next = mp[S[now][0]];
    S[now] = S[now].substr(1, S[now].size());
    now = next;
  }

  if(now == 0) cout << "A" << endl;
  if(now == 1) cout << "B" << endl;
  if(now == 2) cout << "C" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int n, m, i, j, x;
  long long  sum=0;
  //配列の大きさw設定
  scanf("%d", &n);
  int a[n];
  //配列に値を入れる
  for(m = 0; m < n; m++){
        scanf("%ld", &a[m]);
        //合計の計算
        sum = sum + a[m];
  }

  //配列の並び換え（大きい順）
  for(i=0; i < n ;i++){
    for(j = i+1; j < n ;j++){
      if(a[i] > a[j]){
	x = a[i];
        a[i] = a[j];
        a[j] = x;
      }
    }
  }
  n--;
  //計算結果の出力
  printf("%d %d %lld\n", a[0], a[n], sum);
  return 0;
}

Measured memory_bytes: 636
#include <iostream>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

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

    int A[N];
    int mini = 1000000005;
    ll sum = 0;
    int cnt = 0;
    for(int i=0; i<N; i++){
        cin >> A[i];
        mini = min(abs(A[i]), mini);
        sum = sum + abs(A[i]);
        if(A[i] < 0) cnt++;
    }

    if(cnt%2 == 0) cout << sum << endl;
    else cout << sum - (ll)2*mini << endl;

    return 0;
}


Measured memory_bytes: 640
# coding: utf-8
W, H, N = map(int, input().split())
min_x, max_x = 0, W
min_y, max_y = 0, H

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if max_x <= x:
            min_x, max_x = 0, 0
        elif min_x <= x:
            min_x = x
    elif a == 2:
        if min_x >= x:
            min_x, max_x = 0, 0
        elif x <= max_x:
            max_x = x
    elif a == 3:
        if max_y <= y:
            min_y, max_y = 0, 0
        elif min_y <= y:
            min_y = y
    else:
        if y <= min_y:
            min_y, max_y = 0, 0
        elif y <= max_y:
            max_y = y
diff_x = max_x - min_x
diff_y = max_y - min_y
print(diff_x * diff_y)


Measured memory_bytes: 3064
#include <algorithm>  // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>     // bitset
#include <cctype>     // isupper, islower, isdigit, toupper, tolower
#include <cstdint>    // int64_t, int*_t
#include <cstdio>     // printf
#include <deque>      // deque
#include <iomanip>    // fixed, setprecision
#include <iostream>   // cout, endl, cin
#include <map>        // map
#include <numeric>    // accumulate
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, to_string, stoi
#include <tuple>      // tuple, make_tuple
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <utility>        // pair, make_pair
#include <vector>         // vector
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll N;
  double x, s = 0;
  string u;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> x >> u;
    if (u == "JPY") {
      s += x;
    } else {
      s += x * 380000;
    }
  }
  cout << fixed << setprecision(5) << s << endl;
}


Measured memory_bytes: 3280
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli h, w;
lli c[10][10];
lli d[10], e[10];
bool fix[10];
lli a[201][201];
int main() {
  cin >> h >> w;
  for (lli j=0; j<=9; ++j)
    for (lli i=0; i<=9; ++i)
      cin >> c[j][i];
  for (lli j=1; j<=h; ++j)
    for (lli i=1; i<=w; ++i)
      cin >> a[j][i];
  for (lli i=0; i<=9; ++i) {
    fill(begin(d), end(d), 1e9);
    fill(begin(fix), end(fix), false);
    d[i] = 0;
    for (lli l=0; l<=9; ++l) {
      lli t, m = 1e9+1;
      for (lli j=0; j<=9; ++j) {
	if (!fix[j] && d[j] < m) {
	  t = j; m = d[j];
	}
      }
      fix[t] = true;
      for (lli j=0; j<=9; ++j) {
	if (!fix[j]) d[j] = min(d[j], d[t] + c[t][j]);
      }
    }
    e[i] = d[1];
    // cout << i << ' ' << e[i] << endl;
  }
  lli ans = 0;
  for (lli j=1; j<=h; ++j)
    for (lli i=1; i<=w; ++i)
      if (a[j][i] >= 0) ans += e[a[j][i]];
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 512
L, R = map(int, input().split())

ans = 2020
for i in range(L, R + 1):
    for j in range(i + 1, R + 1):
        val = (i * j) % 2019
        ans = min(ans, val)
        if val == 0:
            print(ans)
            exit()

print(ans)


Measured memory_bytes: 64540
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<set>
#define sqr(x) (x)*(x)
using namespace std;
int n,m,i,j,q,x,y;
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>q;
	while (q--)
	{
		cin>>x>>y;
		if (n==1)
		{
			cout<<min(x,y)<<endl;
			continue;
		}
		set<int> s;
		while (x!=0)
		{
			s.insert(x);
			if (x%n>1) x+=n-(x%n);
			x/=n;
		}
		x=y;
		while (x!=0)
		{
			if (s.count(x)) break; 
			if (x%n>1) x+=n-(x%n);
			x/=n;
		}
		cout<<x<<endl;
	}
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main(){
    long int i, count1 = 0, count2 = 0;
    string s = "";
    char s1, s2;
    cin >> s;
    
    for(i = 0; i < s.length(); i++){
        if(i%2 == 0){
            s1 = '0';
            s2 = '1';
        }
        else{
            s1 = '1';
            s2 = '0';
        }
        if(s[i] != s1){
            count1++;
        }
        if(s[i] != s2){
            count2++;
        }
    }
    if(count1 <= count2){
        cout << count1 << endl;
    }
    else{
        cout << count2 << endl;
    }
}

Measured memory_bytes: 512
import math
n = int(input())
a = []
b = []

for i in range(n):
    ai, bi = list(map(int, input().split()))
    a.append(ai)
    b.append(bi)

cur = 0

for i in range(n-1, -1, -1):
    res = (a[i]+cur)/b[i]
    if res % 1 == 0:
        continue

    rem = round((math.ceil(res) - res)*b[i])
    cur += rem

print(cur)

Measured memory_bytes: 16892
#include<bits/stdc++.h>
using namespace std;
#define nn 65536*4
#define mod 1000000007
#define ll long long
int n,k;
int a[nn];int tots;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),tots+=a[i];
	
	for(int i=1;i<n;i++)
	{
		if(a[i]+a[i+1]>=k)
		{
			puts("Possible");
			for(int j=1;j<i;j++) printf("%d\n",j);
			for(int j=n-1;j>=i+1;j--) printf("%d\n",j);
			printf("%d\n",i);exit(0);
		}
	}
	puts("Impossible");
	return 0;
} 


Measured memory_bytes: 1152