akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
int N;
int fp = 0;
int sp = 2;

long retrieve_lowest_diff(int mp, long sum[]){
    long l_min_diff = abs(sum[fp] - (sum[mp] - sum[fp]));
    long r_min_diff = abs(sum[sp] - sum[mp] - (sum[N-1] - sum[sp]));
    //cout << l_min_diff << ", " << r_min_diff << "\n";
    long new_l = l_min_diff;
    long new_r = r_min_diff;
    while (l_min_diff >= new_l) {
        l_min_diff = new_l;
        fp++;
        new_l = abs(sum[fp] - (sum[mp] - sum[fp]));
    }
    fp--;
    while (r_min_diff >= new_r){
        r_min_diff = new_r;
        sp++;
        new_r = abs(sum[sp] - sum[mp] - (sum[N-1] - sum[sp]));
    }
    sp--;
    long l1 = sum[fp];
    long l2 = sum[mp] - sum[fp];
    long r1 = sum[sp] - sum[mp];
    long r2 = sum[N-1] - sum[sp];
    long max_p = max(l1, max(l2, max(r1,r2)));
    long min_p = min(l1, min(l2, min(r1,r2)));
    return max_p - min_p;
}

int main(){
    cin >> N;
    long sum[N];
    for (int i = 0; i < N; i++){
        if (i == 0) cin >> sum[i];
        else{
            long tmp;
            cin >> tmp;
            sum[i] = sum[i-1] + tmp;
        }
    }

    long min_diff = long(pow(10, 15));

    for(int i = 1; i < N-1; i++){
        long tmp = retrieve_lowest_diff(i, sum);
        min_diff = min_diff > tmp ? tmp:min_diff;
    }
    cout << min_diff << "\n";

}

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

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    string s;
    cin >> s;
    string ans;
    for(char c : s){
        if(c == 'B'){
            if(ans.size() > 0){
                ans.erase(ans.size() - 1, 1);
            }
        }else{
            ans.push_back(c);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
struct node{
	long long y;
	long long n;
	int data;
}p[2000+5];
const int mod = 1e9+7;
long long poi[2000+5];
long long poiy[2000+5];
int main(){
	int n;
	long long m;
	cin>>n>>m;
	for(int i = 0;i < n;i++){
		cin>>p[i].data;
	}
	long long ans = ((1ll+m)*m)/2%mod;
	long long ans1 = ((m-1ll)*m)/2%mod;
	long long sum = 0;
	for(int i = 0;i < n;i++){
		for(int j = i+1;j < n;j++){
			if(p[i].data > p[j].data){
				sum = (sum+ans)%mod;
			}
		}
		for(int j = 0;j < i;j++){
			if(p[i].data > p[j].data){
				sum = (sum+ans1)%mod;
			}
		}
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()



int main() {
  int s, cnt = 1;
  cin >> s;
  vector<int> a(1e6+1, 0);
  a[s]++;
  while (true) {
    if (s % 2 == 0) s /= 2;
    else s = 3*s + 1;
    cnt++;
    if (a[s]) {
      cout << cnt << endl;
      return 0;
    }
    a[s]++;
  }
}

Measured memory_bytes: 4096
// --------------
// Tejas Pandey  |
// 05 - 10 - 19  |
// AGC #039      |
// --------------

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

#define mod 1000000007
#define vi vector<int>
typedef long long int ll;

int main (void)
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	//cin >> t;
	while(t--)
	{
		//cout << "Case #" << c-t << ": ";
		string s;
		cin >> s;
		ll k;
		cin >> k;
		ll ans = 0,start = 0,end = 0;
		int i = 0,c = 0;
		while(s[i] == s[0]) c++,i++;
		int j = i;
		start = c; c = 0,i = s.size() - 1;
		while(s[i] == s[s.size() - 1]) c++,i--;
		int ke = i;
		end = c;
		if(start == s.size()){
			cout << (k*s.size())/2;
			return 0;
		}
		c = 0;
		for(int i = j;i < ke;i++){
			if(s[i] == s[i + 1])
				c++;
			else
				ans += (c + 1)/2, c = 0;
		}
		ans += (c + 1)/2;
		ans = (ans * k);
		if(s[0] == s[s.size() - 1]){
			ll f = (start + end)/2;
			ans += (f * (k - 1));
			ans += start/2 + end/2;
		}
		else{
			ll f = start/2 + end/2;
			ans += (f * k);
		}
		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int m[2], d[2];
  cin >> m[0] >> d[0] >> m[1] >> d[1];
  if(d[0] - d[1] < 0)
    cout << 0 << endl;
  else
    cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INF -1


int matrix[MAX+1][MAX+1];
int n;
int Q[MAX+1];
int d[MAX+1];
int color[MAX+1];
int head = 0, tail = 0;

void enq(int x){
    Q[tail] = x;
    tail++;

    if( tail == MAX+1 ){
        tail = 0;
    }

}

int deq(){

    int n;
    n = Q[head];
    head++;

    if( head == MAX+1 ){
        head = 0;
    }

    return n;

}

void bfs(int s){

    int i,v,u;

    for( i = 0 ; i <= n ; i++ ){
        color[i] = WHITE;
        d[i] = INF;
    }

    color[s] = GRAY;
    d[s] = 0;
    enq(s);

    while( tail != head ){

        u = deq();

        for( i = 1 ; i <= n ; i++ ){

            if( color[i] == WHITE && matrix[u][i] == 1 ){

                color[i] = GRAY;
                d[i] = d[u]+1;

                enq(i);

            }
            
        }

        color[u] = BLACK;

    }

}

int main(){

    int i,j;
    int row,col;
    int num;

    scanf("%d",&n);


    for( i = 0 ; i <= n ; i++ ){
        for( j = 0 ; j <= n ; j++ ){
            matrix[i][j] = 0;
        }
    }

    for( i = 1 ; i <= n ; i++ ){

        scanf("%d",&row);
        scanf("%d",&col);

        for( j = 0 ; j < col ; j++ ){
            scanf("%d",&num);
            matrix[row][num] = 1;
        }

    }

    bfs(1);

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


    return 0;

}

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

int main(){
    ll N, M; cin >> N >> M;
    vector<ll> A(N+1), SUM(N+1);
    rep(i, 1, N + 1) cin >> A[i];
    rep(i, 1, N + 1) SUM[i] = SUM[i-1] + A[i];

    map<int, ll> MP;
    rep(i, 0, N + 1) MP[SUM[i] % M]++;
    ll ans = 0;
    for(auto e: MP){
        ans += e.second * (e.second-1) / 2;
    }
    cout << ans << endl;
}

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

int main() {
    int n, tmp;
    cin >> n;
    map<int, int>mp;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        mp[tmp]++;
    }
    auto it = mp.end();
    it--;
    ll side1 = 0, side2 = 0;
    while (true) {
        if (it->second >= 2) {
            if (side1 == 0) {
                side1 = it->first;
                if (it->second >= 4) {
                    side2 = it->first;
                    break;
                }
            } else {
                side2 = it->first;
                break;
            }
        }
        if (it == mp.begin()) break;
        it--;
    }
    ll ans = 0;
    if (side2 != 0) ans = side1 * side2;
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  int a[m];
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }
  int count = 0;
  for (int i = 0; i < m; i++) {
    if (a[i] > x) break;
    count++;
  }
  cout << min(count, m - count) << endl;
  return 0;
}


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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
 int N;cin>>N;vi s(N);int tot=0;
  rep(i,N){
    cin>>s[i];
    tot+=s[i];
  }
  if(tot%10 !=0)cout<<tot<<endl;
  else{
    sort(all(s));
    bool ok=false;
    for(int i=0;i<N;i++){
      if(s[i]%10 != 0 ){
        ok =true;
        cout<<tot-s[i]<<endl;
        break;
      }
    }
    if(!ok)cout<<0<<endl;
    
  }
}





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

int main() {
  string s;
  cin >> s;
  
  int count;
  bool bo = false;
  
  for (int i = 0; i < s.size(); i++) {
    count = 0;
    for (int j = 0; j < s.size(); j++) {
      if (s.at(i) == s.at(j)) {
        count++;
      }
      if (j == s.size() - 1) {
        if (count % 2 != 0) {
          bo = true;
          break;
        }
      }
    }
    if (bo) {
      break;
    }
  }
  if (bo) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}


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

#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

inline void Main() {
  // code
  int a;
  string s;
  cin >> a >> s;
  if(a>=3200) cout << s << endl;
  else cout << "red" << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
from string import ascii_lowercase

class BIT(): #1-indexed
    def __init__(self,n): #n: 要素数
        self.size=n
        self.bit=[0]*(n+1)
    def add(self,i,x): #i番目(1-indexed)にxを加算
        while i<=self.size:
            self.bit[i]+=x
            i+=i&-i
    def sum_1_to_i(self,i): #1番目からi番目(含む)までの総和(1-indexed)
        s=0
        while i>0:
            s+=self.bit[i]
            i-=i&-i
        return s
    def sum_i_to_j(self,i,j): #i番目からj番目(含む)までの総和(1-indexed)
        return self.sum_1_to_i(j)-self.sum_1_to_i(i-1)
    def reset(self): #初期化
        self.bit=[0]*(self.size+1)

def main():
    A=ascii_lowercase
    D=dict()
    for i,a in enumerate(A):
        D[a]=i
    n=int(input())
    S=list(input().strip())
    L=[BIT(n) for _ in range(26)]
    for i,s in enumerate(S):
        L[D[s]].add(i+1,1)
    q=int(input())
    for _ in range(q):
        k,a,b=input().split()
        if k=='1':
            i=int(a)-1
            s=S[i]
            L[D[b]].add(i+1,1)
            L[D[s]].add(i+1,-1)
            S[i]=b
        else:
            l=int(a); r=int(b)
            ans=0
            for i in range(26):
                ans+=L[i].sum_i_to_j(l,r)>0
            print(ans)
    
if __name__=='__main__':
    main()

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

int main(){
	//←gcc/g++、及びbits/stdc++.hの導入ができず死んでいる皆さん
	//Heiankyo Walking (本当に動的計画法を使っていますか？？？)
	int data,loop,loop2;
	cin >> data;
	int tox,toy;
	int mts,a,b,c,d;
	pair<int,int> lkg;
	for(loop=0;loop<data;loop++){
		cin >> tox >> toy;
		tox++;
		toy++;
		vector<vector<int>> routes(tox, vector<int>(toy,0));
		vector<vector<int>> rgt(tox, vector<int>(toy,1));
		vector<vector<int>> down(tox, vector<int>(toy,1));
		cin >> mts;
		for(loop2=0;loop2<tox;loop2++){
			down[loop2][toy-1]=0;
		}
		for(loop2=0;loop2<toy;loop2++){
			rgt[tox-1][loop2]=0;
		}
		for(loop2=0;loop2<mts;loop2++){
				cin >> a >> b >> c >> d;
				if(a!=c){
					if(a<c) rgt[a][b]=0;
					else rgt[c][d]=0;
				}else{
					if(b<d) down[a][b]=0;
					else down[c][d]=0;
				}
		}
		queue<pair<int,int>> Q;
		routes[0][0]=1;
		Q.push(make_pair(0,0));
		while(!Q.empty()){
			lkg=Q.front();
			Q.pop();
			if(rgt[lkg.first][lkg.second]){
				if(routes[lkg.first+1][lkg.second]==0){
					Q.push(make_pair(lkg.first+1,lkg.second));
				}
				routes[lkg.first+1][lkg.second]+=routes[lkg.first][lkg.second];
			}
			if(down[lkg.first][lkg.second]){
				if(routes[lkg.first][lkg.second+1]==0){
					Q.push(make_pair(lkg.first,lkg.second+1));
				}
				routes[lkg.first][lkg.second+1]+=routes[lkg.first][lkg.second];
			}
		}
		if(routes[tox-1][toy-1]){
			cout << routes[tox-1][toy-1] << endl;
		}else{
			cout << "Miserable Hokusai!" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3092
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif




#define int long long
#define rng(i,l,r) for(size_t i=(l);i<(r);++i)
#define rep(i,n) rng(i,0,n)
#define gnr(i,l,r) for(size_t i=(r)-1;i>=(l);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(obj) (obj).begin(), (obj).end()   //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend()//...,3,2,1

using namespace std;
//using ll = long long;


const int MOD = 1000000007;
const int INF = 1e18;

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

const double pi = acos(-1);



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


using Graph = vector<vector<int>>;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
//*max_element(ALL(vector))
//count(ALL(vector),num) -> n



void solve(){
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s; cin >> s;
    if(s=="ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
    
}



signed main() {
    solve();
    return 0;
}



Measured memory_bytes: 3648
while True:
  H,W=map(int,input().split())
  if H==0 and W==0:
    break
  for h in range(H):
    for w in range(W):
      if w==0 or w==W-1 or h==0 or h==H-1:
        print("#",end="")
      else:
        print(".",end="")
    print()
  print()


Measured memory_bytes: 7000
// 2020-08-11 22:41:57
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

using ull = unsigned long long;
int n;
vector<vector<int> > A;
vector<int> ST[2];
vector<int> UV[64][2];
void transpose() {
  rep(i, n) REP(j, i+1, n) swap(A[i][j], A[j][i]);
}
bool solve(int b) {
  A.assign(n, vector<int>(n, -1));
  rep(k, 2) {
    rep(i, n) {
      if(ST[k][i] == 0 && UV[b][k][i] == 1) {
        rep(j, n) {
          if(A[i][j] == 0) return false;
          A[i][j] = 1;
        }
      } else if(ST[k][i] == 1 && UV[b][k][i] == 0) {
        rep(j, n) {
          if(A[i][j] == 1) return false;
          A[i][j] = 0;
        }
      }
    }
    transpose();
  }
  rep(_, 2) {
    rep(k, 2) {
      rep(i, n) {
        if(ST[k][i] != UV[b][k][i]) continue;
        bool ok = false;
        vector<int> idx;
        int x = ST[k][i];
        rep(j, n) {
          if(A[i][j] == x) {
            ok = true;
          } else if(A[i][j] == -1) {
            idx.push_back(j);
          }
        }
        if(ok) continue;
        if(idx.size() == 0) return false;
        if(idx.size() == 1) A[i][idx[0]] = x;
      }
      transpose();
    }
  }
  vector<int> is, js;
  rep(k, 2) {
    rep(i, n) rep(j, n) {
      if(A[i][j] == -1) {
        if(k == 0) is.push_back(i);
        else js.push_back(i);
        break;
      }
    }
    transpose();
  }
  rep(i, is.size()) rep(j, js.size()) {
    A[is[i]][js[j]] = (i + j) % 2;
  }
  return true;
}
void answer() {
  cin >> n;
  rep(k, 2) rep(i, n) {
    int x;
    cin >> x;
    ST[k].push_back(x);
  }
  rep(k, 2) rep(i, n) {
    ull x;
    cin >> x;
    rep(j, 64) UV[j][k].push_back((x>>j)&1);
  }
  vector<vector<ull> > ans(n, vector<ull>(n, 0));
  rep(b, 64) {
    if(solve(b)) {
      rep(i, n) {
        rep(j, n) {
          ans[i][j] |= (ull(A[i][j])<<b);
        }
      }
    } else {
      cout << -1 << '\n';
      return;
    }
  }
  rep(i, n) {
    rep(j, n) {
      if(j) cout << ' ';
      cout << ans[i][j];
    }
    cout << '\n';
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 8900
def gcd(x, y):
    while y > 0:
        x, y = y, x%y
    return x

def lcm(x, y):
    return x/gcd(x, y)*y


a, b, c, d = (int(i) for i in input().split())
m = int(lcm(c, d))
#print(m)
print((b-a+1)-(int((b)//c)-int((a-1)//c))-(int((b)//d)-int((a-1)//d))+(int((b)//(m))-int((a-1)//(m))))
##print(m)
#print("b-a", (b-a+1))
#print(int((b)//c)-int((a-1)//c))
#print((int((b)//d)-int((a-1)//d)))
#print((int((b-1)//m)-int((a-1)//m)))


Measured memory_bytes: 38384
#include <iostream>
using namespace std;
 
int main() {
    int a, b, ttl, cnt;
    ttl = 1;
    cnt = 0;

    cin >> a >> b;

    while(1){
        if(b == 1){
            break;
        }
        ttl = ttl - 1;
        ttl = ttl + a;
        ++cnt;
        if(ttl>=b){
            break;
        }

    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

vector <string> ss;

void solve(void){
    string S;
    int K;
    cin >> S >> K;
    int L = (int)S.length();
    Rep(1, 10, l){
        rep(L-l+1, i) {
            ss.pb(S.substr(i, l));
        }
    }

    sort(all(ss));
    uniq(ss);
    /*
    for (auto s : ss){
        cout << s << endl;
    }*/

    cout << ss[K-1] << endl;

}

int main(void){
  solve();
  //cout << "yui(*-v・)yui" << endl;
  return 0;
}


Measured memory_bytes: 2936
N = int(input())
dic = {}
Max = 1

for _ in range(N):
  S = input()
  if not S in dic:
    dic[S] = 1
  else:
    dic[S] += 1
    Max = max([Max, dic[S]])

ans = []
    
for x in dic:
  if dic[x] == Max:
    ans.append(x)

ans_sorted = sorted(ans)
for y in range(len(ans)):
  print(ans_sorted[y])

Measured memory_bytes: 32988
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const LL mod = 1e9 + 7;
int n, m, K;
LL dp[21][1 << 19], pd[1 << 19][21];
int lim[21][21], pw2[21];
//inline void ADD(int &x,int &y){x = (x + y < mod) ? (x + y) : (x + y - mod);}
inline int lowbit(const int &i){ return i & (-i); }
#define add(x,y) ((x+y<mod)?(x+=y):(x+=y-mod))
void trans(int i)
{
	for (int s=0;s<(1<<n);s++)
	{
		memset(pd[s], 0, sizeof(pd[s][0]) * (n + 1));
		bool f = 1;
		for (int j=0;j<n;j++) if(~lim[i][j] && ((s >> j) & 1) != lim[i][j]){ f = 0; break; }
		pd[s][0] = (f ? dp[i - 1][s] : 0);
	}
	LL tmp;
	for (int i=0;i<n;i++) for (int s=0;s<(1<<n);s++) if(tmp = pd[s][i]) 
	{
		if(!((s >> i) & 1))
		{
			int t = pw2[n] ^ pw2[i + 1];
			t &= s;
			pd[s ^ lowbit(t) | (1 << i)][i + 1] += tmp;
		}
		pd[s][i + 1] += tmp;
	}
	for (int s=0;s<(1<<n);s++) dp[i][s] = pd[s][n] % mod;
}

int main()
{
	for (int i=0;i<=20;i++) pw2[i] = (1 << i) - 1;
	cin>>n>>m>>K;
	memset(lim, -1, sizeof lim);
	for (int i=0;i<K;i++){int x, y;cin>>x>>y;cin>>lim[x][y - 1];}
	n--;
	for (int s=0;s<(1<<n);s++)dp[0][s]=1;
	for (int i=1;i<=m;i++)trans(i);
	printf("%d\n", dp[m][(1 << n) - 1]);
}

Measured memory_bytes: 172416
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin >> n >> k;
	int h[n];
	for(int i = 0; i < n;i++)
	{
		cin >> h[i];
	}
	long long dp[n] = {0};
	dp[0] = 0;
	for(int i = 1; i < min(k,n);i++)
	{
		dp[i] = abs(h[i] - h[0]);
	}
	for(int i = k;i < n;i++)
	{
		dp[i] = 1000000000000;
		for(int j = 0; j < k;j++)
		{
			dp[i] = min(dp[i],dp[i-1-j] + abs(h[i] - h[i-1-j]));
		}
	}
	cout << dp[n-1] << endl;	

}

Measured memory_bytes: 1408
#  --*-coding:utf-8-*--

def main():
    N,M = map(int, input().split())

    X = [None]*N

    for _ in range(M):
        s, c = map(int, input().split())
        s -= 1
        
        if X[s] != None and X[s] != c:
            print(-1)
            return

        X[s] = c

    if N == 1 and (X[0] == None or X[0] == 0):
        print(0)
        return


    if X[0] == 0:
        print(-1)
        return

    if X[0] == None:
        X[0] = 1

    for i in range(N):
        if X[i] == None:
            X[i] = 0

    print(''.join(map(str, X)))


main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#pragma GCC optimize ("-O3")
    using namespace std;
    #define ll long long
    #define ld long double
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define pll pair<ll,ll>
    #define ff first
    #define ss second
    #define pb push_back
    #define deb(x) cout<<#x<<" : "<<x<<endl;
    #define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
    #define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define deb4(w,x,y,z) cout<<#w<<" : "<<w<<"\t"<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define printv(a)  for(ll i=0;i<a.size();i++)  cout<<a[i]<<" ";
   
   
    const int mod=998244353.;
    const int N=1e6+5; 
   
    bool sortbysec(const pair<pair<ll,ll>,ll> &a, 
                      const pair<pair<ll,ll>,ll> &b) 
        { 
            return (a.second > b.second); 
        } 
        ll powermod(ll x, ll y, ll p)
        {
            ll res = 1;
            x = x % p;
            while (y > 0)
            {
                if (y & 1) res = (res*x) % p;
                y = y>>1;
                x = (x*x) % p;
            }
            return res;
        }
       
        bool isprime(int n) 
        { 
            if (n <= 1)  return false; 
            if (n <= 3)  return true; 
            if (n%2 == 0 || n%3 == 0) return false; 
            for (int i=5; i*i<=n; i=i+6) 
                if (n%i == 0 || n%(i+2) == 0) 
                   return false; 
           return true; 
        }
      template <typename T>  void  max ( T& a,  T& b) {
  a=max(a,b);   
}
       bool first_row_or_first_col(pair<ll,ll> p){
       return (p.first ==0 || p.ss==0);
       }
        int main()
    {
        FAST;
       string s,t;
       cin>>s>>t;
       vector<vector<pair<ll,pair<ll,ll>>>>dp(s.size()+1,vector<pair<ll,pair<ll,ll>>>(t.size()+1,{0,{0,0}}));
       for(ll i=0;i<s.size();i++)
       {
           for(ll j=0;j<t.size();j++)
           {
               if(s[i]==t[j])
               {
                   dp[i+1][j+1]=max(dp[i+1][j+1],{dp[i][j].ff+1,{i,j}});
               }
               dp[i+1][j]=max(dp[i+1][j],{dp[i][j].ff,{i,j}});
               dp[i][j+1]=max(dp[i][j+1],{dp[i][j].ff,{i,j}});
           }
       }
       pair<ll,pair<ll,ll>> answer={0,{0,0}};
       for(ll i=0;i<=s.size();i++)
       {
           for(ll j=0;j<=t.size();j++)
           answer=max(answer,{dp[i][j].ff,{i,j}});
       }
      string ans;
      pair<ll,ll> cur=answer.ss;
      while(!first_row_or_first_col(cur))
      {
         ll i=cur.ff;
         ll j=cur.ss;
         pair<ll,ll> previous=dp[i][j].ss;
         if(previous==make_pair(i-1,j-1))
         {
             if(s[i-1]==t[j-1])
             ans+=s[i-1];
         }
         cur=previous;
      }
      reverse(ans.begin(),ans.end());
      cout<<ans<<"\n";
       
        return 0;
    }

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

int main(){
  string S;cin>>S;
  int s=0,e=0,n=0,w=0;
  for(int i=0;i<S.size();i++){
    if(S[i]=='S')s++;
    else if(S[i]=='E')e++;
    else if(S[i]=='N')n++;
    else w++;
  }
  if(0<s&&0<e&&0<n&&0<w)cout<<"Yes";
  else if((s==0&&0<n)||(n==0&&0<s))cout<<"No";
  else if((w==0&&0<e)||(e==0&&0<w))cout<<"No";
  else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
from math import *
PI = 3.1415926535898
res = []
while True:
	try:
		arr = map(int, raw_input().strip().split(','))
		res.append(arr)
	except EOFError:
		break
ans1 = 0
ans2 = 0
for x in res:
	if x[0]*x[0] + x[1]*x[1] == x[2]*x[2]:
		ans1 += 1
	elif x[0]==x[1]:
		ans2 += 1
print ans1
print ans2

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

#define ln '\n'
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

bool sqrt_table[17000];

bool is_sqrt(int x) {
    return sqrt_table[x];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    REP(i, 17000) sqrt_table[i] = false;
    FOR(i, 1, 130) sqrt_table[i * i] = true;

    int n, d;
    cin >> n >> d;
    VVI vv(n);
    REP(i, n) {
        REP(j, d) {
            int x;
            cin >> x;
            vv[i].push_back(x);
        }
    }

    int sum = 0;
    REP(i, n)FOR(j, i + 1, n - 1) {
        int dist = 0;
        REP(k, d) dist += (vv[i][k] - vv[j][k]) * (vv[i][k] - vv[j][k]);
        if(is_sqrt(dist)) sum++;
    }
    cout << sum << ln;
    return 0;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

n,x = li()
t = li()

ans = 0

for i in range(n-1):
    ans += min(t[i+1] - t[i], x)

ans += x

print(ans)

Measured memory_bytes: 25744
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200200;
int main(){
	int n; cin >> n;
	multiset<double> se;
	for(int i = 0; i < n; i++){
		int v; cin >> v;
		se.insert(v);
	}
	for(int i = 0; i < n - 1; i++){
		auto it = *se.begin(); se.erase(se.begin());
		auto ot = *se.begin(); se.erase(se.begin());
		se.insert((it + ot) / 2);
	}
	cout << fixed << setprecision(9) << *se.begin() << endl;
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def ball(nums):
    l = []
    r = []
    for i, num in enumerate(nums):
        if i == 0:
            l.append(num)
        elif l[-1] < num:
            l.append(num)
        elif len(r) == 0:
            r.append(num)
        elif r[-1] < num:
            r.append(num)
        else:
            return 'NO'
    return 'YES'

N = int(input())
# N = 1


for _ in range(N):
    nums = [int(e) for e in input().split()]
    # nums = [3, 1, 4, 2, 5, 6, 7, 8, 9, 10]
    # nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
    print(ball(nums))

Measured memory_bytes: 7712
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>	// upper_bound(A, A+N, num), lower_bound(A, A+N, num)
#include <functional>
#include <string>
#include <sstream>
#include <complex>
#include <vector>		// V[i],  push_back(x), pop_back(), insert(index, x), erase(index), sort(v.begin(), v.end(), greater<int>())
#include <list>			// push_front(x), push_back(x), pop_front(), pop_back(), insert(index, x)
#include <queue>		// push(x), front(), pop()
#include <deque>
#include <stack>		// push(x), top(), pop()
#include <map>			// M[key],  insert(key, val), erase(key), find(key), 
#include <set>			// insert(key), erase(key), find(key)

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

#define PI 3.141592653589793)
#define MOD 1000000007
#define REP(i, n) for(int i = 0; i < n; i++)

int N, M;
int box[100001];
bool flag[100001];

void solve() {
	cin >> N >> M;
	flag[0] = true;
	int ans = 1;
	for (int i = 0; i < M; i++) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		if (box[x] > 0 && flag[x]) {
			ans++;
			box[x]--;
			box[y]++;
			if (flag[y]) ans--;
			flag[y] = true;
		}
		else if (box[x] == 0 && flag[x]) {
			box[x]--;
			box[y]++;
			if (flag[y]) ans--;
			flag[x] = false;
			flag[y] = true;
		}
		else {
			box[x]--;
			box[y]++;
		}
	}
	cout << ans << endl;
}

int main() {
	solve();
	return 0;
}

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

using namespace std;
const int maxn=100000+5;

int fa[maxn];
int V,E;
void init(){
    for(int i=1;i<=V;i++)
        fa[i]=i;
}

int find(int x){
    int y=fa[x];
    for(;fa[y]!=y;y=fa[y]);
    while(x!=y){
        int temp=fa[x];
        fa[x]=y;
        x=temp;
    }
    return y;
}

void merge(int x,int y){
    int nx=find(x);
    int ny=find(y);
    if(nx!=ny){
        fa[nx]=ny;
    }
}
int main(){
    cin>>V>>E;
    init();
    while(E--){
        int in,out;
        cin>>in>>out;
        merge(in,out);
    }
    int T;
    cin>>T;
    while(T--){
        int x,y;
        cin>>x>>y;
        if(find(x)!=find(y)) cout<<"no"<<endl;
        else cout<<"yes"<<endl;
    }
}

Measured memory_bytes: 3468
#include<bits/stdc++.h>
using namespace std;
int c[101][101];
int main(){
	int W,H,N,x,y,a;
	cin>>W>>H>>N;
	for(int n=1;n<=N;n++){
		cin>>x>>y>>a;
		if(a==1){
			for(int i=0;i<x;i++){
				for(int j=0;j<H;j++){
					c[i][j]=1;
				}
			}
		}
		if(a==2){
			for(int i=x;i<W;i++){
				for(int j=0;j<H;j++){
					c[i][j]=1;
				}
			}
		}
		if(a==3){
			for(int i=0;i<W;i++){
				for(int j=0;j<y;j++){
					c[i][j]=1;
				}
			}
		}
		if(a==4){
			for(int i=0;i<W;i++){
				for(int j=y;j<H;j++){
					c[i][j]=1;
				}
			}
		}
	}
	int ans=0;
	for(int i=0;i<W;i++){
		for(int j=0;j<H;j++){
			if(!c[i][j]) ans++;
		}
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector> 
using namespace std;
long long int max_sum(long long int we[],long long int v[],long long int w,int n){
    long long int dp[n+1][w+1];
    for(int i=0;i<n+1;i++){
        for(int j=0;j<w+1;j++){
            if(i==0 || j==0) dp[i][j]=0;
            else if(j-we[i-1] >=0)
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-we[i-1]] + v[i-1]);
            else dp[i][j]=dp[i-1][j];
        }
    }
    return dp[n][w];
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    long long int w;
    cin>>n>>w;
    long long int we[n],v[n];
    // int a,b;
    // vector<vector<long long>> knap(n,vector<int>(2,-1));
    for(int i=0;i<n;i++){
        cin>>we[i]>>v[i];
        // cin>>a>>b;
        // knap[i].push_back(a);
        // knap[i].push_back(b);
    }
    cout<<max_sum(we,v,w,n);
	return 0;
}


Measured memory_bytes: 82408
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#define my_abs(x) ((x) < 0 ? -(x) : (x))
#define mp std::make_pair
#define pb push_back
using ll = long long;
std::vector<int> vec;
char str[100005];
int main()
{
	// freopen("ARC103-E.in", "r", stdin);
	scanf("%s", str);
	int n = strlen(str);
	if (str[n - 1] == '1' || str[0] == '0')
	{
		puts("-1");
		return 0;
	}
	for (int i = 0; i + 1 < n; i++)
	{
		if (str[i] != str[n - i - 2])
		{
			puts("-1");
			return 0;
		}
	}
	for (int i = 0; i + 1 < n; i++)
	{
		if (str[i] - '0')
		{
			for (int x : vec)
				printf("%d %d\n", i + 1, x + 1);
			vec.clear();
		}
		vec.pb(i);
	}
	for (int x : vec)
		printf("%d %d\n", n, x + 1);
	return 0;
}


Measured memory_bytes: 2040
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>


int main(){

    string s;
    ll n;
    cin >> n >> s;
    ll cnt = 0LL;
    ll r,g,b;
    r = g = b = 0LL;
    for(ll i=0LL;i < n;i++){
        if(s[i] == 'R') r++;
        if(s[i] == 'G') g++;
        if(s[i] == 'B') b++;
    }

    cnt = r * g * b;

    //補集合の要素数を全体集合の要素数から引く（r * g * b）

    //jとjから等距離にある文字がすべて異なる
    for(ll j = 1;j < n;j++){
        for(ll diff = 1;diff < n;diff++){
            if(j-diff >= 0LL && j + diff < n && s[j - diff] != s[j] && s[j] != s[j + diff] && s[j + diff] != s[j - diff]) cnt--;

        }
    }

    cout << cnt << endl;

    
    return 0;
}

Measured memory_bytes: 3612
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char[] c = str.toCharArray();
        
        int zero = 0;
        int one = 0;
        for (int i = 0; i < c.length; i++) {
            if (c[i] =='0') {
                zero++;
            } else {
                one++;
            }
        }
        
        System.out.println(Math.min(zero, one) * 2);
    }
}


Measured memory_bytes: 25812
#include <stdio.h>
int main ()
{
  int N1,N2,i,j,a,A[10000],A1[100000],k=0,key;
	scanf("%d",&N1);
	for(i = 0;i<N1;i++)scanf("%d",&A[i]);
	
	scanf("%d",&N2);
	for(i=0;i<N2;i++)
	{
		scanf("%d",&A1[i]);
		for(j=0;j<N1;j++)
		{
			if(A[j]==A1[i])
			 {
			 k++;
			 break;
			 }
		}
	}
	printf("%d\n",k);
	return 0;
}


Measured memory_bytes: 2104
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H;
	string s;
	while(cin>>s) {
		ll ans = -4+2*count(ALL(s), '+');
		cout<<ans<<endl;
	}
	
	return 0;
}


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

struct map{
	int w1, w2, h1, h2;
};

int main()
{
	while (1){
		int w, h;
		cin >> w >> h;
		if (!w && !h){ break; }

		map cross[101][101];
		for (int i = 0; i <= w; i++){
			for (int j = 0; j <= h; j++){
				cross[i][j] = { 0, 0, 0, 0 };
			}
		}

		cross[2][1].w1 = 1;
		cross[1][2].h1 = 1;

		for (int i = 1; i <= w; i++){
			for (int j = 1; j <= h; j++){
				cross[i][j].w1 += (cross[i - 1][j].w1 + cross[i - 1][j].w2) % 100000;
				cross[i][j].w2 += cross[i - 1][j].h1 % 100000;
				cross[i][j].h1 += (cross[i][j - 1].h1 + cross[i][j - 1].h2) % 100000;
				cross[i][j].h2 += cross[i][j - 1].w1 % 100000;
			}
		}
		cout << (cross[w][h].w1 + cross[w][h].w2 + cross[w][h].h1 + cross[w][h].h2) % 100000 << endl;
	}
	return 0;
}

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

#define ll long long
#define ull unsigned long long 
#define endl '\n'
#define pii pair<int, int>
#define all(a) a.begin(),a.end()

template <typename T>
inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; }

int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i=0; i<n; ++i){
        cin >> a[i];
    }
    for(int i=0; i<n; ++i){
        cin >> b[i];
    }

    vector<int> p(n), s(n);
    p[0] = a[0];
    s[n-1] = b[n-1];
    for(int i=1; i<n; ++i){
        p[i] = a[i]+p[i-1];
    }
    for(int i=n-2; i>=0; --i){
        s[i] = b[i]+s[i+1];
    }

    int ans = 0;
    for(int i=0; i<n; ++i){
        ans = max(ans, p[i]+s[i]);
    }
    cout << ans;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAXN 100005
#define INF 1000000000000000LL
#define MOD 1000000007
#define pb push_back
 
typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;

int n, k;
int dp[MAXN];
int v[105];
 
int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(0);
 
	cin >> n >> k;

	for(int i = 1; i <= n; i++) cin >> v[i];
 
	sort(v + 1, v + n + 1);

	for(int i = 1; i <= k; i++){
		for(int j = 1; j <= n; j++){
			if(v[j] > i) break;
			if(!dp[i - v[j]]) dp[i] = 1;
		}
	}

	cout << (dp[k] ? "First" : "Second") << endl;

	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
const int N = 15;
int main()
{
	int n, S[N] = {0}, H[N] = {0}, C[N] = {0}, D[N] = {0};
	
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
	{
		int p;
		char k;
		scanf(" %c %d", &k, &p);
		if(k == 'S')
		{
			S[p]++;
		}
		else if(k == 'H')
		{
			H[p]++;
		}
		else if(k == 'C')
		{
			C[p]++;
		}
		else if(k == 'D')
		{
			D[p]++;
		}				
	}
	for(int j = 1; j <= 13; j++)
	{
		if(S[j] == 0)
		{
			printf("S %d\n", j);
		}
	}
	for(int j = 1; j <= 13; j++)
	{
		if(H[j] == 0)
		{
			printf("H %d\n", j);
		}
	}
	for(int j = 1; j <= 13; j++)
	{
		if(C[j] == 0)
		{
			printf("C %d\n", j);
		}
	}
	for(int j = 1; j <= 13; j++)
	{
		if(D[j] == 0)
		{
			printf("D %d\n", j);
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}


Measured memory_bytes: 2608
N, K = (int(x) for x in input().split())
list = [0] * N
# K個のお菓子について
for i in range(K):
    d = int(input())
    for j in (int(x) for x in input().split()):
        list[j-1] = 1
count = 0
for i in list:
    if i == 0:
        count += 1
print(count)


Measured memory_bytes: 9180
n=int(input())
s=input().split()
l=[int(s[i]) for i in range(n)]
su=sum(l)
best=10000000000000000
res=0
for i in range(n):
  if(abs(su-n*l[i])<best):
    best=abs(su-n*l[i])
    res=i
print(res)


Measured memory_bytes: 38256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func readLine() []string {
	rdr := bufio.NewReaderSize(os.Stdin, 1000000)
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return strings.Split(string(buf), " ")
}

func readAsInts(strs []string) []int {
	ret := make([]int, len(strs))
	for i, v := range strs {
		j, err := strconv.Atoi(v)
		if err != nil {
			panic("fail to convert")
		}
		ret[i] = j
	}
	return ret
}

func main() {
	vals := readAsInts(readLine())
	subs := vals[2] - (vals[0] - vals[1])
	var ans int
	if subs < 0 {
		ans = 0
	} else {
		ans = subs
	}
	fmt.Printf("%v\n", ans)
}


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

int main(){
  int n,mi=100000000,sum,count=0;
  cin >> n;
  vector<int> v(n,0);
  r(i,n)cin >> v.at(i);
  sum=accumulate(v.begin(),v.end(),0);
  r(i,n){
    count+=v.at(i);
    mi=min(mi,abs(sum-2*count));
  }
  cout << mi << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
l = list()
r = list()
for i in range(m):
    a, b = map(int, input().split())
    l.append(a)
    r.append(b)

if min(r) >= max(l):
    print(min(r) - max(l) + 1)
else:
    print(0)

Measured memory_bytes: 10996
import sys
import itertools
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


n = int(readline())
# n = 10**4
# n = 1700 ** 0.5
# print(n)

l = [0]*(10**5)
# for x in range(1, 101):
#     for y in range(1, 101):
#         for z in range(1, 101):
#             i = x ** 2 + y ** 2 + z ** 2 + x*y + y*z + z*x
#             l[i] += 1

pattern = list(itertools.combinations_with_replacement(range(1, 101), 3))
# print(len(pattern))
# print(pattern[:10:])
for p in pattern:
    x, y, z = p

    i = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
    if len(set(p)) == 3:
        l[i] += 6
    elif len(set(p)) == 2:
        l[i] += 3
    else:
        l[i] += 1

    # print(x, y, z)
# for x in range(1, 101):
#     for y in range(1, 101):
#         for z in range(1, 101):
#             i = x ** 2 + y ** 2 + z ** 2 + x*y + y*z + z*x
#             l[i] += 1

for j in range(1, n+1):
    print(l[j])
# # print(l[1:100:])
# print(l[1:n:])


Measured memory_bytes: 22192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solveA();
		// new Main().solveB();
		// new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int numA = 0;
		int numB = 0;

		try {
			scanner = new Scanner(System.in);
			numA = scanner.nextInt();
			numB = scanner.nextInt();

			System.out.println(Math.max(numA + numB, Math.max(numA - numB, numA * numB)));

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 21844
def max2(x,y):
    return x if x > y else y

N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

off = max(C)
m2 = off
for i in range(N):
    tmp = 0
    m1 = off
    l = i
    S = 0
    k = 0
    for j in range(N):
        S += C[l]
        l = P[l] - 1
        if l==i:
            k = j+1
            break
    cnt = K // k - (K % k == 0)
    cnt = max2(0, cnt -2)
    a = K-cnt*k
    l = i
    for j in range(a):
        tmp += C[l]
        m1 = max2(m1, tmp)
        l = P[l] - 1
    if S > 0:
        m1 += cnt*S
    m2 = max2(m1, m2)

print(m2)
"""
2 4
2 1
10 -7
"""


Measured memory_bytes: 74260