akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
#pragma region chminmax
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    ll n, m, k;
    cin >> n >> m >> k;
    vll a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];

    vll sa(n + 1), sb(m + 1);
    rep(i, n) sa[i + 1] = sa[i] + a[i];
    rep(i, m) sb[i + 1] = sb[i] + b[i];
    int ans = 0;

    rep(i, n + 1)
    {
        int books = i;
        ll nowP = sa[i];
        ll nowK = k - nowP;

        if (nowK < 0)
            break;

        int bBooks = upper_bound(sb.begin(), sb.end(), nowK) - sb.begin() - 1;
        bBooks = max(0, bBooks);
        ll bPrice = sb[bBooks];

        if (nowK - bPrice < 0)
            continue;

        chmax(ans, books + bBooks);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9596
#include <stdio.h>

int r, c;
int tange_sakura[100][100];

int main(void) {
	int i, j;
	int oohasi_ayaka, minase_inori = 0;
	if (scanf("%d%d", &r, &c) != 2) return 1;
	for (i = 0; i < r; i++) {
		for (j = 0; j < c; j++) {
			if (scanf("%d", &tange_sakura[i][j]) != 1) return 1;
		}
	}
	for (i = 0; i < r; i++) {
		oohasi_ayaka = 0;
		for (j = 0; j < c; j++) {
			printf("%d ", tange_sakura[i][j]);
			oohasi_ayaka += tange_sakura[i][j];
		}
		printf("%d\n", oohasi_ayaka);
	}
	for (j = 0; j < c; j++) {
		oohasi_ayaka = 0;
		for (i = 0; i < r; i++) oohasi_ayaka += tange_sakura[i][j];
		printf("%d ", oohasi_ayaka);
		minase_inori += oohasi_ayaka;
	}
	printf("%d\n", minase_inori);
	return 0;
}



Measured memory_bytes: 2060
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int64 q,h,s,d;
  scanf("%lld%lld%lld%lld",&q,&h,&s,&d);
  int64 n;
  scanf("%lld",&n);
  int64 t=MIN(4*q,MIN(2*h,s));
  int64 min=MIN(n*t,(n/2)*d+(n%2)*t);
  printf("%lld\n",min);
}

int main(void){
  run();
  return 0;
}


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

#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second
#define all(x) x.begin(), x.end();

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

ll sum(int n){
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}
using namespace std;


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

   string s; cin >> s;
   char f = s[0];
   int m = 0;
   for(int i = 1; i < s.size(); i++){
      if(i % 2 == 0 && s[i] != f){
         m++;
      }else if(i % 2 != 0 && s[i] == f){
         m++;
      }
   }
   cout << m;
   return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define SZ(n)  (int)n.size()
#define dump(x) cerr<<#x<<" = "<<(x)<<endl;
#define debug(x)cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define MP make_pair
#define PB push_back
const int INF=1<<28;
	int ta[10000];
	double dp[120][120];//i繧ソ繝シ繝ウ逶ョ縺ォ,繝槭せj縺ォ縺?ｋ繝代ち繝シ繝ウ縺ョ蜷郁ィ?	bool bre[120][120];
	int main(){
	int n,t,l,b;
	while(cin>>n>>t>>l>>b,n+t+l+b){
	for(int i=0;i<l;i++){int a;cin>>a;ta[a]=1;}
	for(int i=0;i<b;i++){int a;cin>>a;ta[a]=2;}
	dp[0][0]=1;
	for(int i=0;i<t;i++){
		for(int j=0;j<n;j++){
			for(int k=1;k<=6;k++){
				int next=j+k;
				if(next>n)next=n-(j+k-n);
				if(ta[next]==2)dp[i+1][0]+=dp[i][j]*(1.0/6.0);
				else if(ta[next]==1)dp[i+2][next]+=dp[i][j]*(1.0/6.0);
				else dp[i+1][next]+=dp[i][j]*(1.0/6.0);
			}
			
		}
	}

	double ans=0.0;
	for(int i=0;i<=t;i++)ans+=dp[i][n];
	/*for(int i=0;i<=t;i++){
		for(int j=0;j<=n;j++)printf("%.3lf  ",dp[i][j]);
		cout<<endl;
	}*/
	printf("%.6lf\n",ans);
	//int kaku=0;
	//for(int i=0;i<=n;i++)kaku+=dp[t][i];
	//cout<<(double)dp[t][n]/(double)kaku<<endl;
	for(int i=0;i<120;i++)for(int j=0;j<120;j++)dp[i][j]=0,ta[i]=0;
	}
	return 0;
} 

Measured memory_bytes: 1304
def LI():return list(map(int,input().split()))
def II():return int(input())
def yes():return print("Yes")
def no():return print("No")
INF=float("inf")
from collections import deque, defaultdict, Counter
from heapq import heappop, heappush
from itertools import product, combinations
from functools import reduce, lru_cache
from math import pi, gcd
from decimal import Decimal

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

class Unionfind:
    def __init__(self, N):
        self.p = list(range(N))
        self.rank = [0] * N
        self.size = [1] * N

    def root(self, x):
        if self.p[x] != x:
            self.p[x] = self.root(self.p[x])

        return self.p[x]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        u = self.root(x)
        v = self.root(y)

        if u == v: return

        if self.rank[u] < self.rank[v]:
            self.p[u] = v
            self.size[v] += self.size[u]
            self.size[u] = 0
        else:
            self.p[v] = u
            self.size[u] += self.size[v]
            self.size[v] = 0

            if self.rank[u] == self.rank[v]:
                self.rank[u] += 1

    def count(self, x):
        return self.size[self.root(x)]


d,t,s=LI()

if (d<=t*s):
    yes()
else:
    no()


Measured memory_bytes: 72576
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
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; }

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
  int N;
  cin >> N;

  vector<int> H(N);
  rep(i, N) cin >> H[i];

  int ans = 1;
  int prevMax = H[0];
  for(int i = 1; i < N; i++){
    if(H[i] >= prevMax){
      prevMax = H[i];
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}



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

int main() {
	int N; cin>>N;
	int wgt[N];
	double diff = std::numeric_limits<double>::infinity();
	int differ;
		int sum1=0;
			int sum2=0;
	for(int a=0;a<N;a++){
		cin>>wgt[a];
	}
	for(int T=1;T<N;T++){
		for(int a=0;a<=T;a++){
			sum1+=wgt[a];
		}
		for(int b=N-1;b>T;b--){
			sum2+=wgt[b];
		}
		
		 differ=sum1-sum2;
		if(differ<=diff){
			diff=abs(differ);
		}
		sum1=0;
		sum2=0;
	}
	if(diff==0){
		printf("0\n");
	}
	else {
		cout<<diff<<endl;
	}
	return 0;
}

Measured memory_bytes: 3764
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,x,y;
vector<ll>v[100009];
ll dp[100009];

ll f(ll N){
	if (v[N].empty())return 0;
	if(dp[N]!=-1)return dp[N];
	ll z=0;
	for(int i=0; i<v[N].size(); i++){
		z=max(z,f(v[N][i])+1);
	}
	dp[N]=z;
	return dp[N];
}

int main(){
	cin >> n >> m;
	memset(dp,-1,sizeof dp);
	for(int i=1; i<=m; i++){
		cin >> x >> y;
		v[x].push_back(y);
	}
	ll jwb=0;
	for(int i=1; i<=n; i++){
		jwb=max(jwb,f(i));
	}
	cout << jwb << endl;
}

Measured memory_bytes: 8576
#include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long
#define pii pair<int,int>
#define pb(x) push_back(x)
#define lbound lower_bound
#define ubound upper_bound
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcountll(x)
#define heap_min priority_queue<int,vector<int>,greater<int>>
#define heap_max priority_queue<int>
#define printv(v) for(auto p : v) cout << p << " ";
#define printa(a,n) for(int i = 0 ; i < n ; i++) cout << a[i] << " ";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int a[3001];
int dp[3001][3001];

int solve(int i,int j){
	if(i>j){
		return 0;
	}
	if(dp[i][j]!=-1){
		return dp[i][j];
	}
	return dp[i][j] = max(a[i]+min(solve(i+2,j),solve(i+1,j-1)),a[j]+min(solve(i,j-2),solve(i+1,j-1)));
	
}
int32_t main()
{
	int n,k;
	cin >> n;
	int tot = 0;
	for(int i = 0 ; i < n ; i++){
		cin >> a[i];
		tot+=a[i];
	}
	memset(dp,-1,sizeof(dp));
	k = solve(0,n-1);
	cout << k-(tot-k);
}


Measured memory_bytes: 74096
n=int(input())
str_list=[input() for i in range(n)]

# AC, WA, TLE, RE 
ac = str_list.count("AC")
wa = str_list.count("WA")
tle = str_list.count("TLE")
re = str_list.count("RE")

# AC x C
print("AC x {}".format(ac))
print("WA x {}".format(wa))
print("TLE x {}".format(tle))
print("RE x {}".format(re))

Measured memory_bytes: 16152
n = int(input())
h = list(map(int,input().split()))
h1 = [[h[i],i] for i in range(n)]
h1.sort()
a = list(map(int,input().split()))
dp = [0]*n
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
 
    def sum(self, i):
        # [0, i) の要素の総和を返す
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s
    def max(self, i):
        # [0, i) の要素の最大値を返す
        s = 0
        i += 1
        while i>0:
            s = max(s,self.tree[i])
            i -= i & -i
        return s
 
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] = max(x,self.tree[i])
            i += i & -i
bit = Bit(2*n+1)

for i in range(n):
    s = h1[i][1]
    x = a[s]+bit.max(s-1)
    dp[s] = x
    bit.add(s,x)
    
print(max(dp))

Measured memory_bytes: 126672
import Control.Monad (replicateM, unless)
import Control.Applicative ((<$>))

surfaceArea :: Double -> Double -> Double
surfaceArea x h = (*) x $ (+) x $ sqrt $ x * x + 4 * h * h

main :: IO ()
main = do
    [x, h] <- replicateM 2 $ read <$> getLine
    unless (x == 0.0 && h == 0.0) $ do
        putStrLn $ show $ surfaceArea x h
        main

Measured memory_bytes: 3976
#include<iostream>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<bits/stdc++.h>
#include<limits>

#define lp2(i,n) for(int i=0;i<n;i++)
#define lp3(i,a,b) for(int i=a;i<b;i++)

using namespace std;
int main(){
  int n;
  cin>>n;
  cout<<n/3<<endl;
  return 0;
  
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int a[3][3];
int main() {
  for(int i = 0; i < 3; ++i){
    for(int j = 0; j < 3; ++j){
      cin >> a[i][j];
    }
  }
  
  for(int i = 0; i < 3; ++i){
    int tmp = a[i][0];
    for(int j = 0; j < 3; ++j){
      a[i][j] -= tmp;
    }
  }
  
  for(int j = 0; j < 3; ++j){
    int tmp = a[0][j];
    for(int i = 0; i < 3; ++i){
      a[i][j] -= tmp;
    }
  }
  
  bool ok = true;
  for(int i = 0; i < 3; ++i){
    for(int j = 0; j < 3; ++j){
      if(a[i][j] != 0) ok = false;
    }
  }
  
  cout << (ok ? "Yes" : "No") << endl;
}

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

int main(){
  int N, M, X, Lcost = 0, Rcost = 0;
  cin >> N >> M >> X;
  
  for (int i = 0; i < M; i++){
    int a;
    cin >> a;
    
    if (a < X){
      Lcost++;
    }
    else{
      Rcost++;
    }
  }
  
  int ans = min(Lcost, Rcost);
  cout << ans << endl;
}

Measured memory_bytes: 3604
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		int n = int.Parse(input[0]);
		int k = int.Parse(input[1]);

    if(n <= k) Console.WriteLine(1);
    else Console.WriteLine(0);
	}
}


Measured memory_bytes: 20008
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define il inline
#define rg register
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define rep(i,st,ed) for(rg int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(rg int i=(ed);i>=(st);--i)
#define rep0(i,n) for(rg int i=0;i<(n);++i)
#define per0(i,n) for(rg int i=int(n)-1;i>=0;--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &x,const T &y){return x<y?x:y;}
template<typename T> il T qmax(const T &x,const T &y){return x>y?x:y;}
template<typename T> il bool getmin(T &x,const T &y){return y<x?x=y,true:false;}
template<typename T> il bool getmax(T &x,const T &y){return y>x?x=y,true:false;}
il void fileio(const string &s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e18+7;
const int N=105;

int n,s[N],sum;

int main(){
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",s+i),sum+=s[i];
	if(sum%10>0) return printf("%d\n",sum),0;
	int mn=sum;
	rep(i,1,n){
		if(s[i]%10>0&&s[i]<mn){
			mn=s[i];
		}
	}
	printf("%d\n",sum-mn);
	return 0;
}



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

int main(){
    int H,W,D;
    cin >> H>> W>>D;
    vector<pair<int,int>> numbers(H*W);
    vector<vector<int>> boards(H);
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            int A;
            cin >> A;
            A--;
            boards[i].push_back(A);
            numbers[A].first = i;
            numbers[A].second = j;
        }
    }
    int Q;
    cin >> Q;
    vector<int> f(H*W,0);
    for(int i=D;i<(H*W);i++){
        f[i] = f[i-D] + abs(numbers[i].first-numbers[i-D].first) + abs(numbers[i].second-numbers[i-D].second); 
        // cerr <<"i=" <<i<<"f(i)="<<f[i] << endl;
    }
    
    for(int i=0;i<Q;i++){
        int L,R;
        cin >> L >>R;
        L--;R--;
        // cerr << "fR="<<f[R] << "fL=" << f[L] << endl;
        cout << f[R]-f[L] << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 2816
import math

n,a,b = map(int, input().split())
h = [int(input()) for i in range(n)]
h.sort(reverse=True)

def erase(k):
  bomb_time = 0
  for i in h:
    normal_damage = b * k
    if i <= normal_damage:
      break
    i -= normal_damage
    bomb_time += math.ceil(i / (a-b))
    if bomb_time > k:
      return False
  return True

ok = 10**9
ng = 0
while ok-ng > 1:
    mid = (ok+ng)//2
    if erase(mid):
        ok = mid
    else:
        ng = mid
print(ok)

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

Graph G;
vector<int> color;

void dfs(int p, int v, int c) {
  color[v] = c;
  for (auto u : G[v]) {
    if (u.first == p) continue;
    if (u.second % 2 == 0) dfs(v,u.first,c);
    else dfs(v,u.first,1-c);
  }
  return ;
}

int main(){
  int n;
  cin >> n;
  G.resize(n);
  color.resize(n,-1);
  rep(i,n-1) {
    int u,v,w;
    cin >> u >> v >> w;
    u--;v--;
    G[u].push_back({v,w});
    G[v].push_back({u,w});
  }
  
  dfs(-1,0,0);
  for (auto ans : color) {
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 8960
n=int(input())
dekai=[0,0]
onaji=0
alist=[]
for i in range(n):
    ai=int(input())
    if ai>dekai[0]:
        dekai[1]=dekai[0]
        dekai[0]=ai
    elif ai>dekai[1]:
        dekai[1]=ai
    alist.append(ai)

for i in range(n):
    x=alist[i]
    if x==dekai[0]:
        print(dekai[1])
    else:
        print(dekai[0])

Measured memory_bytes: 12520
#include<iostream>
#include<iomanip>
#include<vector>
#include<queue>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>
#include<memory>

using namespace std;

int main()
{
  double h, mx, mn;

  cin >> h;
  mx = h;
  mn = h;

  while ( cin >> h )
    {
      mx = max( mx, h );
      mn = min( mn, h );
    }

  cout << mx - mn << endl;
  
  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<string,int> P;
typedef map<string,int> M;

M add(M a,M b){
  for(P p2:b) a[p2.first] += p2.second;
  return a;
}

M Minus(M a,M b){
  for(P p2:b) a[p2.first] -= p2.second;
  return a;
}
 
M mult(M a,M b){
  M res;
  for(P p1:a)
    for(P p2:b){
      string s = p1.first + p2.first; sort(s.begin(),s.end());
      int num = p1.second * p2.second;
      res[s] += num;
    }
  return res;
}
 
M bnf();
int pos;
string S;
void skipsp(){while(S[pos] == ' ') pos++;}
 
int getNum(){
  int res = 0;
  while(isdigit(S[pos])) res = res * 10 + S[pos++]-'0';
  return res;
}
 
int getNum2(const string &S,int &pos){
  int res = 0;
  while(isdigit(S[pos])) res = res * 10 + S[pos++]-'0';
  return res;
}

string getBlock(){
  string res;
  skipsp();
  while(isdigit(S[pos]) || isalpha(S[pos])) res += S[pos++];
  skipsp();
  if(S[pos] == '^') {
    pos++;
    skipsp();
    assert(isdigit(S[pos])&&"hut");
    int p = getNum();
    for(int i=0;i<p-1;i++) res += res.back();
  }
  return res;
}
 
M BtoM(string b){
  M res;
  int num = 1;
  string val;
  for(int i=0;i<(int)b.size();i++){
    char ch = b[i];
    if(isalpha(ch)) val += ch;
    else if(isdigit(ch)) num *= getNum2(b,i),i--;
    else assert(ch == ' ' &&  "BtoM");
  }
  res[val] = num;
  return res;
}
 
M calc(){
  M res; res[""] = 1;
  while(1){
    skipsp();
    char ch = S[pos];
    if(ch == '(') pos++,res = mult(res,bnf()),pos++;
    else if(isalpha(ch) || isdigit(ch)){
      string block = getBlock();
      res = mult(res,BtoM(block));
    }
    else if(ch == '^') assert(!"^");
    else break;
  }
  return res;
}
 
M bnf(){
  M res = calc();
  while(1){
    skipsp();
    char ch = S[pos];
    if(isalpha(ch) || isdigit(ch)) res = mult(res,calc());
    else if(ch == '+')pos++,res = add(res,calc());
    else if(ch == '-')pos++,res = Minus(res,calc());
    else if(ch == '(') pos++,res = mult(res,bnf()),pos++;
    else if(ch == '^') assert(!"^");
    else break;
  }
  for(auto it=res.begin();it!=res.end();it++) if(it->second == 0) res.erase(it);
  return res;
}
 
signed main(){
  while(1){
    getline(cin,S);
    if(S == ".") break;
    pos = 0;
    M ori = bnf();
    while(1){
      getline(cin,S);
      if(S == ".") break;
      pos = 0;
      M res = bnf();
      cout<<((ori == res)? "yes":"no")<<endl;
    }
    cout<<"."<<endl;
  }
  return 0;
}

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define Mashu cout << "UUZ ate it." << endl
#define RE register int
#define ll long long
using namespace std;

inline int read(){
	char ch=getchar();
	int x=0,cf=1;
	while(ch<'0'||ch>'9') {
		if(ch=='-') cf=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		x=(x<<3)+(x<<1)+(ch^48);
		ch=getchar();
	}
	if (cf < 0) return -x;
	else return x;
}

int G[55];
template<class T> inline void write(T x){
	int g=0;
	do{G[++g]=x%10;x/=10;}while(x);
	for(int i=g;i>=1;--i)putchar('0'+G[i]);putchar('\n');
}

long long qwq[500010];
int vis[500010];
long long qzh[500010];

long long QAQ(int n, int s){
	long long ans = 0;
	for (int i = s; i <= s + n - 1; i++){
		ans += qwq[i];
	} 
	return ans;
}

int main(){
	long long n, x, p;
	cin >> n >> x >> p;
	qwq[1] = x;
	qzh[1] = x;
	vis[x] = 1;
	for (int i = 2; i <= n; i++){
		qwq[i] = qwq[i - 1] * qwq[i - 1] % p;
		qzh[i] = qzh[i - 1] + qwq[i];
		if (vis[qwq[i]]){
			long long ovo = qzh[i] - qzh[vis[qwq[i]]];
			int awa = i - vis[qwq[i]];
			cout << qzh[i] + ((n - i) / awa) * ovo + QAQ((n - i) % awa, vis[qwq[i]] + 1);
			return 0;
		}
		else{
			vis[qwq[i]] = i;
		}
	}
	cout << qzh[n] << endl;
	return 0;
	Mashu;
}


Measured memory_bytes: 4776
arr = sorted(list(map(int, input().split())))

ans = 0
if (arr[1] - arr[0]) % 2 == 1:
  arr[1] += 1
  arr[2] += 1
  ans += 1

ans += (arr[1] - arr[0]) // 2
ans += arr[2] - arr[1]
print(ans)

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '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 vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  string s; cin >> s;
  for(int i = 0; i < s.size(); i = i + 2) {
    cout << s[i];
  }
  cout << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int d, n;
    cin >> d >> n;
    int add_num;
    if ( d == 0 ) {
        add_num = 1;
    }
    else if ( d == 1 ) {
        add_num = 100;
    }
    else {
        add_num = 10000;
    }
    int ans = 0;
    for ( int i = 1; i <= n; ++i ) {
        ans += add_num;
    }
    if ( n == 100 ) {
        ans += add_num;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <map>
#include <cstring>
#include <algorithm>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))
#define rush() int T;scanf("%d",&T);while(T--)

typedef long long ll;
const int maxn = 105;
const ll mod = 1e9+7;
const int INF = 0x3f3f3f;
const double eps = 1e-9;

int main()
{
    int a,b,c,d;
    while(~scanf("%d%d%d%d",&a,&b,&c,&d))
    {
        int t[105]={0};
        for(int i=a;i<=b;i++)
        {
            t[i]++;
        }
        for(int i=c;i<=d;i++)
        {
            t[i]++;
        }
        int ans=0;
        for(int i=0;i<105;i++)
        {
            if(t[i]==2)
            {
                ans++;
            }
        }
        ans--;
        if(ans<0) ans=0;
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;

class Person implements Comparable<Person>{
	int A, B;
	public Person(int a, int b) {
		A = a; B = b;
	}
	public int compareTo(Person p) {
		return A - p.A;
	}
}

class Main{
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		int N = sc.nextInt();
		Person[] ps = new Person[N];
		for(int i = 0; i < N; i++) {
			ps[i] = new Person(sc.nextInt(), sc.nextInt());
		}
		Arrays.sort(ps);
		int rank = 0;
		long cnt = N;
		for(int i = 0; i < N; i++) {
			if(rank + 1 <= ps[i].A) {
				// 前の人との間に誰か居る
				cnt += (long)(ps[i].A - rank - 1);
				rank = ps[i].A;
			}
			if(i == N - 1) {
				// 最後の人
				cnt += (long)ps[i].B;
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 92104
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

mod util {
    #[allow(dead_code)]
    pub fn chmin<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x > y && {
            *x = y;
            true
        }
    }

    #[allow(dead_code)]
    pub fn chmax<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x < y && {
            *x = y;
            true
        }
    }

    /// 整数除算切り上げ
    #[allow(dead_code)]
    pub fn roundup(a: i64, b: i64) -> i64 {
        (a + b - 1) / b
    }

    #[allow(dead_code)]
    pub fn ctoi(c: char) -> i64 {
        c as i64 - 48
    }
}

#[allow(unused_imports)]
use util::*;

use std::cmp::Ordering;
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque};

fn main() {
    input! {
        n:usize,
        mut vs:[i64;n]
    }
    vs.sort();
    let mut ans = (vs[0] + vs[1]) as f64 / 2.0;
    for i in 2..n {
        ans += vs[i] as f64;
        ans /= 2.0;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<stdlib.h>
#define MAX 50000
int judge(const void* a,const void* b){
    return *(long long int*)a-*(long long int*)b;
}
 
int main(){
    long long int a[MAX];
    long long int i,n,ans,wait;
    while(1){
        scanf("%d",&n);
        if(n==0)break;
            for(i=0;i<MAX;i++){
                a[i]=0;
            }
        for(i=0;i<n;i++){
            scanf("%lld",&a[i]);
        }
        qsort(a,n,sizeof(long long int),judge);
        ans=0;
        wait=0;
        for(i=0;i<n-1;i++){
            wait+=a[i];
            ans+=wait;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

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

int main(void){
    int a,b,x;
    scanf("%d %d %d", &a, &b, &x);
    if (a<=x&&x<=a+b)
    {
        printf("YES");
    }else
    {
        printf("NO");
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,fast-math,unroll-loops")

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

typedef long long ll;
typedef string str;

#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()



int main() {
    IOS;
	
	int a,b,c;
	cin >> a >> b >> c;
	if(a == b && b == c){
		cout << 1;
			
	}
	else if(a == b || b == c || a == c){
		cout << 2;
	}
	else{
		cout << 3;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<limits>
#include<list>
#include <stdio.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0;i < (n); ++i)
#pragma GCC optimize("Ofast")



int main() {
	int n;
	cin >> n;
	vector<int>d(n);
	rep(i, n) {
		cin >> d[i];
	}
	vector<int>ans(n);
	
	rep(i, n) {
		ans[d[i]-1] = i+1;
	}
	rep(i, n) {
		cout << ans[i] << endl;
	}

	return 0;
}


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

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

int main(){
	int n, r;
	cin >> r >> n;
	int kari = r;
	int cnt = 0;
	while (kari!=0) {
		int s;
		s = kari % n;
		kari = (kari - s) / n;
		cnt++;
	}

	cout << cnt << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MATRIX_MAX 101
#define LOOP_RESET 0
#define MATRIX_RESET 0
#define DIFF 1
#define RETURN 0

int main(){
	unsigned long ulW_D_inact[MATRIX_MAX][MATRIX_MAX];	/* 行列Ａの格納用配列 */
	unsigned long ulW_D_act[MATRIX_MAX][MATRIX_MAX];  	/* 行列Ｂの格納用配列 */
	unsigned long ulW_D_ans[MATRIX_MAX][MATRIX_MAX];  	/* 積の格納用変数 */
	unsigned short usW_D_row;                         	/* 行数の格納用変数 */
	unsigned short usW_D_share;                       	/* 共用部分の格納用変数 */
	unsigned short usW_D_col;                         	/* 列数の格納用変数 */
	unsigned short usW_C_i, usW_C_j, usW_C_k;         	/* ループ変数 */
	
	/* 配列の初期化 */
	for(usW_C_i = LOOP_RESET;usW_C_i < MATRIX_MAX;usW_C_i++){
		for(usW_C_j = LOOP_RESET;usW_C_j < MATRIX_MAX;usW_C_j++){
			ulW_D_inact[usW_C_i][usW_C_j] = MATRIX_RESET;
			ulW_D_act[usW_C_i][usW_C_j] = MATRIX_RESET;
			ulW_D_ans[usW_C_i][usW_C_j] = MATRIX_RESET;
		}
	}
	
	/* 行数、共通部分、列数の入力 */
	scanf("%d %d %d", &usW_D_row, &usW_D_share, &usW_D_col);
	
	/* 行列Ａの入力 */
	for(usW_C_i = LOOP_RESET;usW_C_i < usW_D_row;usW_C_i++){
		for(usW_C_j = LOOP_RESET;usW_C_j < usW_D_share;usW_C_j++){
			scanf("%ld", &ulW_D_inact[usW_C_i][usW_C_j]);
		}
	}
	
	/* 行列Ｂの入力 */
	for(usW_C_i = LOOP_RESET;usW_C_i < usW_D_share;usW_C_i++){
		for(usW_C_j = LOOP_RESET;usW_C_j < usW_D_col;usW_C_j++){
			scanf("%ld", &ulW_D_act[usW_C_i][usW_C_j]);
		}
	}
	
	/* 行列Ａと行列Ｂの積の計算 */
	for(usW_C_i = LOOP_RESET;usW_C_i < usW_D_row;usW_C_i++){
		for(usW_C_j = LOOP_RESET;usW_C_j < usW_D_col;usW_C_j++){
			for(usW_C_k = LOOP_RESET;usW_C_k < MATRIX_MAX;usW_C_k++){
				ulW_D_ans[usW_C_i][usW_C_j] += ulW_D_inact[usW_C_i][usW_C_k] * ulW_D_act[usW_C_k][usW_C_j];
			}
		}
	}
	
	/* 計算結果の出力 */
	for(usW_C_i = LOOP_RESET;usW_C_i < usW_D_row;usW_C_i++){
		for(usW_C_j = LOOP_RESET;usW_C_j < usW_D_col - DIFF;usW_C_j++){
			/* 末端列以外の出力 */
			printf("%ld ", ulW_D_ans[usW_C_i][usW_C_j]);
		}
		/* 末端列の出力 */
		printf("%ld\n", ulW_D_ans[usW_C_i][usW_D_col - DIFF]);
	}
	
	return RETURN;
}




Measured memory_bytes: 2076
#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>;
int main(void){
  int N, M;
  cin >> N >> M;
  vector <int> A(N);
  rep(i,N) cin >> A.at(i);

  int sum = accumulate(all(A), 0);
  double kagen = sum * 0.25 / M;

  int ans = 0;
  rep(i,N){
    if (A.at(i) >= kagen) ans ++;
  }
  if (ans >= M) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int n, x; cin >> n >> x;
    V<int> l(n);
    for(int i = 0; i < n; i++) cin >> l[i];

    int ans = 1;
    int d = 0;
    for(int i = 0; i < n; i++){
        d = d + l[i];
        if(d <= x){
            ans++;
        }else{
            break;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();

    let a = n / 100;
    let b = (n / 10) % 10;
    let c = n % 10;
    // println!("{} {} {}", a, b, c);

    let mut ans = 0;

    if a == 9 {
        ans += 100
    } else {
        ans += 900
    }

    if b == 9 {
        ans += 10
    } else {
        ans += 90
    }
    if c == 9 {
        ans += 1
    } else {
        ans += 9
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
A = set(list(input()))
if len(A) == 2 and("S" in A and "N" in A ):
    print("Yes")
elif  len(A) == 2 and ("W" in A and "E" in A):
    print("Yes")
elif len(A) == 4:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
from sys import stdin


def input():
    return stdin.readline().strip()


def main():
    A, B, N = map(int, input().split())

    if N < B:
        ans = (A * N) // B
    else:
        ans = (A * (B - 1)) // B

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9124
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

bool isDistanceAInteger(vector<int> a, vector<int> b) {
    int sum = 0;
    for (int i = 0; i < a.size(); i++) {
        sum += abs((a[i] - b[i]) * (a[i] - b[i]));
    }
    int s = sqrt(sum);
    return s * s == sum;
}

int main() {
    int n, d;
    cin >> n >> d;
    vector<vector<int> > points = vector<vector<int> >(n);

    for (int i = 0; i < n; i++) {
        vector<int> coordinates = vector<int>(d);
        for (int j = 0; j < d; j++) {
            cin >> coordinates[j];
        }
        points[i] = coordinates;
    }

    int c = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            if (isDistanceAInteger(points[i], points[j])) {
                c++;
            }
        }
    }

    cout << c << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

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

ll solve(int N, int X, vl &XX){

	ll g = abs(XX[0]-X);
	rp(i, 1, N){
		// printf("%lld %lld\n",g, abs(XX[i]-X));
		g = gcd(g, abs(XX[i]-X));
	}

	return g;
}

int main(){
	int N,X; cin>>N>>X;
	vl XX(N);
	rpz(i,N)cin>>XX[i];
	ote(solve(N,X,XX));
}


Measured memory_bytes: 1024
// 27
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define len(x) int(x.size())
#define lli __int128_t
#define li long long int
#define ld long double
#ifdef LOCAL
#define debug(e) cerr << "\033[48;5;196m\033[38;5;15m" << e << "\033[0m";
#else
#define debug(e)
#endif
// 4
template <class A, class B>
ostream &operator<<(ostream &o, const pair<A, B> &p) {
  return o << "(" << p.fi << " " << p.se << ")";
}
// 8
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) {
  rep(i, (int)v.size()) o << setw(7) << left << v[i];
  return o << endl;
}
// 5
template <class A, class B>
ostream &operator<<(ostream &o, const map<A, B> &m) {
  for (auto &kv : m) o << kv;
  return o;
}
// 3
void _main(int tc) {
  string s;
  cin >> s;
  int groupcnt = 0;
  for (int i = 0; i < len(s); i++) {
    groupcnt++;
    // checking if the next one is same as current
    while (i + 1 < len(s) && s[i] == s[i + 1]) i++;
  }
  cout << groupcnt - 1 << endl;
}
// 7
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0), exit(0);
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        self.group_count = n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        self.group_count -= 1

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

def int_(num_str):
    return int(num_str) - 1


N, M, K = map(int, input().split())
uf = UnionFind(N)
some = [1] * N
for i in range(M):
    a, b = map(int_, input().split())
    uf.union(a, b)
    some[a] += 1
    some[b] += 1
for i in range(K):
    c, d = map(int_, input().split())
    if uf.same(c, d):
        some[c] += 1
        some[d] += 1


ans = [uf.size(i) - some[i] for i in range(N)]
print(*ans)


Measured memory_bytes: 14192
/**
  * @brief atcoder
  * @author yao
  */
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>
#include <set>
#define ft first
#define sd second
#ifdef DBG
#   define dbg_pri(x...) fprintf(stderr,x)
#else
#   define dbg_pri(x...) 0
#   define NDEBUG
#endif //DBG
#include <cassert>

typedef unsigned int uint;
typedef long long int lli;
typedef unsigned long long int ulli;

#define N 512
#define M 32
#define K (1048576*4)
#define T (512*3)

int c[M];
int s[N][M];
int t[N];
std::set<int> poi[M];

constexpr int n = 365, m = 26;

int count()
{
    for(int i=0;i<m;++i) poi[i] = {-1};
    int res = 0;
    for(int i=0;i<n;++i)
    {
        int l = *std::prev(poi[t[i]].end()), d = i-l;
        poi[t[i]].insert(i);
        res += s[i][t[i]];
        res -= c[t[i]]*d*(d-1)/2;
    }
    for(int i=0;i<m;++i)
    {
        int l = *std::prev(poi[i].end()), d = n-l;
        poi[i].insert(n);
        res -= c[i]*d*(d-1)/2;
    }
    return res;
}

int update(int x, int k)
{
    int pk = t[x];
    int res = s[x][k] - s[x][pk];
    std::set<int>::iterator itl, it, itr;
    it = poi[pk].find(x), itl = std::prev(it), itr = std::next(it);
    assert(it != poi[pk].end());
    res -= c[pk] * (x-*itl) * (*itr-x);
    poi[pk].erase(it);
    itr = poi[k].upper_bound(x), itl = std::prev(itr);
    res += c[k] * (x-*itl) * (*itr-x);
    poi[k].insert(x);
    t[x] = k;
    return res;
}

int main()
{
    int d;
    scanf("%d", &d);
    assert(d == n);
    for(int i=0;i<m;++i) scanf("%d", &c[i]);
    for(int i=0;i<n;++i)for(int j=0;j<m;++j) scanf("%d", &s[i][j]);
    for(int i=0;i<n;++i) t[i] = rand() % m;
    int val = count();
#ifdef DBG
    int init_val = val;
    int ca=0, cb=0;
#endif //DBG
    for(int i=0;i<K;++i)
    {
        int x = rand()%n, k = rand()%m;
        int pre_t = t[x];
        int nxt_v = val + update(x,k);
        if(nxt_v >= val || rand() <= (int)(exp((double)(nxt_v-val)/T)*((lli)RAND_MAX+1)))
        {
#ifdef DBG
            (nxt_v < val ? ca : cb) ++;
#endif //DBG
            val = nxt_v;
        }
        else update(x,pre_t);
    }
    for(int i=0;i<n;++i) printf("%d\n", t[i]+1);
    dbg_pri("poi 3: init=%d val=%d %d %d\n", init_val, val, ca, cb);
    return 0;
}


Measured memory_bytes: 4004
// input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        monsters: [usize; n + 1],
        heros: [usize; n]
    }
    let mut monsters = monsters;
    let mut heros = heros;
    let mut answer = 0;
    for i in 0..n {
        if heros[i] >= monsters[i] {
            heros[i] -= monsters[i];
            answer += monsters[i];
            monsters[i] = 0;

            if heros[i] > monsters[i + 1] {
                heros[i] -= monsters[i + 1];
                answer += monsters[i + 1];
                monsters[i + 1] = 0;
            } else {
                answer += heros[i];
                monsters[i + 1] = monsters[i + 1] - heros[i];
                heros[i] = 0;
            }
        } else {
            answer += heros[i];
            monsters[i] = monsters[i] - heros[i];
            heros[i] = 0;
        }
    }
    println!("{}", answer);
}


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

int main() 
{
    int N;
    cin >> N;
    vector<ll> H(N);
    for(int i = 0; i < N; ++i) cin >> H[i];
    vector<ll> gap, diff;
    gap.push_back(-1);
    for(int i = 0; i < N-1; ++i) {
        if(H[i] < H[i+1]) gap.push_back(i);
    }
    gap.push_back(N-1);
    for(int i = 0; i < (int)gap.size()-1; ++i) {
        diff.push_back(gap[i+1]-gap[i]-1);
    }
    ll ans = 0;
    for(int i = 0; i < (int)diff.size(); ++i) {
        ans = max(ans, diff[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3316
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		ll n;
		cin>>n;

		ll time[n+1];
		ll timesum = 0;
		for(ll i=1; i<=n; i++) {
			cin>>time[i];
			timesum += time[i];
		}

		ll m;
		cin>>m;

		vector<pair<ll,ll> > drinks;
		for(ll i=1; i<=m; i++) {
			ll p,x;
			cin>>p>>x;
			drinks.push_back({p,x});
		}

		for(ll i=1; i<=m; i++) {
			ll prob = drinks[i-1].first;
			cout<<(timesum - time[prob] + drinks[i-1].second)<<endl;
		}

		return 0;
	}


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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=1e9;

const ll INF = 1LL << 60;

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 a,b,c,k;cin>>a>>b>>c>>k;
  if(k<=a)cout<<k;
  else if(k>a && k<=a+b)cout<<a;
  else if(k>a+b)cout<<a-k+(a+b);
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        sc.close();
        if (x >= 30) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 35908
import java.util.Scanner; 
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int tmp;
for (int i = 1; i <= n; i++) {
if (i % 3 == 0 || i % 10 == 3) {
System.out.print(" " + i);
} else if (i >= 30) {
tmp = i;
while (tmp >= 30) {
tmp /= 10;
if (tmp == 3 || tmp % 10 == 3) {
System.out.print(" " + i);
break;
}
} 
}
}
System.out.println();
}
}
 

Measured memory_bytes: 28456
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <map>
using namespace std;
 
 
int main() {
    int n;
    string s;
    cin>>n>>s;
    
    int count=0, ans=-1;
    for(int i=1; i<n; ++i) {
        if(s[i]=='E') ++count;
    }

    ans=count;
    for(int i=1; i<n; i++) {
        if(s[i-1]=='W') ++count;
        if(s[i]=='E') --count;
        ans=min(ans,count);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 900
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
			String line = in.readLine();
			int len = line.length(); // 8
			int halfLen = len / 2;	 // 4
			int count = 0;

// 0123456
// abcdabc : 7
// 0, 6: a, c, 1
// 1, 5: b, b, 1
// 2, 3: c, a, 2

for (int i = 0; i < halfLen; ++i) {
	if (line.charAt(i) != line.charAt(len - i - 1)) {
		count += 1;
}
}
System.out.println(count);
		}
	}

}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e15;
using namespace std;
typedef long long ll;
int main() {
  ll a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  double ans_m, ans_s, mx = -1;
  REP(i, f / (100 * a) + 1) {
    REP(j, f / (100 * b) + 1) {
      REP(k, f / c + 1) {
        REP(l, f / d + 1) {
          double w = i * 100 * a + j * 100 * b, s = k * c + l * d;
          if (s > w * e / 100 || w + s > f) continue;
          double tmp = 100 * s / (w + s);
          if (tmp > mx) {
            mx = tmp;
            ans_m = w + s;
            ans_s = s;
          }
        }
      }
    }
  }
  cout << ans_m << " " << ans_s << endl;
  return 0;
}

Measured memory_bytes: 256