akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bits/stdc++.h>
#define index indexxx
using namespace std;
int n;
int p[10000],m[1000][1000];
int index;
int fun(int left,int right)
{
	if(m[left][right]!=0)
		return m[left][right]; 
	if(left==right){
		return 0;
	}
	int i=left,j=right;
	int u=fun(left,left)+fun(left+1,right)+p[i-1]*p[i]*p[j];
	for(int k=i+1;k<j;k++){//遍历
		int t=fun(i,k)+fun(k+1,right)+p[i-1]*p[k]*p[j]; 
		if(t<u)
		{
			u=t;
		}
	}
	m[left][right]=u;
	return u;
}

int main(void)
{
	cin>>n;
	scanf("%d",p+(index++));
	scanf("%d",p+(index++));
	int tmp,x;
	for(int i=1;i<n;i++){
		scanf("%d",&x);
		scanf("%d",p+(index++));
	}
	printf("%d\n",fun(1,n));
	return 0;
}


Measured memory_bytes: 3560
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end

# 入力値を文字の配列で返却する
def gets_nsp_list()
  gets.chomp.split("")
end

# [a, b].min が遅いので
def min(a, b)
  return a < b ? a : b
end

N = gets_i
s_list = gets_nsp_list

w_count, e_count = 0, 0
counts = s_list.map do |s|
  if s == "W"
    w_count += 1
  else
    e_count += 1
  end
  [w_count, e_count]
end

total = N
N.times do |i|
  l = i - 1 >= 0 ? counts[i - 1][0] : 0
  r = counts[N-1][1] - counts[i][1]
  total = min(total, l + r)
end

puts total

Measured memory_bytes: 36852
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline

M, D = map(int, input().split())

ans = 0
for i in range(1, M + 1):
    for j in range(10, D + 1):
        a, b = map(int, list(str(j)))
        if a >= 2 and b >= 2:
            if a * b == i:
                ans += 1

print(ans)

Measured memory_bytes: 3064
N=int(input())
s=[input() for _ in range(N)]
M=int(input())
t=[input() for _ in range(M)]

ans=0

for i in range(N):
    ans_s=s.count(s[i])
    ans_t=t.count(s[i])
    if ans<ans_s-ans_t:
        ans=ans_s-ans_t

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           ((ll)x.size())
#define hell            (1000000007)
#define inf             ((ll)5e18 + 5)
#define PI              ((double)3.14159265358979323844)
#define DECIMAL(n)      cout << fixed << setprecision(n);
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define bitcount(a)     (ll)__builtin_popcount(a)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

void solve() {
    ll n;
    cin>>n;
    ll arr[n];
    rep(i,0,n){
        cin>>arr[i];
    }
    sort(arr,arr+n,greater <ll> ());
    n--;
    if (n%2){
        ll sumi=0;
        rep(i,1,1+(n-1)/2){
            sumi+=arr[i];
        }
        cout<<2*sumi+arr[0]<<endl;
    }
    else{
        ll sumi=0;
        rep(i,1,1+(n-1)/2){
            sumi+=arr[i];
        }
        cout<<arr[0]+2*sumi + arr[1+(n-1)/2]<<endl;
    }
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

Measured memory_bytes: 5216
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include <cmath>
#include<bits/stdc++.h>
//for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<n;i++) cin >> x[i];
#define pi pair<int,int> 
using namespace std;
using ll = long long;
int main(){
    int n; cin >> n;
    int p[n];
    int res=0;
    for(int i=0;i<n;i++){
        cin >> p[i];
        if(p[i]!=i+1) res++;
    }
    if(res<=2) cout << "YES";
    else cout <<"NO";
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
sys.setrecursionlimit(10**6)

x,y,a,b,c = na()
p = na()
q = na()
r = na()
p = sorted(p, reverse=True)[:x]
q = sorted(q, reverse=True)[:y]
z = sorted(p+q+r, reverse=True)[:x+y]

print(sum(z))

Measured memory_bytes: 103020
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define sym cout<<"-----------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

#define MAX 1005
int JOI[MAX][MAX];
int mark[2][2];
int count_coin[MAX][MAX][4];
int used[MAX][MAX];

signed main(){
  int m,n;
  cin>>m>>n;
  for(int i=1; i<=m; i++){
    for(int j=1; j<=n; j++){
      char ch;
      cin>>ch;
      if(ch=='J') JOI[i][j]=1;
      else if(ch=='O') JOI[i][j]=2;
      else JOI[i][j]=3;
    }
  }
  for(int i=0; i<2; i++) for(int j=0; j<2; j++){
    char ch;
    cin>>ch;
    if(ch=='J') mark[i][j]=1;
    else if(ch=='O') mark[i][j]=2;
    else mark[i][j]=3;
  }
  
  int cnt_four=0;
  for(int i=1; i<=m-1; i++){
    for(int j=1; j<=n-1; j++){
      bool four=true;
      bool trash=false;
      int num=0;
      P where;
      for(int k=0; k<2; k++){
        for(int l=0; l<2; l++){
          if(JOI[i+k][j+l]!=mark[k][l]){
            if(four) {
              four=false;
              where.first=i+k; where.second=j+l;
              num=mark[k][l];
            }
            else trash=true;
          }
        }
      }
      if(four){
        cnt_four++;
        used[i][j]=used[i+1][j]=1;
        used[i][j+1]=used[i+1][j+1]=1;
      }else if(!trash&&!four){
        count_coin[where.first][where.second][num]++;
      }
    }
  }
  
  int maxl=0;
  for(int i=1; i<=m; i++){
    for(int j=1; j<=n; j++){
      for(int k=1; k<=3; k++){
        int c;
        if(used[i][j]) c=count_coin[i][j][k]-1;
        else c=count_coin[i][j][k];
        maxl=max(maxl,c);
      }
    }
  }
  cout<<cnt_four+maxl<<en;
}




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

int main(){
  int N;
  cin>>N;
  long long A[N];
  long long S[N+1];
  S[0]=0;
  for(int i=0;i<N;i++){
    cin>>A[i];
    S[i+1]=S[i]+A[i];
  }
  sort(S,S+N+1);
  map<long long,long long>mp;
  for(int i=0;i<N+1;i++){
    mp[S[i]]++;
  }
  long long ans=0;
  for(auto itr=mp.begin();itr !=mp.end();itr++){
    long long temp=itr->second;
    if(temp>1){
      ans+=temp*(temp-1)/2;
    }
  }
  cout<<setprecision(18)<<ans<<endl;
  return 0;
}


Measured memory_bytes: 15872
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<List<Integer>> g = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            g.add(new ArrayList<>());
        }
        int[] B = new int[N];
        for (int i = 0; i < N-1; i++) {
            int a = sc.nextInt()-1;
            int b = sc.nextInt()-1;
            g.get(a).add(b);
            B[i] = b;
        }

        int K = 0;
        int[] color = new int[N];
        // BFS
        LinkedList<Vtx> q = new LinkedList<>();
        q.offer(new Vtx(0, 0));
        while (!q.isEmpty()) {
            Vtx v = q.poll();
            List<Integer> list = g.get(v.idx);
            int childColor = 1;
            for (int i : list) {
                if (childColor == v.color) {
                    childColor++;
                }
                q.offer(new Vtx(i, childColor));
                color[i] = childColor;
                K = Math.max(K, childColor);
                childColor++;
            }
        }

        System.out.println(K);
        for (int i = 0; i < N-1; i++) {
            System.out.println(color[B[i]]);
        }
    }

    private static class Vtx {
        final int color;
        final int idx;
        Vtx(int idx, int color) {
            this.idx = idx;
            this.color = color;
        }
    }
}


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

using ll = long long; 

signed main() {
  ll h,w,a,b;
    cin>>h>>w>>a>>b;
  for(int i=0;i<h;i++){
    if(i<b){
    	string s(a,'0');
    	string t(w-a,'1');
    	s+=t;
    	cout<<s<<endl;
    }
    else{
      string s(a,'1');
    	string t(w-a,'0');
    	s+=t;
    	cout<<s<<endl;
  }
  }
}


Measured memory_bytes: 1280
let () = Scanf.scanf "%d %d %d\n" @@ fun n k q ->
  let as_ = Array.init q @@ fun _ -> Scanf.scanf "%d\n" @@ fun a -> a in
  let ans = Array.make n 0 in
  Array.iter (fun a ->
    ans.(a - 1) <- 1 + ans.(a - 1)) as_;
  for i = 0 to n - 1 do
    print_endline @@
    if 0 < k + ans.(i) - q
    then "Yes"
    else "No"
  done


Measured memory_bytes: 6400
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, m;std::cin >> n >> m;
  std::cout << (n==m?"Yes":"No") << '\n';
  return 0;
}


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

typedef long long ll;
const ll INF = 1LL << 60;

ll N, R;
int main() {
    cin >> N >> R;
    if (N >= 10) {
        cout << R << endl;
    } else {
        cout << R + 100 * (10 - N) << endl;
    }
}

Measured memory_bytes: 256
n=int(input())
sec=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
    sec[i][0]+=sec[i][1]
    sec[i][1]*=-2
    sec[i][1]+=sec[i][0]
sec.sort()

ans=0
#-inf
t=-10000000000
for i in range(n):
    #=をつけるのを忘れずに
    if t<=sec[i][1]:#スタートがロボットアームのある最大の座標以上でなければならない
        ans+=1#以上なら+1
        t=sec[i][0]#ロボットアームのある最大の座標を更新
print(ans)


Measured memory_bytes: 27872
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=sum(b)
for i in range(1, n):
  if a[i]==a[i-1]+1:
    ans+=c[a[i-1]-1]
print(ans)

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

int ten(int d) { int res = 1; rep(i, d)res *= 10; return res; }
int gcd(int a, int b) { if (!b)return a; return gcd(b, a%b); }
int main() {
	string s; cin >> s;
	if ((int)s.find('(') == -1) {
		int d = s.size() - s.find('.') - 1;
		int k = ten(d);
		s.erase(s.begin() + s.find('.'));
		int x = stoi(s);
		int gc = gcd(x, k);
		cout << x / gc << '/' << k / gc << endl;
		return 0;
	}
	int d = s.size() - s.find('(') - 2;
	int k = s.find('(') - s.find('.') - 1;
	int t = ten(d);
	string v = s.substr(0, s.find('('));
	v.erase(v.begin() + v.find('.'));
	int x = stoi(v);
	s.erase(s.begin() + s.find('.'));
	s.erase(s.begin() + s.find('('));
	s.pop_back();
	int y = stoi(s);
	int gc = gcd(ten(d + k) - ten(k), y - x);
	cout << (y - x) / gc << '/' << (ten(d + k) - ten(k)) / gc << endl;
}

Measured memory_bytes: 3172
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        char a = in.nextChar();
        
        if (a == 'A') {
            out.println("T");
        } else if (a == 'T') {
            out.println("A");
        } else if (a == 'C') {
            out.println("G");
        } else if (a == 'G') {
            out.println("C");
        }

    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}

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

using namespace std;

int main() {
    string C;  
    cin >> C;
    char A = C[0];
    bool c = false;

    for (int i = 1;i < 3;i++) {
        if (C[i] != A) {
            c = true;
        } else {
            A = C[i];
        }
    }

    if (c) {
        cout << "Yes" << endl;      
    } else {
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 256
s = input()
mmax = 0
n = len(s)
while(n>1):
  s = s[0:n-1]
  n = len(s)
  if n<2:
    break
  if s[0:int(n/2)]==s[int(n/2):n]:
    mmax = max(mmax, n)
print(mmax)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
void YN(bool ans){
    if(ans)cout<<"Yes"<<endl;
    else cout <<"No"<<endl;
    return;
}
int main(){
    v ok ={0,4,8,12,16,20,24,7,11,15,19,23,14,18,22,26,21,25};
    ll N;
    cin>>N;
    if(N<28){
        rep(i,0,ok.size())if(ok[i] == N){
            YN(1);
            return 0;
        }
        YN(0);return 0;
    }
    YN(1);
    return 0;
}

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

int main(){
    int q, c, a, n;
    cin >> q;
    while(q-- > 0){
        cin >> c >> a >> n;
        int can, cca, ccc;
        
        can = min(c, min(a,n));
        c -= can, a -= can, n -= can;
        
        cca = min(c/2, a);
        c -= cca*2, a -= cca;
        
        ccc = c/3;
        c -= ccc*3;
        
        cout << can+cca+ccc << endl;
    }
    return 0;
}



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

int gcd(int a, int b){
	if(!a) return b;
	return gcd(b%a,a);
}

signed main() {
  int N, X;
  cin >> N >> X;
  
  vector<int> A(N+1);
  A.at(0) = X;
  for( int i = 1; i <= N; i++ ) cin >> A.at(i);
  sort(A.begin(), A.end());
  
  vector<int> SA(N);
  for( int i = 1; i <= N; i++ ){
    SA.at(i-1) = A.at(i) - A.at(i-1);
  }
  
  if( N == 1 ){
    cout << SA.at(0) << endl;
    return 0;
  }
  
  int ans = gcd(SA.at(0), SA.at(1));
  for( int i = 2; i < N; i++ ){
    ans = gcd(ans, SA.at(i));
  }
  
  cout << ans << endl;
  
  
  
  
  
}

Measured memory_bytes: 1792
#include <iostream>
#include <assert.h>
#include <algorithm>
#include <vector>

struct point
{
    int32_t x;
    int32_t y;
    bool checked;
    point()
    { x = 0; y = 0; checked = false;}
    point(int32_t x, int32_t y, bool checked)
        :x(x), y(y), checked(checked)
    {}
    bool operator<(const point &rth) const{
        return x < rth.x;
    }
    bool can_make_friend(const point &rth) const{
        return (x < rth.x) && (y < rth.y);
    }
};

bool greater_cmp(const point &a, const point &b){
    return a.y > b.y;
}


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

    int32_t N;
    std::cin >> N;
    assert(1 <= N);
    std::vector<point> reds(N);
    std::vector<point> blues(N);
    for(auto& i : reds){
        std::cin >> i.x >> i.y;
        i.checked = false;
    }
    for(auto& i : blues){
        std::cin >> i.x >> i.y;
        i.checked = false;
    }
    std::sort(reds.begin(), reds.end(), greater_cmp);
    std::sort(blues.begin(), blues.end());

    int32_t num_pair = 0;
    for(int32_t red_idx = 0; red_idx < N; red_idx++){
        for(int32_t blued_idx = 0; blued_idx < N; blued_idx++){
            if(blues[blued_idx].checked) continue;
            if(reds[red_idx].can_make_friend(blues[blued_idx])){
                num_pair++;
                blues[blued_idx].checked = true;
                break;
            }
        }
    }

    std::cout << num_pair << std::endl;
    return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>
#include <map>
#include <time.h>
#include <iomanip>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

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

    int ren = 0;
    int max = 0;

    rep(i, 0, n) {
        int a, b;
        cin >> a >> b;

        if(a == b) {
            ren++;
            if(ren > max) max = ren;
        }else {
            ren = 0;
        }
    }

    if(max >= 3) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3652
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut graph = vec![vec![]; n];
    let mut inv = vec![vec![]; n];
    for _ in 0..m {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        graph[a].push(b);
        inv[b].push(a);
    }

    let p = calc(&graph, &inv, (n, n));
    let mut ans = p[0];
    for from in 0..n {
        if graph[from].len() <= 1 {
            continue;
        }
        let to = *graph[from]
            .iter()
            .max_by(|&&to1, &&to2| p[to1].partial_cmp(&p[to2]).unwrap())
            .unwrap();
        let ans1 = calc(&graph, &inv, (from, to))[0];
        if ans > ans1 {
            ans = ans1;
        }
    }

    println!("{}", ans);
}

fn calc(graph: &Vec<Vec<usize>>, inv: &Vec<Vec<usize>>, (from, to): (usize, usize)) -> Vec<f64> {
    let n = graph.len();
    let mut p = vec![0.0; n];
    for i in (0..n).rev() {
        for &prev in inv[i].iter() {
            if (prev, i) == (from, to) {
                continue;
            }
            let mut count = graph[prev].len() as f64;
            if prev == from {
                count -= 1.0;
            }
            p[prev] += (p[i] + 1.0) / count;
        }
    }
    p
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 8444
#include <iostream>

#define _USE_MATH_DEFINES

#include <cmath>

using namespace std;

class point{
public:
	double x, y;
	int set_x();
	int set_y();
};

int point::set_x()
{
	cin >> x;
	return 0;
}
int point::set_y()
{
	cin >> y;
	return 0;
}

int main()
{
	point P[1000] = {};
	int n;
	int i;
	double d1 = 0, d2 = 0, d3 = 0, d4 = 0;
	double max = 0;

	cin >> n;

	for (i = 0; i < n; i++){
		P[i].set_x();
	}

	for (i = 0; i < n; i++){
		P[i].set_y();
	}

	for (i = 0; i < n; i++){
		d1 += abs(P[i].x - P[i].y);
		d2 += abs(P[i].x - P[i].y) * abs(P[i].x - P[i].y);
		d3 += pow(abs(P[i].x - P[i].y), 3);
		if (max < abs(P[i].x - P[i].y))
			max = abs(P[i].x - P[i].y);
	}

	d2 = sqrt(d2);
	d3 = pow(d3, 1.0 / 3.0);
	d4 = max;

	cout << fixed << d1 << endl << d2 << endl << d3 << endl << d4 << endl;

	return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    string s,t;cin>>s>>t;
    ll res = 0;
    rep(i,3){
        if(s[i] == t[i])res++;
    }
    out(res);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include <iomanip>
#include<deque>
#include<stack>
#include<set>
#include <numeric>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;




int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================


	ll X, Y;
	cin >> X >> Y;

	ll ans = 0;
	while (X<Y) {
		ans++;
		X *= 2;
	}

	if (X == Y) {
		cout << ans + 1;
	}
	else {
		cout << ans;
	}

}	




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

typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    for(int i=1; i<=9; i++){
        for(int j=1; j<=9; j++){
            if(i*j == n){
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
    return 0;
}


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

int main(){
    int n, y;
    cin >> n >> y;
    vector<int> ans(3, -1);
    rep(i, n+1){
        for (int j = 0; i+j < n+1; ++j){  // j < n+1の時, kが負の場合も受け入れてしまう
            int k = n - i - j;
            if(i+j+k == n && y == i*10000 + j*5000 + k*1000) {  //条件の自由度分のループで済む
                ans.at(0) = i;
                ans.at(1) = j;
                ans.at(2) = k;
            }
        }
    }

    rep(i, 3) cout << ans.at(i) <<" ";
    cout << "" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (int argc, char *argv[]) {
int length;

    do{
        scanf("%d",&length);
    }while(length < 2 && length >100);
    int tank;
    scanf("%d", &tank);       
    int max = tank;
    int min = tank;

    for(int i = 1; i < length; i++){
       scanf("%d", &tank);
       if(max < tank)  max = tank;
       if(tank < min)  min = tank;
    }
    printf("%d \n",max-min);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{
	int n,l,r,ans;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>l>>r;
		ans+=r-l+1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  100005

void solve()
{
    ll n;
    cin>>n;
    double p[n+1],o=1;
    rep(i,0,n)
    cin>>p[i];
    double dp[n+1][n+1];
    memset(dp,0,sizeof(dp));
    dp[0][0]=o-p[0];
    dp[0][1]=p[0];
    rep(i,1,n)
    {
        //if tail 
        rep(j,0,i+1)
        {
            dp[i][j]+=dp[i-1][j]*(o-p[i]);
            dp[i][j+1]+=dp[i-1][j]*p[i];
        }
    }
    double ans=0;
    rep(i,(n+1)/2,n+1)
    ans+=dp[n-1][i];
    cout<<setprecision(10)<<ans<<endl;

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 74140
# https://atcoder.jp/contests/abc157/tasks/abc157_e
# セグメント木
# 各文字をビットに対応させる(セグ木を26本持っても良い)
import sys
read = sys.stdin.readline
from functools import reduce


def read_a_int():
    return int(read())


class SqrtDecomposedList:
    def __init__(self, ls, segfunc, identity_element):
        from math import sqrt
        from copy import copy
        self.f = segfunc  # queryのfunction
        self.ide = identity_element
        self.n = len(ls)
        self.ls = copy(ls)
        self.b = int(sqrt(self.n)) + 1
        self.bucket = [self.ide] * (self.b + 1)
        self._build()

    def _build(self):
        for d in range(self.b):
            self.bucket[d] = reduce(
                self.f, self.ls[(d * self.b):((d + 1) * self.b)], self.ide)
        # for i, v in enumerate(self.ls):
        #     self.bucket[i // self.b] = \
        #         self.f(v, self.bucket[i // self.b])

    def __getitem__(self, idx):
        return self.ls[idx]

    def update(self, i, x):
        '''i番目の要素をxに更新する O(√n)'''
        self.ls[i] = x
        s = i // self.b * self.b
        t = s + self.b
        # print(i, self.b, i // self.b, s, t)
        self.bucket[i // self.b] = reduce(self.f,
                                          self.ls[s:t], self.ide)

    def query(self, l, r):
        '''半開区間[l,r)で指定すること O(√n)'''
        if r - l < 2 * self.b:
            return reduce(self.f, self.ls[l:r])
        l_bucket = (l - 1) // self.b + 1
        r_bucket = r // self.b  # 半開区間なのでこれでいい
        ret = reduce(self.f, self.bucket[l_bucket:r_bucket], self.ide)
        ret = self.f(
            reduce(self.f, self.ls[l:(l_bucket * self.b)], self.ide),
            ret)
        ret = self.f(
            reduce(self.f, self.ls[(r_bucket * self.b):r], self.ide),
            ret)
        return ret


def segfunc(x, y):
    # 処理したい内容
    return x | y


def moji_to_bit(a):
    return 1 << (ord(a) - ord('a'))


def bit_to_sum(n):
    return sum([(n >> i) & 1 for i in range(n.bit_length())])


N = read_a_int()
S = read()[:-1]
S_bit = [moji_to_bit(s) for s in S]

# build segment tree
st = SqrtDecomposedList(S_bit, segfunc, 0)

Q = read_a_int()
for q in range(Q):
    com, a, b = read().split()
    if int(com) == 1:
        i, c = int(a) - 1, b
        st.update(i, moji_to_bit(c))
    else:
        l, r = int(a) - 1, int(b)
        print(bit_to_sum(st.query(l, r)))


Measured memory_bytes: 77460
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
const int MAX=1e5;
int a[MAX];
int main()
{
    memset(a,0,sizeof(a));
    int n,k,q;
    cin>>n>>k>>q;
    int t=q;
    int b;
    while(q--){
        cin>>b;
        a[b-1]++;
    }
    for(int i=0;i<n;i++){
        if(a[i]>t-k){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;

string s;
long long m, n;

int main()
{
  VLL t(2),a(2),b(2);
  rep(i, 2) cin >> t[i];
  rep(i, 2) cin >> a[i];
  rep(i, 2) cin >> b[i];
  if ( a[0] * t[0] + a[1] * t[1] == b[0] * t[0] + b[1] * t[1]){
    cout << "infinity" << endl;
    return 0;
  }
  m = (b[0] - a[0]) * t[0];
  n = (b[1] - a[1]) * t[1];
  if (m>0&&n>0||m<0&&n<0)
  {
    cout << 0 << endl;
    return 0;
  }
  if(abs(m)-abs(n)>0){
    cout << 0 << endl;
    return 0;
  }
  m = abs(m);
  n = abs(n);
  if(n%(n-m)==0){
    cout << (n * 2) / (n - m) - 2 << endl;
    return 0;
  }
  cout<<(n/(n-m))*2-1<<endl;
  return 0;
}


Measured memory_bytes: 256
import bisect

N=int(input())
A=sorted([int(i) for i in input().split()])
B=sorted([int(i) for i in input().split()])
C=sorted([int(i) for i in input().split()])

ans=0
for b in B:
  ans+=bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b))

print(ans)

Measured memory_bytes: 23092
/*input
9
*/
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define sz(a) int((a).size())
#define pb push_back
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())     
#define rep(i,j,n) for(ll i=j;i<n;i++)
#define mp make_pair
#define N 998244353
#define PI acos(-1.0)
//if (s.find('R') != std::string::npos)
//s.replace(s.find("10"), sizeof("10") - 1, "");
using namespace std;
bool comp(pair<string,ll>a,pair<string,ll>b){
  if(a.first==b.first) return a.second>b.second;
  return a.first<b.first;
}
int main()
{
  // added the two lines below 
  ios_base::sync_with_stdio (false); 
  cin.tie(NULL);
  cout.tie(0);
  
  ll n;
  cin>>n;
  ll a[n],b[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  ll ans=0;
  rep(i,0,n) cin>>b[i];
  rep(i,0,n){
    if(a[i]-b[i]>0) ans+=a[i]-b[i];
  }
  cout<<ans;
}

Measured memory_bytes: 256
/// --- In the name of ALLAH --- ///


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


typedef long long              ll;
typedef vector<int>            vi;
typedef vector<ll>             vl;
typedef vector<vi>             vvi;
typedef vector<vl>             vvl;
typedef pair<int,int>          pii;
typedef pair<double, double>   pdd;
typedef pair<ll, ll>           pll;
typedef vector<pii>            vii;
typedef vector<pll>            vll;
typedef double                 dl;

#define endl                   '\n'
#define PB                     push_back
#define F                      first
#define S                      second
#define all(a)                 (a).begin(),(a).end()
#define rall(a)                (a).rbegin(),(a).rend()
#define sz(x)                  (ll)x.size()
#define wt                     ll t; cin>>t; while(t--)
#define input(a,n)             for(int i=0;i<n;i++) cin>>a[i];

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;


#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))
#define mod 10000007
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

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


const ll mx=1e9;









int main()
{
    optimize();

   int n,m,i,j,p=0;
   cin>>n>>m;
   if(m%n==0)
   cout<<m+n<<endl;
   else
    cout<<m-n<<endl;




    return 0;
}









































Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
const int mod=1e9+7;

int64_t f(int64_t x){
  int64_t cnt=(x+1)/2;
  int64_t ans=cnt%2;
  if(x%2==0){ans^=x;}
  return ans;
}
int main(){
  int64_t A,B;
  cin>>A>>B;
  int64_t ans=f(B)^f(A-1);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, s, n) for(int i = s; i < n; i++)
using namespace std;
using P = pair<int, int>;

struct UnionFind {
  vector<int> par;
  
  UnionFind(int N): par(N){
    for(int i = 0; i < N; i++) par[i] = i;
  }
  
  int root(int x){
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  
  bool unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return false;
    par[rx] = ry;
    return true;
  }
};

struct corridor {
  int x, y, len;
  corridor(int x, int y, int len) : x(x), y(y), len(len){}
  // ソート用
  bool operator <(const corridor& rhs) const{
    if (len != rhs.len) return len < rhs.len;
    if (x != rhs.x) return x < rhs.x;
    return y < rhs.y;
  }
};

int main(){
  int n;
  cin >> n;
  UnionFind tree(n);
  vector<int> x(n), y(n);
  vector<P> px(n), py(n);
  rep(i, n){
    cin >> x[i] >> y[i];
    px[i] = P(x[i], i);
    py[i] = P(y[i], i);
  }
  sort(px.begin(), px.end());
  sort(py.begin(), py.end());
  vector<corridor> cor;
  rep(i, n-1){
    cor.push_back(corridor(px[i].second, px[i+1].second, abs(px[i].first-px[i+1].first)));
    cor.push_back(corridor(py[i].second, py[i+1].second, abs(py[i].first-py[i+1].first)));
  }
  sort(cor.begin(), cor.end());
  
  ll ans = 0;
  int count = 0;
  for(auto itr = cor.begin(); itr != cor.end(); itr++){
    if (count == n-1) break;
    if (tree.unite(itr->x, itr->y)){
      ans += itr->len;
      count++;
    }
  }
  cout << ans << endl;
  
  return 0;
}


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

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

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

    ll a,b,c; cin >> a >> b >> c;

    if(c-a-b < 0){
        cout << "No" << endl;
    }else{
        if((c-a-b)*(c-a-b) > 4*a*b) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;

}

Measured memory_bytes: 256
#%%
n = int(input())
a = [[0] * 10 for _ in range(10)]
for i in range(1, n+1):
    tmp = str(i)
    mae = int(tmp[0])
    usiro = int(tmp[-1])

    a[mae][usiro] += 1
    #a[usiro][mae] += 1



ans = 0
for i in range(10):
    for j in range(10):
        tmp = a[i][j] * a[j][i]
        ans += tmp
print(ans)

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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(t, x) t ipt; cin >> ipt; x.push_back(ipt);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, tmp, sum, a, b, c, d, k, m, h, w, q, x, y;
string s, t;

int main() {
    cin >> a >> b;
    ll dist = abs(a - b);
    if (dist % 2 != 0) {
        MSG("IMPOSSIBLE")
        exit(0);
    }
    dist /= 2;

    MSG(max(a - dist, b - dist))
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main{
	public static void main(String[] args) {

		Input test = new Input();
		test.num();

		
	}
}

class Input{
	void num() {
		
		Scanner sc=new Scanner(System.in);
        int x = sc.nextInt();
        int x2 = sc.nextInt();
        System.out.print(x*x2);
        System.out.print(" ");
        System.out.println((x+x2)*2);

	}
}

Measured memory_bytes: 26192
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
string s;
int a=-1,b=-1,num;
cin>>s;
int ls=s.length();
for(int i=0;i<ls;i++)
{
    if(s[i]=='A')
    {
        a=i;
        i=ls+i;
    }
}

for(int i=ls-1;i>0;i--)
{
    if(s[i]=='Z')
        {b=i;
        i=0; }
}

num=(b-a)+1;
cout<<num;
    return 0;
}


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

int main() {	
  string s;
  cin >>s;
  deque<char> d;
  rep(i,s.size()){
  d.push_back(s[i]);
  }
  int q;cin >>q;
  int t,f,rcount;
  bool ts=true;
  int tsc =0;
  char c;
  rep(i,q){
    cin >>t;
    if(t==1){
      if(ts == true){
      ts=false;
      }else{
      ts=true;
      }
      tsc++;
    }else{
      cin >>f;cin >>c;
      if(ts ==true){
     if(f == 1){
      d.push_front(c); 
     }else{
       d.push_back(c);
     }
      }else{
            if(f == 1){
      d.push_back(c); 
     }else{
       d.push_front(c);
     } 
      }
    }
  }
 
  if(tsc%2 == 0){
  while(!d.empty()){
  cout <<d.front();d.pop_front();
  }
  }else{
  while(!d.empty()){
 cout<<d.back();d.pop_back();
  }
  }

}

Measured memory_bytes: 896
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-4;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	llint n,K;cin>>n>>K;
	n=min(n,70LL);
	llint bmax=K+1,bmin=0;
	while(bmax-bmin>1){
		llint bgen=(bmax+bmin)/2;
		llint a=bgen,e=0;
		for(llint i=0;i<n;i++){e+=a;a/=2;}
		if(e>K){bmax=bgen;}
		else{bmin=bgen;}
	}
	cout<<bmin<<endl;
	return 0;
}
//1000
//100
//10
//1


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

int main() {
	set<int>s;
	int n;
	int temp;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> temp;
		s.insert(temp);
	}
	cout << s.size() << endl;
	return 0;
}

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

    using namespace std;

    int main()
    {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int n; cin >> n;
        double val = ceil((double)n/2);
        // cout << val << endl;
        double ans  = (float)(val/n);

        cout << fixed  <<  setprecision(10) << ans << endl;

        return 0;
    }


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int n,d,check;
  scanf("%d",&n);
  while(d!=7&&n>0){
    d=n%10;
    n=n/10;
  }
  if(d==7)
    printf("Yes");
  if(d!=7)
    printf("No");
}

Measured memory_bytes: 1736
#include<cstdio>
#include<map>
using namespace std;
const int MAXN=405;

long long encode(long long a,long long b,long long c,long long d)
{
	return (a<<30LL)|(b<<20LL)|(c<<10LL)|d;
}

map<long long,long long> cnt;
void Add(long long c,int delta)
{
	for(int i=0;i<4;i++)
	{
		cnt[c]+=delta;
		c=(c>>10LL)|((c&1023LL)<<30LL);
	}
}

int n;
int c[MAXN][4];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d%d",c[i],c[i]+1,c[i]+2,c[i]+3);
		Add(encode(c[i][0],c[i][1],c[i][2],c[i][3]),1);
	}
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		Add(encode(c[i][0],c[i][1],c[i][2],c[i][3]),-1);
		for(int j=i+1;j<=n;j++)
		{
			Add(encode(c[j][0],c[j][1],c[j][2],c[j][3]),-1);
			for(int k=0;k<4;k++)
			{
				long long u[4]=
				{encode(c[i][1],c[i][0],c[j][(k+1)&3],c[j][(k+0)&3]),
				 encode(c[i][0],c[i][3],c[j][(k+2)&3],c[j][(k+1)&3]),
				 encode(c[i][3],c[i][2],c[j][(k+3)&3],c[j][(k+2)&3]),
				 encode(c[i][2],c[i][1],c[j][(k+0)&3],c[j][(k+3)&3])
				};
				if(cnt[u[0]]&&cnt[u[1]]&&cnt[u[2]]&&cnt[u[3]])
				{
					long long tmp=1;
					for(int l=0;l<4;l++)
						tmp*=cnt[u[l]],Add(u[l],-1);
					for(int l=0;l<4;l++)
						Add(u[l],1);
					ans+=tmp;
				}
			}
			Add(encode(c[j][0],c[j][1],c[j][2],c[j][3]),1);
		}
	}
	printf("%lld\n",ans);
	
	return 0;
}


Measured memory_bytes: 20352
//
// Created by watemus on 10.05.2020.
//

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

using namespace std;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second

using ll = long long;
using ld = long double;
#define int ll

constexpr ll INFL = 1'000'000'000'000'000'228;
constexpr int INFI = 1'000'000'228;

#ifdef LOCAL
#else
#endif


void run() {
    string s, t;
    cin >> s >> t;
    t.pop_back();
    cout << (s==t ? "Yes\n" : "No\n");
}

signed main() {
#ifdef LOCAL
    std::freopen("input.txt", "r", stdin);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    int t = 1;
//    cin >> t;
    while (t--) {
        run();
    }
    return 0;
}

Measured memory_bytes: 3640