akhauriyash/Code-Regression huggingface dataset:
s = input()
n = len(s)
if s[0] == '1' and s[-1] == '0' and s[:n//2] == s[(n-1)//2:-1][::-1]:
    q = []
    now = 0
    for i in range(n):
        m = s[i]
        if m == '1':
            now = str(i+1)
            while q:
                print( q.pop() + ' ' + now)
        q.append( str(i+1))
    while q:
        a = q.pop()
        if now != a:
            print( a + ' ' + now)
else:
    print(-1)

Measured memory_bytes: 9696
#include <iostream>

using namespace std;

int main()
{
	int N, T, A, min;
	int ans = 0;
	int maxV = 0;
	cin >> N >> T;

	cin >> min;
	for (int i = 1;i < N;i++)
	{
		cin >> A;
		if (A - min > maxV)
		{
			ans = 1;
			maxV = A - min;
		}
		else if (A - min == maxV)
			ans++;

		if (A < min)
		{
			min = A;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int A, B, C;
    cin >> A >> B >> C;
    bool a = A == B;
    bool b = B == C;
    bool c = A == C;
    int sum = 0;
    if (a) sum++;
    if (b) sum++;
    if (c) sum++;
    if (sum == 1) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine((nm[0]-1)*(nm[1]-1));
        }
    }
}


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

int main() {
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	int a = (n > k) ? k : n;
	int b = (n > k) ? n - k : 0;
	cout << a * x + b * y << endl;
    return 0;
}

Measured memory_bytes: 256
a, b, c, x, y = [int(i) for i in input().split()]
ans = (a + b + c) * (x + y)
for i in range(max(x, y) + 1):
  ans = min(2 * c * i + a * max(x - i, 0) + b * max(y - i, 0), ans)
print(ans)

Measured memory_bytes: 3060
import collections

n,m,k = map(int,raw_input().split(' '))

friendships = [map(int, raw_input().split(' ')) for _ in range(m)]
disses = [map(int, raw_input().split(' ')) for _ in range(k)]

parent = {i:i for i in range(0, n+1)}
sizes = {i:1 for i in range(0, n+1)}

hd = collections.Counter()

adj = collections.defaultdict(set)

def f(parent, u):
	if parent[u] != u: 
		parent[u] = f(parent, parent[u])
	return parent[u]

for a,b in friendships:

	pa,pb = f(parent, a), f(parent, b)
	
	adj[a].add(b)
	adj[b].add(a)

	if pa != pb:
		if sizes[pa] >= sizes[pb]:
			parent[pb] = pa
			sizes[pa] += sizes[pb]
		else:
			parent[pa] = pb
			sizes[pb] += sizes[pa]

for c,d in disses:
	pc,pd = f(parent, c), f(parent, d)
	if d not in adj[c] and (pc == pd):
		hd[c] += 1
		hd[d] += 1

print ' '.join([str(sizes[f(parent,u)] - len(adj[u]) - hd[u] - 1)  for u in range(1, n+1)])

Measured memory_bytes: 116252
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  int x, y;
  cin >> x >> y;
  cout << (a[x] == a[y] ? "Yes" : "No") << endl;
  
  return 0;
}

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

using namespace std;

#define debug printf("Debug\n");
#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define p_b push_back
#define m_p make_pair

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll val,pos;
};
vector<ll>v;


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

    for(ll i=1;i<=s.length();i++){
        cout<<'x';
    }
    cout<<endl;



    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
     
    int a,b,sum,num;
     
    while(scanf("%d %d", &a, &b) != EOF){
        num=a+b;
        sum=0;
        while(num!=0){
            num/=10;
            sum++;
        }
        printf("%d\n", sum);
    }
     
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int r0,w0,c,r;

void solve(){
    for(int x=0;x<=10010;x++){
        if(r0+x*r >= w0*c){
            cout << x << endl;
            return;
        }
    }
}

int main(){
    while(1){
        cin >> r0 >> w0 >> c >> r;
        if(r0 == 0 and w0 == 0 and c == 0 and r == 0) break;
        solve();
    }
}

Measured memory_bytes: 3080
def triangler(left, right)
  mid = (right - left) * Complex(Math.cos(Math::PI/3.0), Math.sin(Math::PI/3.0)) + left
  [left, mid, right]
end

def div3(left, right)
  l2 = left + (right - left) / 3.0
  r2 = left + (right - left) * 2.0 / 3.0
  [left, *triangler(l2, r2) , right]
end

points = Complex(0.0, 0.0), Complex(100.0, 0.0)
n = gets.to_i

n.times do
  tmp = []
  loop do
    l = points.shift
    if points.empty?
      tmp << l
      break
    end
    tmp << div3(l, points[0])[0..3]
  end
  points = tmp.flatten
end

points.each do |p|
  puts p.rectangular.map(&:to_s).join(' ')
end


Measured memory_bytes: 7224
from collections import defaultdict
d=defaultdict(int)
for i in range(int(input())):
    d[input()]+=1
ans=[]
d=list(d.items())
d.sort(key=lambda x:-x[1])

m=d[0][1]
for i,j in d:
    if m==j:
        ans+=[i]

for i in sorted(ans):
    print(i)

Measured memory_bytes: 119512
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;

ll comb[3000 + 1][3000 + 1];

void init() {
  comb[0][0] = 1;
  comb[1][0] = 1;
  comb[1][1] = 1;
  rep(i, 2001) {
    rep(j, i + 1) {
      if (j == 0 || i == j) {
        comb[i][j] = 1;
      } else {
        comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % MOD;
      }
    }
  }
}

int main() {
  //
  init();
  int n, k;
  cin >> n >> k;
  REP(i, 1, k + 1) {
    ll ans = comb[k - 1][i - 1] * comb[n - k + 1][i] % MOD;
    cout << ans << endl;
  }
  return 0;
}


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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

//実行部
void Main()
{
  ll n, a, b; cin >> n >> a >> b;
  ll ans = n - a;
  ans = min(ans, b - 1);
  if((a + b) % 2 == 0) ans = min(ans, (b - a) / 2);
  else
  {
    ans = min(ans, (a + b - 1) / 2);
    ans = min(ans, (1 + n - b + n - a) / 2);
  }
  fin(ans);
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

/*
//test時
  g++ test.cpp -o test;./test
*/


Measured memory_bytes: 256
#include <iostream>
using namespace std;
unsigned long long abs(unsigned long long x) {
  if (x < 0) {
    return -x;
  } else {
    return x;
  }
}
int main() {
  unsigned long long n, k;
  cin >> n >> k;
  unsigned long long x = n;
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (k == 1) {
    cout << 0 << endl;
    return 0;
  }

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

Measured memory_bytes: 256
def do_bubble_sort(data, n):
    """ ??°???data??????????????????????????????????????§???????????????????????????n?????°????????????
    ?????????????????????????????°??¨????????????????????????????????????
    """
    flag = True
    i = 0
    while flag is True:
        flag = False
        for j in range(n-1, i, -1):
            dj = int(data[j][1])
            dj_1 = int(data[j-1][1])
            #if data[j] < data[j-1]:
            if dj < dj_1:
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
                flag = True
        i == 1
    return



def do_selection_sort(data, size):
    assert size == len(data), "data size error"
    for i in range(size):
        minj = i
        for j in range(i, size):
            dj = int(data[j][1])
            dmin = int(data[minj][1])
            if dj < dmin:
            #if data[j] < data[minj]:
                minj = j
        temp = data[i]
        data[i] = data[minj]
        data[minj] = temp
    return


def is_stable(bubble_d, selection_d):
    for b, s in zip(bubble_d, selection_d):
        if b != s:
            return False
    return True


if __name__ == '__main__':
    # ??????????????\???
    num = int(input())
    cards = [x for x in input().split(' ')]
    #cards = ['H4', 'C9', 'S4', 'D2', 'C3']
    #cards = ['S1', 'H1']
    t = cards[:]  # ???????????????
    u = cards[:]

    # ???????????????????????????
    do_bubble_sort(t, len(t))
    do_selection_sort(u, len(u))
    result = is_stable(t, u)

    # ???????????????
    print('{0}'.format(' '.join(map(str, t))))
    print('Stable')
    print('{0}'.format(' '.join(map(str, u))))
    if result is True:
        print('Stable')
    else:
        print('Not stable')

Measured memory_bytes: 7832
using namespace std;
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
void solve()
{
int n;
cin>>n;
int ac=0,tle=0,wa=0,re=0;
for (int i = 0; i < n; i++)
{
    string s;
    cin>>s;
    if(s=="AC")
    ac++;
    else if(s=="TLE")
    tle++;
    else if(s=="WA")
    wa++;
    else if(s=="RE")
    re++;
}
char c=42;
cout<<"AC"<<" "<<'x'<<" "<<ac<<endl;
cout<<"WA"<<" "<<'x'<<" "<<wa<<endl;
cout<<"TLE"<<" "<<'x'<<" "<<tle<<endl;
cout<<"RE"<<" "<<'x'<<" "<<re<<endl;

}
int main()
{
     #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
FASTIO
 long long int t;
 t=1;
 while(t--)
  solve();
  return 0;
}


Measured memory_bytes: 3572
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<ll, int> P;
//////////////////////////////////////BIT
struct BIT{
  vector<ll> data;
  int n;
  // 最大値求めたいとき最初は0を入れておく？
  // データはaddで随時追加してもいいし最初に全部入れても良い問題による
  BIT(int n) : data(n + 1, 0), n(n){return;}
  ll sum(int l, int r){return sum_(r) - sum_(l);}
  ll sum_(int i){
    ll res = 0;
    while(i > 0){res += data[i];i -= i & -i;}
    return res;
  }
  void add(int i, int x){
    while(i <= n){data[i] += x;i += i & -i;}
    return;
  }
};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K; cin >> N >> K;
  int a[N];
  vector<ll> sum(N+1, 0), sortSum(N+1, 0);
  FOR(i,0,N) {
    cin >> a[i];
    a[i] -= K;
    sum[i+1] = sum[i] + a[i];
    sortSum[i+1] = sortSum[i] + a[i];
  }
  sort(sortSum.begin(), sortSum.end());
  BIT bit(202020);
  ll ans = 0;
  FOR(i,0,N+1) {
    int x = lower_bound(sortSum.begin(), sortSum.end(), sum[i]) - sortSum.begin();
    ans += bit.sum_(x+1);
    bit.add(x+1, 1);
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N);
  
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  int ans = 0;
  
  if(vec.at(N/2 - 1) != vec.at(N/2)){
    ans = vec.at(N/2) - vec.at(N/2 - 1);
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		int K = reader.nextInt();
		int ans = 0;
		if (N % K > 0) {
			ans = 1;
		}

		reader.close();
		System.out.print(ans);
	}
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

class Main {
public:
    Main() {
        int H, W;
        cin >> H >> W;
        vector<string> A(H);
        vector<vector<int>> cost(H, vector<int>(W, -1));
        queue<P> qu;
        int di[4] = {1, 0, -1, 0};
        int dj[4] = {0, 1, 0, -1};
        REP(i, H) {
            cin >> A[i];
            REP(j, W) {
                if (A[i][j] == '#') {
                    cost[i][j] = 0;
                    qu.emplace(i, j);
                }
            }
        }
        int res = 0;
        while (!qu.empty()) {
            int i, j;
            tie(i, j) = qu.front();
            qu.pop();
            res = cost[i][j];
            REP(k, 4) {
                int a = i + di[k];
                int b = j + dj[k];
                if (a >= 0 && a < H && b >= 0 && b < W) {
                    if (cost[a][b] == -1) {
                        cost[a][b] = cost[i][j] + 1;
                        qu.emplace(a, b);
                    }
                }
            }
        }
        cout << res << endl;
    }
};

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

    Main ans;

    return 0;
}


Measured memory_bytes: 16280
n =  gets.to_i
a = gets.split.map(&:to_i)


f = n % 2 == 0 ? n/2 : n/2 + 1
k = n % 2 == 0 ? 1 : 2

f.times do |i|
	t = a[n - 2 * i - 1]
	print "#{t} "
end
(n-f).times do |i|
	t = a[k + 2 * i - 1]
	print "#{t} "
end

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

using namespace std;

int myPow(int n){
    int ans = 1;
    for(int i = 0; i < n; i++){
        ans *= 10;
    }
    return ans;
}

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

Measured memory_bytes: 256
N,M=map(int,input().split())
A=[0]+list(map(int,input().split()))
S=set()
dict={}
ans=0
for i in range(N):
    A[i+1]+=A[i]

for a in A:
    tmp=a%M
    if tmp not in S:
        S.add(tmp)
        dict[tmp]=1
    else:
        dict[tmp]+=1

for s in S:
    tmp=dict[s]
    ans+=tmp*(tmp-1)//2

print(ans)

Measured memory_bytes: 14972
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
using ll=long long;
int main(){ _;
  ll x;cin>>x;
  cout<<(x/11)*2+((x%11)==0?0:(x%11)<7?1:2)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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

	int N, M;
	cin >> N >> M;
	int a[2000], b[2000],c[2000];

	REP(i, M) {
		cin >> a[i] >> b[i] >> c[i];
		c[i] = -c[i];
	}
	int dis[1000];
	REP(i, N)dis[i] = LLINF;
	dis[0] = 0;
	REP(j, N - 1) {
		REP(i, M) {
			if (dis[a[i] - 1] == LLINF)continue;

			if (dis[b[i] - 1] > dis[a[i] - 1] + c[i]) {
				dis[b[i] - 1] = dis[a[i] - 1] + c[i];
			}
		}
	}
	int ans = dis[N - 1];
	bool neg[1000];
	REP(i, N)neg[i] = false;

	REP(j, N) {
		REP(i, M) {
			if (dis[a[i] - 1] == LLINF)continue;

			if (dis[b[i] - 1] > dis[a[i] - 1] + c[i]) {
				dis[b[i] - 1] = dis[a[i] - 1] + c[i];
				neg[b[i] - 1] = true;
			}
			if (neg[a[i] - 1]) neg[b[i] - 1] = true;
		}
	}
	if (neg[N - 1])
		cout << "inf" << endl;
	else
		cout << -ans << endl;
	return 0;
}



Measured memory_bytes: 256
/******************************************
* AUTHOR :kamesh_11 *
* INSTITUTION : GVPCOE *
******************************************/

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define MOD 1000000007
#define pi 3.141592653589793
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define bs binary_search
#define endl '\n'
#define start_clock clock_t beginn=clock()
#define end_clock clock_t endd=clock()
#define cal_exec_time double time_spent=(double)(endd-beginn)/CLOCKS_PER_SEC
#define print_exec_time cout<<endl<<time_spent<<" secs"

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

	ll N, W;
	cin>>N>>W;
	ll wt[N], val[N];
	for(ll i=0;i<N;i++)
		cin>>wt[i]>>val[i];

	ll dp[N][W+1];
	for(ll i=0;i<=W;i++){
		if(i>=wt[0])
			dp[0][i] = val[0];
		else
			dp[0][i] = 0;
	}
	for(ll i=1;i<N;i++){
		for(ll j=0;j<=W;j++){
			if(j >= wt[i]){
				dp[i][j] = max(dp[i-1][j-wt[i]] + val[i], dp[i-1][j]);
			}
			else	
				dp[i][j] = dp[i-1][j];
		}
	}
	cout<<dp[N-1][W];

	return 0;
}

Measured memory_bytes: 78336
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1E9 + 9;
const int INF = 1 << 29;

int main() {
  int K, S;
  cin >> K >> S;
  int ans = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      int res = S - i - j;
      if ((0 <= res) && (res <= K)) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>

using namespace std;


int main(){
    string s;
    cin >> s;
    char c;
    int frag = 0;
    while (s.length() > 0){
        c = s.back();
        s.pop_back();
        frag = 0;
        for (int i = 0; i < s.length(); i++){
            if (s[i] == c){
                s.erase(s.begin()+i);
                frag = 1;
                break;
            }
        }
        if (frag == 0){break;}
    }
    if (frag == 1) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, n, s) for (int i = s; i < (int)(n); i++)

ll calcNumOfCombination(ll n, ll r) {
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

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

int findSumDigits(int s) {
    int num = 0;
    int temp = 0;
    while (s) {
        temp = s % 10;
        num += temp;
        s = s / 10;
    }
    return num;
}

int countDivisorNum(int n) {
    int count = 0;
    for (int i = 1; i <= n; i++) {
        if (n % i == 0) {
            count++;
        }
    }
    return count;
}


int main() {
    ll x;
    cin >> x;
    ll temp = 0;

    for (int i = -150; i <= 150; i++) {
        for (int j = -150; j <= 150; j++) {
            temp = pow(i,5) - pow(j,5);
            if (temp == x) {
                cout << i << ' ' << j << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3940
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll, ll> 
#define tri pair<pll, ll>
#define vl vector<ll> 
#define vvl vector< vector<ll> > 
#define vlp vector< pair<ll, ll> >
#define vllp vector<pair<pll, ll> > 
#define mll map<ll, ll> 
#define rep(i,a)  for(ll i=0; i< a; i++)
#define rep1(i,a)   for(ll i = 1; i< a; i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
#define mp make_pair
#define all(v)  (v).begin(), (v).end()
#define fst first
#define sec second
#define ff first.first
#define fs first.second
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1000001
#define MOD 1000000007
// #define MOD 998244353
#define endl "\n"
#define INF (ll)1e18
#define s(v) (ll)v.size()
#define e(v) v.empty()
#define bscount(x) __builtin_popcountll(x)
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
// using namespace __gnu_pbds;

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll cpow(ll a, ll b, ll M){ll ans = 1;while(b){if(b&1) ans = ans*a%M; b/=2;a=a*a%M;}return ans;}
void ingraph(vvl& graph, ll m){ll x, y;rep(i, m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}
ll modify(ll n){ll res = n;res%=MOD;res+=MOD;res%=MOD;return res;}
ll fexp(ll a, ll b) {return cpow(a, b, MOD);}
ll cinv(ll a, ll p){return cpow(a, p-2, p);} 
ll inverse(ll a)    {return cinv(a, MOD);}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("../input.txt", "r", stdin);
    //     freopen("../output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll t;
    // cin>>t;
    t = 1;
    while(t--){
        ll h, w, k;
        cin>>h>>w>>k;
        ll mat[h][w];
        char x;
        rep(i, h){
            rep(j, w){
                cin>>x;
                mat[i][j] = (x == '#');
                // cout<<mat[h]
            }
        }
        ll ans =0 ;
        rep(msk, 1LL<<(h+w)){
            ll tmp =0;
            rep(i, h){
                rep(j, w){
                    if(mat[i][j] == 1 && (msk & (1LL<<i)) == 0 && (msk & (1LL<<(j+h))) == 0)    tmp++;
                }
            }
            ans += (tmp == k);
        }
        cout<<ans;
    }
}

Measured memory_bytes: 3644
#!/usr/bin/env python3
def main():
    A, B = map(int, input().split())

    for price in [str(x) for x in range(10, 1001)]:
        a = str(int(price) * 8)
        a = int(a[:-2]) if len(a) >= 3 else 0
        b = int(price[:-1]) if len(price) >= 2 else 0
        if a == A and b == B and a <= 100 and b <= 100:
            print(price)
            return
    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9176
K, N = input().split()
distance = list(map(int, input().split()))

relative = []
relative.append(distance[0])
for i in range(int(N)-1):
    relative.append(distance[i+1] - distance[i])
relative[0] += (int(K) -  distance[-1])
print(sum(relative) - max(relative))

Measured memory_bytes: 26420
/*
 * test.cpp
 *
 *
 *      Author: Fireworks
 */

#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<cmath>
#include<bitset>
#include<set>
#include<iomanip>
#include<fstream>
#include<bitset>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<list>
#include<sstream>

using namespace std;

typedef pair<int,int> ii;
typedef pair<int,long long> il;
typedef pair<long long,long long> ll;
typedef pair<ll,int> lli;
typedef pair<long long,int> li;
typedef pair<double,double> dd;
typedef pair<ii,int> iii;
typedef pair<double,int> di;
long long mod = 1000000007LL;
long long base = 10000007;
long long large = 1000000000000000000LL;




int main(){

	string s;
	cin>>s;
	int n = (int)s.length();
	cout<<s.substr(0,n-8)<<endl;


	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    string S,ans="";
    cin >> N >> S;

    char ch[N];

    for(int i = 0; i < (int)S.size(); i++){
        ch[i] = S[i];
    }
    ans += ch[0];

    int count = 0;
    for (int i = 0; i+1 < N; i++){
        if(ch[i] == ch[i+1]){
            if( !(ans[count] == ch[i+1]) ){
                ans += ch[i+1];
                count++;
            }
        } else {
            ans += ch[i+1];
            count++;
        }
    }
    
    cout << ans.size()<< endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
using namespace std;
#define INF 1000000007
#define LINF 8000000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
    {          \
    }
#define ARDEB(i, X) \
    {               \
    }
#define END \
    {       \
    }
#endif
typedef pair<int, int> P;
struct edge{int to,cost;};

typedef long long ll;

using namespace std;


int ans,ans2;
int n,m;
string s,t;

int a[111111],dp[111111];


signed main(){

	cin>>n;
	rep(i,n)cin>>a[i];
	fill(dp,dp+n,INF);
	dp[0]=0;
	rep(i,n){
		dp[i+1]=min(dp[i+1],dp[i]+abs(a[i]-a[i+1]));
		dp[i+2]=dp[i]+abs(a[i]-a[i+2]);
	}
	cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
using mpint = mp::cpp_int;  // 多倍長整数（任意精度）

/*
 * 定数
 */
const long double PI = (acos(-1));
const long double EPS = 1e-10;
const long long INF = 1e18;



int main() {
  ll N, K;
  cin >> N >> K;

  vector<ll> A(N);

  for (auto &v : A) {
    ll tmp;
    cin >> tmp;
    --tmp;
    v = tmp;
  }

  map<ll, ll> mem;
  vector<ll> ans(1, 0);
  mem[0] = 0;
  ll before = 0;
  ll first = 0;

  ll r = -1;

  for (ll i = 1; i < K; ++i) {
    if (mem.find(A[before]) != mem.end()) {
      first = mem[A[before]];
      r = i - mem[A[before]];
      break;
    }
    mem[A[before]] = i;
    ans.emplace_back(A[before]);
    before = A[before];
  }


  if (r == -1) {
    cout << A[before] + 1 << endl;
  } else {
    cout << ans[(K - first) % r + first] + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 15952
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

bool check(int n, vector<ll> &a, ll k, ll x) {
    ll cnt = 0;
    for (int i = 0; i < n; i++)
        cnt += (a[i] + x - 1)/x - 1;
    return k >= cnt;
}

int main() {
    int n;  cin >> n;   ll k;   cin >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];

    ll l = 0, r = 1e9, m;
    while (r - l > 1) {
        m = (r + l)/2;

        if (check(n, a, k, m))
            r = m;
        else 
            l = m;
    }

    cout << r << endl;
    return 0;
}

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

int main() {
  int X,temp;
  int fx;
  int ans = 0;
  
  cin >> X;
  fx = X % 10;
  temp = X;
  while (temp /= 10) {
	  fx += temp % 10;
  }
  if ( X % fx == 0) cout << "Yes" << endl;
  else cout << "No"	<< endl;
}



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

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

int main() {
    string s;
    cin >> s;
    string ans = "";
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'B') {
            if (ans.size() != 0) {
                ans = ans.substr(0, ans.size() - 1);    
            }
        } else {
            ans += s[i];
        }
    }
    
    cout << ans << endl;
    return 0;
}

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

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#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 UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
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();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} Accelerate_Cin;

struct edge {
  int to, cost;
};

int N;
vector<edge> G[101010];
int d[101010];

void dfs(int n, int pre) {
  for (auto x : G[n]) {
    if (x.to != pre) {
      d[x.to] = d[n] + x.cost;
      dfs(x.to, n);
    }
  }
}

signed main() {
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--, v--;
    G[u].push_back({v, w});
    G[v].push_back({u, w});
  }

  dfs(0, -1);

  for (int i = 0; i < N; i++) {
    if (d[i] % 2 == 0) {
      cout << 0 << endl;
    } else {
      cout << 1 << endl;
    }
  }

  return 0;
}


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

using namespace std;

class Solution {
public:
	void solve() {
		int n;
		cin >> n;
		vector<int> a(n, 0);
		for (int i = 0; i < n; i++) cin >> a[i];
		int ans = 0;
		for (int i = 0; i < n; i += 2) {
			if (a[i] % 2) ans++;
		}
		cout << ans << "\n";

		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;
string a,b,u;
int s,s1;
int main() {
  cin>>a>>b;
  cin>>s>>s1;
  cin>>u;
  if(u==a) --s;
  else if(u==b) --s1;
  cout<<s<<" "<<s1<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int m = scan.nextInt();
    long k = scan.nextLong();

    long[] a = new long[n];
    long[] b = new long[m];
    long[] c = new long[n+1];
    long[] d = new long[m+1];

    for (int i=0;i<n;i++){
      a[i] = scan.nextLong();
    }

    for (int i=0;i<m;i++){
      b[i] = scan.nextLong();
    }

    for (int i=0;i<n;i++){
      c[i+1] = c[i]+a[i];
    }

    for (int i=0;i<m;i++){
      d[i+1] = d[i]+b[i];
    }

    int sum = 0;

    for (int i=0;i<=n;i++){
      int a1 = i;
      long a2 = c[i];
      if (c[i] > k){
        break;
      }
      long b2 = k-c[i];
      int b1 = search(d,b2);
      if (a1+b1>sum){
        sum = a1+b1;
      }
    }

    System.out.println(sum);
  }

  static int search(long[] a, long b){
    int ret = 0;

    int start = 0;
    int end = a.length-1;

    while (start < end){
      int mid = (int) (start+end+1)/2;

      if (a[mid] == b){
        return mid;
      }

      if (a[mid] < b){
        start = mid;
      }
      else{
        end = mid-1;
      }
    }
    return start;
  }
}


Measured memory_bytes: 66328
rgb = list(map(int, input().split(' ')))
r = rgb[0]
g = rgb[1]
b = rgb[2]
k = int(input())

for i in range(k):
    if(r >= g):
        g = g * 2
    elif(g >= b):
        b = b * 2

if (r < g < b):
    print('Yes')
else:
    print('No')


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

/*void f(int n,int cnt){
    int reverse=0;
    int temp=n;
    while(temp!=0){
        reverse=reverse*10+temp%10;
        temp/=10;
    }
    if(reverse==n) cnt++;
}*/

int main(){
    int a,b;
    cin>>a>>b;
    int cnt=0;
    for(int i=a;i<=b;i++){
        int reverse=0;
        int temp=i;
        while(temp!=0){
            reverse=reverse*10+temp%10;
            temp/=10;
        }
        if(reverse==i) cnt++;
    }
    cout<<cnt<<"\n";
    return 0;
}

Measured memory_bytes: 3616
read = lambda: map(int, input().split())
mod = 10 ** 9 + 7
n, m = read()
if abs(n - m) > 1:
    print(0)
    exit()
N = max(n, m) + 1
fac = [0] * N
fac[0] = 1
for i in range(1, N):
    fac[i] = (fac[i - 1] * i) % mod
if n == m:
    ans = (2 * fac[n] * fac[m]) % mod
else:
    ans = fac[n] * fac[m] % mod
print(ans % mod)

Measured memory_bytes: 40048
import sys


fin = sys.stdin.readline
N, Q = map(int, fin().split())
S = fin().rstrip("\n")
queries = tuple(tuple(int(elem) - 1 for elem in fin().split()) for _ in range(Q))

# [0, i]
prefix_num_ACs = [0] * len(S)
for i, char in enumerate(S[1:], start=1):
    if char == "C" and S[i - 1] == "A":
        prefix_num_ACs[i] = prefix_num_ACs[i - 1] + 1
    else:
        prefix_num_ACs[i] = prefix_num_ACs[i - 1]
# print(prefix_num_ACs)
for l, r in queries:
    num_ACs = prefix_num_ACs[r] - prefix_num_ACs[l]
    print(num_ACs)


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

#define crap ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define CN cout<<"No\n"
#define CY cout<<"Yes\n"

using namespace std;
using ll = long long;
void solve()
{
    string s;
    cin>>s;
    ll sum=0;
    for(auto e:s)
    {
        sum+=(e-48);
    }
    if(sum%9==0) CY;
    else CN;
}
int main()
{
    crap;
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r", stdin) ;
        freopen("output.txt","w", stdout) ;
        freopen("error.txt","w", stderr) ;
    #endif
    int t;t=1;
 //  cin>>t;
    while(t--)
        {solve();}
    return 0;
}

Measured memory_bytes: 3764
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define MN 100005
using namespace std;
inline int in(){
    int x=0;bool f=0;char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
struct st{
	int l,r,id;
}a[MN],b[MN];
ll res1,res2;
int n,tot,cur;
bool vis[MN],c;
inline bool cmp(st x,st y){
	return (x.r==y.r)?x.l<y.l:x.r<y.r;
}
inline bool cmp2(st x,st y){
	return (x.l==y.l)?x.r<y.r:x.l<y.l;
}

int main()
{
	n=in();
	for (int i=1;i<=n;++i){
		a[i].l=b[i].l=in();a[i].r=b[i].r=in();
		a[i].id=b[i].id=i;
	}sort(a+1,a+n+1,cmp);sort(b+1,b+n+1,cmp2);
	int hd=1,tl=n;c=tot=cur=0;
	while (tot<n){
		while (vis[a[hd].id]) ++hd;
		while (vis[a[tl].id]) --tl;c^=1;
		if (c){
			res1+=1ll*max(0,b[tl].l-cur);
			if (b[tl].l-cur>0) cur=b[tl].l;
			vis[a[tl].id]=1;--tl;++tot;
		}else{
			res1+=1ll*max(0,cur-a[hd].r);
			if (cur-a[hd].r>0) cur=a[hd].r;
			vis[a[hd].id]=1;++hd;++tot;
		}
	}res1+=1ll*abs(cur);
	hd=1,tl=n;c=1;tot=cur=0;
	memset(vis,0,sizeof(vis));
	while (tot<n){
		while (vis[a[hd].id]) ++hd;
		while (vis[a[tl].id]) --tl;c^=1;
		if (c){
			res2+=1ll*max(0,b[tl].l-cur);
			if (b[tl].l-cur>0) cur=b[tl].l;
			vis[a[tl].id]=1;--tl;++tot;
		}else{
			res2+=1ll*max(0,cur-a[hd].r);
			if (cur-a[hd].r>0) cur=a[hd].r;
			vis[a[hd].id]=1;++hd;++tot;
		}
	}res2+=1ll*abs(cur);
	printf("%lld",max(res1,res2));return 0;
}

Measured memory_bytes: 2560
N = int(input())
s = [int(input()) for i in range(N)]
S = sum(s)
b = []
for j in range(N):
  if s[j] % 10 !=0:
     b.append(s[j])
  else:
     pass

if S % 10 !=0:
    print(S)
elif len(b)==0:
    print(0)
else:
    print(S-min(b))

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, M;
char A[200][200], B[200][200];
bool ans = false;

int Solve(int I, int J){
  for (int i = 0; i < M; i++){
    for (int j = 0; j < M; j++){
      if (B[i][j] != A[I + i][J + j]) return 0;
    }
  }
  ans = true;
  return 0;
}

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

  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      Solve(i, j);
    }
  }

  if (ans) Yes();
  else No();

  return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ull unsigned long long int
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define of(i,p,n) for(ll i=n-1;i>=p;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define mem(x,p) memset(x,p,sizeof(x))
#define trav(it,a) for(auto it=a.begin();it!=a.end();++it)
#define kk "\n"
const ll mod=1e9+7;
int main()
{
  IOS
    string s;
    cin>>s;
    if(s[2]==s[3])
    {
      if(s[4]==s[5])
        cout<<"Yes";
      else
        cout<<"No";
    }
    else
      cout<<"No";
  return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  ProCon
//
//  Created by hashimotoryoma on 2017/08/20.
//  Copyright © 2017年 hashimotoryoma. All rights reserved.
//


#include <iostream>
//#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <queue>

using namespace std;

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

//const ll MOD = 1e9+7;

int N;
ll A[2*112345];
ll sum[2*112345];
map<ll,int> mp;
ll ans;

int main() {
    // insert code here...    return 0;
  //////
    // input from txt
    /*
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    std::ofstream out("output.txt");
    std::cout.rdbuf(out.rdbuf());
   ////
     */
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> A[i];
        sum[i] += A[i];
        mp[sum[i]]++;
        sum[i+1] = sum[i];
    }
    if(mp.find(0) != mp.end())
        ans += mp[0];
    for(auto itr = mp.begin();itr != mp.end(); itr++){
        ll n = itr->second;
        ans += n*(n-1)/2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15872
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per0(i, st, ed) for (int i = (st); i > ed; --i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
#define chmin(a, b) (a = a > b ? b : a)
#define chmax(a, b) (a = a < b ? b : a)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
template <class T> void out(const T &val) { cout << val << endl; }
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

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


int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        #if __cplusplus >= 201103L
        auto start = steady_clock::now();
        #endif
    #endif
    ll n;
    sf(n);
    ll ans = LONG_LONG_MAX;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ll t = i - 1 + n / i - 1;
            ans = min(t, ans);
        }
    }
    out(ans);
    #ifdef LOCAL
        #if __cplusplus >= 201103L
        auto end = steady_clock::now();
        duration<double> time_span = duration_cast<duration<double>>(end - start);;
        printf("Total time: %.6fs\n", time_span.count());
        #endif
    #endif
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
s = input()
q = []
for _ in range(Q):
  q.append(input().split())
q.reverse()

l = 0
r = N-1
for i in range(Q):
  t, d = q[i]
  if l-1 >= 0 and t == s[l-1] and d == 'R':
    l -= 1
  elif t == s[l] and d == 'L':
    l += 1

  if r+1 <= N-1 and t == s[r+1] and d == 'L':
    r += 1
  elif t == s[r] and d == 'R':
    r -= 1

print(max(0, r-l+1))

Measured memory_bytes: 39660
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second
//#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void println(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
//lambda: [](int x, int y){return x<y;}

int solve(string s, char c){
    set<char> set;
    int n = s.length();
    rfor(c, s) set.insert(c);
    if(n == 1 || set.size() == 1) return 0;
    string res = "";
    rep(i, n - 1) {
        if(s[i + 1] == c) res += {c};
        else res += {s[i]};
    }
    //cout << res << endl;
    return 1 + solve(res, c);
}

signed main(void) {
    string s; cin >> s;
    int ans = INT_MAX;
    rep(i, 26) {
        chmin(ans, solve(s, 'a' + i));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;
struct S{
	int x, y;
};
struct node {
	int x, y;
};

S s[100];
node no[100];

void run() {
	int n, m;
	while(cin >> n >> m) {
		for(int i = 1; i <= n; ++i)
			cin >> s[i].x >> s[i].y;
		for(int i = 1; i <= m; ++i)
			cin >> no[i].x >> no[i].y;
			
		for(int i = 1; i <=n; ++i) {
			int min_index = 0;
			int mix_value = 0x3f3f3f3f;
			for(int j = 1; j <= m; ++j) {
				int dis = abs(s[i].x - no[j].x) + abs(s[i].y - no[j].y);
				if(dis < mix_value) {
					mix_value = dis;
					min_index = j;
				}
			}
			cout << min_index << endl;
		}
	}
}
int main(int argc, char *argv[]) {
	//freopen("data.txt", "r", stdin);
	run();
}

Measured memory_bytes: 256