akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

int dist[2002][2];

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

  string A,B;
  cin>>A;
  cin>>B;

  int N=A.size();
  bool allz=true;
  rep(i,N) if(B[i]=='1') allz=false;
  if(allz){
    if(A==B) cout<<0<<endl;
    else cout<<-1<<endl;
    return 0;
  }

  for(int i=0;i<N;i++){
    for(int j=0;j<2;j++){
      int d=1;
      if(j==1) d=-1;
      for(int k=0;k<N;k++){
        int x=(i+k*d+N)%N;
        if(B[x]=='1'){
          dist[i][j]=k;
          break;
        }
      }
    }
  }

  auto go=[&](int a,int d){
    return (a+d+N)%N;
  };

  int ans=N*N;
  for(int k=0;k<2;k++){
    for(int i=0;i<N;i++){
      int w=-i;
      if(k) w=N-i;
      int diff=0;
      set<pair<int,int>> se;
      set<pair<int,int>> rest;
      for(int j=0;j<N;j++){
        int nex=go(j,w);
        if(A[j]!=B[nex]){
          diff++;
          if(dist[j][1-k]<=abs(w)) continue;
          se.insert(mkp(dist[j][k],j));
          rest.insert(mkp(dist[nex][1-k],nex));
        }
      }
      if(se.size()==0){
        chmin(ans,abs(w)+diff);
        continue;
      }

      auto it=rest.end();
      it--;
      chmin(ans,abs(w)+diff+(*it).first*2);

      while(se.size()){
        auto f=se.begin();
        int now=(*f).second;
        int cost=(*f).first;
        rest.erase(mkp(dist[go(now,w)][1-k],go(now,w)));
        se.erase(f);

        int res=cost*2;
        if(rest.size()){
          auto itr=rest.end();
          itr--;
          res+=(*itr).first*2;
        }
        chmin(ans,abs(w)+res+diff);
      }
    }
  }

  cout<<ans<<endl;

  return 0;
}


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

using namespace std;

int main()
{
    long long a,bruh=0;
    string s;
    cin>>a;
    cin>>s;
    for(int i=2;i<a;i++)
    {
        if(s[i]=='C'&&s[i-1]=='B'&&s[i-2]=='A')
            bruh++;
    }
    cout<<bruh;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, a;
  in(n);
  double b, c, h, t, k;
  h = 9999999999999;
  in2(t, k);
  rep(i, n){
    in(b);
    c = abs(k - (t - b * 0.006));
    if(c < h){
      h = c;
      a = i;
    }
  }
  out(a + 1);
  memi;
}

Measured memory_bytes: 256
N = int(input())
s = [input() for i in range(N)]
count = 0
flag = 1
a_count = 0
b_count = 0
for i in range(N):
    count += s[i].count('AB')
    if s[i][0]=='B' and s[i][-1]!='A':
        flag = 0
    if s[i][0]!='B' and s[i][-1]=='A':
        flag = 0
    if s[i][0]=='B':
        b_count += 1
    if s[i][-1] =='A':
        a_count += 1

if a_count >0 and b_count > 0:
    count += min(a_count, b_count)-flag

print(count)

Measured memory_bytes: 3700
#include <bits/stdc++.h>
    using namespace std;
     
    
    #define int long long
     
    const int N = 505;
     
    int n, k, sum = 0;
    int a[N];
     
    int check(int x)
    {
    	int reqd = 0;
    	vector<int> v;
    	for(int i = 0; i < n; i++)
    	{
    		int cur = a[i] % x;
    		v.push_back(cur);
    	}
    	sort(v.begin(), v.end());
    	int l = 0, r = v.size() - 1;
    	int rem = 0;
    	while(l <= r)
    	{
    		if(rem <= 0)
    		{
    			rem += v[l];
    			reqd += v[l];
    			l++;
    		}
    		else
    		{
    			rem -= (x - v[r]);
    			reqd += (x - v[r]);
    			r--;
    		}
    	}
    	if(reqd > 2 * k)
    		return 0;
    	if(rem != 0)
    		return 0;

    	return 1;
    }
     
    int32_t main()
    {
    	
    	cin >> n >> k;
    	for(int i = 0; i < n; i++)
    	{
    		cin >> a[i];
    		sum += a[i];
    	}
    	int ans = 1;
    	for(int i = 1; i * i <= sum; i++)
    	{
    		if(sum % i == 0)
    		{
    			if(check(i))
    				ans = max(ans, i);
    			if(check(sum / i))
    				ans = max(ans, sum / i);
    		}
    	}
    	cout << ans;
    	return 0;
    }

Measured memory_bytes: 256
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for(auto &e: a) cin >> e;
  auto b = a;
  for(int i = 1; i < n; i++) a[i] = max(a[i], a[i-1]);
  swap(a,b);
  reverse(begin(a), end(a));
  for(int i = 1; i < n; i++) a[i] = max(a[i], a[i-1]);
  reverse(begin(a), end(a));
  swap(a,b);
  for(int i = 0; i < n; i++ ){
    cout << max(i-1>=0?a[i-1]:0, i+1<n?b[i+1]:0) << endl;
  }
  return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000000000000LL
#define MOD 1000000007
#define writeln(n) cout<<n<<endl;
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main()
{
    llong x,y;
    cin>>x>>y;
    llong cnt=1;
    llong d=y/x;

    while(d>1)
    {
        d/=2;
        ++cnt;
    }
    cout<<cnt<<endl;

}

Measured memory_bytes: 256
n = int(input())
c = input()

count_r = 0
count_w = 0
R = []
W = []
for i in range(n):
    if c[i:i+1] == "R":
        count_r += 1
        R.append(i)
    else:
        count_w += 1
        W.append(i)

ans_count = 0
while count_r * count_w:
    if  ans_count+1 > count_r or ans_count+1 > count_w:
        break
    if R[-(1+ans_count)] < W[ans_count]:
        break
    ans_count += 1

print(min(ans_count,count_r,count_w))

Measured memory_bytes: 17388
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

int dp[200005][2];

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

    string s;
    cin >> s;

    int n = s.size();
    fill(dp[0], dp[n + 1], 0);

    for (int i = 0; i < n; i++) {
        dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + 1);
        if (i == 0 || (i > 0 && s[i - 1] != s[i])) {
            dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + 1);
        }

        dp[i + 2][1] = max(dp[i + 2][1], dp[i][0] + 1);
        if (i <= 1 || (i >= 2 && i < n - 1 && s.substr(i - 2, 2) != s.substr(i, 2))) {
            dp[i + 2][1] = max(dp[i + 2][1], dp[i][1] + 1);
        }
    }

    cout << max(dp[n][0], dp[n][1]) << "\n";
    return 0;
}

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

int main(){
  int n,k,d,ai;
  int count = 0;
  cin >> n >> k;
  vector<int> A(n);
  for(int i = 0; i < k; i++){
    cin >> d;
    for(int j = 0; j < d; j++){
      cin >> ai;
      A.at(ai-1) = 1;
    }
  }
  
  for(int i = 0; i < n; i++){
    if(A.at(i) == 0){
      count++;
    }
  }
  
  cout << count << endl;
}

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

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

typedef pair<int, int> pint;

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front

#define MOD (1000 * 1000 * 1000 + 7)

double dot(double x1, double y1, double x2, double y2) {
    return x1 * x2 + y1 * y2;
}

#define M 1000

signed main() {
    int N;
    vector<int> xx, yy;

    cin >> N;
    REP(i, N) {
        int x, y;
        cin >> x >> y;
        xx.pb(x);
        yy.pb(y);
    }

    double ans = 0;

    REP(i, M) {
        double rad = (double) i / M * M_PI * 2;
        double vec_x = cos(rad);
        double vec_y = sin(rad);
        double total_x = 0;
        double total_y = 0;

        REP(i, N) {
            if (dot(xx[i], yy[i], vec_x, vec_y) >= 0) {
                total_x += xx[i];
                total_y += yy[i];
            }
        }

        if (pow(total_x, 2) + pow(total_y, 2) > ans) {
            ans = pow(total_x, 2) + pow(total_y, 2);
        }
    }
    ans = sqrt(ans);

    cout << setprecision(12) << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#define rep(i,n) for(int i = 0 ; i< (n);i++)
#define ic(n) int (n); cin>>(n);
#define SORT(a) sort((a).begin(),(a).end());
#define che(a,string) cout<<string<<":"<<(a)<<endl;
#define ch(a,string) cout<<string<<":"<<(a)<<" ";
using namespace std;
typedef pair<int,int> P;
int main(){
	ic(n);ic(t);
	vector<tuple<int,int,int>> A(n);//cost,timeの順番に入れる
	rep(i,n){
		ic(a);ic(b);
		A[i]=make_tuple(a,b,i+1);
	  }
	SORT(A);
	int check=0;
	rep(i,n){
		int c,d,e;
		tie(c,d,e) = A[i];
		if(d<=t){
			cout<<c<<endl;
			check=1;
			break;
		  }
	  }
	  if(0==check){
		  cout<<"TLE"<<endl;
		}
  }

Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

enum MOD = (10 ^^ 9) + 7;

void main()
{
    long N = lread();
    auto A = aryread();
    foreach (i; 1 .. N)
    {
        A[i] += A[i - 1];
    }
    long ans = long.max;
    foreach (B; [true, false])
    {
        long cnt;
        long x;
        foreach (i; 0 .. N)
        {
            if (B == (i & 1))
            {
                long tmp = (A[i] + x <= 0) ? abs(A[i] + x) + 1 : 0;
                x += tmp;
                cnt += tmp;
            }
            else
            {
                long tmp = (0 <= A[i] + x) ? abs(A[i] + x) + 1 : 0;
                x -= tmp;
                cnt += tmp;
            }
        }
        ans = ans.min(cnt);
    }
    writeln(ans);
}


Measured memory_bytes: 4484
#include <iostream>

using namespace std;

#define MAX_N 50
#define MAX_S 50
// 入力
int n;
string S[MAX_N];

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

    int mem[26] = {};
    for (int l = 0; l < 26; ++l) {
        mem[l] = MAX_S;
    }

    for (int i = 0; i < n; ++i) {
        int cnt[26] = {};
        for (int j = 0; j < S[i].length(); ++j) {
            cnt[S[i][j] - 'a']++;
        }
//        for (int l = 0; l < 26; ++l) {
//            cout << cnt[l] << " ";
//        }
//        cout << endl;
        for (int l = 0; l < 26; ++l) {
            mem[l] = min(mem[l], cnt[l]);
        }
    }

    for (int l = 0; l < 26; ++l) {
        while (mem[l] > 0) {
            cout << (char) ('a' + l);
            mem[l]--;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
const int MOD = 1000000007;
int main(){
    int n, k;
    cin >> n >> k;

    long long int ans = 0;
    long long int coans = 0;
    long long int c = 0;
    for(long long int i = 1; i <= n+1; i++){
        c += i-1;
        coans = n * i + 1;
        coans -= 2 * c;
        coans %= MOD;
        if(i >= k) ans += coans;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
using namespace std;
int cnt[27],cntt[4];
int main(){
	int n,m; cin>>m>>n;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{char c;while((c=getchar())<'a'||c>'z');cnt[c-'a']++;}
	for(int i=0;i<27;i++) cntt[cnt[i]&3]++;
	cntt[2]+=cntt[3]; cntt[1]+=cntt[3]; cntt[3]=0;
	
	if((n&1)&&(m&1)&&cntt[2]<(n+m)>>1&&cntt[1]==1){printf("Yes"); return 0;}
	if((n&1)&&!(m&1)&&cntt[2]<=m>>1&&cntt[1]==0){printf("Yes"); return 0;}
	if(!(n&1)&&(m&1)&&cntt[2]<=n>>1&&cntt[1]==0){printf("Yes"); return 0;}
	if(!(n&1)&&!(m&1)&&cntt[2]+cntt[1]==0){printf("Yes"); return 0;}
	printf("No");
}

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

int main() {
  string A, B, C;
  cin >> A >> B >> C;

  cout << (A.at(A.size() - 1) == B.at(0) && B.at(B.size() - 1) == C.at(0) ? "YES" : "NO") << endl;
}

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

int main() {
  int a,b; cin >> a >> b;
  if (a<10 && b<10) cout << a*b << endl;
  else cout << -1 << endl;
}

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

typedef long long ll;
typedef long double ld;

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

    int n;
    cin >> n;

    vector<int> a(26, 1000000);

    for(int i = 0; i < n; i++) {
        string S;
        cin >> S;
        vector<int> b(26);
        for(int j = 0; j < S.length(); j++) {
            b[S[j] - 'a']++;
        }
        for(int j = 0; j < 26; j++) {
            a[j] = min(a[j], b[j]);
        }
    }

    for(int i = 0; i < 26; i++) {
        if(a[i] == 1000000) a[i] = 0;
        for(int j = 0; j < a[i]; j++) {
            cout << char(i + 'a');
        }
    }

    cout << endl;
}

Measured memory_bytes: 256
n = int(input())
S = [input() for _ in range(n)]

ans = list(S[0])
for i in range(1, n):
    tmp = ''
    for s in S[i]:
        if s in ans:
            tmp += s
            ans.remove(s)
    ans = list(tmp)

print(''.join(sorted(ans)))



        




Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>

using namespace std;

string S;
long long int kotae;
long long int moji[30];

int main(){
	cin >> S;
	long long int m = S.size();
	for(int i=0;i<m;i++){
		moji[S[i]-'a'] ++;
	}
	kotae = 1 + m*(m-1)/2;
	for(int i=0;i<26;i++){
		kotae -= moji[i]*(moji[i]-1)/2;
	}
	cout << kotae << endl;
	return 0;
}

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

int main(){
    int X, A, B;
    cin >> X;
    for (int a = -1000; a < 1000; a++){
        for (int b = -1000; b < 1000; b++){
            if(pow(a, 5) - pow(b, 5) == X){
                A = a, B = b;
                break;
            }
        }
    }
    cout << A << " " << B << endl; 
}

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

int main(void){
    long long n, k, c, big, small;
    cin >> n >> k;
    if(n == 0){
        cout << n << endl;
        return 0;
    }

    long long ans = min(n % k,k - (n % k));
    cout << ans << endl;
    return 0;
}

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

// i > 0
int parent(int i) { return ((i + 1) / 2) - 1; }

int left(int i) { return 2 * (i + 1) - 1; }

int right(int i) { return 2 * (i + 1); }

void PercolateDown(vector<int> &v, int i) {
  if (i >= v.size())
    return;

  int max_ch = -1;
  if (left(i) < v.size() and v[left(i)] > v[i])
    max_ch = left(i);
  if (right(i) < v.size() and v[right(i)] > v[i]) {
    if (max_ch == -1 or v[right(i)] > v[left(i)])
      max_ch = right(i);
  }
  if (max_ch != -1) {
    swap(v[i], v[max_ch]);
    PercolateDown(v, max_ch);
  }
}

void PercolateUp(vector<int> &v, int i) {
  if (i == 0)
    return;
  if (v[parent(i)] < v[i]) {
    swap(v[i], v[parent(i)]);
    PercolateUp(v, parent(i));
  }
}

int main() {
  vector<int> v;
  int k;
  for (string cmd; cin >> cmd;) {
    if (cmd == "insert") {
      cin >> k;
      v.push_back(k);
      PercolateUp(v, v.size() - 1);
    }

    if (cmd == "extract") {
      if (!v.empty()) {
        cout << v[0];
        v[0] = v.back();
        v.pop_back();
        PercolateDown(v, 0);
      }
      cout << endl;
    }
  }
}



Measured memory_bytes: 7064
#include<bits/stdc++.h>
using namespace std;
int main(){

int n ;
int m ;
cin>>n>>m;
int a[m];
int sum = 0 ;
for(int i =0 ; i<m; i++){

    cin>>a[i];
    sum+=a[i];
}
if((n-sum)<=0)cout<<"Yes";
else cout<<"No";



}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;

    long long ans = 0;

    int D = min( A+B, C*2 );

    ans += D*min(X,Y);

    // cout << ans << endl;


    ans += abs(Y-X)*min( D, (X < Y ? B : A) );

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void Dice(char *p, int d[]);

void Dice(char *p, int d[]){
    int tmp;
    while (*p) {
        if (*p == 'S') {
            tmp = d[0];
            d[0] = d[4];
            d[4] = d[5];
            d[5] = d[1];
            d[1] = tmp;
        }
        if (*p == 'W') {
            tmp = d[0];
            d[0] = d[2];
            d[2] = d[5];
            d[5] = d[3];
            d[3] = tmp;
        }
        if (*p == 'E') {
            tmp = d[0];
            d[0] = d[3];
            d[3] = d[5];
            d[5] = d[2];
            d[2] = tmp;
        }
        if (*p == 'N') {
            tmp = d[0];
            d[0] = d[1];
            d[1] = d[5];
            d[5] = d[4];
            d[4] = tmp;
        }
        *p++;
    }
}


int main(int argc, const char * argv[]) {
    
    //構造体の型を宣言
//    static Dice
//    {
//        int label[6];
//    };
    
    
    int d[6], i;
    char req[101], *p;
    
    //ダイス目取得
    for (i=0; i<6; i++) {
        scanf("%d", &d[i]);
    }
    
    scanf("%s", req);
    
    p = req;    //ポインタを文字列"req"の先頭に指定
    Dice(p, d);
    printf("%d\n", d[0]);
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int A, B, X;

int main(void){
    
    scanf("%d %d %d", &A, &B, &X);
    if(A > X || A + B < X) printf("NO\n");
    else printf("YES\n");
    
    return 0;
}

Measured memory_bytes: 256
def solve(str):
  ans = ""
  for s in str:
    if s == '0':
      ans += '0'
    elif s == '1':
      ans += '1'
    elif s == 'B':
      if len(ans) == 0:
        continue
      else:
        ans = ans[:-1]
    else:
      RuntimeError("input is not 0 or 1 or B.")
      return
  return ans

if __name__ == "__main__":
  s = input()
  ans = solve(s)
  print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<int, int> P;
typedef pair<pair<int, int>, int> PP;
typedef bitset<61> Bitset;
const ll INFL = 1LL << 60;
const ll MOD = 1000000007;
const int INF = INT_MAX;
const int MAX = 300000;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
//------------------------------------------------------------------------------------------------------------------------------

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll X;cin>>X;
    for(ll a = -200; a < 200; a++) {
        for(ll b = -200; b < 200; b++) {
            ll A = a*a*a*a*a;
            ll B = b*b*b*b*b;
            if(A-B==X){
                cout<<a<<' '<<b<<endl;
                return 0;
            }
        }
    }


}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  int a[100001];
  for (int i=0;i<100001;i++) a[i]=0;
 
  for(int i=0;i<N;i++){
    int b;
    cin>>b;
    if(b==0){
      a[0] ++;
      a[1] ++;
    }
    else{
      a[b-1]++;
      a[b]++;
      a[b+1]++;
    }
  }
  int m=0;
  for(int i=0;i<100001;i++){
    m = max(m,a[i]);
  }
cout<<m<<endl;
}

Measured memory_bytes: 640
while True:
  n = int(input())
  if n == 0:
    break
  lst = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x:x[-1])
  acc = 0
  for w, b in lst:
    acc += w
    if acc > b:
      print("No")
      break
  else:
    print("Yes")



Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
	cin>>a>>b>>c;
	for(int i=1;i<=b;i++)if((a*i)%b==c){cout<<"YES"<<endl;return 0;}
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
import Control.Monad
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.ByteString.Char8 as BS

main = do
  n <- readLn
  happiness <- V.replicateM n $ do
    [a,b,c] <- map (read . BS.unpack) . BS.words <$> BS.getLine
    -- a,b,c <= 10^4
    return (a,b,c :: Int)
  let (a,b,c) = V.foldl1' (\(a,b,c) (a',b',c') -> (max b c + a', max a c + b', max a b + c')) happiness
  print (max a (max b c))


Measured memory_bytes: 23932
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    string s;
    cin >> s;

    vector<bool> alpha(26);
    rep(i, s.size()) {
        alpha[s[i] - 'a'] = 1;
    }

    int ans = 1e9;
    int ch = 0;
    repd(i, 1, s.size()) {
        if (s[i] == s[i - 1]) ch++;
    }

    if (ch + 1 == (int)s.size()) ans = 0;
    rep(j, 26) {
        bool flag = true;
        int cnt = 0;
        string t, check = s;
        if (!alpha[j]) continue;
        while (flag && (int)check.size() >= 2) {
            char ct = 'a' + j;
            // cout << ct << " ";
            t = check;
            check = "";
            repd(i, 1, t.size()) {
                if (t[i] == ct || t[i - 1] == ct) {
                    check += ct;
                }
                else {
                    check += t[i];
                }
            }
            repd(i, 1, check.size()) {
                if (check[i] == check[i - 1]) flag = false;
                else {
                    flag = true;
                    break;
                } 
            }
            cnt++;
        }
        chmin(ans, cnt);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

lint lcm(lint a, lint b) {
    return (a / gcd(a, b)) * b;
}

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<lint> t(n);
    REP(i, n){
        cin >> t[i];
    }
    int m;
    cin >> m;
    vector<lint> p(m);
    vector<lint> x(m);
    REP(i, m){
        cin >> p[i] >> x[i];
        p[i]--;
    }
    lint sum = 0;
    REP(i, m){
        sum = 0;
        REP(j, n){
            if(p[i] == j){
                sum += x[i];
            }
            else {
                sum += t[j];
            }
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
id = []
ans = 0
cnt = 0
for i in range(n-1):
    if h[i]>=h[i+1]:
        cnt += 1
    else:
        ans = max(ans,cnt)
        cnt = 0
ans = max(ans,cnt)
print(max(ans,cnt))
    

Measured memory_bytes: 14252
int main(){
  int a, b, c;
  int x;

    scanf("%d %d %d", &a, &b, &c);
    for(int i=0; i<= b-a; i++){
      if(c%(a+i) == 0) x++;

    };

    printf("%d\n", x);



  return 0;
}


Measured memory_bytes: 2060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
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 (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T iabs(const T& x) { return max(x, -x); }
// #define abs gabs

struct Edge { int v, w; };

int n;
vector<vector<Edge>> g;
vector<int> ans;

void dfs(int u, int p) {
    for (auto e : g[u]) {
        if (e.v == p) continue;
        ans[e.v] = (ans[u] + e.w) % 2;
        dfs(e.v, u);
    }
}

int main() {
    cin >> n;
    g.resize(n + 1);
    for (int i = 0; i < n - 1; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        w %= 2;
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }
    ans.resize(n + 1);
    dfs(1, 0);
    for (int u = 1; u <= n; ++u) cout << ans[u] << '\n';
    return 0;
}

Measured memory_bytes: 8192
# include <iostream>
# include <vector>


using namespace std;


int score(char x, int r, int s, int p) {
    if (x == 'r') return r;
    if (x == 's') return s;
    if (x == 'p') return p;
    return -1;
}


int main() {
    int n, k; cin >> n >> k;
    int r, s, p; cin >> r >> s >> p;
    string t; cin >> t;

    string a = "";
    for (char c: t) {
        if (c == 'r') a += 'p';
        if (c == 's') a += 'r';
        if (c == 'p') a += 's';
    }

    int ans = 0;
    for (int i=0; i<n; i++) {
        if (i<k) {
            ans += score(a[i], r, s, p);
            continue;
        }
        if (a[i] != a[i-k]) {
            ans += score(a[i], r, s, p);
            continue;
        }

        a[i] = 'x';
    }

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }                            /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }                            /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }                     /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX 100001
#define MOD 1000000007
#define INF 1000000001

typedef long long int lli;

int main(void)
{
  int n, a[MAX];
  scanf("%d", &n);

  rep(ai, n)
  {
    scanf("%d", &a[ai]);
  }
  int ai;
  int num_minus = 0;
  long long int sum = 0;
  int min = INF;
  rep(ai, n)
  {
    if (a[ai] < 0)
      num_minus++;
    min = min(min, abs(a[ai]));
    sum += abs(a[ai]);
  }
  long long int ans = sum;
  if (num_minus % 2 == 1)
    ans -= 2 * min;
  printf("%lld\n", ans);
  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 GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
#define VI vector<int>
#define VL vector<LL>
#define VII vector< vector<int> >
#define VLL vector< vector<LL> >
#define VS  vector<string>
#define VSS vector< vector<string> >
#define PII pair<int,int>
#define PIS pair<int,string>
#define PSI pair<string,int>
#define PLL pair<LL,LL>
const LL MOD = 1000000007;
const LL INF = 1e16;
LL facctorialMethod(int k);
int main(){
    LL n,two,count_zoro;
    two = 2;
    count_zoro = 0;
    cin >> n;
    VLL d_ary(n,vector<LL>(two));
    for(int i = 0; i < n; i++) {
        cin >> d_ary[i][0] >>  d_ary[i][1];
        if(d_ary[i][0] == d_ary[i][1]) {
            count_zoro++;
        }else{
            count_zoro = 0;
        }
        if(count_zoro == 3){
            cout << "Yes" << endl;
            break;
        }
    }
    if(count_zoro < 3) {
        cout << "No" << endl;
    }


    return 0;
}

LL facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i){
        sum *= i;
    }
    return sum;
}


Measured memory_bytes: 3628
#include <iostream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#define inf 3
#define MAX 200001
using namespace std;

//ifstream in("input.txt");
//ofstream out("output.txt");

int T;
long long N, M, W, K;
long long D[MAX];
vector <int> E[MAX];
priority_queue <int> q;


int main() {
	int u, v;
	cin >> K;
	N = 50;
	cout << N << endl;
	for (int i = 0; i < 50; ++i) D[i] = i + K / N;
	K %= N;
	while (K > 0) {
		long long min_i = 0;
		for (int i = 1; i < 50; ++i) {
			if (D[i] < D[min_i]) min_i = i;
		}
		for (int i = 0; i < 50; ++i) {
			if (i == min_i) D[i] += N;
			else D[i] -= 1;
		}
		K -= 1;
	}
	for (int i = 0; i < 50; ++i) cout << D[i] << " ";
}

Measured memory_bytes: 6400
/************************************************
┆  ┏┓　　　┏┓ ┆
┆┏┛┻━━━┛┻┓ ┆
┆┃　　　　　　　┃ ┆
┆┃　　　━　　　┃ ┆
┆┃　┳┛　┗┳　┃ ┆
┆┃　　　　　　　┃ ┆
┆┃　　　┻　　　┃ ┆
┆┗━┓　  　┏━┛ ┆
┆　　┃　  　┃　　┆　　　　　　
┆　　┃　  　┗━━━┓ ┆
┆　　┃　 AC代马 　　┣┓┆
┆　　┃　        　　┏┛┆
┆　　┗┓┓┏━┳┓┏┛ ┆
┆　　　┃┫┫　┃┫┫ ┆
┆　　　┗┻┛　┗┻┛ ┆
************************************************ */
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <string>
#include <sstream>
#include <cstdio>
#include <cstring>
#include<cctype>
#include <math.h>
#include <cmath>
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define lb long double
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define random(x) (rand()%x)
#define sgn(x) (fabs(x) < eps ? 0 : ((x) < 0 ? -1 : 1))
#define rep(i, a, b) for(int i=a;i<b;i++)
#define req(j, a, b) for(int j=a;j<b;j++)
#define mem(a, b) memset(a, b, sizeof(a))
#define PI 3.14
#define K 20

using namespace std;
typedef long long ll;
const int maxn = 1e6 + 5;
const double eps =1e-14;
const double pi = acos(-1);
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;

inline int read()
{
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}

inline double dbread()
{
    double X=0,Y=1.0; int w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=X*10+(ch^48),ch=getchar();
    ch=getchar();//读入小数点
    while(isdigit(ch)) X+=(Y/=10)*(ch^48),ch=getchar();
    return w?-X:X;
}

inline void write(int x)
{
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

ll gcd(ll a,ll b)//辗转相除法（欧几里德算法）求最大公约数
{
    return b ? gcd(b,a%b) : a;
}
ll lcm(ll a,ll b)
{
    return a*b/gcd(a,b);//最小公倍数
}
ll q_pow(ll base, ll p)
{
    ll result = 1;
    while(p > 0)
    {
        if(p&1)
        {//此处等价于if(power%2==1)
            result = result * base % 1000;
        }
        p >>= 1;//此处等价于power=power/2
        base = (base * base) % 1000;
    }
    return result;
}

struct node
{
    double k;
    double b;
}p[maxn];

bool cmp(node op1, node op2)
{
    if(op1.k == op2.k)
        return op1.b > op2.b;
    return op1.k < op2.k;
}

const int N = 250005;
int flag;
int fri[N];

void  init()
{
    for(int i = 0; i <= N; i++)
        fri[i] = i;
}
int find(int a)		//查找根节点
{
    int tem1 = a,tem2;
    while(a != fri[a])
        a = fri[a];
    while(tem1 != a)
    {
        tem2 = fri[tem1];
        fri[tem1] = a;
        tem1 = tem2;
    }
    return a;
}
void Union(int a,int b)
{
    int fri_a = find(a);
    int fri_b = find(b);
    if(fri_a != fri_b)
    {
        fri[fri_a] = fri_b;
        flag = 1;
    }
    return ;
}


int ans[105];
int main()
{
    int n;
    cin >> n;
    int f = 1;
    while(n--)
    {
        int x;
        cin >> x;
        if(x % 2 == 0)
        {
            if(x % 3 != 0 && x % 5 != 0)
                f = 0;
        }
    }
    if(f)
        cout << "APPROVED" << endl;
    else
        cout << "DENIED" << endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
*/#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")    
using namespace std;
/*namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;
*/
#define ll long long
#define INF 999999999999
#define rep(i,m,n) for(ll i = m;i < n;i++)
#define rrep(i,m,n) for(ll i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(50) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
Vec(ans, long long, 0, 0);
Vec(isSeen, bool, 0, 0);
void dfs(int v, vector<ll>& A, vector<ll>& dp, vector<vector<ll>>& G) {
	ll old, num;
	if(!v) {
		old = 0;
		num = INF;
		dp[0] = A[0];
		ans[0] = 0;
	} else {
		int ok = -1, ng = A.size();
	  	while(ng - ok > 1) {
		  	int mid = (ok + ng) / 2;
		  	if(dp[mid] < A[v]) ok = mid;
		  	else ng = mid;
	  	}
		old = ok + 1;
		num = dp[old];
	  	dp[ok + 1] = A[v];
		ok = -1, ng = A.size();
	  	while(ng - ok > 1) {
		  	int mid = (ok + ng) / 2;
		  	if(dp[mid] < INF) ok = mid;
		  	else ng = mid;
	  	}
		ans[v] = ok;
	}
	isSeen[v] = true;
	for(auto nv: G[v]) if(!isSeen[nv]) dfs(nv, A, dp, G);
	dp[old] = num;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll B,C,D,E,H,W,M,K,L,R,N,num=0,sum=0,flag=0;string S,T;
  cin >> N;
  Vec(A, long long, N, 0);
  rep(i, 0, N) cin >> A[i];
  DV(G, long long, N, 0, 0);
  rep(i, 0, N - 1) {
	  cin >> L >> R;
	  G[L - 1].pb(R - 1);
	  G[R - 1].pb(L - 1);
  }
  Vec(dp, long long, N, INF); //dp[i]:=長さがiの狭義増加部分列の末尾の要素の最小値
  ans.resize(N);
  isSeen.resize(N);
  dfs(0, A, dp, G);
  rep(i, 0, N) cout << ans[i] + 1 << endl;
}


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

int main() {
    int N, T;
    cin >> N >> T;
    vector<int> t(N);
    for (int i = 0; i < N; i++) {
        cin >> t.at(i);
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (i < N - 1) {
            ans += min(T, t.at(i + 1) - t.at(i));
        } else {
            ans += T;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
fn main() {
    let (a, b, k): (i64, i64, i64) = {
        let temp = read_vec();
        (temp[0], temp[1], temp[2])
    };
    if k <= a {
        println!("{} {}", a - k, b);
    } else if k <= a + b {
        println!("{} {}", 0, b - (k - a));
    } else {
        println!("{} {}", 0, 0);
    }
}


fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

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

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

    int sum = 0;
    for(int i = 0; i < n; i++){
        int l, r;
        cin >> l >> r;
        sum += (r - l + 1);
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#define N 100000

typedef struct process {
   char name[20];
   int time;
} Process;

typedef struct queue {
  int head;
  int size;
  Process data[N];
} Queue;

void initialize(Queue*);
void enqueue(Queue*, Process);
Process dequeue(Queue*);
int is_empty(Queue*);

int main(){
    int n, q, current, time, i;
    char name[5];
    Queue *queue = malloc(sizeof(struct queue));

    initialize(queue);

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

    for(i=0; i<n; i++){
        Process p;
        scanf("%s %d", p.name, &p.time);
        enqueue(queue, p);
    }

    current = 0;
    while(!is_empty(queue)){
        Process p = dequeue(queue);
        if(p.time <= q){
            current += p.time;
            printf("%s %d\n", p.name, current);
        }else{
            current += q;
            p.time -= q;
            enqueue(queue, p);
        }
    }

    free(queue);

    return 0;
}

void initialize(Queue *queue){
    queue->head = 0;
    queue->size = 0;
}

void enqueue(Queue* queue, Process process){
    queue->data[(queue->head + queue->size) % N] = process;
    queue->size++;
}

Process dequeue(Queue* queue){
    Process p = queue->data[queue->head];
    queue->head = (queue->head + 1) % N;
    queue->size--;

    return p;
}

int is_empty(Queue *queue){
    return queue->size == 0;
}

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

typedef double ld;
const ld INF = 10000.0;
const ld EPS = 0.0000000000001;

ld culc(ld x1,ld x2,ld y1,ld y2,ld h){
	if(y1 > h)return h*(x2-x1);
	if(y2 < 0.0)return 0.0;
	ld ret = 0.0;
	if(y1 < 0.0){
		x1 = (x1*y2-x2*y1)/(y2-y1);
		y1 = 0.0;
	}
	if(y2 > h){
		ld x_ = (x1*(y2-h)+x2*(h-y1))/(y2-y1);
		ret += (x2-x_)*h;
		x2 = x_;
		y2 = h;
	}
	return ret+(x2-x1)*(y1+y2)/2.0;
}

int main(){
	while(1){
		int n;
		ld w,h;
		ld x[202],y[202];
		scanf("%lf%lf%d",&w,&h,&n);
		if(n == 0)return 0;
		for(int i = 0 ; i < 2*n ; i ++){
			scanf("%lf%lf",&x[i],&y[i]);
			if(x[i] < EPS)x[i] = EPS;
		}
		
		vector<ld> checkpoints;
		for(int i = 0 ; i < 2*n ; i ++){
			for(int j = 1 ; j < 2*n ; j ++){
				if(x[i] == x[j])continue;
				checkpoints.push_back(y[i]-x[i]*(y[i]-y[j])/(x[i]-x[j]));
			}
		}
		checkpoints.push_back(0.0);
		checkpoints.push_back(h);
		sort(checkpoints.begin(),checkpoints.end());
		
		/*for(int Y: checkpoints){
			cout << Y << endl;
		}*/
		
		vector<ld> s,t;
		for(int i = 0 ; i < checkpoints.size() ; i ++){
			ld y_l = checkpoints[i];
			vector<ld> sl;
			for(int j = 0 ; j < 2*n ; j ++){
				//x[j] == EPS?
				sl.push_back((y[j]-y_l)/x[j]);
			}
			sort(sl.begin(),sl.end());
			s.push_back(y_l+w*sl[n-1]);
			t.push_back(y_l+w*sl[n]);
			
			//cout << y_l << " " << s[s.size()-1] << " " << t[t.size()-1] << endl;
		}
		
		ld ret = 0.0;
		for(int i = 0 ; i+1 < checkpoints.size() ; i ++){
			ld X = checkpoints[i];
			ld X_ = checkpoints[i+1];
			if(X < -EPS || X_ > h+EPS)continue;
			ret -= culc(X,X_,s[i+1],s[i],h);
			ret += culc(X,X_,t[i+1],t[i],h);
		}
		
		//cout << ret << endl;
		printf("%.12f\n",ret/(h*h));
	}
}




Measured memory_bytes: 4804
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int A[]=new int[N];
		int z=0,ans=0;
		while(z<N){
			A[z]=stdIn.nextInt();
			z++;
		}z=1;
		while(z<N-1){
			int a=A[z-1];
			int c=A[z+1];
			int b=A[z];
			if(a<b&&b<c)
				ans++;
			else
				if(a>b&&b>c)
					ans++;
			z++;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main(void){
    char s[100];
    int i,n,flag=0;
    scanf("%s",s);
    n=strlen(s);
    for(i=0; i<n/2; i++){
        if(s[i]!=s[n-i-1])flag=1;
    }
    for(i=0; i<(n-1)/4; i++){
        if(s[i]!=s[(n-3)/2-i])flag=1;
        else if(s[i+(n+1)/2]!=s[n-i-1])flag=1;
    }
    if(flag==1)printf("No");
    else printf("Yes");
    return 0;
}

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

#ifdef SG
	#include <debug.h>
#else
	template<typename T> struct outputer;
	struct outputable {};
	#define PRINT(...)
	#define OUTPUT(...)
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
	#define fbegin(...)
	#define fend
	#define pbegin(...)
	#define pend
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb emplace_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef int64_t ll;
typedef uint64_t ull;
typedef uint32_t ui;
typedef uint16_t us;
typedef uint8_t uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

const int N = 100000;

struct Input {
	int n;
	int a[N];
	
	bool read () {
		if (!(cin >> n)) {
			return 0;
		}
		forn (i, n) {
			scanf("%d", &a[i]);
		}
		return 1;
	}

	void init (const Input &input) {
		*this = input;
	}
};

struct Data: Input {
	ll ans;
	
	void write () {
		cout << ans << endl;
	}
};


namespace Main {
	
	struct Solution: Data {
		
		ll calc (int i, ll s, bool b) {
			if (i == n) {
				return 0;
			}
			s += a[i];
			ll pr = s;
			if (b) {
				umx(s, 1);
			} else {
				umn(s, -1);
			}
			return abs(s - pr) + calc(i + 1, s, !b);
		}
		
		void solve () {
			ans = min(calc(0, 0, 0), calc(0, 0, 1));
		}
		
		void clear () {
			*this = Solution();
		}
	};
}


Main::Solution sol;

int main () {
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);

	#ifdef SG
		freopen((problemname + ".in").c_str(), "r", stdin);
//		freopen((problemname + ".out").c_str(), "w", stdout);
		while (sol.read()) {
			sol.solve();
			sol.write();
			sol.clear();
		}
	#else
		sol.read();
		sol.solve();
		sol.write();
	#endif
	
	/*
	int t;
	cin >> t;
	forn (i, t) {
		sol.read();
		sol.solve();
		sol.write();
		sol.clear();
	}
	*/
	
	return 0;
}


Measured memory_bytes: 1664
import sys
from collections import deque

H,W=map(int,input().split())
si,sj=[int(x)-1 for x in input().split()]
ti,tj=[int(x)-1 for x in input().split()]
A=list(sys.stdin)

dirs=[-2,-1,0,1,2]
dist=[[10**6]*W for _ in range(H)]
dist[si][sj]=0
dq=deque()
dq.append((0,si,sj))
ok=False
while dq:
    k,i,j=dq.popleft()
    if k>dist[i][j]:
        continue
    if i==ti and j==tj:
        ok=True
        break
    for di in dirs:
        for dj in dirs:
            if di==dj==0:
                continue
            ni,nj=i+di,j+dj
            if not (0<=ni<H and 0<=nj<W):
                continue
            if A[ni][nj]=='#':
                continue
            if abs(di)+abs(dj)==1:
                append=dq.appendleft
                nk=k
            else:
                append=dq.append
                nk=k+1
            if k>=dist[ni][nj]:
                continue
            dist[ni][nj]=nk
            append((nk,ni,nj))
      
if ok:
    ans=dist[ti][tj]
else:
    ans=-1

print(ans)


Measured memory_bytes: 217728
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  vector<int> lot(5);
  for(int i=0; i<5; i++) cin >>lot[i];
  sort(lot.begin(),lot.end());
  for(int i=0; i<5; i++){
    cout <<lot[4-i];
    if(i == 4) cout <<endl;
    else cout <<" ";
  }
  return 0;
}

Measured memory_bytes: 1204
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N_MAX   100
#define M_MAX   100
#define STR_MAX 501

int mat[N_MAX][M_MAX] = {{}};
int vec[M_MAX] = {};
int ans[N_MAX] = {};

void multiply(int n, int m)
{
    int i, j;
    int sum;

    for(i=0;i<n;i++) {
        for(j=0;j<m;j++) {
            ans[i] += mat[i][j] * vec[j];
        }
    }
    return;
}

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

int main(void)
{
    int i,j;
    int n, m;
    char str[STR_MAX], *tok;

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

    for(i=0;i<n;i++) {
        fgets(str, STR_MAX, stdin);
        tok = strtok(str, " \n");
        mat[i][0] = atoi(tok);
        for(j=1;j<m;j++) {
            tok = strtok(NULL, " \n");
            mat[i][j] = atoi(tok);
        }
    }

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

    multiply(n,m);

    show_vec(n);

    return 0;
}

Measured memory_bytes: 644