akhauriyash/Code-Regression huggingface dataset:
// kartikay26
#include <bits/stdc++.h>
using namespace std;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(x) x.begin(), x.end()
#ifdef LOCAL
#include "prettyprint.hpp"
#else
#define debug(...)
#define debuga(arr, n)
#define debugg(grid, n) 
#endif
typedef long long int ll;
#define int ll
#define F first
#define S second
#define float double
const int inf = LLONG_MAX;
int get() { int x; cin >> x; return x; }
void getl(int* ar, int sz){ for(int i=0; i<sz; i++) cin >> ar[i];}
template <typename T> void print(T x) { cout << x << "\n";}
template <typename T> void prints(T x) { cout << x << " ";}
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int mod = 1e9+7;
const int N = 2e5+2;

int n, q;
vi adj[N];
bool vis[N];
int parent[N];
int val[N];

void dfs(int a){
	vis[a] = 1;
	for(auto &i : adj[a]){
		if(!vis[i]){
			parent[i] = a;
			dfs(i);
		}
	}
}

void query(int p, int x){
	val[p] += x;
}

void bfs(){
	queue<int> q;
	vector<bool> used(n+1);
	vector<int> d(n+1), p(n+1);
	int s = 1;
	q.push(s);
	used[s] = true;
	p[s] = -1;
	while (!q.empty()) {
		int v = q.front();
		q.pop();
		for (int u : adj[v]) {
			if (!used[u]) {
				val[u] += val[v];
				used[u] = true;
				q.push(u);
				d[u] = d[v] + 1;
				p[u] = v;
			}
		}
	}
}

int32_t main(){
	fast_io();
	cin >> n >> q;
	for (int i = 0; i < n-1; ++i) {
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	dfs(1);
	for (int i = 0; i < q; ++i) {
		int p, x;
		cin >> p >> x;
		query(p,x);
	}
	bfs();
	for (int i = 1; i <= n; ++i) {
		cout << val[i] << " ";
	}
	return 0;
}

Measured memory_bytes: 23936
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  char a, b; cin >> a >> b;
  if(a == 'H'){
    cout << b << endl;
  }
  else{
    if(b == 'H') cout << 'D' << endl;
    else cout << 'H' << endl;
  }
  return;
}

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


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN=110000;
int t[MAXN];
int main()
{
//	freopen("A.in", "r", stdin);
//	freopen("A.out", "w", stdout);
	int n, c, k;
	scanf("%d%d%d", &n, &c, &k);
	for (int i=1; i<=n; i++) scanf("%d", &t[i]);
	sort(t+1, t+n+1);
	int ans=0;
	for (int i=1, j; i<=n; i++, i=j)
	{
		ans++; j=i;
		for (int p=0; j<=n&&p<c&&t[i]+k>=t[j]; j++) p++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
//cout << fixed << setprecision(0)
int main() { 
  int a,b,c,d;cin>>a>>b>>c>>d;
  int ans;
  rep(i,a+1){
    rep(j,b+1){
      int x = d-(500*i+100*j);
      if(x>=0&&x/50<=c)ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
    "fmt"
    "bufio"
    "os"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var s string
	if sc.Scan() {
		s = sc.Text()
	}

	var tf bool = true

	for i, c := range s {
		if (i+1)%2==1 {
			if !(c=='R' || c=='U' || c=='D') {
				tf = false
			}
		} else {
			if !(c=='L' || c=='U' || c=='D') {
				tf = false
			}
		}
		if !tf {
			break
		}
	}

	if tf {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[200005];
int check(long long x, long long y, long long t){
	if ( y - x - t <= 0) return y - x;
	else return t;
}
int main()
{
	long long n,t,m,k;
	scanf("%lld %lld",&n,&t);
	long long ans;
	ans = t;
	for( int i = 1 ; i <= n; i++)  scanf("%d",&a[i]);
	sort(a + 1 , a + 1 + n);
	for( int i = 1; i <= n - 1; i++){
		m = a[i];
		k = a[i + 1];
		ans += check(m,k,t);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
using namespace std;
int main()
{
	int n;cin >> n;
	int a[n],b[n],c[n-1];
	for(int i = 0;i < n;i++)
		cin >> a[i];
	for(int i = 0;i < n;i++)
		cin >> b[i];
	for(int i = 0;i < n-1;i++)
		cin >> c[i];
	int cnt = 0,i = 0;
	int k = a[i];
	while(i < n)
	{
		if(i == 0)
			cnt += b[a[i] - 1];
		else
		{
			if(k == a[i] - 1)
				cnt += b[a[i] - 1] + c[a[i] - 2];
			else
				cnt += b[a[i] - 1];
		}
		k = a[i];
		i++;
	}
	cout << cnt;
	return 0;
}


Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    int a, p;
    cin >> a >> p;
    cout << (a * 3 + p) / 2 << endl;
    return 0;
}

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

int main() {
	long long a,b,c,d; cin >> a >> b >> c >> d;
  	
	long long ac = a * c;
    long long ad = a * d;
    long long bc = b * c;
    long long bd = b * d;
	long long ans = max(max(max(ac,ad),bc),bd);
    cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3624
n=int(input())
l=list(map(int,input().split()))

flag=0
for i in range(n):
  if l[i]%2==0:
    if l[i]%3!=0 and l[i]%5!=0:
      flag=1
      break

if flag==0:
  print("APPROVED")
else:
  print("DENIED")
    

Measured memory_bytes: 2940
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return 0;
}
int h,a;
int main(){
	cin>>h>>a;
	cout<<(h+a-1)/a;
	re 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/arc074/tasks/arc074_b

#include <bits/stdc++.h>

using namespace std;

#define ll long long 
#define REP1(i,n) for(ll i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define radrad(a)  180.0 * a / M_PI
#define pow(x) x*x
static const int MAX = 1000010;
static const ll INFTY = 1e12;
static const ll NUMMAX = 1000000007;
static const ll MOD = 1000000007;
#define LOOP 10000000
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 入力
int H, W;
vector<string> field;
int result = 100;
int dfs_res = 0;

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

 

int main() {

    ll N;
    cin >> N;
    ll k;
    ll sum_zenhan = 0, sum_kohan = 0;
    ll ans = -INFTY;
    vector<ll> a(3 * N);
    REP(i, 3*N)cin >> a[i];

    // 左から前処理
    vector<long long> S(N*2+1, 0);
    priority_queue<long long, vector<long long>, greater<long long> > que1;
    for (int i = 0; i < N; ++i) {
        S[i+1] = S[i] + a[i];
        que1.push(a[i]);
    }
    for (int i = N; i < N*2; ++i) {
        long long mi = que1.top();
        if (a[i] > mi) {
            S[i+1] = S[i] - mi + a[i];
            que1.pop();
            que1.push(a[i]);
        }
        else S[i+1] = S[i];
    }

    // 右から前処理
    vector<long long> T(N*2+ 1, 0);
    priority_queue<long long> que2;
    for (int i = 0; i < N; ++i) {
        T[i+1] = T[i] + a[N*3-1 - i];
        que2.push(a[N*3-1 - i]);
    }
    for (int i = N; i < N*2; ++i) {
        long long ma = que2.top();
        if (a[N*3-1 - i] < ma) {
            T[i+1] = T[i] - ma + a[N*3-1 - i];
            que2.pop();
            que2.push(a[N*3-1 - i]);
        }
        else T[i+1] = T[i];
    }

    // 集計
    long long res = -(1LL<<60);
    for (int i = N; i <= N*2; ++i) {
        res = max(res, S[i] - T[N*3-i]);
    }
    cout << res << endl;
 

 
    return 0;
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/




Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std;
int n,a[100005];
long long ans;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
	cin>>a[i];	
	ans+=a[i]-1;
	}
    cout<<ans<<endl;
    return 0;
	} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    vector<vector<int>> x(n), y(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        x[i].resize(a[i]);
        y[i].resize(a[i]);
        for (int j = 0; j < a[i]; j++) {
            cin >> x[i][j] >> y[i][j];
            --x[i][j];
        }
    }
    int ma = 0;
    for (int i = 0; i < (1 << n); i++) {
        int f = 1;
        for (int j = 0; j < n; j++) {
            if ((i >> j) & 1) {
                for (int k = 0; k < a[j]; k++) {
                    if (y[j][k] != ((i >> x[j][k]) & 1)) {
                        f = 0;
                        break;
                    }
                }
            }
        }
        if (f) {
            chmax(ma, __builtin_popcount(i));
        }
    }
    cout << ma << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

void out(int last ,int n){
	for(int i=1;i<last;i++)
		cout << i << endl;
	for(int i=n-1;i>=last;i--)
		cout << i << endl;
}


int main(){
	int n,l,prev;
	cin >> n >> l >> prev;
	for(int i = 1;i<n;i++){
		int a;
		cin >> a;
		if(prev + a >= l){
			cout << "Possible" << endl;
			out(i,n);
			return 0;
		}
		prev = a;
	}
	cout << "Impossible" << endl;
	return 0;
}

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

int main()
{
int H,W;
cin>> H>>W;
while(H!=0||W!=0)
{
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
cout << "#";
}
cout << endl;
}
cout << endl;
cin >> H>>W;
}
return 0;
}

Measured memory_bytes: 1152
a,b = map(int, input().split())
coin = 0
a2 = 0
coin = 0
a2 = 0
b2 = 0
if a > b :
  coin += a
  a2 = a-1
  if a2 > b :
    coin += a2
  else :
    coin += b
else :
  coin += b
  b2 = b-1
  if b2 > a :
    coin += b2
  else :
    coin += a
print(coin)

Measured memory_bytes: 3188
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int inf=1000000000;
struct edge{
	int t,next,v;
}g[210001];
struct data{
	int a,b,v;
}e[210001];
int te,i,j,k,n,m,a[21][21],h[411],tot,dis[411],q[210001],v[411],num,s,t,w,tx,ty,fl;
void addedge(int x,int y,int z){
	//printf("%d %d %d\n",x,y,z);
	g[++tot].t=y;g[tot].next=h[x];h[x]=tot;g[tot].v=z;
	e[++te].a=x;e[te].b=y;e[te].v=z;
}
int gv(int x){
	if (x>=0) return x;
	if (x==-1) return tx;else return ty;
}
int work(int x,int y){
	int i,j,res=0;
	for (i=1;i<=n;i++)
	 for (j=1;j<=m;j++) res=max(res,a[i][j]-i*x-j*y);
	return res;
}
int spfa(){
	int i,j,k,l,r;
	memset(v,0,sizeof(v));
	for (i=1;i<=num;i++) dis[i]=inf;
	l=0;r=1;q[1]=1;dis[1]=0;
	while (l<r){
		j=q[++l];v[j]=0;
		for (i=h[j];i;i=g[i].next)
		 if (dis[g[i].t]>dis[j]+gv(g[i].v)){
		 	dis[g[i].t]=dis[j]+gv(g[i].v);
		 	if (!v[g[i].t]) v[g[i].t]=1,q[++r]=g[i].t;
		 }
	}
	return dis[num];
}
int main(){
	scanf("%d%d",&n,&m);w=105;
	for (i=1;i<=n;i++)
	 for (j=1;j<=m;j++) scanf("%d",&a[i][j]);
	num=2*w;s=1;t=num;tot=te=0;memset(h,0,sizeof(h));
	for (i=1;i<w;i++) addedge(i,i+1,-1),addedge(i+w,i+w+1,-2);
	for (i=0;i<w;i++)
	 for (j=0;j<w;j++) addedge(i+1,2*w-j,work(i,j));
	for (i=fl=1;fl&&i<=n;i++)
	 for (j=1;fl&&j<=m;j++){
	 	tx=i;ty=j;
		k=spfa();
		if (k!=a[i][j]) fl=0;//,printf("** %d %d %d\n",i,j,k);
	 }
	if (!fl){
		puts("Impossible");
	}else{
		puts("Possible");
		printf("%d %d\n",num,te);
		for (i=1;i<=te;i++){
			printf("%d %d ",e[i].a,e[i].b);
			if (e[i].v==-1) printf("X\n");
			if (e[i].v==-2) printf("Y\n");
			if (e[i].v>=0) printf("%d\n",e[i].v);
		}
		printf("%d %d\n",1,num);
	}
	return 0;
}

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


int main() {
  int N,M;
  cin >>N>>M;
  vector<int>a(M),b(M),c(M);
  rep(i,M){
    cin>>a.at(i)>>b.at(i)>>c.at(i);
    a.at(i)--;
    b.at(i)--;
  }
  vector<vector<int>>d(N,vector<int>(N));
  rep(i,N){
    rep(j,N){
      if(i==j){
        d.at(i).at(j)=0;
      }
      else{
        d.at(i).at(j)=1001001001;
      }
    }
  }
  rep(i,M){
    d.at(a.at(i)).at(b.at(i))=c.at(i);
    d.at(b.at(i)).at(a.at(i))=c.at(i);
  }
  
  
  
  for(int k = 0; k < N; k++) {
    for(int i = 0; i < N; i++) {
      for(int j = 0; j < N; j++) {        
        d[i][j] =min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
 
  int ans=M;
  rep(i,M){
    bool ex=false;
    rep(j,N){
      if(d.at(j).at(a.at(i))+c.at(i)==d.at(j).at(b.at(i))){
        ex=true;
      }
    }
    if(ex){
      ans--;
    }
    
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=[]
for k in range(n):
        b.append(abs(a[k]))
b.sort()
for i in range(n):
        if a[i]==0:
                print(sum(b))
                break
      
else:
        for j in range(n):
                if a[j]>0:
                        if j%2==0:
                                print(sum(b))
                                break
                        elif j%2!=0:
                                print(sum(b)-b[0]-b[0])
                                break
        else:
                if n%2==0:
                        print(sum(b))
                else:
                        print(sum(b)-b[0]-b[0])




Measured memory_bytes: 14492
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            int n = sc.nextInt();
            if(n==0) break;

            int[][] mato1 = new int[n][2];
            for(int i=0; i<n; i++){
                mato1[i][0] = sc.nextInt(); 
                mato1[i][1] = sc.nextInt();
            }
            int m = sc.nextInt();
            int[][] mato2 = new int[m][2];
            for(int i=0; i<m; i++){
                mato2[i][0] = sc.nextInt();
                mato2[i][1] = sc.nextInt();
            }
            int[][] mato = new int[n+m+1][2];
            int idx = 1;
            for(int i=0; i<n; i++) mato[idx++] = mato1[i];
            for(int i=0; i<m; i++) mato[idx++] = mato2[i];

            Arrays.sort(mato, new Comparator<int[]>(){
                    public int compare(int[] a, int[] b){
                        if(a[0]<b[0]) return -1;
                        if(a[0]>b[0]) return 1;
                        if(a[1]<b[1]) return -1;
                        if(a[1]>b[1]) return 1;
                        return 0;
                    }
                });

            int[] dp = new int[n+m+1];
            int max = 1;
            for(int i=0; i<=n+m; i++){
                for(int j=0; j<i; j++){
                    if(mato[i][0]>mato[j][0] && mato[i][1]>mato[j][1]){
                        dp[i] = Math.max(dp[i], dp[j] + 1);
                        max = Math.max(max, dp[i]);
                    }
                }
            }
            System.out.println(max);
        }
    }

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

Measured memory_bytes: 25108
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
l=[0]*(n+1)
r=[0]*(n+1)
for i in range(n):
    l[i+1]=gcd(l[i],a[i])
for i in range(n-1,-1,-1):
    r[i]=gcd(r[i+1],a[i])
ans=l[-1]
for i in range(n):
    ans=max(ans,gcd(l[i],r[i+1]))
print(ans)
    

Measured memory_bytes: 16144
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6 # 入力の最大値
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


# 入力
x, y = map(int, input().split())

# (1,2)か(2,1)で割り切れる場合
if (2*y-x)%3 == 0 and (2*x-y)%3 == 0:
    m = (2*y-x)//3
    n = (2*x-y)//3

    # 連立方程式の解のそれぞれが0以上の時
    if n >= 0 and m >= 0:
        print( str(int(cmb(n+m,n, mod) % (10e9+7)) ))
    else:
        print(0)
# 到達できない場合
else:
    print(0)


Measured memory_bytes: 123880
#include <iostream>

using namespace std;

bool f(int a, int b, int c) {
    return b - a == c - b;
}

int main() {

    int a, b, c;
    cin >> a >> b >> c;

    if (f(a, b, c)) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)

//positionbit目が立っているか判定
bool contain(int mask, int position){
    if((mask & (1 << position)) != 0) return true;
    else return false;
}

int main(void){
    string str; cin >> str;
    int n = 3;
    
    for(int mask = 0; mask < (1 << n); ++mask){
		int sum = stoi(str.substr(0,1),nullptr,10);
		for(int i = 0; i < n;i++){
			if(contain(mask,i)){
				sum += stoi(str.substr(i+1,1),nullptr,10);
			}else{
				sum -= stoi(str.substr(i+1,1),nullptr,10);
			}
		}
		if(sum == 7){
			cout<<str.substr(0,1);
			for(int i = 0; i < n; i++){
				if(contain(mask,i)){
					cout<<'+';
				}else{
					cout<<'-';
				}
				cout<<str.substr(i+1,1);
			}
			cout<<"=7"<<endl;
			break;
		}
    }
	
    return 0;
}

Measured memory_bytes: 256
import io.StdIn._

object Main extends App {
  val Seq(n, m, c) = readLine().split(" ").map(_.toInt).toSeq
  val b            = readLine().split(" ").map(_.toInt).toSeq

  require(1 <= n && n <= 20)
  require(1 <= m && m <= 20)
  require(b.forall(i => -100 <= i && i <= 100))

  var i = 0
  var j = 0
  while (i < n) {
    val a = readLine().split(" ").map(_.toInt).toSeq
    require(a.forall(i => -100 <= i && i <= 100))
    if (a.zip(b).map(ab => ab._1 * ab._2).sum + c > 0) j = j + 1
    i = i + 1
  }
  println(j)
}


Measured memory_bytes: 55020
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define mt make_tuple
#define pb push_back
const int N = 1e5 + 10;
ll dp[110][N],inp[110][2];

int main(){
    int n,w;
    cin>>n>>w;
    for(int i=1;i<=n;i++){
        cin>>inp[i][0]>>inp[i][1];
    }
    for(int i=0;i<=w;i++)    dp[0][i] = 0;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=w;j++){
            if(inp[i][0] <= j)   dp[i][j] = max(dp[i-1][j-inp[i][0]] + inp[i][1],dp[i-1][j]);
            else    dp[i][j] = dp[i-1][j];
        }
    }
    cout<<dp[n][w]<<endl;
    return 0;
}

Measured memory_bytes: 80256
#include <stdio.h>

int main(){
  int n;
  double sum = 0.0;
  char a[40] = "JPY";
  scanf("%d",&n);
  for (int i = 0; i < n; i++) {
    double x;
    char u[100];
    scanf("%lf %s",&x,u);
    if (u[0] == a[0]) {
      sum += x;
    }else{
      sum += x * 380000.0;
    }
  }
  printf("%lf\n",sum);
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1
#define pb push_back

using namespace std;

int main() {
  string s;
  bool flag;
  while (getline(cin, s), s != ".") {
    flag = true;
    stack<char> kakko;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '(' || s[i] == '[') {
        kakko.push(s[i]);
      }
      if (s[i] == ')') {
        if (kakko.empty() || kakko.top() != '(') {
          flag = false;
          break;
        }
        kakko.pop();
      }
      if (s[i] == ']') {
        if (kakko.empty() || kakko.top() != '[') {
          flag = false;
          break;
        }
        kakko.pop();
      }
    }
    if (!kakko.empty()) flag = false;
    if (flag) cout << "yes" << el;
    else cout << "no" << el;
  }
}

Measured memory_bytes: 1176
import java.util.*;

public class Main {

	void run() {

		//
		// 画面入力
		//
		Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	char[] charArray = sc.next().toCharArray();
    	int Q = sc.nextInt();
    	
        @SuppressWarnings("unchecked")
		TreeSet<Integer>[] table = (TreeSet<Integer>[])new TreeSet<?>[26]; // new TreeSet<Integer>[26]は通らない

        // 0 → a, 25 → z
        for(int i=0;i<26;i++){
        	table[i] = new TreeSet<Integer>();
        }

        // a-z別index対応表を作る
        for(int i=0; i<N; i++){
        	table[charArray[i]-'a'].add(i);
        }
    	

    	for (int i=0; i<Q; i++) {
        	if(sc.nextInt()==1){
        		int b=sc.nextInt();
        		char[] d = sc.next().toCharArray();
        		char tmp = charArray[b-1];
        		charArray[b-1] = d[0];

        		table[tmp-'a'].remove(b-1);
        		table[d[0]-'a'].add(b-1);
        		
        	}else{
        		int begin=sc.nextInt();
        		int end=sc.nextInt();
        		int n = 0;
        		
        		for(int j=0; j < 26; j++){
        			Integer x = table[j].higher(begin - 2);
        			if(x != null && x <= end-1){
        				n++;
        			}
        		}
            	System.out.println(n);
            	
            	/* 遅い
            	int alCnt = 0;
            	for(char al = 'a'; al <= 'z'; al++){
            		if(subS.indexOf(al)!=-1){
            			alCnt++;
            		}
            	}
            	System.out.println(alCnt);
            	*/
            	
        		/* 遅い
            	Set<Character> uniqueChar = new HashSet<Character>();
        		for(int j=b-1; j <= c-1; j++ ){
        			uniqueChar.add(charArray[j]);
        		}
        		System.out.println(uniqueChar.size());
        		*/
        	}
    	}
    	
    	sc.close();
    	
	}
	
    public static void main(String[] args) {
        new Main().run();
    }
}

Measured memory_bytes: 107852
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static void main(String args[]) throws Exception {
        String[] tokens = br.readLine().split(" ");
        int x = Integer.parseInt(tokens[0]);
        int y = Integer.parseInt(tokens[1]);
        boolean flag = true;
        if(!(y-2*x>=0 && (y-2*x)%2==0))
            flag = false;
        if(!(4*x-y>=0 && (4*x-y)%2==0))
            flag = false;
        if(flag)
            System.out.println("Yes");
        else
            System.out.println("No");
    }




    private static class Pair{
        int first,second;

        public Pair(int first,int second){
            this.first = first;
            this.second = second;
        }

        public int hashCode(){
            return Objects.hash(first,second);
        }

        public boolean equals(Object obj){
            if(obj!=null || !(obj instanceof  Pair))
                return false;
            Pair pair = (Pair)obj;
            return pair.first == first && pair.second == second;
        }
    }




}

Measured memory_bytes: 25360
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main(){
	int n,m;
	cin>>n>>m;
	vector<int>way[alength];
	fori(m){
		int a,b;cin>>a>>b;
		way[a-1].push_back(b-1);
		way[b-1].push_back(a-1);
	}

	queue<int>q;
	vector<int>dist(n,INF);
	vector<int>pre(n,-1);
	dist[0]=0;
	q.push(0);
	while(!q.empty()){
		int v=q.front();q.pop();
		for(int u:way[v]){
			if(dist[u]!=INF){
				continue;
			}
			dist[u]=dist[v]+1;
			pre[u]=v;
			q.push(u);
		}
	}
	cout << "Yes\n";
	fori(n-1){
		int ans=pre[i+1];
		cout << ans+1 << endl;
	}
}


Measured memory_bytes: 10572
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i <= (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const ll INF=1e18;

int main() {
  ll n,m,k;
  cin >>n>>m;
  rep(i,n){
    rep(j,n-i){
      k=n-i-j;
      if(m==i*10000+j*5000+k*1000){
        cout << i<<" "<< j<<" "<<k<<endl;
        return 0;
      }
    }
  }
  cout <<"-1 -1 -1"<<endl;
}

Measured memory_bytes: 3592
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> P(N), C(N);
    rep(i, N) cin >> P[i];
    rep(i, N) cin >> C[i];
    vector<vector<ll>> cum(N, vector<ll>(N + 1));
    vector<ll> lens(N);
    rep(i, N) {
        vector<ll> tmp(N);
        int cur = i;
        int len = 0;
        rep(j, N) {
            len++;
            cur = P[cur] - 1;
            tmp[j] = C[cur];
            if(cur == i) {
                break;
            }
        }
        lens[i] = len;
        rep(j, N) { cum[i][j + 1] = tmp[j] + cum[i][j]; }
    }
    ll res = -LINF;
    rep(i, N) {
        FOR(j, 1, min(K + 1, lens[i] + 1)) { res = max(res, cum[i][j]); }
    }

    rep(i, N) {
        ll tmp = K / lens[i];
        if(tmp <= 0)
            continue;
        ll score = tmp * cum[i][lens[i]];
        ll rest = K % lens[i];
        rep(j, rest + 1) { res = max(res, score + cum[i][j]); }
    }

    rep(i, N) {
        ll tmp = K / lens[i] - 1;
        if(tmp <= 0)
            continue;
        ll score = tmp * cum[i][lens[i]];
        ll rest = K % lens[i];
        rep(j, lens[i] + 1) { res = max(res, score + cum[i][j]); }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 199288
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);

double calcAngle(double h, double m) { 
	double hour_angle = 0.5 * (h * 60 + m); 
	double  minute_angle = 6 * m; 
	double angle = abs(hour_angle - minute_angle); 
	angle = min(360 - angle, angle); 
	return angle; 
} 


int32_t main(){
	cout<<setprecision(30)<<fixed;
	int t=1;
	//cin>>t;
	while(t--){
		int a,b,h,m;
		cin>>a>>b>>h>>m;
		double theta = calcAngle(h,m);
		theta /=180;
		theta *= PI;
		double ans  = sqrt(a*a + b*b - 2*a*b*cos(theta));
		cout<<ans<<endl;
	}
}

 

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	int S, W, ans=0;

	cin >> S >> W;

	cout << (S>W? "safe" : "unsafe") << endl;

	return 0;
}

Measured memory_bytes: 3640
#include<cstdio>
#include<cstring>
#include<algorithm>
int n,k,a[60],ans;
template<class T>
inline void read(T&a){
	char c=getchar();
	for(a=0;c<'0'||c>'9';c=getchar());
	for(;c>='0'&&c<='9';c=getchar())a=a*10+c-'0';
}
int main(){
	read(n),read(k);
	for(int i=1;i<=n;i++)read(a[i]);
	std::sort(a+1,a+1+n);
	for(int i=n;i>n-k;i--)ans+=a[i];
	printf("%d\n",ans);return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		int total = 0;

		for(int i=1;i<=n;i++){
			int sum = i/10000 + i%10000/1000 + i%1000/100 + i%100/10 + i%10;
			if (a<=sum&&sum<=b){
				total = total + i;
			}
		}
		System.out.println(total);
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    cout << (N+1)/2 << '\n';
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<map>
#include<math.h>
#include<queue>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000001;
const long long LINF = 1e18;
const int MAX = 510000;
int main() {
	int n;
	int m = 0;
	cin >> n;
	vector< int> a(n+1),b(n+1);
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
	}
	a.at(n) = INF;
	for (int i = n - 1; i >= 0; i--) {
		if (a.at(i + 1) <= a.at(i))b.at(i) = b.at(i + 1) + 1;
	}
	for (int i = 0; i < n; i++) {
		if (b.at(i) > m)m = b.at(i);
	}
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 4040
//IOI 2021
//this will accept, By the order of the peaky fucking blinders
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

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

string t;
string s[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> t;
	for (int i = 0; i < 7; i++)
		if (s[i] == t) {
			cout << 7 - i << endl;
		}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 100;
int n, sum = 0;
int L[maxn << 1 | 1];
int main() {
    scanf("%d", &n);
    n <<= 1;
    for (int i = 1; i <= n; ++i)
        scanf("%d", &L[i]);
    sort(L + 1, L + n + 1);
    for (int i = 1; i <= n; i += 2)
        sum += L[i];
    printf("%d\n", sum);
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  ll A, B;
  cin >> A >> B;

  if ((A+B)%2!=0) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }

  cout << (A+B)/2 << endl;

  return 0;
}


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

int keta(long long n){
  int i=0;
  while(n!=0){
    n/=10;
    i++;
  }
  return i;
}

int main(){
  long long n;
  int ans= 1<<21;

  scanf("%lld",&n);

  for(long long i=1;i*i<=n;i++){
    if(n%i!=0) continue;
    long long j=n/i;
    ans = min(ans,(max(keta(i),keta(j))));
 }

  printf("%d\n",ans);

  return 0;
} 


Measured memory_bytes: 128
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm> 
#include<climits>
#include<stack>
#include<queue>
#include<set>
#include<cctype>
#include<bitset> 
#include<type_traits>
#include<numeric>
#include<array>
using namespace std;

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<int,int> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

const int mod = 1000000007;
const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
}

int main(){

    int N,K;cin >> N >> K;

    vector<int> h(N);
    REP(i,N) cin >> h[i];
  
    auto dp = make_vec<int>(N+1);
    fill_v(dp,inf);
    
    dp[0]=0;
    REP(i,N) {
        rep(k,1,K+1){
            if(i-k<0) break;
            chmin(dp[i],dp[i-k]+abs(h[i]-h[i-k]));
        }
    }

    pl(dp[N-1])

    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication11 {
    class Program {
        static void Main(string[] args) {
            new Program().solve();
        }

        void solve() {
            while (true) {
                string input = Console.ReadLine();
                if (input == "0") return;

                int[] score = new int[2];
                for (int i = 0; i < input.Length; i++) {
                    if (scored(input , i)) {
                        score[0]++;
                    } else {
                        score[1]++;
                    }
                }
                Console.WriteLine(score[0]+" "+score[1]);
            }
        }

        bool scored(string log, int idx) {
            if (log.Length - 1 == idx) {
                if (log.Substring(idx,1) == "A") {
                    return true;
                } else {
                    return false;
                }
            }

            if (log.Substring(idx, 2) == "AA" || log.Substring(idx, 2) == "BA") {
                return true;
            } else {
                return false;
            }
        }
    }
}

Measured memory_bytes: 8884
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <stdlib.h>

using namespace std;

void solve()
{
    string s, t;

    cin >> s >> t;

    int m = s.size();
    int n = t.size();

    vector<vector<int>> dp(m + 1, vector<int>(n + 1, 0));
    //vector<vector<vector<int>>> sdp(m, vector<vector<int>>(n, vector<int>(0)));

    for (int i = 1; i < m + 1; ++i) {
        for (int j = 1; j < n + 1; ++j) {
            if (s[i - 1] == t[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
            else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }

    string ans = "";

    int i = m;
    int j = n;

    while (i && j) {
        if (s[i - 1] == t[j - 1]) {
            ans = s[i - 1] + ans;
            i--;
            j--;
        }
        else {
            if (dp[i][j - 1] > dp[i - 1][j]) {
                j--;
            }
            else {
                i--;
            }
        }
    }

    cout << ans;
}

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

    solve();
}


Measured memory_bytes: 38960
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
typedef long long ll;
using namespace std;
int main(void){
    string s;cin>>s;
    //int n=s.size();
    int q;cin>>q;
    vector<char> x,y;
    int now=1;
    rep(i,q){
        int t;cin>>t;
        if(t==1){
            now*=(-1);
        }else{
            int f;cin>>f;
            char c;cin>>c;
            if((f==1&&now==1)||(f==2&&now==-1))x.push_back(c);
            else y.push_back(c);
        }
    }
    if(now==1){
        reverse(x.begin(),x.end());
        rep(i,x.size()) cout<<x[i];
        cout<<s;
        rep(i,y.size()) cout<<y[i];
        cout<<endl;
    }else{
        reverse(s.begin(),s.end());
        reverse(y.begin(),y.end());
        rep(i,y.size()) cout<<y[i];
        cout<<s;
        rep(i,x.size()) cout<<x[i];
        cout<<endl;
    }
}


Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>









ll a,b,c,d,e,f,rw,rs,w,w2,s;





void solve()
{
	cin>>a>>b>>c>>d>>e>>f;
	rw=0;
	rs=0;
	for(int i=0;i*a*100<=f;i++)
	{
		for(int j=0;j*b*100<=f;j++)
		{
			w2=(i*a)+(j*b);
			w=w2*100;
			if(w>f)break;
			for(int x=0;x*c<=w2*e;x++)
			{
				for(int y=0;y*d<=w2*e;y++)
				{
					s=min((x*c)+(y*d),f-w);
					if(s>w2*e)break;
					if((rs==0&&rw==0)||s*(rw+rs)>=rs*(w+s))
					{
						rs=s;
						rw=w;
					}
				}
			}
		}
	}
	cout<<rw+rs<<" "<<rs<<"\n";
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

Measured memory_bytes: 256
import sys
for x1, y1, x2, y2, x3, y3, x4, y4 in (map(float, l.split()) for l in sys.stdin.readlines()):
    a = sorted([((x1, y1), (x2, y2)), ((x3, y3), (x4, y4))])
    b = sorted(a, key=lambda x: x[0][1])
    if a[0][1][0] >= a[1][0][0] and b[0][1][1] >= b[1][0][1]:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 5588
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a;
    cin>>n;
    int min_num=10000,max_num=0;
    for (int i=0;i<n;i++) {
        cin>>a;
        if (a<min_num) {
            min_num=a;
        }
        if (a>max_num) {
            max_num=a;
        }
    }
    cout<<max_num-min_num<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n,i,s;
	cin>>n;
	int * a=new int[n];
	for(i=0;i<n;i++)
		cin>>a[i];

	for(i=0;(n/2)>i;i++){
		s=a[i];
		a[i]=a[n-1-i];
		a[n-1-i]=s;
	}
	for(i=0;i<n;i++){
		cout<<a[i];
		if(i!=n-1)
			cout<<" ";
	}
	cout<<endl;
	delete[] a;
	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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;}

int main()
{
    int h,w;
    cin >> h >> w;
    vector<vector<int>> v(h,vector<int>(w));
    REP(i,h){
        REP(j,w){
            cin >> v[i][j];
        }
    }
    queue<pair<int,int>> q1;
    queue<pair<int,int>> q2;
    int n=0;
    REP(i,h){
        REP(j,w){
            if(v[i][j]%2==1){
                v[i][j]--;
                q1.push(make_pair(i+1,j+1));
                if(j+1==w){
                    if(i+1==h){
                        continue;
                    }
                    v[i+1][j]++;
                    q2.push(make_pair(i + 2, j + 1));
                }
                else{
                    v[i][j+1]++;
                    q2.push(make_pair(i + 1, j + 2));
                }
                n++;
            }
        }
    }
    cout << n << endl;
    REP(i,n){
        cout << q1.front().first << " " << q1.front().second << " ";
        cout << q2.front().first << " " << q2.front().second << endl;
        q1.pop();
        q2.pop();
    }
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  ll n,k ;
  cin >> n ;
  vector<vector<ll>> v(n,vector<ll>(3,0)),dp(n+1,vector<ll>(3,0));
  for(ll i=0;i<n;i++) cin >> v[i][0] >> v[i][1] >> v[i][2]  ;
  for(ll i=1;i<=n;i++)
  {
    dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + v[i-1][0] ;
    dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + v[i-1][1] ;
    dp[i][2] = max(dp[i-1][1],dp[i-1][0]) + v[i-1][2] ;

  }
  cout << max(dp[n][0],max(dp[n][1],dp[n][2])) << endl;

}

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

int main(){
    int a[10000],min,max,n,i;
    long long sum=0;
    cin >> n;
    for(i=0 ;i<n;i++){
        cin >> a[i];
        sum += a[i];
    }
    max = min = a[0];
    for(i = 1; i < n; i++){
        if(a[i] > max ) max = a[i];
        if(a[i] < min ) min = a[i];
    }
    cout << min << ' ' << max << ' ' << sum << endl;
} 


Measured memory_bytes: 3128
#include<stdio.h>

int main() {
	//def
	int n, a[101], i, j, temp;
	//input
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	//sort
	for (i = 0; i < n - 1; i++) {
		for (j = 0; j < n - 1 - i; j++) {
			if (a[j] < a[j + 1]) {
				temp = a[j]; a[j] = a[j + 1]; a[j + 1] = temp;
			}
		}
	}
	//fit
	if (n % 2 == 1) {
		a[n] = 0;
		n++;
	}
	//calc
	temp = 0;
	for (i = 0; i < n; i += 2) {
		temp += a[i] - a[i + 1];
	}
	printf("%d", temp);
	return 0;
}

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

int main(){
    int n;cin>>n;
    string s;cin>>s;

    map<char, int> alphabet{
        {'A', 0},
        {'B', 1},
        {'C', 2},
        {'D', 3},
        {'E', 4},
        {'F', 5},
        {'G', 6},
        {'H', 7},
        {'I', 8},
        {'J', 9},
        {'K', 10},
        {'L', 11},
        {'M', 12},
        {'N', 13},
        {'O', 14},
        {'P', 15},
        {'Q', 16},
        {'R', 17},
        {'S', 18},
        {'T', 19},
        {'U', 20},
        {'V', 21},
        {'W', 22},
        {'X', 23},
        {'Y', 24},
        {'Z', 25}
    };
    map<int, char> rev_alphabet;
    for (auto item : alphabet){
        rev_alphabet[item.second] = item.first;
    }

    for (int i=0;i<s.size();i++){
        cout << rev_alphabet[(alphabet[s[i]] + n) % 26];
    }
    cout << endl;
    return 0;


}

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

struct scc{
	int n;
	vector<vector<int>> edge, rev;
	vector<int> vs, cmp;
	vector<bool> used;

	scc(int n_){
		n = n_;
		edge.assign(n, vector<int>());
		rev.assign(n, vector<int>());
		used.assign(n, false);
		cmp.assign(n, 0);
	}

	void addedge(int from, int to){
		edge[from].emplace_back(to);
		rev[to].emplace_back(from);
	}

	void dfs(int v){
		used[v] = true;
		for(auto n:edge[v]) if(!used[n]) dfs(n);
		vs.emplace_back(v);
	}

	void rdfs(int v, int k){
		used[v] = true;
		cmp[v] = k;
		for(auto n:rev[v]) if(!used[n]) rdfs(n, k);
		vs.emplace_back(v);
	}

	int calc(){
		for(int i = 0; i < n; i++) if(!used[i]) dfs(i);
		used.assign(n, false);
		int k = 0;
		for(int i = vs.size() - 1; i >= 0; i--){
			int v = vs[i];
			if(!used[v]) rdfs(v, k++);
		}
		return k;
	}

	bool same(int a, int b){
		return cmp[a] == cmp[b];
	}
};

/*
5 6
0 1
1 0
1 2
2 4
4 3
3 2
4
0 1
0 3
2 3
3 4
*/

int main(){
	int v, e;
	cin >> v >> e;
	scc scc(v);
	while(e--){
		int s, t;
		cin >> s >> t;
		scc.addedge(s, t);
	}
	scc.calc();
	int q;
	cin >> q;
	while(q--){
		int u, vv;
		cin >> u >> vv;
		cout << scc.same(u, vv) << endl;
	}
}

Measured memory_bytes: 4500