akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

int N;
double x[50000], r[50000];

bool check(double height)
{
  map< double, int > shake;
  for(int i = 0; i < N; i++) {
    if(r[i] > height) {
      double dist = sqrt(r[i] * r[i] - height * height);
      shake[x[i] - dist]++;
      shake[x[i] + dist]--;
    }
  }
  int sz = 0;
  double rev = 1e9, ret = -1;
  for(auto &p : shake) {
    if(sz == 0) rev = p.first;
    sz += p.second;
    if(sz == 0) ret = max(ret, p.first - rev);
  }
  return (height * 2 <= ret);
}

int main()
{
  while(cin >> N, N) {
    for(int i = 0; i < N; i++) {
      cin >> x[i] >> r[i];
    }
    double low = 0, high = 1e5;
    for(int i = 0; i < 50; i++) {
      double mid = (low + high) * 0.5;
      if(check(mid)) low = mid;
      else high = mid;
    }
    cout << fixed << setprecision(10) << low * 2 << endl;
  }
}

Measured memory_bytes: 10180
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;

int main() {
  int h, w;
  cin >> h >> w;
  vector<vc> s(h + 2, vc(w + 2, '.'));
  vi di = {-1, 0, 0, 1};
  vi dj = {0, -1, 1, 0};
  rep2(i, 1, h + 1) rep2(j, 1, w + 1) cin >> s[i][j];
  rep2(i, 1, h + 1) rep2(j, 1, w + 1) {
    if(s[i][j] == '#') {
      bool yes = false;
      rep(k, 4) if(s[i + di[k]][j + dj[k]] == '#') {
        yes = true;
        break;
      }
      if(yes == false) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
s = []
for i in range(2):
    s.append(input().split())
n = int(s[0][0])
k = int(s[0][1])
answer = 0
hs = s[1]
h = [int(a) for a in hs]
h.sort()
h.reverse()
if(k<n):
    for i in range(k,n):
        answer = answer + h[i]
print(answer)

Measured memory_bytes: 28012
#060-D
n,w=map(int,input().split())
v=[[] for i in range(4)]
w1,v1=map(int,input().split())
v[0].append(v1)
for i in range(1,n):
    tw,tv=map(int,input().split())
    v[tw-w1].append(tv)
for i in range(4):
    v[i].sort(reverse=True)
cum=[[0] for i in range(4)]
for i in range(4):
    for j in range(len(v[i])):
        cum[i].append(cum[i][j]+v[i][j])
s=0
for i in range(len(v[0])+1):
    for j in range(len(v[1])+1):
        for k in range(len(v[2])+1):
            for l in range(len(v[3])+1):
                if w1*(i+j+k+l)+j+2*k+3*l>w:
                    continue
                s=max(s,cum[0][i]+cum[1][j]+cum[2][k]+cum[3][l])
print(s)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<stack>
#include<vector>
#include<string>
#include<queue>

using namespace std;

typedef long long ll;

string s;

int main() {
	cin >> s;

	bool direct = true;//最初の向き
	deque<char> dq;
	int q;
	cin >> q;
	for (int i = 0; i < s.size(); i++)dq.push_back(s[i]);
	while (q--) {
		int fl;
		cin >> fl;
		if (fl == 1)direct = !direct;
		else {
			int F;
			char c;
			cin >> F >> c;
			if (F == 1 && direct) {
				dq.push_front(c);
			}
			else if(F == 2 && direct){
				dq.push_back(c);
			}
			else if (F == 1 && !direct) {
				dq.push_back(c);
			}
			else if (F == 2 && !direct) {
				dq.push_front(c);
			}
		}
	}
	if (direct) {
		while (dq.size()) {
			cout << dq.front();
			dq.pop_front();
		}
	}
	else {
		while (dq.size()) {
			cout << dq.back();
			dq.pop_back();
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1088
#include<bits/stdc++.h>
using namespace std;
#define com(x,y,c,s) s+=c*x;y-=x;x=0;
#define abc(a,c,x) (a>c?c:a)*x
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int a, b, c, x, y, sum = 0;
  cin >> a >> b >> c >> x >> y;
  c *= 2;
  if (a + b >= c) {
    if (x < y) {
      com(x, y, c, sum)
    } else {
      com(y, x, c, sum)
    }
  }
  sum += abc(a, c, x);
  sum += abc(b, c, y);
  cout << sum;
}


Measured memory_bytes: 256
// abc165_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll A, B, N;
    cin >> A >> B >> N;

    ll x = min(B-1, N);
    ll ans = A * x / B;
    print(ans);


    return 0;
}


Measured memory_bytes: 3648
import collections

N = int(input())
S = input()

count = collections.Counter(S)

ans = count['R'] * count['G'] * count['B']

for distance in range(1, (N - 1) // 2 + 1):
    for i in range(N):
        if i + 2 * distance >= N:
            break
        
        if len({S[i], S[i + distance], S[i + 2 * distance]}) == 3:
             ans -= 1
    

print(ans)

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

int main() {
  int N;
  cin >> N; 
  string Sl;
  
  for(int i = 0; i < N; i++){
    cin >> Sl;
    if(Sl == "Y"){
      cout << "Four" << endl;
      break;
    }
    if(Sl != "Y" && i + 1 == N ){
      cout << "Three" << endl;
   }
  }
  cout << endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<ll,ll> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int main()
{   
    set<string> al;
    int n;cin>>n;
    string s;
    REP(i,n)
    {
        cin>>s;
        REP(j,s.size()-1)
        {
            string s1=s.substr(0,j+1);
            string s2=s.substr(j+1);
            string s1r=s1;
            string s2r=s2;
            reverse(ALL(s1r));
            reverse(ALL(s2r));
            al.insert(s1+s2);
            al.insert(s2+s1);
            al.insert(s1r+s2);
            al.insert(s2+s1r);
            al.insert(s1+s2r);
            al.insert(s2r+s1);
            al.insert(s1r+s2r);
            al.insert(s2r+s1r);
        }
        //for_each(al.begin(),al.end(),[](string x){cout<<" "<<x;});
        cout<<al.size()<<endl;
        al.clear();
    }
}


Measured memory_bytes: 3180
N = int(input())


min_ = 10000000
sum_ = 0

X = input().split()

for t in range(1,101):
  for i in range(N):
    tmp = int(X[i])
    sum_ += (tmp-t)**2
    
  if min_ > sum_:
    min_ = sum_
    
  sum_ = 0  
      
print(min_)    

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 1000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;
int num[N];
int main() {
    int n;
    scanf("%d",&n);
    for(int i=2;i<=n;i++){
        int temp=i;
        for(int j=2;j<=temp;j++){
            while(temp%j==0){
                num[j]++;
                temp/=j;
            }
        }
        if(temp!=1)
            num[temp]++;
    }

    LL res=1;
    for(int i=1; i<=n; i++)
        if(num[i])
            res=(res*(num[i]+1))%MOD;
    printf("%lld\n",res);

    return 0;
}

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

using namespace std;
using ll = long long;

class UF{
private:
    std::vector<long long> data; //data[i] : 頂点iの親
public:
    UF(int n){
        data.resize(n,-1);
    }
    //頂点iの親を返す
    int root(int i){
        if(data[i] < 0)return i;
        else return data[i] = root(data[i]);
    }
    //連結
    void unit(int i,int j){
        i = root(i);j = root(j);
        if(i != j){
            data[i] += data[j];
            data[j] = i;
        }
    }

    //頂点iの属する集合の頂点数
    int size(int i){
        i = root(i);
        return -data[i];
    }
};

int main()
{
    int n; cin >> n;
    vector<pair<int,int>> ax(n), ay(n);
    vector<tuple<int,int,int>> aida(n);
    for(int i = 0; i < n; i++) {
        cin >> ax[i].first >> ay[i].first;
        ax[i].second = ay[i].second = i;
    }
    sort(ax.begin(), ax.end()); sort(ay.begin(), ay.end());
    for(int i = 0; i < n - 1; i++) {
        aida.emplace_back(ax[i + 1].first - ax[i].first, ax[i].second, ax[i + 1].second);
        aida.emplace_back(ay[i + 1].first - ay[i].first, ay[i].second, ay[i + 1].second);
    }
    UF tree(n);
    ll cost = 0;
    sort(aida.begin(), aida.end(), greater<tuple<int,int,int>>());

    while(aida.size()) {
        int dist, a, b;
        tie(dist, a, b) = aida.back();
        aida.pop_back();
        if(tree.root(a) == tree.root(b))continue;
        tree.unit(a, b);
        cost += dist;
    }
    cout << cost << endl;
}

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

using namespace std;

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

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

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

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

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

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

char alf1[30];
char alf2[30];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s, t;
	cin>>s>>t;
	REP(i, 30){
		alf1[i]='#';
		alf2[i]='#';
	}
	REP(i, s.size()){
		if(alf1[s[i]-'a']!='#'){
			if(t[i]!=alf1[s[i]-'a']){
				cout<<"No"<<'\n';
				return 0;
			}
		}
		else{
			alf1[s[i]-'a']=t[i];
		}
		if(alf2[t[i]-'a']!='#'){
			if(s[i]!=alf2[t[i]-'a']){
				cout<<"No"<<'\n';
				return 0;
			}
		}
		else{
			alf2[t[i]-'a']=s[i];
		}
	}
	cout<<"Yes"<<'\n';
	return 0;
}


Measured memory_bytes: 916
#include <iostream>

using namespace std;

int main(){
    int N;
    long A[100000];
    long dp[2][100000];
    long sum = 0;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        sum += A[i];
    }
    if(A[0]%2 == 0){
        dp[1][0] = -1;
        dp[0][0] = 0;
    }else{
        dp[1][0] = 1;
        dp[0][0] = -1;
    }
    for(int i = 1; i < N; i++){
        if(A[i] == 0){
            if(dp[0][i-1] == -1 && dp[1][i-1] == -1) dp[0][i] = -1;
            if(dp[0][i-1] == -1 && dp[1][i-1] != -1) dp[0][i] = dp[1][i-1];
            if(dp[0][i-1] != -1 && dp[1][i-1] == -1) dp[0][i] = dp[0][i-1];
            if(dp[0][i-1] != -1 && dp[1][i-1] != -1) dp[0][i] = min(dp[0][i-1], dp[1][i-1]);
            dp[1][i] = -1;
        }else if(A[i]%2 == 0){
            if(dp[0][i-1] == -1 && dp[1][i-1] == -1) dp[0][i] = -1;
            if(dp[0][i-1] == -1 && dp[1][i-1] != -1) dp[0][i] = dp[1][i-1];
            if(dp[0][i-1] != -1 && dp[1][i-1] == -1) dp[0][i] = dp[0][i-1];
            if(dp[0][i-1] != -1 && dp[1][i-1] != -1) dp[0][i] = min(dp[0][i-1], dp[1][i-1]);
            dp[1][i] = dp[1][i-1];
        }else{
            if(dp[0][i-1] == -1 && dp[1][i-1] == -1) dp[1][i] = -1;
            if(dp[0][i-1] == -1 && dp[1][i-1] != -1) dp[1][i] = dp[1][i-1]+1;
            if(dp[0][i-1] != -1 && dp[1][i-1] == -1) dp[1][i] = dp[0][i-1]+1;
            if(dp[0][i-1] != -1 && dp[1][i-1] != -1) dp[1][i] = min(dp[0][i-1]+1, dp[1][i-1]+1);
            if(dp[1][i-1] == -1) dp[0][i] = -1;
            if(dp[1][i-1] != -1) dp[0][i] = dp[1][i-1]-1;
        }
    }
    /*
    for(int i = 0; i < N; i++) cout << dp[0][i] << ' ';
    cout << endl;
    for(int i = 0; i < N; i++) cout << dp[1][i] << ' ';
    cout << endl;
    */
    long rem = INT32_MAX;
    if(dp[0][N-1] != -1) rem = min(rem, dp[0][N-1]);
    if(dp[1][N-1] != -1) rem = min(rem, dp[1][N-1]);
    cout << (sum-rem)/2 << endl;
}

Measured memory_bytes: 3192
#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;

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

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

  std::string A, B;
  std::cin >> A >> B;

  if (A.size() > B.size()) print("GREATER");
  else if (B.size() > A.size()) print("LESS");
  else {
    std::string judge = "EQUAL";
    for (ll i = 0; i < (ll)A.size(); i++) {
      if (A[i] > B[i]) {
	judge = "GREATER";
	break;
      }
      if (A[i] < B[i]) {
	judge = "LESS";
	break;
      }
    }
    print(judge);
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
   int n;
   cin>>n;
   int k;
   cin>>k;
   int a[n];
   for(int i=0;i<n;i++)
   {
       cin>>a[i];
   }
   sort(a,a+n);
   ll sum=0;
   for(int i=0;i<k;i++)
    sum+=a[i];
   cout<<sum<<endl;
} 

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
struct Dice {
	int V[6];
	void role(char c) {
		int a;
		if (c == 'E') {
			a = V[0];
			V[0] = V[3];
			V[3] = V[5];
			V[5] = V[2];
			V[2] = a;
		}
		if (c == 'N') {
			a = V[0];
			V[0] = V[1];
			V[1] = V[5];
			V[5] = V[4];
			V[4] = a;
		}
		if (c == 'S') {
			a = V[0];
			V[0] = V[4];
			V[4] = V[5];
			V[5] = V[1];
			V[1] = a;
		}
		if (c == 'W') {
			a = V[0];
			V[0] = V[2];
			V[2] = V[5];
			V[5] = V[3];
			V[3] = a;
		}
		if (c == 'R') {
			a = V[1];
			V[1] = V[2];
			V[2] = V[4];
			V[4] = V[3];
			V[3] = a;
		}
	}
	int top() {
		return V[0];
	}
	int right() {
		return V[2];
	}
	int left() {
		return V[3];
	}
	int front() {
		return V[1];
	}
	int back() {
		return V[4];
	}
	int bottom() {
		return V[5];
	}
};

int main() {
	Dice d;
	for (int i = 0; i < 6; i++) 
		cin >> d.V[i];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		if (d.left() == x)
			d.role('E');
		if (d.right() == x)
			d.role('W');
		while (d.top() != x)
			d.role('S');
		while (d.front() != y)
			d.role('R');
		cout << d.right() << endl;
	}
}


Measured memory_bytes: 3084
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

A, B = map(int, input().split())
S = input().strip()

import string

for v in S[:A]:
    if v not in string.digits:
        print('No')
        sys.exit(0)
if S[A] != '-':
    print('No')
    sys.exit(0)
for v in S[A+1:]:
    if v not in string.digits:
        print('No')
        sys.exit(0)
print('Yes')


Measured memory_bytes: 71908
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int r;
    cin >> r;
    cout << r * r << endl;
    return 0;
}

Measured memory_bytes: 3632
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> H(N);
    for (ll i = 0; i < N; i++) {
        cin >> H[i];
    }

    //dp[i][j] := 最も右の項の番号がi,サイズがｊであるときのコストの最小値
    vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, LLONG_MAX / 2));
    dp[0][0] = 0;
    for (ll i = 1; i <= N; i++) {
        for (ll j = 1; j <= N; j++) {
            //kからiまでを削除する
            for (ll k = 0; k < i; k++) {
                dp[i][j] = min(dp[i][j], dp[k][j - 1] + max((ll)0, H[i - 1] - (k == 0 ? 0 : H[k - 1])));
            }
        }
    }

    ll ans = LLONG_MAX;
    for (ll i = 0; i <= N; i++) {
        ans = min(ans, dp[i][N - K]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <cstdio>   
#define pb          push_back 
#define endl        "\n"
#define mostrar(x,y) cout<<x<<" "<<y<<endl;
#define f           first
#define s           second
#define mod         1000000007
#define EPS         1e-9
using namespace std;
typedef pair<int,int> ii;
typedef pair<pair<int,int>,int> iii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef long long ll;

int a[100004];
int dp[100004];

ll costo_min(int n){
    ll res;
    if(n ==0) res=0;
    else if(n == 1) res = abs(a[n]-a[n-1]);
    else{
        if(dp[n]!=-1){
            res = dp[n];
        }
        else{
            res = min(costo_min(n-1)+abs(a[n]-a[n-1]),costo_min(n-2)+abs(a[n]-a[n-2]));
            dp[n] = res;
        }
    }
    return res;
}

int main(){
    ofstream out("output.txt");


    ll n;
    cin>>n;
    for(int i =0; i<n; i++){
        cin>>a[i];
        dp[i] = -1;
    }

    cout<<costo_min(n-1)<<endl;


    return 0;
}



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

int main()
{
  int n;cin>>n;
  vector<int> t(n);
  vector<int> v(n);
  int i,j;
  for(i=0;i<n;i++)cin>>t.at(i);
  for(i=0;i<n;i++)cin>>v.at(i);
  vector<int> sum(n);
  sum.at(0)=t.at(0);
  for(i=1;i<n;i++)sum.at(i)=sum.at(i-1)+t.at(i);
  int tsum=sum.at(n-1);
  vector<int> sp(tsum+1,0);
  vector<int> upper(tsum+1,0);
  vector<int> uppermid(tsum,0);
  int now=1;
  int sec=0;
  while(now<tsum)
  {
    if(now<sum.at(sec))upper.at(now)=v.at(sec);
    else
    {
      upper.at(now)=min(v.at(sec),v.at(sec+1));
      sec++;
    }
    now++;   
  }
  now=0;
  sec=0;
  while(now<tsum)
  {
    if(sum.at(sec)<=now)
    {
      sec++;
      uppermid.at(now)=v.at(sec);
    }
    else uppermid.at(now)=v.at(sec);
    now++;
  }
  for(i=1;i<=100;i++)
  {
    vector<int> spch(tsum+1,0);
    for(j=1;j<tsum;j++)
    {
      if(i<=upper.at(j)&&sp.at(j-1)==sp.at(j)&&sp.at(j)==sp.at(j+1))
      {
        spch.at(j)=i;
      }
    }
    for(j=1;j<tsum;j++)sp.at(j)=max(spch.at(j),sp.at(j));
  }
  double ans=0.0;
  for(i=0;i<tsum;i++)
  {
    if(sp.at(i)!=sp.at(i+1))ans+=double(sp.at(i)+sp.at(i+1))/2;
    else if(sp.at(i)==upper.at(i)&&upper.at(i)==uppermid.at(i))ans+=double(sp.at(i));
    else ans+=double(sp.at(i))+0.25;
  }
  cout<<fixed<<setprecision(10)<<ans<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) FOR(i,n,0)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int n;
ll a[1000000];
ll b[1000000];
map<ll,ll> mp;
ll ans;

int main(){
  cin>>n;
  mp[0]++;
  rep(i,n){
    cin>>a[i];
    b[i]=a[i];
    if(i!=0) b[i]+=b[i-1];
    if(mp[b[i]]) ans+=mp[b[i]];
    mp[b[i]]++;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 18432
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    int b = 1;
    char c[] = "LR";
    for (int i = 0; i < n; i++) {
        if (s[i] == c[i % 2]) b = 0;
    }

    cout << (b ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
//#include <fstream>
 
int main()
{
    const u_int max_point = 16;
    u_int a, b, n, x, y;
    //std::ifstream ifs("515.txt");
    while(1){
        //ifs >> a >> b;
        std::cin >> a >> b;
        if(a == 0 && b == 0)
            break;
        
        std::array<std::array<u_int, max_point>, max_point> path;
        for(u_int i = 0; i < max_point; ++i){
            path[i].fill(0);
        }
        //ifs >> n;
        std::cin >> n;
        for(u_int i = 0; i < n; ++i){
            //ifs >> x >> y;
            std::cin >> x >> y;
            path[x - 1][y - 1] = -1;
        }
         
        //path[0][0] = 1;
        for(u_int i = 0; i < a; ++i){
            for(u_int j = 0; j < b; ++j){
                if(path[i][j] != -1){
                    if(i ==0 && j == 0){
                        path[i][j] = 1;
                    }
                    else if(i == 0){
                        path[i][j] = path[i][j - 1];
                    }
                    else if(j == 0){
                        path[i][j] = path[i - 1][j];
                    }
                    else{
                        path[i][j] = path[i - 1][j] + path[i][j - 1];
                    }
                }
                else{
                    path[i][j] = 0;
                }
            }
        }
        std::cout << path[a - 1][b - 1] << std::endl;              
    }
    //ifs.close();
 
    return 0;
}

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

int main() {
    int n; cin >> n;
    vector<long long> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    int res = 0;
    int counter = 0;
    for (int i = 0; i < n - 1; i++) {
        if (h[i] >= h[i+1]) {
            counter++;
        } else {
            counter = 0;
        }
        res = max(counter, res);
    }
    cout << res << endl;
    return 0;
}


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

using ll = long long;

int main() {
	int N; cin >> N;
	vector<pair<int, int>> A(N);
	for (int i = 0; i < N; i++) {
		A[i].first = i + 1;	// 出席番号
		cin >> A[i].second;	// 登校した時点で何人生徒がいたか(自分含む)
	}

	sort(A.begin(), A.end(), [](const auto &lhs, const auto &rhs) {
		return lhs.second < rhs.second;
	});

	for (int i = 0; i < N; i++) {
		cout << A[i].first;
		if (i < (N - 1)) cout << " ";
	}
	cout << endl;
}


Measured memory_bytes: 1664
#include <iostream>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <tuple>
using namespace std;
string S, T, V1, V2; bool B = false; int L, maxn = 0;
int main() {
	cin >> L >> S >> T;
	while (V1.size() <= 10000000)V1 += S;
	while (V2.size() <= 10000000)V2 += T;
	if (V1 > V2) { swap(S, T); }
	for (int i = 0; i <= L; i += (int)S.size()) {
		if ((L - i) % (int)T.size() != 0)continue;
		maxn = max(maxn, i / (int)S.size());
	}
	string U = "";
	for (int i = 0; i < maxn; i++)U += S;
	while ((int)U.size() < L)U += T;
	cout << U << endl;
	return 0;
}

Measured memory_bytes: 38244
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.*;
 
public class Main {
	final int INF = (int)1e9 + 7;
	int N,M;
	int[] B,P,one,zero;
	public int calc(int n,int[] a,int[] b)
	{
		int ret = 0;
		for(int i = 0;i < N;i++){
			if(a[i] != b[i]){
				boolean find = false;
				for(int j = i + 1;j < N;j++){
					if(a[j] != b[i])continue;
					find = true;
					ret += j - i;
					int copy = a[j];
					
					for(int k = j;k > i;k--){
					
						a[k] = a[k - 1];
					}
					a[i] = copy;
					break;
				}
				if(!find){
					return INF;
				}
			}
		}
		return ret;
		
	}
	
	public void solve() {
		N = nextInt();
		M = nextInt();
		
		B = new int[N];
		P = new int[M];
		for(int i = 0;i < N;i++){
			B[i] = nextInt();
		}
		
		for(int i = 0;i < M;i++){
			P[i] = nextInt();
		}
		one = new int[N];
		zero = new int[N];
		int k = 0;
		for(int i = 0;i < M;i++){
			for(int j = 0;j < P[i];j++){
				one[k + j] = i % 2 == 0 ? 1 : 0;
			}
			k += P[i];
		}
		k = 0;
		for(int i = 0;i < M;i++){
			for(int j = 0;j < P[i];j++){
				zero[k + j] = i % 2 == 0 ? 0 : 1;
			}
			k += P[i];
		}
		int ans = calc(0,Arrays.copyOf(B,N),one);
		ans = Math.min(ans,calc(0,Arrays.copyOf(B,N),zero));
		out.println(ans);
	}
 
	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}
 
	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;
 
	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}
 
	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}
 
	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}
 
	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}
 
	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}
 
	public int nextInt() {
		return Integer.parseInt(next());
	}
 
	public long nextLong() {
		return Long.parseLong(next());
	}
 
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 24420
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
using namespace std;
int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    string alpha = "abcdefghijklmnopqrstuvwxyz";
    int check[26];
    for(int i = 0;i<26;i++){
        check[i] = 0;
    }
    for(int i = 0;i<n;i++){
        for(int j = 0;j<26;j++){
            if(s[i] == alpha[j]){
                check[j]++;
                break;            }
        }
    }
    long long ans = 1;
    for(int i = 0;i<26;i++){
        ans = ans * (check[i] + 1);
        ans = ans % 1000000007;
    }
    cout << ans - 1 << endl;
}

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

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    
    for (int i = 1; ; i++) {
        if (y * i + z * (i + 1) > x) {
            cout << i - 1 << endl;
            break;
        }
    }
    return 0;
}

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

vector<int> to[605], from[605];

template <typename T>
void printv(vector<T>& v) {
    for (T i : v) {
        cout << i << ", ";
    }
    cout << endl;
}

int main(){
    int N, M;
    cin >> N >> M;
    rep(i, M) {
        int s, t;
        cin >> s >> t;
        s--, t--;
        to[s].push_back(t);
        from[t].push_back(s);
    }

    vector<double> dp(N);
    dp[N - 1] = 0;
    for (int i = N - 2; i >= 0; --i) {
        double res = 0;
        for (int v : to[i]) {
            res += dp[v];
        }
        dp[i] = res / to[i].size() + 1;
    }

    double ans = dp[0];

    rep(i, N - 1) {
        if (to[i].size() <= 1) continue;

        double maxe = 0;
        for (int v : to[i]) {
            maxe = max(maxe, dp[v]);
        }

        for (int j = i; j >= 0; --j) {
            double res = 0;
            for (int v : to[j]) {
                res += dp[v];
            }
            if (i == j) {
                res -= maxe;
                dp[j] = res / (to[j].size() - 1) + 1;
            } else {
                dp[j] = res / to[j].size() + 1;
            }
        }

        ans = min(ans, dp[0]);
    }

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

Measured memory_bytes: 2560
#include <iostream>
#include<bits/stdc++.h>
#include<cmath>
#include <algorithm> 
#include <unordered_map>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long n,d;
	cin >> n>>d;
	double a;
	long long ct = 0;
	for (long long i = 0; i < n; i++) {
		long long x, y;
		cin >> x >> y;
		long long b = x * x + y * y;
		a = pow(b, 0.5);
		if (d >= a) {
			ct++;
		}
	}
	cout << ct;
	return 0;
}

Measured memory_bytes: 4268
#include<stdio.h>
#define N 100001

typedef struct{
  int p, lc, rs, deg, dep;
}node;

int main(){
  int n, i, j, id, dep, temp, betemp;
  node t[N];
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    t[i].p = -1;
    t[i].lc = -1;
   t[i].rs = -1;
  }
  for(i = 0; i < n; i++){
    scanf("%d", &id);
    scanf("%d", &t[id].deg);
    for(j = 0; j < t[id].deg; j++){
      scanf("%d", &temp);
      if(j == 0){
	t[id].lc = temp;
	t[temp].p = id;
      }
      else{
	t[betemp].rs = temp;
	t[temp].p = id;
      }
      betemp = temp;
    }
  }
  for(i = 0; i < n; i++){
    t[i].dep = 0;
    temp = t[i].p;
    while(1){
      if(temp == -1) break; 
      else {
	t[i].dep++;
	temp = t[temp].p;
      }
    }
  }
  for(i = 0; i < n; i++){
    printf("node %d: parent = %d, depth = %d, ", i, t[i].p, t[i].dep);
    if(t[i].p == -1) printf("root, [");
    else if(t[i].deg == 0) printf("leaf, [");
    else printf("internal node, [");
    temp = t[i].lc;
    for(j = 0; j < t[i].deg; j++){
      printf("%d", temp);
      temp = t[temp].rs;
      if(j < t[i].deg - 1) printf(", ");
    }
    printf("]\n");
  }
 return 0;
}

Measured memory_bytes: 2564
#include <stdio.h>
#include <string.h>

int main() 
{
    char s[101];
    int l, ans, i;
    
    scanf("%s", s);
    l = strlen(s);
    if(l == 1) puts(s);
    else{
    	ans = s[0] - 49 + 9 * (l - 1);
    	for(i = 1; s[i] && s[i] == 57; i++);
    	if(i == l) ans++;
    	printf("%d\n", ans);
	}
	
    return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		for(; sc.hasNext();){
			int[] a=new int[5];
			for(int i=0; i<5; i++)
				a[i]=sc.nextInt();
			sort(a);
			for(int i=0; i<5; i++)
				print(a[4-i]+(i==4?"":" "));
			println("");
		}
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

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

int main(){
  int n;
  double x,y,ax,ay;
  while(1){
    cin>>n;
    if(n==-1)break;
    x=1,y=0;
    ax=0,ay=1;
    for(int i=0;i<n-1;i++){
      x+=ax;
      y+=ay;
      ax=(-y)/sqrt(x*x+y*y);
      ay=x/sqrt(x*x+y*y);
    }
    cout<<x<<endl<<y<<endl;
  }

  return 0;
}

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

int main() {
  int N, K, x;
  cin >> N >> K;
  int d = 0;
  for (int i = 0; i < N; i++) {
    cin >> x;
    if (2*x < K)
      d = d + 2*x;
    else
      d = d + 2*(K-x);
  }
  cout << d << endl;
}
    


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
    long a,b;
    cin >> a >> b;
    
    if(a == b){
        cout << "0" << endl;
    }else if(a != b){
        if((a+b)%2 == 0)cout << (a+b)/2 << endl;
        if((a+b)%2 != 0)cout << "IMPOSSIBLE" << endl;
    }
    
    return 0;
}


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

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i <= n; i++)
		if (int(i * 1.08) == n)
		{
			printf("%d", i);
			return 0;
		}
	puts(":(");
	return 0;
}

Measured memory_bytes: 128
N,K=map(int,input().split(' '))
count = 0
for b in range(K+1,N+1):
    l, h, n = K, b-1, b-K
    while l <= N:
        if h <= N:
            count += n
            if l==0:
                count -=1
        else:
            count += N-l+1
            if l==0:
                count -=1
            break
        l+=b
        h+=b
print(count)

Measured memory_bytes: 40556
#define _USE_MATH_DEFINES
#include<cmath>
#include<iostream>
int main()
{
	double x = 0, y = 0;
	int a = 90;
	while (true)
	{
		int di, ai;
		char temp;
		std::cin >> di >> temp >> ai;
		if (di == 0 && ai == 0)
		{
			break;
		}
		x += di * cos(a * M_PI / 180);
		y += di * sin(a * M_PI / 180);
		a -= ai;
	}
	const int x_int = static_cast<int>(x >= 0 ? floor(x) : ceil(x));
	const int y_int = static_cast<int>(y >= 0 ? floor(y) : ceil(y));
	std::cout << x_int << std::endl;
	std::cout << y_int << std::endl;
	return 0;
}


Measured memory_bytes: 3396
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
const int mod = 1e9 + 7;
vector<vector<ll>> ans;
ll fp(ll base, ll exp)
{
    if (exp == 0)
        return 1;
    ll ans = fp(base, exp / 2);
    if (exp % 2 == 0)
        return (ans * ans) % mod;
    else
        return (((ans * ans)% mod) * base)% mod;
}
vector<ll> solve(ll n)
{
    vector<ll> v;
    while(n)
    {
        v.push_back(n % 2);
        n /= 2;
    }
    while(true)
    {
        if(v.size() == 64)
            break;
        v.push_back(0);
    }
    return v;
}
int main()
{
    Hello
    ll n, finall = 0;
    cin >> n;
    ll arr[n + 5];
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
        ans.push_back(solve(arr[i]));
    }
    for(int j = 0; j < 64; j++)
    {
        ll one = 0, zero = 0;
        for(int i = 0; i < ans.size(); i++)
        {
            if(ans[i][j] == 1)
                one++;
            else if(ans[i][j] == 0)
                zero++;
        }
        /// += zero * one * pow(2, pos)
        ll zAo = (((zero * one) % mod) * fp(2, j)) % mod;
        finall = (finall + zAo) % mod;
    }
    cout << finall;
    return 0;
}


Measured memory_bytes: 166184
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 100
using namespace std;
string s,p;int n,k;
I bool Check() {for(RI i=1;i^n;++i) if(s[i]^s[i-1]) return false;return true;}
int main()
{
	RI i;long long t1=0,t2=0;if(cin>>s>>k,n=s.length(),Check()) return printf("%lld",(1LL*n*k)>>1),0;
	for(p=s,i=1;i^n;++i) s[i]==s[i-1]&&(s[i]=0,++t1);t1*=k,s[0]==s[n-1]&&(t1+=k-1);
	for(s=p,i=n-2;~i;--i) s[i]==s[i+1]&&(s[i]=0,++t2);t2*=k,s[0]==s[n-1]&&(t2+=k-1);
	return printf("%lld",min(t1,t2)),0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;


int main(){
    
    const int MAX_SIZE = 100;
    int n;

    int a[MAX_SIZE];

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

    for(int i=n-1; i>=0; i--){
        if(i>0){
            cout << a[i] << " ";
        }else if(i==0){
            cout << a[i] << endl;
        }
    }

    return 0;
}




Measured memory_bytes: 3084
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#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>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> AB(N);
    rep(i, N) {
        int a, b;
        cin >> a >> b;
        AB[i] = (make_pair(a, b));
    }
    sort(AB.begin(), AB.end());
    priority_queue<int> pq;
    int M_prev_day = 1;
    int i = 0;
    ll ans = 0;
    while(1){
        if ( i< AB.size() && AB[i].first <= M_prev_day) {
            pq.push(AB[i].second);
            i++;
        }
        else {
            if (pq.size() > 0) {
                ans += ll(pq.top());
                pq.pop();
            }
            M_prev_day++;
        }
        if (M_prev_day > M) break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1660
n, *w = map(int, open(0).read().split())

ans = abs(sum(w[:1]) - sum(w[1:]))

for i in range(1,n - 1):
    dis = abs(sum(w[:i + 1]) - sum(w[i + 1:]))
    ans = min(dis, ans)
    #print(w[:i + 1], w[i + 1:], dis, ans)
    
print(ans)

Measured memory_bytes: 3060
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#l = list(map(int, input().split()))
import math

n,m = map(int, input().split())

if (n >= 2):
    a = math.factorial(n)//(2*math.factorial(n-2))
else:
    a = 0

if (m >= 2):
    b = math.factorial(m)//(2*math.factorial(m-2))
else:
    b = 0

print(a+b)



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

using namespace std;

int main()
{
  string a, b, c;
  string::size_type d;
  cin >> a >> c;
  b = a + a;
  d = b.find(c);
  if(d == string::npos) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 3188
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int a;
int b;
char c;
string str1,str2;
int main(){
	int ans=0;
	cin>>str1;
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>a;
		if(a==1){
			ans++;continue;
		}
		cin>>b>>c;
		if(ans%2==0){
			if(b==1) str2=str2+c;
			else str1=str1+c;
		}
		else{
			if(b==1) str1=str1+c;
			else str2=str2+c;
		}

	}
	if(ans%2==0){
		reverse(str2.begin(),str2.end());
		cout<<str2<<str1<<endl;
	}
	else{
		reverse(str1.begin(),str1.end());
		cout<<str1<<str2<<endl;
	}
	return 0;
}

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

int main(){
    int r;
    cin >> r;
    if(r < 1200){
        cout << "ABC" << endl;
    }else if(r < 2800){
        cout << "ARC" << endl;
    }else{
        cout <<"AGC" << endl;
    }
}

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

#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)

using namespace std;

template <class T>
using vec = std::vector<T>;
typedef long long ll;
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1LL << 60;

const double PI = acos(-1.0);

// long long積のオーバーフロー検出
bool detect_mul_overflow(ll a, ll b)
{
    return a >= LONG_MAX / b;
}

int lcm(int a, int b)
{
    //最小公倍数
    return a / __gcd(a, b) * b;
}

struct edge
{
    int from, to, cost;
};

// int型の2次元配列(3×4要素の)の宣言
// vector<vector<int>> data(3, vector<int>(4));


int N;

int main()
{
    cin>>N;
    int tmp=N%1000;
    if(tmp==0){
        cout<<0<<endl;
    }else{
        cout<<1000-tmp<<endl;
    }

    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    vector<int> abc(3);
    for (int i=0; i<3; i++) cin >> abc[i];
    sort(abc.begin(), abc.end());
    int ans = 0;
    if (abc[0] == abc[1]) ans = abc[2];
    if (abc[2] == abc[1]) ans = abc[0];

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;

inline bool valid(int x, int n) {
    return 0 <= x && x < n;
}

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

template <typename T>
inline T pop(queue<T>& q) {
    T front = q.front();
    q.pop();
    return front;
}

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

template <typename T>
tuple<T, T, T> xgcd(T a, T b) {
    if (b == 0) return {1, 0, a};
    T x, y, g;
    tie(x, y, g) = xgcd(b, a%b);
    return {y, x-(a/b)*y, g};
}

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

    int N; cin >> N;
    vvi graph(N+1);
    for (int i = 0; i < N-1; i++) {
        int A, B; cin >> A >> B;
        graph[A].push_back(B);
        graph[B].push_back(A);
    }

    queue<int> q;
    vi visit(N+1, -1);
    visit[1] = 0;
    q.push(1);
    while (q.size()) {
        int c = pop(q);
        for (int n : graph[c]) {
            if (visit[n] != -1) continue;
            visit[n] = visit[c] + 1;
            q.push(n);
        }
    }

    vi red;
    vi blue;
    for (int i = 1; i <= N; i++) {
        if (visit[i] % 2) red.push_back(i);
        else blue.push_back(i);
    }

    if (red.size() > blue.size()) swap(red, blue);

    vi rst(N+1);
    vb used(N+1);
    if (red.size() <= N/3) {
        for (int i = 0, j = 3; i < red.size() && j <= N; i++, j+=3) {
            rst[red[i]] = j;
            used[j] = 1;
        }
    }
    else {
        for (int i = 0, j = 1; i < red.size() && j <= N; i++, j+=3) {
            rst[red[i]] = j;
            used[j] = 1;
        }
        for (int i = 0, j = 2; i < blue.size() && j <= N; i++, j+=3) {
            rst[blue[i]] = j;
            used[j] = 1;
        }
    }

    for (int i = 1; i <= N; i++) {
        if (used[i]) continue;
        q.push(i);
    }

    for (int i = 1; i <= N; i++) {
        if (rst[i]) continue;
        rst[i] = pop(q);
    }

    for (int i = 1; i <= N; i++) cout << rst[i] << " ";
}

Measured memory_bytes: 16880
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);

void cntdivisors(int n){
  int div[n];
  div[0] = 0;
  for(int i = 1; i <= n; i++ ){
    div[i] = 1;
  }

  for(int i = 2; i <= n; ++i){
    int j = i;
    while(j <= n){
      ++div[j];
      j = j + i;
    }
  }
  ll sum = 0;
  REP(i,n){
    //cout << i << " " << div[i] << endl;
    sum += (ll)i*div[i];
  }
  cout << sum << endl;
}

int main(){
  int n;
  cin >> n;
  cntdivisors(n+1);

  return 0;
}

Measured memory_bytes: 42720
n,m,l = map(int,input().split())
A = [list(map(int,input().split())) for i in range(n)]
B = [list(map(int, input().split())) for i in range(m)]
ANS = [[0]*l for i in range(n)]


for i in range(n):
    for j in range(l):
        for k in range(m):
            ANS[i][j] += A[i][k]*B[k][j]
for i in ANS:
    print(*i)


Measured memory_bytes: 7044
class MyLib
  def count_div(a,b,num)
    first = a+(num-a%num)%num
    count = (b-a+1)/num
    additional = (first + count*num <= b) ? 1 : 0
    count += additional
  end
end
a, b, c, d = gets.split.map(&:to_i)
# 時間かかる
# a.upto(b) do |num|
#   count+=1 if num%c!=0 && num%d!=0
# end

# 全部-(cで割れる+dで割れる)+(cかつdで割れる)
res = b-a+1 - MyLib.new.count_div(a,b,c) - MyLib.new.count_div(a,b,d)+ MyLib.new.count_div(a,b,c.lcm(d))

puts res

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

int main() {
    int N;
    cin >> N;
    map<int, int> myMap;
    for(int i = 0; i < N; i++) {
        int current;
        cin >> current;
        myMap.insert(pair<int, int>(i, current-1));
    }
    int res = 0;
    for(auto& current : myMap) {
        int first = current.first;
        int second = current.second;
        pair<int, int> compare = *(myMap.find(second));
        res += (compare.second == first);
    }
    res /= 2;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
using namespace std;
int main(void){
    int r, g, b;
    cin >> r >> g >> b;
    
    int sum = 100 * r + 10 * g + b;
    
    if(sum % 4 == 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {

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

        final int A = sc.nextInt();
        final int B = sc.nextInt();
        final int C = sc.nextInt();
        final int X = sc.nextInt();
        final int Y = sc.nextInt();
        final int min = Math.min(X, Y);
        final int max = Math.max(X, Y);

        System.out.println(Math.min(Math.min(A + B, 2 * C) * min + A * (X - min) + B * (Y - min), max * 2 * C));
    }
}


Measured memory_bytes: 23124