akhauriyash/Code-Regression huggingface dataset:
import sys
from operator import itemgetter, attrgetter
from itertools import starmap
import cmath
from math import isinf, sqrt, acos, atan2
readline = sys.stdin.readline
EPS = 1e-9
ONLINE_FRONT = -2
CLOCKWISE = -1
ON_SEGMENT = 0
COUNTER_CLOCKWISE = 1
ONLINE_BACK = 2
class Circle(object):
    __slots__ = ('c', 'r')
    def __init__(self, c, r):
        self.c = c
        self.r = r
class Segment(object):
    __slots__ = ('fi', 'se')
    def __init__(self, fi, se):
        self.fi = fi
        self.se = se
Line = Segment
def cross(a, b):
    return a.real * b.imag - a.imag * b.real
def dot(a, b):
    return a.real * b.real + a.imag * b.imag
def norm(base):
    return abs(base) ** 2
def project(s, p2):
    base = s.fi - s.se
    r = dot(p2 - s.fi, base) / norm(base)
    return s.fi + base * r
def reflect(s, p):
    return p + (project(s, p) - p) * 2.0
def ccw(p1, p2, p3):
    a = p2 - p1
    b = p3 - p1
    if cross(a, b) > EPS: return 1
    if cross(a, b) < -EPS: return -1
    if dot(a, b) < -EPS: return 2
    if norm(a) < norm(b): return -2
    return 0
def intersect4(p1, p2, p3, p4):
    return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 and
			ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0)
def intersect2(s1, s2):
    return intersect4(s1.fi, s1.se, s2.fi, s2.se)
def getDistance(a, b):  return abs(a - b)
def getDistanceLP(l, p):
    return abs(cross(l.se - l.fi, p - l.fi) / abs(l.se - l.fi))
def getDistanceSP(s, p):
    if dot(s.se - s.fi, p - s.fi) < 0.0: return abs(p - s.fi)
    if dot(s.fi - s.se, p - s.se) < 0.0: return abs(p - s.se)
    return getDistanceLP(s, p)
def getDistances(s1, s2):
    if intersect2(s1, s2): return 0.0
    return min(getDistanceSP(s1, s2.fi), getDistanceSP(s1, s2.se),
               getDistanceSP(s2, s1.fi), getDistanceSP(s2, s1.se))
def getCrossPoint(s1, s2):
	base = s2.se - s2.fi
	d1 = abs(cross(base, s1.fi - s2.fi))
	d2 = abs(cross(base, s1.se - s2.fi))
	t = d1 / (d1 + d2)
	return s1.fi + (s1.se - s1.fi) * t
def getCrossPointsCL(c, l):
    pr = project(l, c.c)
    e = (l.se - l.fi) / abs(l.se - l.fi)
    base = sqrt(c.r * c.r - norm(pr - c.c))
    return Segment(*sorted((pr + e * base, pr - e * base)), key=attrgetter('real', 'imag'))
def getCrossPointsCC(c1, c2):
    d = abs(c1.c - c2.c)
    a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2.0 * c1.r * d))
    t = cmath.phase(c2.c - c1.c)
    return Segment(*sorted((c1.c + cmath.rect(c1.r, t + a), c1.c + cmath.rect(c1.r, t - a)), key=attrgetter('real', 'imag')))
def contains(g, p):
    n = len(g)
    x = False
    for i in range(n):
        a = g[i] - p
        b = g[(i + 1) % n] - p
        if abs(cross(a, b)) < EPS and dot(a, b) < EPS: return 1
        if a.imag > b.imag: a, b = b, a
        if a.imag < EPS and EPS < b.imag and cross(a, b) > EPS: x = not x
    return 2 if x else 0
n = int(readline())
pg = tuple(complex(*map(int, readline().split())) for _ in [0] * n)
q = int(readline())
for _ in [0] * q:
    x, y = map(int, readline().split())
    print(contains(pg, complex(x, y)))

Measured memory_bytes: 8344
def main():
    X, Y = map(int, input().split())

    ans = 0
    if X == 3:
        ans += 100000
    if X == 2:
        ans += 200000
    if X == 1:
        ans += 300000

    if Y == 3:
        ans += 100000
    if Y == 2:
        ans += 200000
    if Y == 1:
        ans += 300000

    if X == 1 and Y == 1:
        ans += 400000

    print(ans)

if __name__ == "__main__":
    main()

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

struct Node {
    int key;
    Node* left;
    Node* right;
    Node(int key_in){
        key   = key_in;
        left  = NULL;
        right = NULL;
    }
};

class Tree {
    Node* root;
    void inorder(Node* n){
        if (n == NULL) return;
        inorder(n->left);
        cout << " " << n->key;
        inorder(n->right);
    }
    void preorder(Node* n){
        if (n == NULL) return;
        cout << " " << n->key;
        preorder(n->left);
        preorder(n->right);
    }
public:
    Tree(){
        root = NULL;
    }
    void insert(int key){
        Node* z = new Node(key);
        if (root == NULL) {
            root = z;
            return;
        }
        Node* x = root;
        while(1) {
            if (key < x->key) {
                if (x->left == NULL) {
                    x->left = z;
                    break;
                }
                x = x->left;
            } else {
                if (x->right == NULL) {
                    x->right = z;
                    break;
                }
                x = x->right;
            }
        }
    }
    void print(){
        inorder(root);
        cout << endl;
        preorder(root);
        cout << endl;
    }
};


int main(){
    int m;
    cin >> m;
    Tree T;
    for (int i = 0; i < m; i++) {
        string str;
        cin >> str;
        if (str == "insert") {
            int num;
            cin >> num;
            T.insert(num);
            continue;
        }
        if (str == "print") {
            T.print();
        }
    }
    return 0;
}

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

#define fi first
#define se second
#define FAST() cin.tie(0), ios::sync_with_stdio(false)

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

const int INF = 1 << 29;
const int dx[] = {1, 0, -1, 0,  1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1,  -1, 1, 1, -1};

int main(){

  FAST();

  ll x,y;

  cin>>x>>y;

  if(x%y==0){
    cout<<-1<<endl;
  }
  else{
    cout<<x<<endl;
  }
  return 0;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int s, w; cin >> s >> w;
    cout << ((s <= w) ? "unsafe" : "safe") << endl;
    return 0;
}


Measured memory_bytes: 3608
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a: usize,
        b: usize,
    }
    let mut result = "".to_string();
    if a > b {
        let s = b.to_string();
        for _ in 0..a {
            result += &s;
        }
    } else {
        let s = a.to_string();
        for _ in 0..b {
            result += &s;
        }
    }
    println!("{}", result);
}


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


int main() {
  int h, w;
  std::cin >> h >> w;
  while (h != 0 && w != 0) {
    for (int i = 0; i < w; ++i) {
      std::cout << "#";
    }
    std::cout << std::endl;
    for (int j = 0; j < (h - 2); ++j) {
      std::cout << "#";
      for (int k = 0; k < (w - 2); ++k) {
        std::cout << ".";
      }
      std::cout << "#" << std::endl;
    }
    for (int l = 0; l < w; ++l) {
      std::cout << "#";
    }
    std::cout << std::endl;
    std::cout << std::endl;
    std::cin >> h >> w;
  }
  return 0;
}



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

using namespace std;

int ans, s, idx = 1, element;
vector<int> hist;
bool ispre = false;


int main(){
	cin >> s;
	element = s;
	while(true){
		hist.push_back(element);
		if(hist[hist.size() - 4] == element){
			if(ispre){
				ans = idx;
				break;
			}else{
				ispre = true;
			}
		}
		if(element % 2 == 0){
			element /= 2;
		}else{
			element = 3 * element + 1;
		}
		idx++;
	}
	ans--;
	cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

def main():
    s = input()
    t = input()
    n = len(s)
    flag = False
    for i in range(n):
        s = rot(s)
        if s == t:
            flag = True
    print("Yes" if flag else "No")

def rot(s):
    r = s[1:] + s[0]
    return r

main()


Measured memory_bytes: 2940
//#define NDEBUG

#include <bits/stdc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define F first
#define S second
#define B back()
#define FR front()
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}
#define pii pair<int, int>
#define pll pair<ll, ll>
#define tiii tuple<int, int, int>
#define mt make_tuple
#define gt(t, i) get<i>(t)

//#define TEST

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

pii d[4] = {mp(1,0), mp(0, 1), mp(-1, 0), mp(0, -1)};

int main(){
    StarBurstStream

    int h, w;
    cin >> h >> w;

    vector<string> g(h + 2, string(w + 2, '#'));
    for(int i = 1; i <= h ;i++){
        cin >> g[i];
        g[i] = '#' + g[i] + '#';
    }

    int ans = 0;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(g[i][j] == '#') continue;

            vector<vector<bool>> visit(h + 2, vector<bool>(w + 2));
            queue<pair<pii, int>> q;
            q.push(mp(mp(i, j), 0));
            visit[i][j] = true;
            while(!q.empty()){
                ans = max(ans, q.front().S);
                for(auto & k : d){
                    pii nw = mp(q.front().F.F + k.F, q.front().F.S + k.S);
                    if(g[nw.F][nw.S] == '#' || visit[nw.F][nw.S]) continue;
                    visit[nw.F][nw.S] = true;
                    q.push(mp(nw, q.front().S + 1));
                }
                q.pop();
            }
        }
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<cmath>
 
#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)
 
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9
#define MOD 1000000007
 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef std::pair<ll, ll> P;
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}

typedef std::pair<ll, ll> P;
 
using namespace std;

int main(){
    vector<ll> v(5, 0);
    ll n;
    cin >> n;
    rep(i, n){
        string s;
        cin >> s;
        if(s[0] == 'M') v[0]++;
        if(s[0] == 'A') v[1]++;
        if(s[0] == 'R') v[2]++;
        if(s[0] == 'C') v[3]++;
        if(s[0] == 'H') v[4]++;
    }
    ll ans = 0;
    rep(i, 3){
        for(int j=i+1; j<=3; j++){
            for(int k=j+1; k<=4; k++){
                ans += (v[i]*v[j]*v[k]);
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
string st;
int n,OK,s[100000],t[100000];
int main(void){
    cin>>st;
    n=st.size();
    for(int i=0;i<n;i++){
        if(st[i]=='R'){
            OK=1;
        }
        else if(st[i]=='L'){
            s[i]=OK;
            OK++;
        }
    }
    
    for(int i=n-1;i>=0;i--){
        if(st[i]=='L'){
            OK=1;
        }
        else if(st[i]=='R'){
            s[i]=OK;
            OK++;
        }
    }
    for(int i=0;i<n;i++){
        if(st[i]=='R')t[i+s[i]-1+(s[i]%2==0)]++;
        else t[i-s[i]+1-(s[i]%2==0)]++;
    }
    for(int i=0;i<n;i++){
        cout<<t[i]<<" ";
    }
    cout<<endl;
}


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

using namespace std;

int main(int argc, char *argv[])
{
  int n, k;
  cin >> n >> k;

  vector<int> l(n);

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

  sort(l.begin(), l.end());

  int sum = 0;
  for (int i = n - 1; i >= n - k; i--) {
    sum += l[i];
  }

  cout << sum << endl;


  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        long a = scanner.nextLong() - 1;
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();
        long e = lcm(c, d);
        System.out.println((b - a) - (b / c - a / c) - (b / d - a / d) + (b / e - a / e));
    }

    static long gcd(long a, long b) {
        return 0 < b ? gcd(b, a % b) : a;
    }

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

Measured memory_bytes: 21716
def main():

    import sys
    input = lambda: sys.stdin.readline().rstrip("\r\n")

    from math import gcd

    def prime_factorize(n):
        a = []
        while n % 2 == 0:
            a.append(2)
            n //= 2
        f = 3
        while f * f <= n:
            if n % f == 0:
                a.append(f)
                n //= f
            else:
                f += 2
        if n != 1:
            a.append(n)
        return a

    n = int(input())
    a = [int(x) for x in input().split()]

    primes = set()

    flag = 1

    for i in a:
        prime_factors = set(prime_factorize(i))
        for j in prime_factors:
            if j in primes:
                flag = 0
            else:
                primes.add(j)


    if flag:
        print('pairwise coprime')
        sys.exit()
                
    
    import math
    from functools import reduce
    
    def gcd(*numbers):
        return abs(reduce(math.gcd, numbers))
    
    if gcd(*a) == 1:
        print('setwise coprime')
    else:
        print('not coprime')

main()

Measured memory_bytes: 213324
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
string s, t;
int main(){
    ios::sync_with_stdio(false);
    cin >> s;
    t = s;
    reverse(s.begin(), s.end());
    for(int i = 0; i < (int)s.size(); ++i){
        if(s[i] == 98) s[i] = 100;
        else if(s[i] == 100) s[i] = 98;
        else if(s[i] == 112) s[i] = 113;
        else if(s[i] == 113) s[i] = 112;
    }
    if(s == t) cout << (char)89 << (char)101 << (char)115;
    else cout << (char)78 << (char)111;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

int main()
{
  int a,b,c,d,e,k;
  cin>>a>>b>>c>>d>>e>>k;
  if(e-a<=k){
    cout<<"Yay!"<<endl;
  }else{
    cout<<":("<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll md = 1000000007;
vector<ll> fact(1e6 + 7), invfact(1e6 + 7);

ll fn(ll a, ll r, ll n, ll mod = md) {
    ll res = 1, x = r%mod;
    ll ans = 0;
    while(n) {
        if(n&1) ans = (x*ans + res)%mod;
        res = ((res*x)%mod + res%mod)%mod;
        x = (x*x)%mod;
        n = n/2;
    }
    ans = (ans*a)%mod;
    return ans;
}

ll nCr(ll n, ll r) {
    if(r == 0) return 1;
    ll num = fact[n];
    ll den = (invfact[r] % md *invfact[n-r] % md)%md;
    return (num*den)%md;
}

ll mul(ll a, ll b, ll mod = md) {
    ll res = (a%mod * b%mod)%mod;
    return res;
}

ll mulm(ll a, ll b, ll mod = md) {
    ll r = 0;
    a %= mod;
    while (b) {
        if (b & 1) r = (r+a)%mod;
        a = (a+a)%mod;
        b = b/2;
    }
    r %= mod;
    return r;
}

ll power(ll x, ll n, ll mod = md) {
    ll res = 1;
    x %= mod;
    while (n) {
        if (n & 1)  res = (res*x)%mod;
        n = n/2;
        x = (x*x)%mod;
    }
    return res;
}

ll power2(ll x, ll n) {
    ll res = 1;
    while (n)  
    {  
        if (n & 1)  res = (res*x);  
        n = n/2; 
        x = (x*x);  
    }  
    return res;
}

bool is_prime(ll x) {
    if(x == 1 || x == 0) return false;
    for(int i=2; i*i <= x; i++) {
        if(x%i == 0) return false;
    }
    return true;
}

ll compgcd(ll n, vector<ll> const &primes) { 
    ll res = n; 
    for (ll i=0; primes[i]*primes[i] <= n; i++) {
        if (n % primes[i]== 0) { 
            res -= (res / primes[i]); 
            while (n%primes[i]== 0) {
               n/=primes[i]; 
            }
        } 
    } 
    if (n > 1) {
       res -= (res / n); 
    }
    return res; 
} 

void sieve(vector<bool> &prime, vector<ll> &primes, ll lim) {
    for(int i = 2; i*i <= lim; i++) {
        if(prime[i]) {
            for(int j = 2; j*i <= lim; j++) {
                prime[j*i] = false;
            }
        }
    }
    for(int i = 2; i <= lim; i++) {
        if(prime[i]) {
            primes.push_back(i);
        }
    }
}

void sieveGCD(ll lim, vector<ll> &tab, vector<ll> const &primes) {
    for(int  i = 1; i <= lim; i++) {
        tab[i] = i;
    }
    for(int i = 0; i<primes.size() && primes[i] <= lim; i++) {
        tab[primes[i]] = primes[i]-1;
        for(int j = 2; primes[i]*j <= lim; j++) {
            tab[primes[i]*j] = (tab[primes[i]*j]/primes[i])*(primes[i]-1);
        }
    }
}

int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b, c, x, y, res;
    cin >> a >> b >> c >> x >> y;
    if(2*c < a+b) {
        res = (2*c)*min(x,y) + abs(x-y)*(x>y? (2*c < a ? (2*c) : a) : (2*c < b ? (2*c) : b));
    } else {
        res = a*x + b*y;
    }
    cout << res << "\n";
    return 0; 
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln << "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;
struct edge {
	int to,cost;
	edge(int t, int c):to(t),cost(c) {}
};

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

//--------------------------------------------------

// dp[i][j]: i???????????§???????????§?????????j????¶???????????????????????????????????????????????????§???
int n, W, v[101], w[101], dp[101][10001];

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

	cin >> n >> W;
	repst(i,1,n) cin >> v[i] >> w[i];
	repst(i,1,100) fill(dp[i], dp[i]+10001, -1);
	repst(i,1,n) {
		rept(j,W) {
			if (j<w[i]) dp[i][j] = dp[i-1][j];
			else dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]]+v[i]);
		}
	}
	cout << dp[n][W] ln;
}

Measured memory_bytes: 7076
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <queue>
#include <deque>
#include <algorithm>
#include <time.h>

using namespace std;
int n,p;
int a[100100];
int main()
{
	scanf("%d",&n);
	p=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]%2==1)
		{
			p=1;
		}
	}
	if(p==1)
		printf("first");
	else
		printf("second");
	return 0;
}

Measured memory_bytes: 640
from collections import deque
S = input()
Q = int(input())
Query = [input().split() for _ in range(Q)]
s = list(S)
d = deque(s)
d_is_reversed = False
for j in range(Q):
    if Query[j][0] == '1':
        d_is_reversed = not d_is_reversed
    elif Query[j][1] == '1':
        if d_is_reversed == False:
            d.appendleft(Query[j][2])
        else:
            d.append(Query[j][2])
    else:
        if d_is_reversed == False:
            d.append(Query[j][2])
        else:
            d.appendleft(Query[j][2])
if d_is_reversed == True:
    d.reverse()
printed = ''.join(d)
print(printed)

Measured memory_bytes: 45428
#include<iostream>
#include<complex>
#include<algorithm>
#define EPS 1e-10
using namespace std;

typedef complex<double> P;

int n,m;
P p[100][4];

double cross(P a,P b){return imag(conj(a)*b);}
double dot(P a,P b){return real(conj(a)*b);}

int ccw(P a,P b,P c){
  b -= a;c -= a;
  if (cross(b,c)>EPS) return 1;
  if (cross(b,c)<-EPS) return -1;
  if (dot(b, c)<-EPS) return 2;
  if (abs(b)<abs(c)) return -2;
  return 0;
}

bool is_cp(P a1, P a2, P b1, P b2){
    return ( ccw(a1, a2, b1) * ccw(a1, a2, b2) <= 0 &&
     ccw(b1, b2, a1) * ccw(b1, b2, a2) <= 0 );
}

bool interp(int q, P x){
  for(int i=0;i<4;i++){
    if ( ccw(p[q][i], p[q][(i+1)%4], x ) == 1 ) return false;
  }
  return true;
}

bool inter(int q1,int q2){
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
      if(is_cp(p[q1][i],p[q1][(i+1)%4],p[q2][j],p[q2][(j+1)%4]))return true;
  for(int i=0;i<4;i++)if(interp(q1,p[q2][i]))return true;
  for(int i=0;i<4;i++)if(interp(q2,p[q1][i]))return true;
  return false;
}

int par[100];
int rank[100];

void init(int n){
  for(int i=0;i<n;i++){
    par[i] = i;
    rank[i] = 0;
  }
}

int find(int x){
  if(par[x] == x)return x;
  return par[x] = find(par[x]);
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x==y)return;

  if(rank[x] < rank[y])par[x] = y;
  else{
    par[y] = x;
    if(rank[x] == rank[y])rank[x]++;
  }
}

int main(){
  while(cin >> n && n){
    for(int i=0;i<n;i++){
      cin >> m;
      for(int j=0;j<m;j++)
	for(int k=0;k<4;k++)cin >> p[j][k].real() >> p[j][k].imag();

      init(m);

      for(int j=0;j<m;j++)
	for(int k=0;k<j;k++)
	  if(find(j)!=find(k) && inter(j,k))unite(j,k);

      int ans = 0;
      for(int j=0;j<m;j++){
	find(j);
	if(par[j]==j)ans++;
      }
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 0
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int a = sc.nextInt();
	static int b = sc.nextInt();
	static int c = sc.nextInt();
	static int d = sc.nextInt();
	static int e = sc.nextInt();
	static int f = sc.nextInt();
	public static void main(String[] args) {
		selectSubject();
	}

	private static void selectSubject() {
		ArrayList<Integer> sc = new ArrayList<Integer>();
		ArrayList<Integer> ss = new ArrayList<Integer>();

		sc.add(a); sc.add(b); sc.add(c); sc.add(d);
		ss.add(e); ss.add(f);

		Collections.sort(sc);
		Collections.sort(ss);

		System.out.println(sc.get(1) + sc.get(2) + sc.get(3) + ss.get(1));
	}

}



Measured memory_bytes: 26128
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 105

char buf[SIZE];

int main(){

	scanf("%s",buf);

	for(int i = 0; buf[i] != '\0'; i++){

		buf[i] = 'x';
	}

	printf("%s\n",buf);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
    int K, S;
    cin >> K >> S;
    int count = 0;
    for (int x = 0; (x <= K); ++x) {
        if (x > S) break;
        for (int y = 0; (y <= K); ++y) {
            if (x+y > S) break;
            if ((S-x-y) <= K) count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
use std::io::Read;
use std::str::SplitWhitespace;
use std::str::FromStr;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

pub trait Parse<T> {
    fn parse(&mut self) -> T;
}

impl<'a, T> Parse<T> for SplitWhitespace<'a>
where
    T: FromStr,
{
    fn parse(&mut self) -> T {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let n: usize = iter.parse();
    let dest: Vec<i32> = (0..3).map(|_| iter.parse()).collect();
    let ls: Vec<i32> = (0..n).map(|_| iter.parse()).collect();
    let all = 4_u32.pow(n as u32);

    let mut v = Vec::new();
    for i in 0..all {
        let mut base = i as i32;
        let mut mp = 0;
        let mut current = vec![0_i32; 3];
        for j in 0..n {
            for k in 0..3 {
                if base % 4 == k as i32 {
                    if current[k] != 0 {
                        mp += 10;
                    }
                    current[k] += ls[j];
                }
            }
            base /= 4;
        }

        if current.iter().any(|&x| x == 0) {
            continue;
        }

        for (x, d) in current.iter().zip(dest.iter()) {
            mp += (x - d).abs();
        }

        v.push(mp);
    }

    println!("{}", v.into_iter().min().unwrap());
}

Measured memory_bytes: 4352
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

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

#define v vector
#define ALL(x) x.begin(),x.end()
#define rALL(x) x.rbegin(),x.rend()
#define endl '\n'
#define F first
#define S second
#define DEBUG

template<typename T> void DBG(const char* name, T&& H) {
	cerr << name << " = " << H << ')' << endl;
}

template<typename T, typename... Args> void DBG(const char* names, T&& H, Args&&... args) {
	const char* NEXT = strchr(names+1, ',');
	cerr.write(names, NEXT-names) << " = " << H << " |";
	DBG(NEXT+1, args...);
}

#ifdef DEBUG
	#define dbg(...) cerr << __FUNCTION__ << ' ' <<__LINE__ << " : (", DBG(#__VA_ARGS__, __VA_ARGS__)
#else
	#define dbg(...)
#endif

using ll = long long;
using ld = long double;

const long long mod = 998244353;
const long double PI = acos(-1.0);
const long long INF = 1e18;
const int maxN = 5e5+1;

struct BIT {
	using T = int;
	vector<T> arr;
	T total;
	BIT(T s = 1e6) {
		total = 0;
		arr.assign(s+1 , 0);
	}
	T sum(T pos) {
		T ans = 0;
		while(pos > 0) {
			ans += arr[pos];
			pos = pos - (pos & (-pos));
		}
		return ans;
	}
	void update(T pos, T val) {
		while((pos > 0) && (pos < arr.size())) {
			arr[pos] += val;
			pos = pos + (pos & (-pos));
		}
	}
	T rQuery(T l, T r) {
		return sum(r) - sum(l-1);
	}
};

void Solve() {
	int N, Q;
	cin >> N >> Q;
	vector<int> ptr(maxN, 0);
	vector<int> a(N+1);
	vector<vector<int>> color(maxN);
	BIT dis(maxN);
	for(int i = 1; i <= N; i ++) {
		int in;
		cin >> in;
		a[i] = in;
		if(color[in].size() == 0) dis.update(i, 1);
		color[in].push_back(i);
	}
	vector<int> ans(Q);
	vector<tuple<int, int, int>> query(Q);
	for(int i = 0; i < Q; i ++) {
		int L, R;
		cin >> L >> R;
		query[i] = make_tuple(L, R, i);
	}
	sort(query.begin(), query.end());
	int id = 1;
	for(int i = 0; i < Q; i ++) {
		while(id < get<0>(query[i])) {
			int cur = a[id];
			dis.update(color[cur][ptr[cur]], -1);
			ptr[cur] ++;
			if(color[cur].size() >= ptr[cur]+1) {
				dis.update(color[cur][ptr[cur]], 1);
			}
			id ++;
		}
		ans[get<2>(query[i])] = dis.rQuery(get<0>(query[i]), get<1>(query[i]));
	}
	for(auto i : ans) cout << i << endl;
}

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

	int tt = 1;
	while(tt --) {
		Solve();
	}
	
	return 0;
}

Measured memory_bytes: 44804
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;

map<int,int> dp[11][1024];
int res[11][550];

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

    dp[0][0][0] = 1;
    for (int i=0; i<11; ++i) {
        for (int j=0; j<1024; ++j) {
            if (dp[i][j].empty()) continue;
            for (auto it = dp[i][j].begin(); it != dp[i][j].end(); ++it) {
                for (int k=0; k<=9; ++k) {
                    if ((j & (1<<k)) == 0) {
                        dp[i+1][j|(1<<k)][it->first + (i+1)*k] += it->second;
                    }
                }
            }
        }
    }

    int n, s;
    while (cin >> n >> s) {
        int res = 0;
        for (int i=0; i<1024; ++i) {
            res += dp[n][i][s];
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 5916
#include<stdio.h>
int main(void){
	int n,i,memo,flag,box1,box2,ball[11];
	scanf("%d",&n);
	while(n--){
		for(i=1;i<=10;i++){scanf("%d",&ball[i]);}
		flag=0;box1=0;box2=0;
		for(i=1;i<=10;i++){
			if(ball[i]>box1){box1=ball[i];}
			else if(ball[i]>box2){box2=ball[i];}
			else {flag++;break;}
		}
		if(flag)printf("NO\n");
		else printf("YES\n");
	}
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  bool b=false;
  while ( n ) {
    if ( n%10==9 ) b=true;
    n/=10;
  }
  if ( b ) cout << "Yes" << '\n';
  else cout << "No" << '\n';
  return 0;
}


Measured memory_bytes: 384
import copy
import itertools

h, w, k = map(int,input().split())
li = [list(input()) for i in range(h)]
ans = 0


#ビット全探索
for i in range(2**h):
    for j in range(2**w):
        x = copy.deepcopy(li)
        count = 0

        for b in range(h):
            if ((i >> b) & 1): #フラグが立っていたら
                x[b] = ["-"] * w
        for b in range(w):
            if ((j >> b) & 1): #フラグが立っていたら
                for a in range(h):
                    x[a][b] = "-"
        
        x = list(itertools.chain.from_iterable(x))
        if x.count("#") == k:
            ans += 1


print(ans)

Measured memory_bytes: 73364
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define ifYN(x) cout<<(x?"Yes":"No")<<"\n" 
#define dcml(n) fixed<<setprecision(n)

 
ll GCD(ll a,ll b) { return b ? GCD(b,a%b) : a; } 
ll LCM(ll a,ll b) { return a/GCD(a,b)*b; } 
ll Factorial(ll n){ ll m=1;while(n>=1)m*=n--;return m; } 
ll modPow(ll x,ll n,ll mod=MOD){ 
    return (!n?1:!n%2?modPow(x*x,n/2,mod)%mod:x%mod*modPow(x,n-1,mod)%mod); 
} 
using namespace std;
//-------------------------------------------
typedef pair<ll,ll> P;
int main(void){
    ll N;cin>>N;
    ll A[N],B[N],C[N-1];REP(i,N){cin>>A[i];A[i]--;}
    REP(i,N){cin>>B[i];}
    REP(i,N-1){cin>>C[i];}
    ll ans=0;
    ll za=INF;
    REP(i,N){
        if(za+1==A[i])ans+=C[za];
        ans += B[za=A[i]];
    }
    cout<<ans<<"\n";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

ll dp[110][100010]; // i番目までの子にj個配るパターン数
ll a[110];

int main(){
    int n, k;
    cin >> n >> k;
    rep(i, n) cin >> a[i];
    dp[0][0] = 1;
    rep(i, n){
        ll acc[k+10] = {};
        rep(j, k+1) {
            acc[j+1] += dp[i][j] + acc[j];
            acc[j+1] %= MOD;
        }
        rep(j, k+1){
            dp[i+1][j] += acc[j+1] - acc[max((ll)0, j-a[i])] + MOD;
            dp[i+1][j] %= MOD;
        }
    }
    cout << (dp[n][k] + MOD) % MOD << endl;
    return 0;
}

Measured memory_bytes: 82432
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	int out=inf;
	vvi dp(n+1,vi(2));
	rep(i,n)if(s[i]=='W')dp[i+1][0]=dp[i][0]+1;else dp[i+1][0]=dp[i][0];
	for(int i=n-1;i>=0;i--)if(s[i]=='E')dp[i][1]=dp[i+1][1]+1;else dp[i][1]=dp[i+1][1];
	rep(i,n)out=min(out,dp[i][0]+dp[i+1][1]);
	cout<<out<<endl;
}










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

#define PI acos(-1)
#define int long long int
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fir first
#define sec second
#define MAXN 501
#define MAXL 20
#define mod 1000000007

vector<int> facts;
void primefactors(int n)
{
  while (n % 2 == 0)
  {
    facts.pb(2);
    n = n / 2;
  }
  for (int i = 3; i <= sqrt(n); i += 2)
  {
    while (n % i == 0)
    {
      facts.pb(i);
      n = n / i;
    }
  }
  if (n > 2)
    facts.pb(n);
}
signed main()
{
  int n;
  cin >> n;
  primefactors(n);
  sort(facts.begin(), facts.end());
  //for (auto const &i : facts)
  //cout << i << endl;
  map<int, int> freq;
  map<int, int> at;
  int ans = 0;
  for (auto const &i : facts)
  {
    if (at[i] == 0)
      at[i] = 1;
    freq[i]++;
    if (freq[i] == at[i])
    {
      ans++;
      freq[i] = 0;
      at[i]++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3732
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    ll a, b;
    cin >> a >> b;
    ll k;
    if (b == 100)
    {
        k = a * 1000 + b;
    }
    else if (b >= 10)
    {
        k = a * 100 + b;
    }
    else 
    {
        k = a * 10 + b;
    }

    for (ll i = 1; i < 400; i++)
    {
        if (i * i == k)
        {
            cout << "Yes" << endl;
            exit(0);
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    HashMap<Integer, ArrayList> map1 = new HashMap<Integer, ArrayList>();
    HashMap<Integer, ArrayList> map2 = new HashMap<Integer, ArrayList>();
    int[] a = new int[n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      if(map2.containsKey(a[i])) {
        ArrayList<Integer> list = map2.get(a[i]);
        list.add(i);
        map2.put(a[i], list);
      } else {
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(i);
        map2.put(a[i], list);
      }
    }
    Arrays.sort(a);
    for(int i = 0; i < n; i++) {
      if(map1.containsKey(a[i])) {
        ArrayList<Integer> list = map1.get(a[i]);
        list.add(i);
        map1.put(a[i], list);
      } else {
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(i);
        map1.put(a[i], list);
      }
    }

    int odd = 0;
    int even = 0;

    for(int key : map1.keySet()) {
      ArrayList<Integer> list1 = map1.get(key);
      ArrayList<Integer> list2 = map2.get(key);
 
      int odd1 = 0;
      int even1 = 0;

      int odd2 = 0;
      int even2 = 0;

      for(int i = 0; i < list1.size(); i++) {
        int c = list1.get(i);
        if(c % 2 == 0) {
          even1++;
        } else {
          odd1++;
        }
      }

      for(int i = 0; i < list2.size(); i++) {
        int c = list2.get(i);
        if(c % 2 == 0) {
          even2++;
        } else {
          odd2++;
        }
      }

      if(odd2 > odd1) {
        odd += (odd2 - odd1);
      } else if(even2 > even1) {
        even += (even2 - even1);
      }
    }

    int ans = Math.max(odd, even);
    System.out.println(ans);
  }
}

Measured memory_bytes: 82920
#include<stdio.h>

int main()
{
    int i,f=0;
    char s,e;

    scanf("%c",&s);
    for(i=0;i<3;i++){
        e=s;
        scanf("%c",&s);
        if(s==e) f=1;
    }

    if(f==1) printf("Bad");
    else printf("Good");

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}


int main()
{
  ll n,l[2000],r[2000],ans;
  ans=0;
  cin >> n;
  rep(i,n)cin >> l[i] >> r[i];
  rep(i,n)ans+=r[i]-l[i]+1;
  printf("%lld",ans);
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)

ans = a[0]
ans_l = []
ans_e = a[-1]


if n > 2:
    if ans_e >= 0:
        for i in range(1,n-1):
            if a[i] < 0:
                ans_l += [(ans_e, a[i])]
                ans_e -= a[i]
            if a[i] >= 0:
                ans_l += [(ans, a[i])]
                ans -= a[i]

        ans_l += [(ans_e,ans)]
        ans = ans_e - ans

    else:
        ans = ans_e
        for i in range(0,n-1):
            ans_l += [(ans, a[i])]
            ans -= a[i]

else:
    ans_l += [(ans_e,ans)]
    ans = ans_e - ans

print(ans)

for x, y in ans_l:
    print(x,y)


Measured memory_bytes: 63196
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
	__INIT() {
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}__init;

int main(void) {
    ll n;
    cin>>n;
    vl p(n),q(n),pitsu(n);
    rep(i,n) cin>>p[i];
    rep(i,n) cin>>q[i];
    rep(i,n) pitsu[i] = i+1;
    ll i = 0,a,b;
    do{
        if(pitsu == p) a = i;
        if(pitsu == q) b = i;
        i++;
    }while(next_permutation(all(pitsu)));
    cout<<abs(a-b)<<endl;
	return 0;
}


Measured memory_bytes: 3612
#define _GLIBCXX_DEBUG
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  ll i = 0;
  for (auto x : v){os << " [" << i++ << "]" << x; if (i % 10 == 0) os << std::endl;}
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll H, W;
  std::cin >> H >> W;
  H += 2;
  W += 2;
  std::vector< std::string > grid(H, std::string(W, '#'));

  for (ll y = 1; y < H-1; y++) {
    for (ll x = 1; x < W-1; x++) {
      std::cin >> grid[y][x];
    }
  }

  for (ll y = 0; y < H; y++) {
    print(grid[y]);
  }
  return 0;
}


Measured memory_bytes: 256
s = gets.chomp.to_i

def f(n)
  if n%2 == 0
    return n/2
  else
    return 3*n+1
  end
end

hash = {}
temp = s

for i in 1..1000000 do
  if !hash.key?(temp.to_s)
    hash[temp.to_s] = temp
  else
    puts i
    exit
  end
  temp = f(temp)

end


Measured memory_bytes: 1788
#include<stdio.h>
#include<math.h>
#include<string.h>
int main(void)
{
  char ketueki[3]={'\0'};
  int count[4]={0};
  int i;

  for(;scanf("%d,%s",&i,ketueki)!=EOF;){
    if(ketueki[0]=='A'){
      if(ketueki[1]=='B')
	count[2]++;
      else
	count[0]++;
    }
    else if(ketueki[0]=='B')
      count[1]++;
    else if(ketueki[0]=='O')
      count[3]++;
  }

  for(i=0;i<4;i++)
    printf("%d\n",count[i]);

  return 0;
}

Measured memory_bytes: 596
# coding:UTF-8
import sys
from math import factorial

MOD = 10 ** 9 + 7
INF = float('inf')

A, B, C, X, Y = list(map(int, input().split()))     # スペース区切り連続数字

mcost = INF

cnum = max(X, Y)
for i in range(cnum+1):
    anum = max(0, (X - i))
    bnum = max(0, (Y - i))
    cost = A * anum + B * bnum + C * i * 2
    mcost = min(mcost, cost)

print("{}".format(mcost))


Measured memory_bytes: 66984
function solve()
    N, M = parse.(Int, split(readline()))
    A = zeros(Int, N, N)
    B = zeros(Int, M, M)

    for i = 1:N
        s = readline()
        for j = 1:N
            if s[j] == '#' A[i, j] = 1 end
        end
    end

    for i = 1:M
        s = readline()
        for j = 1:M
            if s[j] == '#' B[i, j] = 1 end
        end
    end

    res = false


    for i = 1:max(N-M, 1)
        for j = 1:max(N-M, 1)
            match = true
            for k = 1:M for l = 1:M
                if A[i+k-1, j+l-1] != B[k, l] match = false end
            end end
            if match res = true end
        end
    end

    if res println("Yes")
    else println("No")
    end
end

solve()


Measured memory_bytes: 173516
#include <bits/stdc++.h>
using namespace std;
//二つのせいの整数の平均の小数点以下を切り上げた値を出力する。
//足した値が奇数か偶数かで分ければいいかな？
int main(){
int a,b;
cin >>a>>b;
if((a+b)%2==0){
	cout <<( a+b)/2 <<endl;
}
else {
	cout << (a+b)/2 + 1 <<endl;
}
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String args[]){

    	Scanner scan = new Scanner(System.in);
    	int n = Integer.parseInt(scan.next());
    	scan.close();
    	int waru;
    	int max = 0;
    	int cnt = 0;
    	int max_num = 1;

    	while(n > 0){
    		cnt = 0;
    		waru = n;
        	while(waru % 2 == 0){
        		cnt++;
        		waru = waru / 2;
        	}
        	if(max < cnt){
        		max = cnt;
        		max_num = n;
        	}
        	n--;

    	}
    	System.out.println(max_num);
    }
}

Measured memory_bytes: 21972
#include <iostream>

using namespace std;

int main() {

    int i=0,a=0,b=0,count=0;
    string temp;
    cin>>a>>b;

    for(i=a;i<=b;i++){
        temp=to_string(i);
        if((temp[0]==temp[4])&&(temp[1]==temp[3]))count++;


    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d %d", $a, $b, $c);
if($a == $b && $a == $c && $b == $c) {
    echo 1, PHP_EOL;
} elseif($a == $b || $a == $c || $b == $c) {
    echo 2, PHP_EOL;
} else {
    echo 3, PHP_EOL;
}

Measured memory_bytes: 4728
#include <map>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 200000;

typedef long long ll;

ll s, ans;
int n, a;
map<ll, int> mp;

int main() {
#ifdef Wearry 
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    scanf("%d", &n);

    mp[0] = 1;
    for(int i = 1; i <= n; ++i) {
        scanf("%d", &a);
        s += a;
        ans = (ans + mp[s]);

        if(!mp.count(s)) {
            mp[s] = 1;
        } else mp[s] ++;
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 12800