akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate
from bisect import bisect_right, bisect_left

def solve():
    N, M, K = MI()
    A = LI()
    B = LI()
    A = [0] + list(accumulate(A))
    B = [0] + list(accumulate(B))

    ans = 0
    for i, a in enumerate(A):
        if a > K:
            break
        idx = bisect_right(B, K - a) - 1
        ans = max(ans, i + idx)
    print(ans)

        



if __name__ == '__main__':
    solve()


Measured memory_bytes: 41004
from collections import defaultdict as dd
n=int(input())
d=dd(int)
ans=0
for i in range(n):
    s=input()
    d[s]+=1
m=int(input())
for i in range(m):
    s=input()
    d[s]-=1
v=max(d.values())
print(max(v,0))

Measured memory_bytes: 3316
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

int n;

vector<int> dijkstra(int s, vector<vector<P>> &G){
    vector<int> dist(n, 1e9);
    priority_queue<P, vector<P>, greater<P>> que;
    dist[s] = 0;
    que.emplace(0, s);

    while(que.size()){
        int ccost, cv;
        tie(ccost, cv) = que.top(); que.pop();

        if(dist[cv] < ccost) continue;

        for(auto nxt : G[cv]){
            int nv, ncost;
            tie(nv, ncost) = nxt;

            if(dist[cv] + ncost < dist[nv]){
                dist[nv] = dist[cv] + ncost;
                que.emplace(dist[nv], nv);
            }
        }
    }

    return dist;
}

int diameter(vector<vector<P>> &G){
    vector<int> dist1 = dijkstra(0, G);
    int v1 = max_element(dist1.begin(), dist1.end()) - dist1.begin();
    vector<int> dist2 = dijkstra(v1, G);
    return *max_element(dist2.begin(), dist2.end());
}

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

    cin>>n;
    vector<vector<P>> G(n);
    for(int i=0; i<n-1; i++){
        int a, b; cin>>a>>b;
        a--, b--;
        G[a].emplace_back(b, 1);
        G[b].emplace_back(a, 1);
    }

    int K = diameter(G);

    cout << (K % 3 != 1 ? "First" : "Second") << endl;
}

Measured memory_bytes: 17876
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#define int 		long long
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b)	for(int i=a;i<b;i++)
using namespace std;

void solve(){
	int n;
	cin>>n;
	vi x(n);
	vi y(n);
	rep(i,0,n)cin>>x[i]>>y[i];
	int ans=0;
	for(int i=n-1;i>=0;i--){
		x[i]+=ans;
		ans+=((x[i]+y[i]-1)/y[i])*y[i]-x[i];
	}
	cout<<ans<<endl;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 1792
from collections import deque
K = int(input())
q = deque(list(range(1,10)))
x = 0
for i in range(1, K+1):
    x = q.popleft()
    xs = str(x)
    if xs[-1] != '0':
        add_n = int(xs + str(int(xs[-1]) - 1))
        q.append(add_n)
    add_n = int(xs + str(int(xs[-1])))
    q.append(add_n)
    if xs[-1] != '9':
        add_n = int(xs + str(int(xs[-1]) + 1))
        q.append(add_n)
print(x)

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

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

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

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

int main(){

    bool flag=false;
    char ans;

    string a,b,c;
    queue<char> qa,qb,qc;
    cin>>a>>b>>c;

    rep(i,a.length())qa.push(a[i]);
    rep(i,b.length())qb.push(b[i]);
    rep(i,c.length())qc.push(c[i]);

    int turn=0;
    bool fin=false;

    while(!fin){
        char now;
        
        //db2(now,turn);
        //db3(qa.size(),qb.size(),qc.size());ln;

        switch(turn){
            case 0: if(qa.empty()){fin=true;ans='A';} now=qa.front();qa.pop();break;
            case 1: if(qb.empty()){fin=true;ans='B';} now=qb.front();qb.pop();break;
            case 2: if(qc.empty()){fin=true;ans='C';} now=qc.front();qc.pop();break;
            default : break;
        }

        switch(now){
            case 'a':turn=0;break;
            case 'b':turn=1;break;
            case 'c':turn=2;break;
            default : break;
        }
    }
    cout<<ans<<endl;

    //cout <<fixed<<setprecision(16)<< << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 256
/*
                                                              _        ___    
                                                             //      /        
----__----------------)__----__------__--_/_----__---)__-----/------/___------
  /   ) /   / /   /  /   ) /   )   /   ) /    /   ) /   )   /      /    )     
_(___(_(___/_(___(__/_____(___(___/___/_(_ __(___/_/_______/______(____/______
          /                      /                                            
      (_ /                      /                                             */
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define ld long double
#define repo(i, begin, end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define ll long long
#define bug(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<"  ";
#define fastr ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define rrep(i,a,b) for(int i = (a-1); i >= b; i--) 
#define fi first
#define se second
#define tit(v,i,c) get<c>(v[i])
#define mt make_tuple 
#define pb push_back
#define eb emplace_back
#define mp make_pair
double jk=0.004;
#define power(x,y) pow(x,y)+jk
#define endl "\n"
const long long mod=1e9+7;
const long long N=1000000000;
const int val=1000005;
int in(){
int n;cin>>n;
return n;}
void _do_(){
	ll a;ld b;
	cin>>a>>b;
	ll ans=1.00;
	ans*=a*1.00;
	ans*=b*100;
	ans/=100.0;
	string s;
	//s=to_string(ans);
	//rep(i,0,s.size()-7)cout<<s[i];cout<<endl;
	cout<<(ll)(ans+0.00000000000000001)<<endl;


















	

}
signed main(){
fastr
int tc;
//cin>>tc;
tc=1;
while(tc--)_do_();
cerr<<"Time elapsed:";
cerr<<1000*clock()/CLOCKS_PER_SEC<<" ms ";
return 0;}

Measured memory_bytes: 3744
#include <stdio.h>
#include <stdlib.h>
#define max_size (int)(1e5 + 1)

int main(){
	int i, j, N, ans = 0;
	char *s = (char *)malloc(sizeof(char) * max_size);
	scanf("%s", s);
	for(i = 0; s[i] != '\0'; i++){}
	N = i;
	for(i = 0, j = N - 1; j - i > 0; ){
		if(s[i] == s[j]){
			i++;
			j--;
		}
		else if(s[i] == 'x'){
			ans++;
			i++;
		}
		else if(s[j] == 'x'){
			ans++;
			j--;
		}
		else{
			printf("-1\n");
			return 0;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();
		int a = 0;
		for (int i = 0; i < n; i++) {
			a = Integer.parseInt(sc.next());
		}

		int ans = 1;
		if (n > k) {
			ans += (n - k) / (k - 1);
			if ((n - k) % (k - 1) != 0)
				ans++;
		}

		System.out.println(ans);

	}

}


Measured memory_bytes: 42636
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;
int F[50];
int fib(int i){
	if(i == 0 || i == 1) return 1;

	if(F[i] != -1) return F[i];
	
	return F[i] = fib(i-1) + fib(i-2);
}

int main(){
	int n;
	cin >> n;
	for(int i = 0;i < 50;i++) F[i] = -1;
	cout << fib(n) << endl;
	return 0;
}

Measured memory_bytes: 1160
class Event:
    def __init__(self, type_, time_):
        self.time = time_
        self.etype = type_
    def __lt__(self, other):
        if self.time != other.time:
            return self.time < other.time
        if self.etype != other.etype:
            return self.etype > other.etype
        return self.time < other.time

while 1:
    n = input()
    if n==0 : break

    evs = [0]*2*n
    for i in range(n):
        la = raw_input().split(' ')
        for j in range(2):
            t = map(int,la[j].split(':'))
            t = (t[0]*60+t[1])*60+t[2]
            evs[i*2+j] = Event(j, t)
    evs.sort()

    ans, cur = 0, 0
    for i in evs:
        if i.etype == 0:
            cur+=1
            ans = max(cur, ans)
        else:
            cur-=1
        # print i
    print ans

Measured memory_bytes: 12140
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
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 ll INF = 1e9;
const ll MOD = 1e9 + 7;


int main(){
    int n;
    ll c;
    cin >> n >> c;
    vector<ll> x(n+1), v(n+1), y(n+1), u(n+1);
    for(int i=1; i<=n; i++){
        cin >> x[i] >> v[i];
        y[n-i+1] = (c-x[i]);
        u[n-i+1] = v[i];
    }

    ll sum = 0;
    vector<ll> s(n+1);
    for(int i=1; i<=n; i++){
        sum += (v[i] - (x[i]-x[i-1]));
        chmax(s[i], max(sum, s[i-1]));
    }
    reverse(all(s));

    ll ans = s[0];
    sum = 0;
    for(int i=1; i<=n; i++){
        sum += (u[i] - 2*(y[i]-y[i-1]));
        ll nex = sum + s[i];
        chmax(ans, nex);
    }

    sum = 0;
    vector<ll> t(n+1);
    for(int i=1; i<=n; i++){
        sum += (u[i] - (y[i]-y[i-1]));
        chmax(t[i], max(sum, t[i-1]));
    }
    reverse(all(t));

    sum = 0;
    chmax(ans, t[0]);
    for(int i=1; i<=n; i++){
        sum += (v[i] - 2*(x[i]-x[i-1]));
        ll nex = sum + t[i];
        chmax(ans, nex);
    }


    cout << ans << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[305];
int main(){
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%lld", &a[i]);
    }
    ll x = 0;
    ll y = a[1]+a[2];
    for(int i=3;i<=n;i++) x ^= a[i];
    if(x > y || x%2 != y%2) printf("-1\n");
    else{
        ll z = (y-x)/2;
        ll A = 0, B = 0;
        for(int i=59;i>=0;i--){
            if((z>>i)&1){
                A += (1ll<<i);
                B += (1ll<<i);
            }
        }
        for(int i=59;i>=0;i--){
            if((z>>i)&1) continue;
            else{
                if((x>>i)&1){
                    if(A+(1ll<<i) <= a[1]){
                        A += (1ll<<i);
                    }
                    else{
                        B += (1ll<<i);
                    }
                }
            }
        }
        if(A <= a[1] && B <= a[1]){
            if(A < B) swap(A, B);
        }
        else if(B <= a[1]){
            swap(A, B);
        }
        if(A <= a[1] && A != 0 && A+B == y){
            printf("%lld\n", a[1]-A);
        }
        else{
            printf("-1\n");
        }
    }
}

Measured memory_bytes: 3756
from collections import deque
n, q = map(int, input().split())
lists = [deque() for i in range(n)]
while q:
    q -= 1
    s = [*map(int, input().split())]
    if s[0] == 0:
        lists[s[1]].append(s[2])
    elif s[0] == 1:
        print(*lists[s[1]])
    else:
        l1, l2 = lists[s[1]], lists[s[2]]
        if len(l1) < len(l2):
            l2.extend(l1)
            l1.clear()
        else:
            while len(l2):
                l1.appendleft(l2[-1])
                l2.pop()
            lists[s[1]], lists[s[2]] = lists[s[2]], lists[s[1]]


Measured memory_bytes: 30648
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef   long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define B 998244353ll
#define C 1000000000000000001ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI 3.14159265358979323

ll gcd(ll a,ll b)
{
 if(a%b==0)return b;
 else {return gcd(b,a%b);}
}

ve<pair<ll,ll>> vec;
void primefactor(ll n)
{
    ll b=0;
    while (n % 2 == 0)  
    {  
        b++;
        n = n/2;  
    }  
    if(b>0)
        vec.pb({2,b});
    b=0;
    for (ll i = 3; i*i <= n; i = i + 2)  
    {   
        b=0;
        while (n % i == 0)  
        {  
            b++;
            n = n/i;  
        }  
        if(b>0)
            vec.pb({i,b});
    }  
    if (n > 2)  
        vec.pb({n,1});
}

int main() 
{
    FAST;
    ll a,b;
    cin>>a>>b;
    ll g=gcd(a,b);
    primefactor(g);
    cout<<vec.size()+1;
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

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

using namespace std;

int main() {
    int k, a, b;
    cin >> k >> a >> b;

    for (int i=a;i <= b;i++) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;
}


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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int N;
    cin >> N;
    int A[N];
    rep(i,N) {
        int a;
        cin >> a;
        A[i] = a;
    }
    ll ans = INF;
    for (int n=-100; n<=100; n++) {
        ll tmp = 0;
        rep(i,N) {
            tmp += (n-A[i])*(n-A[i]);
        }
        ans = min(ans,tmp);
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int a[101]={};
char getalpha(int idx){return (char)(a[idx]/1000);};
int getdigit(int idx){return (a[idx]/100) % 10;};
int getrank(int idx){return a[idx] % 100;};

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    cin>>n;
    //int a[101]={};
    REP(i,n){
        string s;
        cin>>s; //^[SHCD][1-9]$
        a[i] = (int)s[0]*1000 + ((int)s[1]-48)*100 + i;
    }
    // auto getalpha = [&](int idx){return (char)(a[idx]/1000);};
    // auto getdigit = [&](int idx){return (a[idx]/100) % 10;};
    // auto getrank = [&](int idx){return a[idx] % 100;};
    
    int atmp[101]={};
    memcpy(atmp, a, sizeof(a));

    bool flg=true;
    //while(flg){
    //    flg=false;
    REP(i,n){
        FORR(j,i+1,n){
            //DEBUG2(getdigit(j),getdigit(j-1));
            if(getdigit(j)<getdigit(j-1)){
                swap(a[j],a[j-1]);
            }
        }
    }

    bool bstable = true;
    REP(i,n){
        cout<<(char)getalpha(i)<<getdigit(i);
        if(i==n-1) cout<<endl;
        else cout<<" ";

        if(i>0 && getdigit(i)==getdigit(i-1) && getrank(i)<getrank(i-1))
            bstable = false;
    }

    if(bstable) cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;

    memcpy(a, atmp, sizeof(atmp));

    //選択ソート
    REP(i,n){
        int mn=i;
        FOR(j,i,n){
            if(getdigit(j)<getdigit(mn)) mn=j;
        }

        if(i!=mn){
            swap(a[i], a[mn]);
        }
    }

    bstable = true;
    REP(i,n){
        cout<<(char)getalpha(i)<<getdigit(i);
        if(i==n-1) cout<<endl;
        else cout<<" ";

        if(i>0 && getdigit(i)==getdigit(i-1) && getrank(i)<getrank(i-1))
            bstable = false;
    }

    if(bstable) cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;

    return 0;
}


Measured memory_bytes: 3180
def BFS(K,path,N):
  """リストのリスト道順path,頂点の個数Nが与えられたとき, 頂点Kから各頂点までの距離をlistで返す"""
  from collections import deque
  dist=[-1]*N
  dist[K]=0
  que=deque()
  que.append(K)
  while que:
    label=que.popleft()
    for i,c in path[label]:
      if dist[i]==-1:
        dist[i]=dist[label]+c
        que+=[i]
  return dist
 
N=int(input())
path=[ [] for i in range(N)]
for i in range(N-1):
  a,b,c=map(int,input().split())
  path[a-1]+=[[b-1,c]]
  path[b-1]+=[[a-1,c]]
Q,K=map(int,input().split())
xy=[list(map(int,input().split())) for i in range(Q)]
distance=BFS(K-1,path,N)
for i in range(Q):
  print(distance[xy[i][0]-1]+distance[xy[i][1]-1])

Measured memory_bytes: 74356
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
  double a, b, x;
  cin >> a >> b >> x;
  double s = x/a;
  double rad;
  if(s <= a*b/2){
    double h = s*2/b;
    rad = atan2(b,h);
  }
  else{
    double h = (a*b-s)*2/a;
    rad = atan2(h,a);
  }
  double pi = acos(-1);
  double deg = rad/(2*pi)*360;
  printf("%.10f\n", deg);
  return 0;
}

Measured memory_bytes: 256
s = input().split()
n = int(s[0])
m = int(s[1])
alist = list(map(int, input().split()))
a_sum = sum(alist)
alist.sort(reverse=True)
std = a_sum/(4*m)
if (alist[m-1]<std):
  print("No")
else:
  print("Yes")

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(){
	cout.precision(10);
	double n,m,d;
	cin >> n >> m >>d;
	if(d==0){
		cout << (m-1)/n << endl;
		return 0;
	}else{
		cout << (2*(n-d)/n)*((m-1)/n) << endl;
	}
}

Measured memory_bytes: 256
//set many funcs template
//Ver.20181228
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<math.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}

typedef struct{
int node;
double cost;
}data;

data heap[262144];
int hsize=0;

void resheap(){
    int i;
    heap[0].node=-1;
    heap[0].cost=-llinf;
    for(i=1;i<262144;i++){
        heap[i].node=-1;
        heap[i].cost=llinf;
    }
}

int swjud(data high,data low){
    if(high.cost > low.cost){return 1;}
    return -1;
}

void pqpush(data x){
    int a,b;
    data m;
    hsize++;
    heap[hsize]=x;
    a=hsize;
    while(1){
        b=a/2;
        if(swjud(heap[b],heap[a]) == 1){
            m=heap[a];heap[a]=heap[b];heap[b]=m;
        }
        else{break;}
        a=b;
    }
}

data pqpop(){
    int a,b,c;
    data m,sw;
    m=heap[1];
    heap[1]=heap[hsize];
    heap[hsize].node=-1;
    heap[hsize].cost=llinf;
    hsize--;
    a=1;
    while(1){
        b=a*2;c=a*2+1;
        if(swjud(heap[a],heap[b])==-1 && swjud(heap[a],heap[c])==-1){break;}
        if(swjud(heap[b],heap[c])==-1){
            sw=heap[a];heap[a]=heap[b];heap[b]=sw;
            a=b;
        }
        else{
            sw=heap[a];heap[a]=heap[c];heap[c]=sw;
            a=c;
        }
    }
    return m;
}

int n;
double x[16],y[16],a[16],ds[16][16];

double calcmst(int fl){
  int i,w,vf=0;
  data pd,od;
  double res=0.0;
  while(hsize>0){od=pqpop();}
  for(i=0;i<n;i++){
    if((fl&(1<<i))!=0){w=i;break;}
  }
  pd.node=w;pd.cost=0.0;pqpush(pd);
  while((vf&fl)!=fl){
    od=pqpop();
    if((vf&(1<<od.node))!=0){continue;}
    vf|=(1<<od.node);
    res+=od.cost;
    for(i=0;i<n;i++){
      if(((vf&(1<<i))!=0) || ((fl&(1<<i))==0)){continue;}
      pd.node=i;
      pd.cost=ds[i][od.node];
      pqpush(pd);
    }
  }
  return res;
}

double csig(int fl){
  int i;
  double res=0.0;
  for(i=0;i<n;i++){
    if((fl&(1<<i))!=0){res+=a[i];}
  }
  return res;
}

int main(void){
    resheap();
    int i,j,w;
    double dp[65536],mst[65536],cs[65536],bc[65536],v;
    scanf("%d",&n);
    for(i=0;i<n;i++){
      scanf("%lf%lf%lf",&x[i],&y[i],&a[i]);
    }
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
        ds[i][j]=sqrt((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]));
      }
    }
    for(i=0;i<65536;i++){dp[i]=-100;mst[i]=-100;}
    dp[0]=inf;
    for(i=0;i<(1<<n);i++){
      if(dp[i]<-1.0){continue;}
      for(j=0;j<n;j++){
        if((i&(1<<j))!=0){w=j;break;}
      }
      for(j=(1<<w);j<(1<<n);j+=(1<<w)){
        if((i&j)!=0){continue;}
        if(mst[j]<-1.0){
          mst[j]=calcmst(j);
          cs[j]=csig(j);
          bc[j]=dsumb(j,2);
        }
        v=dbmax((cs[j]-mst[j])/bc[j],0.0);
        dp[i|j]=dbmax(dbmin(dp[i],v),dp[i|j]);
      }
    }
    printf("%.12lf\n",dp[(1<<n)-1]);
    return 0;
}


Measured memory_bytes: 5760
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<queue>
#include<bitset>

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)

using namespace std;

typedef long long int lli;
typedef long long ll;
typedef vector<int> vi;

int main() {
	string s,t;
	int i, j, k;
	bool u=true;

	cin >> s;

	j = k = 0;
	rep(i, s.length()) {
		if (s[i] == '0')j++;
		else k++;
	}

	if (min(j, k) == 0) {
		cout << 0;
	}
	else {
		cout << min(j, k) * 2;
	}

	return 0;
}

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

x1 = 0
for i in range(1, n, 2):
    x1 += a[i]*2

x1 = sum(a)-x1
ans = [x1]
for i in range(n-1):
    ans.append((a[i]-ans[i]//2)*2)

print(*ans)


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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

int ss[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if(ss[a - 1] == b)
        cout << 1 << '\n';
    else
        cout << 0 << '\n';
    return 0;
}


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

int main(){
  int i, N;
  cin >> N;
  long int sum = 0;
  
  for ( int i = 0; i <= N; i++ ) 
   
  if ( i % 3 == 0 && i % 5 == 0 ) 
     sum = sum + 0;
  else if ( i % 3 == 0 )
     sum = sum + 0;
  else if ( i % 5 == 0 )
     sum = sum + 0;
  else 
     sum = sum + i;
  
     cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin>>n;
    map<string,int>m;
    string s;
    for(int i=1;i<=n;i++){
        cin>>s;
        m[s]++;
    }
    int ans=-1;
    for(auto it=m.begin();it!=m.end();it++){
        ans=max(ans,it->second);
    }
    for(auto x:m){
        if(x.second==ans) cout<<x.first<<endl;
    }
}

Measured memory_bytes: 25216
dice = list(map(int, input().split()))
cmd = input()
for i in range(len(cmd)):
  if cmd[i] == 'N':
    dice[0], dice[1] = dice[1], dice[0]
    dice[1], dice[5] = dice[5], dice[1]
    dice[5], dice[4] = dice[4], dice[5]
  elif cmd[i] == 'E':
    dice[0], dice[3] = dice[3], dice[0]
    dice[3], dice[5] = dice[5], dice[3]
    dice[5], dice[2] = dice[2], dice[5]
  elif cmd[i] == 'W':
    dice[0], dice[2] = dice[2], dice[0]
    dice[2], dice[5] = dice[5], dice[2]
    dice[5], dice[3] = dice[3], dice[5]
  else:
    dice[0], dice[4] = dice[4], dice[0]
    dice[4], dice[5] = dice[5], dice[4]
    dice[5], dice[1] = dice[1], dice[5]
print(dice[0])


Measured memory_bytes: 5612
#include<stdio.h>

int main(void){
  int cnt,f1,f2,f3,f4,n;
  while(scanf("%d",&n) != EOF){
    cnt = 0;
    for(f1 = 0;f1 < 10; f1++){
      for(f2 = 0; f2 < 10; f2++){
	for(f3 = 0;f3 < 10; f3++){
	  for(f4 = 0;f4 < 10; f4++){
	    if(f1 + f2 + f3 + f4 == n){
	      cnt++;
	    }
	  }
	}
      }
    }
    printf("%d\n",cnt);
  }
  return 0;
}

Measured memory_bytes: 596
import numpy as np
N, M = map(int, input().split())

S = []
for m in range(M):
    l = list(map(int, input().split()))
    S.append(np.array(l[1:], dtype = int) - 1)
P = list(map(int, input().split()))

cnt = 0
for n in range(2 ** N):
    tmp = np.array(list(map(int, list(format(n, 'b').zfill(N)))), dtype = int)
    f = True
    for m in range(M):
        # print (S[m])
        if tmp[S[m]].sum() % 2 != P[m]:
            f = False
            break

    if f: cnt += 1

print (cnt)


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

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

int main()
{
	int N;
	while(cin >> N, N){
		int xma = 0, xmi = 0, yma = 0, ymi = 0;
		vector<int> x(N), y(N);
		for(int i = 1, n, d;i < N;i++){
			cin >> n >> d;
			x[i] = x[n] + dx[d];
			y[i] = y[n] + dy[d];
			xma = max(xma, x[i]);
			xmi = min(xmi, x[i]);
			yma = max(yma, y[i]);
			ymi = min(ymi, y[i]);
		}
		cout << (xma - xmi + 1) << ' ' << (yma - ymi + 1) << endl;
	}
	return 0;
}

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

using namespace std;

template<typename T>
class LazySegTree {
public:
    explicit LazySegTree(int n, T init, T def) : N(calcN_(n)), def(def) {
        mVal.assign(2*N+1, init);
        mLazy.assign(2*N+1, 0);
        mDirty.assign(2*N+1, 0);
    }
    void update(int l, int r, T value){
        updateImpl_(l, r, value, 0, 0, N);
    }
    T get(int l, int r){
        return getImpl_(l, r, 0, 0, N);
    }
private:
    int calcN_(int n){
        int res = 1;
        while(res < n) res *= 2;
        return res;
    }
    void updateImpl_(int l, int r, T value, int idx, int rangeL, int rangeR){
        eval_(idx);
        if(r <= rangeL || rangeR <= l) return;
        if(l <= rangeL && rangeR <= r){
            setLazy_(idx, value);
            eval_(idx);
        } else {
            int rangeM = (rangeL+rangeR)/2;
            updateImpl_(l, r, value, 2*idx+1, rangeL, rangeM);
            updateImpl_(l, r, value, 2*idx+2, rangeM, rangeR);
            mVal[idx] = operate_(mVal[2*idx+1], mVal[2*idx+2]);
        }
    }
    void setLazy_(int idx, T value){
        mLazy[idx] += value;
        mDirty[idx] = 1;
    }
    T getImpl_(int l, int r, int idx, int rangeL, int rangeR){
        if(r <= rangeL || rangeR <= l) return def;
        eval_(idx);
        if(l <= rangeL && rangeR <= r) return mVal[idx];
        int rangeM = (rangeL+rangeR)/2;
        T a = getImpl_(l, r, 2*idx+1, rangeL, rangeM);
        T b = getImpl_(l, r, 2*idx+2, rangeM, rangeR);
        return operate_(a, b);
    }
    void eval_(int idx){
        if(!mDirty[idx]) return;
        mVal[idx] += mLazy[idx];
        if(idx < N-1){
            setLazy_(2*idx+1, mLazy[idx]);
            setLazy_(2*idx+2, mLazy[idx]);
        }
        mLazy[idx] = 0;
        mDirty[idx] = 0;
    }
    T operate_(T a, T b) const { return max(a, b); }
    const int N;
    const T def;
    vector<T> mVal;
    vector<T> mLazy;
    vector<int> mDirty;
};

int solve(const string& S, int mergin){
    int mx = 0;
    int sum = 0;
    LazySegTree<int> seg(S.size()+1, 0, -1000000000);
    for(int i=0;i<S.size();i++){
        sum += (S[i] == '1' ? 1 : -1);
        seg.update(i+1, i+2, sum);
        mx = max(mx, sum);
    }
    mx += mergin;
    for(int i=0;i<S.size();i++){
        if(S[i] != '?') continue;
        if(seg.get(i+1, S.size()+1) + 2 <= mx){
            seg.update(i+1, S.size()+1, 2);
        }
    }
    int mv = 1000000000;
    for(int i=0;i<=S.size();i++) mx = min(mx, seg.get(i, i+1));
    return seg.get(0, S.size()+1) - mx;
}

int main(){
    string S; cin >> S;
    cout << min(solve(S, 0), solve(S, 1)) << endl;
}


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

string s;

int main()
{
    cin >> s;
    vector <string> v;

    for (int i(0); i < s.size(); i++) {
        string q;
        for (int j(0); j + i < s.size() && j <= 5; j++) {
            q.push_back(s[i + j]);
            v.push_back(q);
        }
    }

    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());

    int k;
    cin >> k;
    cout << v[k - 1] << '\n';

    return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
  ll n;
  cin>>n;
  ll s = 0;
  ll num = n;
  while (num) {
    ll tmp = num % 10;
    s += tmp;
    num /= 10;
  }
  if (n % s == 0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
/**
 *     author: qodjf
 *     created: 05.01.2020 00:22:27
 */
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

ll N, A, B, C, D;

bool check() {
  for (int i = N - 1; i >= 0; i--) {
    ll left = A - i * D + (N - 1 - i) * C;
    ll right = A - i * C + (N - 1 - i) * D;
    if (left <= B && B <= right) {
      return true;
    }
  }
  return false;
}

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

  cin >> N >> A >> B >> C >> D;

  if (check()) {
    puts("YES");
  } else {
    puts("NO");
  }
}


Measured memory_bytes: 256
N, K = map(int, input().split())

A_list = list(map(int, input().split()))

# search smallest i such that f(i) == True
def auto_bisearch_smallest(f, s = None):
	if s == None:
		s = 0
		w = -1
		while f(s) == True:
			s = w
			w *= 2
	e = s
	w = 1
	while f(e) == False:
		e = s + w
		w *= 2
	
	return bisearch_smallest(f, s, e + 1)

# search smallest i ( s <= i < e ) such that f(i) == True
def bisearch_smallest(f, s, e = None):
	if e == None:
		e = s - 1
		s = 0
	else:
		e -= 1
	
	while s < e:
		m = (s + e) // 2
		if f(m):
			e = m
		else:
			s = m + 1
	
	if s == e and f(s):
		return s
	else:
		return -1

def calc(length):
	count = 0
	for a in A_list:
		if a > length:
			if a % length == 0:
				count += (a // length) - 1
			else:
				count += a // length
	return count

print(auto_bisearch_smallest(lambda length: calc(length) <= K, 1))


Measured memory_bytes: 93856
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

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

int count(int N)
{
        int cnt = 0;
        while (N)
        {
                cnt += N % 10;
                N /= 10;
        }
        return cnt;
}

int main()
{
        int A, B;
        cin >> A >> B;
        int ans = 0;
        for (int i = 1; i < 10; i++)
        {
                for (int j = 0; j < 10; j++)
                {
                        for (int k = 0; k < 10; k++)
                        {
                                int tmp = i * 10001 + j * 1010 + k * 100;
                                if (A <= tmp && tmp <= B)
                                        ans++;
                        }
                }
        }
        cout << ans << endl;

        return 0;
}


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

int main()
{
    string s,t;
    cin >> s >> t;
    int lens = s.size(), lent = t.size();
    int i,j;
    bool flag = false;
    if(lens < lent){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }else{
        for(i = lens-lent;i >= 0;--i){
            for(j = 0;j < lent;++j){
                if(s.at(j+i) == t.at(j) || s.at(j+i) == '?'){
                    continue;
                }else{
                    flag = true;
                    break;
                }
            }
            if(flag){
                flag = false;
                continue;
            }else{
                for(j = 0;j < lent;++j){
                    s.at(j+i) = t.at(j);
                }
                for(i = 0;i < lens;++i){
                    if(s.at(i) == '?'){
                        s.at(i) = 'a';
                    }
                }
                cout << s << endl;
                return 0;
            }
        }
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;

int main(){
    string s; cin >> s;
    
    string T = "ATCG";
    
    int ans = 0;
    int now=0;
    for(int i = 0; i < s.size(); i++){
        bool atcg = false;
        for (int j = 0; j < T.size(); j++) {
            if (s[i] == T[j]) atcg = true;
        }
        if (!atcg) now = 0;
        else {
            now++;
            ans = max(now, ans);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll long long
#define uint unsigned
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
using namespace std;
const int mo=1000000007;
const int N=1000005;
int fac[N],inv[N];
int n,m,L,R;
void init(){
	fac[0]=inv[0]=inv[1]=1;
	For(i,2,N-1) inv[i]=1ll*inv[mo%i]*(mo-mo/i)%mo;
	For(i,1,N-1) inv[i]=1ll*inv[i-1]*inv[i]%mo;
	For(i,1,N-1) fac[i]=1ll*fac[i-1]*i%mo;
}
int C(int x,int y){
	if (x<0||y<0||y>x) return 0;
	return 1ll*fac[x]*inv[y]%mo*inv[x-y]%mo;
}
int Func(int x,int y){
	return C(x+y-1,y-1);
}
int solve(int V,int mx,int cnt){
	if (mx<0) return 0;
	int ans=0;
	For(i,0,min(cnt,V/(mx+1))){
		int val=(i&1?mo-C(cnt,i):C(cnt,i));
		val=1ll*val*Func(V-i*(mx+1),n+1)%mo;
		ans=(ans+val)%mo;
	}
	return ans;
}
int solve(int V){
	if (V<0) return 0;
	int sum=Func(V,n+1);
	For(vm,0,(V/m)-1){
		int val=solve(V-(vm+1)*m,vm,n-m);
		val=(val+mo-solve(V-(vm+1)*m,vm-1,n-m))%mo;
		sum=(sum+mo-1ll*val*C(n,m)%mo)%mo;
	}
	//printf("%d %d\n",V,sum);
	return sum;
}
int main(){
	init();
	scanf("%d%d%d%d",&n,&m,&L,&R);
	printf("%d\n",(solve(R)+mo-solve(L-1))%mo);
}

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

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

// #define int long long
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

void accell() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
}


signed main() {
    accell();
    string a, b;
    cin >> a >> b;
    cout << b + a << endl;
    return 0;
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

int main()
{
  ll n, v;
  cin >> n;
  vecll h(n);
  bool ok = true;
  cin >> v;
  h[0] = v - 1;
  forll(i, 1, n){
	cin >> v;
	if (v < h[i-1]){
	  ok = false;
	  break;
	}else if (v == h[i - 1])
	  h[i] = v;
	else
	  h[i] = v - 1;
  }

  if (ok == true)
	cout << "Yes" << endl;
  else
	cout << "No" << endl;
}

Measured memory_bytes: 1024
from collections import deque

s = input()
d = deque(s)
n = int(input())
flag = 0
for _ in range(n):
    q = input().split()
    if (len(q)==1):
        if(flag == 0):
            flag = 1
        else:
            flag = 0
    else:
        a = int(q[1])
        b = q[2]
        if (a == 1):
            if flag==0:
                d.appendleft(b)
            else:
                d.append(b)
        else:
            if flag==0:
                d.append(b)
            else:
                d.appendleft(b)

if flag==1:
    d.reverse()
ans = list(d)
xxx = "".join(ans)
print(xxx)

Measured memory_bytes: 9460
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, ans = 0;
  string S;
  cin >> N >> S;
  
  ans = N;
  for (int i = 0; i < N; i++) {
      if (i < N - 1 && S.at(i) == S.at(i + 1)) {
        ans--;
      }
  }
  cout << ans << endl;
             
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

struct Work
{
  int delay;
  int pay;
};

long solve(int n, int m, std::vector<Work> works)
{
  std::sort(
      works.begin(),
      works.end(),
      [](const Work& lhs, const Work& rhs)
      {
        if (lhs.pay != rhs.pay) return lhs.pay > rhs.pay;
        return lhs.delay > rhs.delay;
      });

  std::vector<int> indexes(m);
  std::iota(indexes.begin(), indexes.end(), 0);

  long result = 0;
  for (const auto& w : works) {
    if (w.delay > m) continue;
    const auto pos = std::max(0, m - w.delay);
    auto it = std::upper_bound(indexes.begin(), indexes.end(), pos);
    if (it == indexes.begin()) continue;
    indexes.erase(std::prev(it));
    result += w.pay;
  }
  return result;
}

int main()
{
  int n, m;
  std::cin >> n >> m;

  std::vector<Work> works(n);
  for (auto& w : works) {
    std::cin >> w.delay >> w.pay;
  }

  std::cout << solve(n, m, std::move(works)) << std::endl;
}


Measured memory_bytes: 1408
#include<cstdio>
#include<algorithm>
using namespace std;
#define int long long
const int inf=0x3f3f3f3f3f3f3f;
struct node{
	int id,val;
	bool operator<(node b)const{
		if(val==b.val)return id>b.id;
		return val>b.val;
	}
}a[100100];
int ans[100100],n;
signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i].val),a[i].id=i;
	sort(a+1,a+n+1);
	int minn=inf,now=1;
	while(now<=n){
		while(now<=n&&a[now].val==a[now+1].val)now++;
		if(now==n+1)break;
		minn=min(minn,a[now].id);
		ans[minn]+=now*(a[now].val-a[now+1].val);
		now++;
	}
	for(int i=1;i<=n;i++)
		printf("%lld\n",ans[i]);
}

Measured memory_bytes: 3328
n = int(input())
s = [input() for i in range(n)]
#['AC', 'TLE', 'AC', 'AC', 'WA', 'TLE']

AC = str(s.count('AC'))
WA = str(s.count('WA'))
TLE = str(s.count('TLE'))
RE = str(s.count('RE'))

print('AC x '+AC)
print('WA x '+WA)
print('TLE x '+TLE)
print('RE x '+RE)

Measured memory_bytes: 16280
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int64_t a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  int64_t ap=0,bp=0,cp=0;
  
  //1枚ずつそれぞれ買う金額の合計
  ap = a * x + b * y;
  //枚数の少ない方にはハーフサイズで合わせて、残りをソロで買う方法
  if(x > y){
  bp =  c * y * 2;
  bp += a * (x-y);
  }
  else{
  bp =  c * x * 2;
  bp += b * (y-x);    
  }
  //cout << bp << endl;

  //ハーフサイズでそろえる
  if(x > y){
  cp = c * x * 2;
  }
  else{
  cp = c*y*2;  
  }
  if(ap <= bp && ap <= cp) cout<<ap<<endl;
  else if(bp <= ap && bp <= cp )cout<<bp<<endl;
  else cout<<cp<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define PB push_back
#define F first
#define S second
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
 
const ll MOD = 1e9+7;

int dp[200007][225];

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
 
	string s; cin >> s;
	int n = s.size();
	map<int, int> m;
	int cnt = 0;
	ll ans = 0;
	int p10 = 1;
	for(int i = n-1; i>=0; i--){
		int d = s[i]-'0';
		cnt = (d*p10 + cnt) % 2019;
		p10 = p10 * 10 % 2019;
		if(cnt == 0) ans++;
		ans += m[cnt];
		m[cnt]++;
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 3760
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	var ans []string
	for _, v := range s {
		if v == 'B' {
			if len(ans) != 0 {
				ans = ans[:len(ans)-1]
			}
		} else {
			ans = append(ans, string(v))
		}
	}
	for _, v := range ans {
		fmt.Print(v)
	}
	fmt.Println()
}


Measured memory_bytes: 512
#include<string>
#include<complex>
#include<cstdlib>
#include<iostream>

#define	rep(i,n)	for(int i=0;i<n;i++)

using namespace std;

bool overflow;

void checkOverflow(const complex<int> z){
	if(abs(real(z))>10000 || abs(imag(z))>10000)	overflow=true;
}

complex<int> term(const string &s,int &idx);
complex<int> factor(const string &s,int &idx);
complex<int> complex1(const string &s,int &idx);
complex<int> complex2(const string &s,int &idx);
complex<int> number(const string &s,int &idx);

complex<int> expr(const string &s,int &idx){
	complex<int> a=term(s,idx);
	while(idx<s.length() && (s[idx]=='+' || s[idx]=='-')){
		char ope=s[idx++];
		complex<int> b=term(s,idx);
		if(ope=='+')	a+=b;
		else			a-=b;
		checkOverflow(a);
	}
	return a;
}

complex<int> term(const string &s,int &idx){
	complex<int> a=factor(s,idx);
	while(idx<s.length() && s[idx]=='*'){
		idx++;
		complex<int> b=factor(s,idx);
		a*=b;
		checkOverflow(a);
	}
	return a;
}

complex<int> factor(const string &s,int &idx){
	complex<int> a;
	if(s[idx]=='('){
		idx++;
		a=expr(s,idx);
		idx++;
	}
	else	a=complex1(s,idx);
	return a;
}

complex<int> complex1(const string &s,int &idx){
	complex<int> a;
	if(s[idx]=='+' || s[idx]=='-'){
		char ope=s[idx++];
		a=complex1(s,idx);
		if(ope=='-')	a*=-1;
	}
	else	a=complex2(s,idx);
	return a;
}

complex<int> complex2(const string &s,int &idx){
	if(s[idx]=='i'){
		idx++;
		return complex<int>(0,1);
	}
	else	return number(s,idx);
}

complex<int> number(const string &s,int &idx){
	int a=0;
	while(idx<s.length() && isdigit(s[idx])){
		a=10*a+(s[idx++]-'0');
		checkOverflow(a);
	}
	return a;
}

complex<int> parse(const string &s){
	int idx=0;
	return expr(s,idx);
}

int main(){
	for(string s;cin>>s;){
		overflow=false;
		complex<int> ans=parse(s);
		if(overflow)	puts("overflow");
		else{
			if(imag(ans)==0)		printf("%d\n",real(ans));
			else if(real(ans)==0)	printf("%di\n",imag(ans));
			else					printf("%d%+di\n",real(ans),imag(ans));
		}
	}

	return 0;
}

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

void search(int i,int *table, int n, int *d, int *f, int *cnt){
	
	++(*cnt);
	d[i] = *cnt;
	for(int k=0;k<n;++k){
		table[k*n+i] = 0;
	}
	for(int j=0;j<n;++j){
		if(table[i*n+j]){
			search(j,table,n,d,f,cnt);
		}
	}
	
	++(*cnt);
	f[i] = *cnt;
}

int main() {
	int n,*table,*d,*f, cnt;
	
	cin>>n;
	table = new int[n*n];
	d = new int[n];
	f = new int[n];
	
	for(int i=0;i<n;++i){
		int u,k,v;
		cin>>u>>k;
		for(int j=0;j<k;++j){
			cin>>v;
			table[(u-1)*n+v-1]=1;
		}
	}
	cnt = 0;
	
	while(true){
		int rest = 0;
		for(int i=0;i<n;++i){
			for(int j=0;j<n;++j){
				if(table[i*n+j]){
					rest = 1;
					break;
				}
			}
			if(rest){
				search(i,table,n,d,f,&cnt);
				break;
			}
		}
		if(!rest){
			break;
		}
	}
	
	for(int i=0;i<n;++i){
		cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1232