akhauriyash/Code-Regression huggingface dataset:
import math
n = []
while True:
    try:
        n.append(int(raw_input()))
    except:
        break

r = max(n)+1
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

for i in n:
     print sum(p[:i])

Measured memory_bytes: 35064
#include <bits/stdc++.h>
using namespace std;
const int mod=998244353;
int inv(int x){return x==1?1:mod-1ll*mod/x*inv(mod%x)%mod;}
int main(){
    int n,k,ans=0,sum=1;cin>>n>>k;
    for(int i=k;i>=n;i--){
        ans=(ans+sum)%mod;
        sum=1ll*sum*(i-1)%mod*inv(k-i+1)%mod;
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back

ll n,u,v,m;

ll max_elem(vector<ll>& card,vector<vector<ll>>& mat, ll idx, char dir) {
	ll ret=0;
	if(dir=='h') {
		REP(i,n) ret=max(ret,card[mat[idx][i]]);
	}
	if(dir=='v') {
		REP(i,n) ret=max(ret,card[mat[i][idx]]);
	}
	return ret;
}

string solve() {
	cin>>n>>u>>v>>m;
	vector<vector<ll>> usa_mat(n,vector<ll>(n));
	vector<vector<ll>> neko_mat(n,vector<ll>(n));
	REP(i,n) REP(j,n) cin>>usa_mat[i][j];
	REP(i,n) REP(j,n) cin>>neko_mat[i][j];
	vector<ll> card(1000001,INF*INF);
	REP(i,m) {
		ll c;
		cin>>c;
		card[c]=i;
	}
	vector<ll> usa_done(m,0);
	vector<ll> neko_done(m,0);
	REP(i,n) {
		ll tmp=max_elem(card,usa_mat,i,'h');
		if(tmp-INF*INF) usa_done[tmp]++;
		tmp=max_elem(card,usa_mat,i,'v');
		if(tmp-INF*INF) usa_done[tmp]++;
		tmp=max_elem(card,neko_mat,i,'h');
		if(tmp-INF*INF) neko_done[tmp]++;
		tmp=max_elem(card,neko_mat,i,'v');
		if(tmp-INF*INF) neko_done[tmp]++;
	}
	ll naname1=0,naname2=0,naname3=0,naname4=0;
	REP(i,n) {
		naname1=max(naname1,card[usa_mat[i][i]]);
		naname2=max(naname2,card[usa_mat[i][n-1-i]]);
		naname3=max(naname3,card[neko_mat[i][i]]);
		naname4=max(naname4,card[neko_mat[i][n-1-i]]);
	}
	if(naname1!=INF*INF) usa_done[naname1]++;
	if(naname2!=INF*INF) usa_done[naname2]++;
	if(naname3!=INF*INF) neko_done[naname3]++;
	if(naname4!=INF*INF) neko_done[naname4]++;
	ll usa_sum=0,neko_sum=0;
	REP(i,m) {
		if(n!=1) {
			usa_sum+=usa_done[i];
			neko_sum+=neko_done[i];
		} else {
			usa_sum+=usa_done[i]/3;
			neko_sum+=neko_done[i]/3;
		}
		if(usa_sum>=u&&neko_sum<v) return "USAGI";
		if(usa_sum<u&&neko_sum>=v) return "NEKO";
		if(usa_sum>=u&&neko_sum>=v) return "DRAW";
	}
	return "DRAW";
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<solve()<<endl;
}




Measured memory_bytes: 13656
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array.IO
import qualified Data.Vector as V
import qualified Data.Map as M
import Debug.Trace

main = do
  [n, m] <- map read . words <$> getLine
  g <- newArray (0, n - 1) [] :: IO (IOArray Int [Int])
  forM_ [1..m] $ \_ -> do
    [u, v] <- map pred . map read . words <$> getLine
    readArray g u >>= writeArray g u . (v:)
    readArray g v >>= writeArray g v . (u:)
  g' <- V.fromList <$> getElems g
  let (c, f) = testBipartite g'
  let white = length . filter (==True) . map snd . M.toList $ c
  let black = length . filter (==False) . map snd . M.toList $ c
  print $ if f then white*black - m
               else n*(n-1)`div`2 - m

testBipartite :: V.Vector [Int] -> (M.Map Int Bool, Bool)
testBipartite = dfs 0 False M.empty

dfs :: Int -> Bool -> M.Map Int Bool -> V.Vector [Int] -> (M.Map Int Bool, Bool)
dfs u c m g = foldl' f (M.insert u c m, True) $ g V.! u
  where
    f :: (M.Map Int Bool, Bool) -> Int -> (M.Map Int Bool, Bool)
    f (m, False) _ = (m, False)
    f (m, True) v = case M.lookup v m
                    of Just c' -> (m, c /= c')
                       Nothing -> dfs v (not c) m g


Measured memory_bytes: 40828
#include <algorithm>
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll A, ll B, ll C, ll D) {
  cout << max(A*B,C*D) << endl;
}

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  ll C;
  cin >> C;
  ll D;
  cin >> D;
  solve(A, B, C, D);
  return 0;
}


Measured memory_bytes: 384
#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 main() {
  
  int x, y;
  cin >> x >> y;

  rep(i,x+1){
    int j = x-i;
    int leg = 2*i + 4*j;
    if(leg == y) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  
}

Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringJoiner;
import java.util.StringTokenizer;
import java.util.function.IntUnaryOperator;
import java.util.function.LongUnaryOperator;

public class Main {
    static In in = new In();
    static Out out = new Out();
    static long mod = 1000000007;
    static long inf = 0xfffffffffffffffL;

    void solve() {
        double l = in.nextInt();
        System.out.printf("%9.9f", (l / 3) * (l / 3) * (l / 3));
    }

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

class In {
    private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 0x10000);
    private StringTokenizer tokenizer;

    String next() {
        try {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
        } catch (IOException ignored) {
        }
        return tokenizer.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    char[][] nextCharArray(int n, int m) {
        char[][] a = new char[n][m];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        return a;
    }

    int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    int[] nextIntArray(int n, IntUnaryOperator op) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsInt(nextInt());
        }
        return a;
    }

    long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextLong();
        }
        return a;
    }

    long[] nextLongArray(int n, LongUnaryOperator op) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsLong(nextLong());
        }
        return a;
    }
}

class Out {
    private PrintWriter out = new PrintWriter(System.out);
    boolean autoFlush = false;

    void println(Object... a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (Object obj : a) {
            joiner.add(String.valueOf(obj));
        }
        out.println(joiner);
        if (autoFlush) {
            out.flush();
        }
    }

    void println(int[] a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (int i : a) {
            joiner.add(Integer.toString(i));
        }
        out.println(joiner);
        if (autoFlush) {
            out.flush();
        }
    }

    void println(long[] a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (long i : a) {
            joiner.add(Long.toString(i));
        }
        out.println(joiner);
        if (autoFlush) {
            out.flush();
        }
    }

    void flush() {
        out.flush();
    }
}


Measured memory_bytes: 21332
#include<bits/stdc++.h>
using ll= long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define ALL(x) x.begin(),x.end()

#define INF (ll)1e9 //10^9:∞
#define LLINF (ll)1e12
#define MOD (ll)(1e9+7) //10^9+7:合同式の法
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)
#define endl "\n"

using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/


/*.....................DEFINE FUNCTIONS ......................*/



/*.........................kemkemG0...........................*/
signed main() {
	__MAGIC__


	ll N;
	cin>>N;
	VI A(N);
	REP(i,N){cin>>A[i]; A[i]-=(i+1);}

	sort(ALL(A));

	ll b=A[N/2];

	ll ans=0;

	REP(i,N){
		ans+=abs(A[i]-b);
	}
	cout<<ans<<endl;


		return 0;
}


Measured memory_bytes: 3920
ali = []
for i in range(52):
    if i <= 25:
        ali.append(chr(ord("A")+i))
    else:
        ali.append(chr(ord("A")+i-26))
#ここから
n = int(input())
s = input()
news = ""
for i in range(len(s)):
    news += ali[ali.index(s[i]) + n]
print(news)

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

int main()
{
	long long a, b, c, x, y, pom, cena1=0, cena2=0, cena3=0;
	cin >> a >> b >> c >> x >> y;

	cena2 += x*a + y*b;

	pom = min(x,y);

	x-=pom;
	y-=pom;

	cena1 += c*pom*2;
	cena3 += c*pom*2;
	cena3 += c*y*2;
	cena3 += c*x*2;
	cena1 += b*y;
	cena1 += a*x;


	if(cena1 <= cena2 && cena1 <= cena3){
		cout << cena1 <<endl;
		return 0;
	}

	else if(cena2 <= cena3 && cena2 <= cena1){
		cout << cena2 <<endl;
		return 0;
	}

	cout << cena3 <<endl;

    return 0;
}


Measured memory_bytes: 256
#空の辞書作成と標準入力
di = {}
for _ in range(int(input())):
    line = input().split()
    
    #リストの0番目が0なら辞書に追加する1なら出力する
    if line[0] == "0":di[line[1]] = line[2]
    else:print(di[line[1]])


Measured memory_bytes: 41856
import math

N, A, B = map(int, input().split())
h = [int(input()) for _ in range(N)]


def check(t):
    cnt = 0
    for i in range(N):
        cnt += max(0, math.ceil((h[i] - B * t) / (A - B)))
    return cnt <= t


left = 1
right = max(h)
while right - left > 1:
    mid = (left + right) // 2
    if check(mid):
        right = mid
    else:
        left = mid
print(right)

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

char so[32768];

int main(){
	int p,i,j,c;
	
	memset(so,0,sizeof(so));
	
	so[1]=1;
	for(i=2;i<182;i++){
		for(j=2*i;j<=32767;j+=i){
			so[j]=1;
		}
	}
	
	while(0<=scanf("%d",&p)){
		if(p==0)break;
		c=0;
		for(i=1;2*i<=p;i++){
			if(so[i]==0 && so[p-i]==0)++c;
		}
		printf("%d\n",c);
	}
	return 0;
}

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

int main() {
	char input[4] = {};
	cin >> input; 
	int n = 0;
	for (int i = 0; i < 3; i++) {
		if (input[i] == 'o')n++;
	}

	cout << 700+n*100 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#include <queue>
#include <deque>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

int main() {
    int n;
    cin >> n;
    ll ans=0;
    for(int i=1; i<=n; ++i) {
        ll r=n/i;
        ans+=i*(r*(r+1)/2);
    }
    cout << ans << endl;
    return 0;
}

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

N,M,K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))

time = sum(A)
count = len(A)
ans = 0
j=0
for i in range(N,-1,-1):
    if i != N:
        time -= A[i]
        count -= 1
    if time>K:
        continue
    if time <= K and j<M:
        while time+B[j] <=K:
            time +=B[j]
            j +=1
            count +=1
            if j >=M:
                break
    ans = max(ans,count)
print(ans)

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

int main() {
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    if (s == t) {
      cout << "Yes" << endl;
      return 0;
    }
    s.push_back(s[0]);
    s.erase(s.begin());
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        # 根への距離を管理
        self.weight = [0] * (n+1)
        self.flag = 0
 
    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            # 親への重みを追加しながら根まで走査
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y
 
    # 併合
    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        
        if rx == ry:
            if self.diff(x,y) != w:
                self.flag = 1
        # xの木の高さ < yの木の高さ
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        # xの木の高さ ≧ yの木の高さ
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            # 木の高さが同じだった場合の処理
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1
 
    # 同じ集合に属するか
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    # xからyへのコスト
    def diff(self, x, y):
        return self.weight[x] - self.weight[y]
    
def main():
    import sys
    input = sys.stdin.readline
    
    N,M = map(int,input().split())
    flag = 0
    A = WeightedUnionFind(N)
    for i in range(M):
        L,R,D = map(int,input().split())
        A.union(L,R,D)
            
    if A.flag == 1:
        print("No")
    else:
        print("Yes")
    
    
main()

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

int main(void) {
	int a, b; cin >> a >> b;
	int c, i;
	if (b >= 10 && 100 > b) {
		c = a * 100 + b;
	}
	else if (b == 100) {
		c = a * 1000 + b;
	}
	else { c = a * 10 + b; }

	for (i = 3; i <= sqrt(c); i++) {
		if (i*i == c) {
			cout << "Yes" << endl;
			return 0;
			break;
		}
	}

	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};


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

	int ans = 700;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'o') {
			ans += 100;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define endl '\n'
#define rtl rt<<1
#define rtr rt<<1|1
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define maxx(a, b) (a > b ? a : b)
#define minn(a, b) (a < b ? a : b)
#define zero(a) memset(a, 0, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define _test printf("==================================================\n")
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> P2;
const double pi = acos(-1.0);
const double eps = 1e-7;
const ll MOD =  1000000007LL;
const int INF = 0x3f3f3f3f;
const int _NAN = -0x3f3f3f3f;
const double EULC = 0.5772156649015328;
const int NIL = -1;
template<typename T> void read(T &x){
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
const int maxn = 1e4+10;
ll arr[maxn];
int main(void) {
    ll l, r;
    while(~scanf("%lld%lld", &l, &r)) {
        if (l>r) swap(l, r);
        int kase = 0;
        for (ll i = l; i<=r && i<=l+10000LL; ++i, ++kase)
            arr[kase] = i%2019LL;
        sort(arr, arr+kase);
        int pos = unique(arr, arr+kase)-arr;
        ll ans = INF;
        for (int i = 0; i<pos; ++i) 
            for (int j = i+1; j<pos; ++j)
                ans = min(ans, arr[i]*arr[j]%2019);
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 384
//B 0 or 1 Swap
#include<bits/stdc++.h>
using namespace std;

int main()
{
  int n,d,a;
  cin>>n>>d;
  a=2*d+1;
  if(n%a==0)
  {
    cout<<n/a<<endl;
  }
  else
  {
    cout<<n/a+1<<endl;
  }
}


Measured memory_bytes: 256
program main
  implicit none
  integer :: A,B
  integer :: i,j
  logical :: found
  read(*,*) A,B
  j = 100./0.08+1
  found = .false.
  do i = 1, j
     if ( int(i*0.08) == A .and. int(i*0.1) == B )  then
        found = .true.
        exit
     end if
  end do
  if ( found ) then
     write(*,'(i0)') i
  else 
     write(*,'(i0)') -1
  end if
end program main


Measured memory_bytes: 768
#include <stdio.h>

int main(void)
{
        int a,b,A,B,x;
        scanf("%d%d%d",&x,&a,&b);
        A=a-x;B=b-x;
        if(A<0)A=-A;
        if(B<0)B=-B;
        if(A<B)printf("A\n");
        else printf("B\n");
        return 0;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
int main()
{
	string s;
	cin >> s;

	for (int bit = 0; bit < (1 << 3); bit++) {
		bitset<3> b(bit);
		int j = 0;
		int sum = s.at(j) - '0';
		
		for (int i = 0; i < 3; i++) {
			int t = s.at(++j) - '0';
			if (bit & (1 << i)) sum += t;
			else sum -= t;
		}
		if (sum == 7) {
			int cnt = 0;
			for (int i = 0; i < 4; i++) {
				if (i) {
					if (b.test(cnt++)) cout << "+";
					else cout << "-";
				}
				cout << s.at(i);
			}
			cout << "=7" << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#define REP(i, s, e) for(register int i = s; i <= e ;i++)

#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef CraZYali
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
#endif
	int a, b;
	cin >> a >> b;
	if (a < b) cout << 0;
	else cout << a - b;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Debug = System.Diagnostics.Debug;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using StructLayoutAttribute = System.Runtime.InteropServices.StructLayoutAttribute;
using FieldOffsetAttribute = System.Runtime.InteropServices.FieldOffsetAttribute;

static class P
{
    static void Main()
    {
        var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        SegmentTree<int> segmentTree = new SegmentTree<int>(nm[0], 0, (x, y) => x + y);
        for (int i = 0; i < nm[1]; i++)
        {
            var lr = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
            segmentTree.Operate(lr[0], lr[1], 1);
        }
        int res = 0;
        for (int i = 0; i < segmentTree.Size; i++)
        {
            if (segmentTree[i] == nm[1]) res++;
        }
        Console.WriteLine(res);
    }
}


class SegmentTree<T>
{
    public int Size { get; private set; }
    T IdentityElement;
    T[] Operators;
    Func<T, T, T> Merge;
    int LeafCount;

    public SegmentTree(int size, T identityElement, Func<T, T, T> merge) : this(Enumerable.Repeat(identityElement, size).ToArray(), identityElement, merge) { }

    public SegmentTree(T[] elems, T identityElement, Func<T, T, T> merge)
    {
        Size = elems.Length;
        Merge = merge;
        IdentityElement = identityElement;
        LeafCount = 1;
        while (LeafCount < elems.Length) LeafCount <<= 1;

        Operators = new T[LeafCount * 2];
        elems.CopyTo(Operators, LeafCount);
        for (int i = LeafCount - 1; i >= 1; i--) Operators[i] = Merge(Operators[i * 2], Operators[i * 2 + 1]);
    }

    public T this[int index]
    {
        get { return Query(index); }
        set { Operate(index, index + 1, value); }
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Operate(int l, int r, T x)
    {
        l += LeafCount;
        r += LeafCount;
        while (l <= r)
        {
            if (l % 2 == 1) Operators[l] = Merge(x, Operators[l]);
            if (r % 2 == 0) Operators[r] = Merge(x, Operators[r]);
            l = (l + 1) / 2;
            r = (r - 1) / 2;
        }
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Query(int i)
    {
        i += LeafCount;
        T res = Operators[i];
        while (0 < (i >>= 1)) res = Merge(res, Operators[i]);
        return res;
    }
}

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

int x,y,r,z,v;

int check(string s)
{
    int n = s.length();
    for (int i = 0; i < n; i=i+2)
        {
        if (s[i] == 'R'|| s[i] == 'U' || s[i] == 'D')
             x=1;
        else
            z=-1;
        }

    for (int i = 1; i < n; i=i+2)
        {
        if (s[i] == 'L'|| s[i] == 'U' || s[i] == 'D')
             y=1;
        else
            v=-1;
        }


     r=x+y;
    if(r==2)
    {
        if(z!=-1 && v!=-1)
        {
        return 1;
        }
        else
            return 2;
    }
}

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

	int tr=check(s);
	if(tr==1)
        cout << "Yes";
    else
        cout << "No";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
using namespace std;
using i64 = int64_t;

int main()
{
  i64 n,k;
  i64 cnt = 0;
  
  cin >> n >> k;
  for(i64 b = 1; b <= n; b++){
    // a % b >= k, a <= n, b <= n
    cnt += max((b - k), (int64_t)0) * (n / b) + max((n % b) - k +1, (int64_t)0);
  }
  if (k == 0) cnt -= n;
  
  cout << cnt << endl;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define sort(vec) sort(vec.begin(),vec.end())
#define reverse(vec) reverse(vec.begin(),vec.end())
int gcd(int x,int y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
double n,x[20];
double ans=0;
string u[20];
signed main(){
    cin>>n;
    rep(i,n){
        cin>>x[i]>>u[i];
        if(u[i]=="JPY")ans+=x[i];
        else ans+=x[i]*380000.0;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#define lol(i,n) for(ll i=0;i<n;i++)
#define Min(a,b) a=min(a,b);
#define Max(a,b) a=max(a,b);
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N 500010
ll n;string s;

vector<ll> v;
ll mu[N],le[N],ri[N];
ll Solve(){
    if(v.size()==0)return 0;
    if(v.size()==1){
	v.clear();
	return 0;
    }
    lol(i,v.size())mu[i]=le[i]=ri[i]=0;
    for(ll i=0;i<v.size()-1;i++){
	Max(mu[i+1],mu[i]);
	Max(le[i+1],mu[i]+v[i]);
	Max(ri[i+1],mu[i]+v[i+1]);
	
	Max(mu[i+1],ri[i]);
	Max(le[i+1],ri[i]);
	Max(ri[i+1],ri[i]+v[i+1]-1);
	
	Max(mu[i+1],le[i]);
	Max(le[i+1],le[i]+v[i]-1);
	if(v[i]>1){
	    Max(ri[i+1],le[i]+v[i+1]);
	}
    }
    ll pos=v.size()-1;
    ll res=max(mu[pos],max(le[pos],ri[pos]));
    v.clear();
    return res;
}
int main(){
    cin>>n;
    cin>>s;s+="00";
    ll ans=0,len=0;
    lol(i,s.size()){
	if(i&&s[i]=='0'&&s[i-1]=='0'){
	    ans+=Solve();
	    continue;
	}
	if(s[i]=='0'){
	    if(len)v.push_back(len);
	    len=0;
	}
	if(s[i]=='1')len++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4996
#include <cstdio>
#include <cstdlib>

int main(){
    int A1,A2,A3;
    scanf("%d%d%d",&A1,&A2,&A3);
    int t[3];
    t[0] = abs(A1 - A2);
    t[1] = abs(A2 - A3);
    t[2] = abs(A3 - A1);
    int maxt = t[0];
    for(int i = 1; i < 3; i++){
        if(maxt < t[i]){
            maxt = t[i];
        }
    }
    printf("%d\n",t[0] + t[1] + t[2] - maxt);

    return 0;
}

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

using namespace std;

const int INF = 1 << 30;

int N, M;
int g[17][17];
int lookup[1 << 17];
int dp[1 << 17][16];
vector< int > add[1 << 17];

int rec(int mask, int pre)
{
  if(mask == 0) return (0);
  if(~dp[mask][pre]) return (dp[mask][pre]);
  int ret = -INF;
  for(int i = mask; i > 0; i = (i - 1) & mask) {
    for(auto &j : add[i]) {
      if(pre != 15 && g[pre][j] == 0) continue;
      ret = max(ret, rec(mask ^ i, j) + lookup[i] + g[pre][j]);
    }
  }
  return (dp[mask][pre] = ret);
}

signed main()
{
  memset(dp, -1, sizeof(dp));

  cin >> N >> M;
  int all = 0;

  for(int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    g[a][b] = c;
    g[b][a] = c;
    all += c;
  }

  for(int i = 0; i < 1 << N; i++) {
    if(i & 1 && (i >> (N - 1)) & 1) continue;
    for(int j = 0; j < N; j++) {
      if((i >> j) & 1) {
        if(i & 1) {
          if(j == 0) add[i].push_back(j);
        } else if((i >> (N - 1)) & 1) {
          if(j == N - 1) add[i].push_back(j);
        } else {
          add[i].push_back(j);
        }
        for(int k = j + 1; k < N; k++) {
          if((i >> k) & 1) lookup[i] += g[j][k];
        }
      }
    }
  }
  cout << all - rec((1 << N) - 1, 15) << endl;
}

Measured memory_bytes: 12672
n = gets.chomp.to_i
w = gets.split.map(&:to_i)

foward = 0
min = 99999999
while(foward < n - 1) do
  s1 = w[0..foward].inject(:+)
  s2 = w[(foward+1)..(n-1)].inject(:+)
  if (s1 - s2).abs < min
    min = (s1 - s2).abs
  end
  foward += 1
end
puts min

Measured memory_bytes: 1788
{-# LANGUAGE OverloadedStrings #-}

import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.Attoparsec.ByteString.Char8

newtype Input = Input { _X :: Int }
newtype Output = Output { unOutput :: ByteString }

inputParser :: Parser Input
inputParser = Input <$> decimal

instance Show Output where
  show = B.unpack . unOutput

main :: IO ()
main = do
  result <- parseWith B.getContents inputParser ""
  case result of
    Done _ input -> print $ solve input
    _            -> putStrLn "parse error"

solve :: Input -> Output
solve input = Output $ if (_X input) `elem` [7, 5, 3]
  then "YES"
  else "NO"

Measured memory_bytes: 508
#include "bits/stdc++.h"

using namespace std;

int main()
{

  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  
  int v0 = -1;
  int i0 = -1;
  for (int i = 0; i < N; ++i) {
    if (v0 < A[i]) {
      v0 = A[i];
      i0 = i;
    }
  }
  vector<int> B(A);
  B[i0] = 0;
  int v1 = 0;
  for (int i = 0; i < N; ++i) {
    if (v1  < B[i]) {
      v1 = B[i];
    }
  }
    
  for (int i = 0; i < N; ++i) {
    if (A[i] == v0) {
      cout << v1 << endl;
    }
    else {
      cout << v0 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <cstring>

constexpr int MAX_N = 31, MAX_C = 1000001;
int n, max;
int cost[MAX_N];
bool dp[MAX_C];
bool prime_num[MAX_C];

int main() {
	while (1) {
		std::cin >> n >> max;
		if (n + max == 0)
			break;
		std::memset(prime_num, false, sizeof(prime_num));
		std::memset(dp, false, sizeof(dp));
		for (int i = 0; i < n; ++i)
			std::cin >> cost[i];
		for (int i = 2; i * i <= max; ++i) {
			if (!prime_num[i]) {
				for (int j = 2; i*j <= max; ++j)
					prime_num[i*j] = true;
			}
		}
		int ans = 0;
		for (int i = 0; i < n; ++i)
			dp[cost[i]] = true;

		for (int i = 1; i <= MAX_C; ++i) {
			for (int j = 0; j < n; ++j) {
				if (i + cost[j] <= max&&dp[i])
					dp[i + cost[j]] = true;
			}
		}

		for (int i = max; i >= 0; --i) {
			if (dp[i] && !prime_num[i]) {
				ans = i; 
				break;
			}
		}
		if (!ans)
			std::cout << "NA" <<std::endl;
		else
			std::cout << ans << std::endl;
	}
	return 0;
}

Measured memory_bytes: 4964
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int[][] a = new int[4][13];
        for(int i = 0; i < 4; i++) {
            for(int j = 0; j < 13; j++) {
                a[i][j] = j + 1;
            }
        }
        Scanner sc = new Scanner(System.in);
        int b = sc.nextInt();
        for(int i = 0; i < b; i++) {
            String c = sc.next();
            int d = sc.nextInt();
            int e = 0;
            switch(c) {
            case "S":
                e = 0;
                break;
            case "H":
                e = 1;
                break;
            case "C":
                e = 2;
                break;
            case "D":
                e = 3;
                break;
            default:
                break;
            }
            a[e][d - 1] = 0;
        }
        for(int i = 0; i < 4; i++) {
            for(int j = 0; j < 13; j++) {
                if(a[i][j] != 0) {
                    String s = "";
                    switch(i) {
                    case 0:
                        s = "S";
                        break;
                    case 1:
                        s = "H";
                        break;
                    case 2:
                        s = "C";
                        break;
                    case 3:
                        s = "D";
                        break;
                    default:
                        break;
                    }
                    System.out.println(s + " " + a[i][j]);
                }
            }
        }
    }
}


Measured memory_bytes: 26380
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

LL l;
string s;

LL f(int pos, LL now, LL sum) {
	if (pos == l) {
		return sum + now;
	}

	LL s1 = f(pos + 1, now * 10 + s[pos] - '0', sum);
	LL s2 = 0;

	if (pos != 0)s2=f(pos + 1, s[pos] - '0', sum + now);

	return s1 + s2;
}

int main() {

	cin >> s;
	l= s.size();
	
	LL ans = f(0, 0, 0);

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 384
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

bool Found(const int32_t i, const vector<char> &A, const int32_t N) {
  constexpr int32_t kDigitNum = 3;
  const char digits[kDigitNum] = {static_cast<char>(i / 100), static_cast<char>((i / 10) % 10),
                                  static_cast<char>(i % 10)};
  int32_t cpos = 0;
  for (int32_t d = 0; d < kDigitNum; ++d) {
    while (cpos < N && digits[d] != A[cpos]) {
      ++cpos;
    }
    if (cpos >= N) {
      return false;
    }
    ++cpos;
  }
  return true;
}

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

  int32_t N;
  string S;
  cin >> N >> S;
  vector<vector<int64_t>> indices(10, vector<int64_t>(0));
  for (int32_t i = 0; i < N; ++i) {
    int64_t a = static_cast<int64_t>(S.c_str()[i] - '0');
    indices[a].push_back(i);
  }
  int64_t number_of_digits = 3;
  int64_t result = 0;
  for (int64_t i = 0; i <= 999; ++i) {
    vector<int64_t> digits(number_of_digits);
    int64_t temp = i;
    for (int32_t d = 0; d < number_of_digits; ++d) {
      digits[d] = temp % 10;
      temp /= 10;
    }
    int64_t search_from = 0;
    bool found = true;
    for (int32_t d = 0; d < number_of_digits; ++d) {
      auto itr = lower_bound(indices[digits[d]].begin(), indices[digits[d]].end(), search_from);
      if (itr == indices[digits[d]].end()) {
        found = false;
        break;
      }
      search_from = (*itr) + 1;
    }
    if (found) {
      ++result;
    }
  }
  cout << result << endl;
  return 0;
}


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

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

const ll mod =  1000000007;  //ansを出力する時は (ans % mod + mod) % mod とする(負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976


int n,c;
const int V_MAX = 505;
ll d[V_MAX][V_MAX];



int main()
{
    cin >> n >> c;
    rep(i,c) rep(j,c) cin >> d[i][j];
    ll g[n][n];
    rep(i,n) {
        rep(j,n){
            cin >> g[i][j];
            g[i][j]--;
        }
    }
    ll ans = INF;
    ll mod0[c],mod1[c],mod2[c];
    rep(i,c){
        mod0[i] = 0;
        mod1[i] = 0;
        mod2[i] = 0;
    }
    rep(i,c){
        rep(y,n){
            rep(x,n){
                if((x+y) % 3 == 0) mod0[i] += d[g[y][x]][i];
                else if((x+y) % 3 == 1) mod1[i] += d[g[y][x]][i];
                else mod2[i] += d[g[y][x]][i];
            }
        }
    }
    for(int i = 0; i < c; i++){
        for(int j = 0; j < c; j++){
            if(i == j) continue;
            for(int k = 0; k < c; k++){
                if(k == j || i == k) continue;
                ans = min(ans,mod0[i] + mod1[j] + mod2[k]);
            }
        }
    }
    cout << ans << endl;
}

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

#define vt          vector
#define sz(x)       int((x).size())
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

using ll = long long;
using pii = pair<int, int>;

void solve() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a + b + c > 21 ? "bust" : "win");
}

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

    int tcs = 1;
    for (int tc = 1; tc <= tcs; tc++) {
        // cout << "Case " << tc << ": ";
        solve();
    }
}


Measured memory_bytes: 3604
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main(){
	char n;
	cin>>n;
	char x=n;
	x++;
	cout<<x<<endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

int main() {
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  ll s = 0;
  rep(i,1,n) {
    if(a[i] < a[i-1]) {
      int d = a[i-1] - a[i];
      s+=d;
      a[i] += d;
    }
  }
  cout << s << endl;
}


Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1e9+7;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(long long i = a;i < b;i++)
#define rf(i,a,b) for(long long i=a;i>=b;i--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define w(t) while(t--)
#define c(n); cin>>n;
#define p(n) cout<<n;
#define pl(n) cout<<n<<endl;
#define ps(n); cout<<n<<" ";
#define F first
#define S second
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define ull unsigned long long
#define vll vector<ll>
#define vii vector<ii>
#define mkp make_pair
#define ld long double
#define arrin(a,n) f(i,0,n){cin>>a[i];}
#define arrout(a,n) f(i,0,n){cout<<a[i]<<" ";}
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define PI (2*acos(0))
const long long N = 1e6+5;
vll visit,dist,taken;
vector<vll> adj;
vector<vii> adj2;
priority_queue<ii,vector<ii>, greater<ii> > pq;
ll bit[N]={0};
ll siz;
ll res = 0;
ll lcm(ll a,ll b){return (a * b) / __gcd(a,b);}
ll gcd(ll a,ll b){return __gcd(a,b);}
ll power(ll a,ll b){if(b == 0)return 1;if(b == 1)return a;ll ans = power(a,b/2) % MOD;ans *= ans;ans %= MOD;if(b % 2 == 1)ans *= a;return ans%MOD;}
ll inverse(ll x){x%=MOD;return power(x,MOD-2);}
void BITup(ll k, ll x){while(k <= siz){bit[k]+=x;k += k & -k;}}
ll BITq(ll k){ll s=0;while(k>=1){s+=bit[k];k -= k &-k;}return s;}
struct node{ll lazy,val;}seg[4000000];
struct point{ll x,y;};
void dfs(ll v){visit[v] = 1;for(auto x:adj2[v]){if(!visit[x.F])dfs(x.F);}}
void bfs(ll s){visit[s] = 1;queue<ll>q;q.push(s);while(!q.empty()){ll u = q.front();q.pop();for(auto x:adj[u]){if(!visit[x])q.push(x);}}}
void dijkstra(ll s){pq.push(ii(0,s));dist[s] = 0;while(!pq.empty()){ii f = pq.top();pq.pop();ll w = f.F;ll u = f.S;if(w > dist[u]){continue;}for(auto v:adj2[u]){if(dist[u] + v.S < dist[v.F]){dist[v.F] = dist[u] + v.S;pq.push(ii(dist[v.F],v.F));}}}}
void prim(ll edge) {taken[edge] = 1;for(auto v:adj2[edge]) {if (taken[v.first]==0)pq.push(ii(v.second, v.first));}}
ll mst(ll s){taken.assign(N, 0);prim(s);ll cost = 0;while(!pq.empty()){ii front = pq.top();pq.pop();ll w = front.first;ll u = front.second;if(taken[u]==0)cost += w;prim(u);}return cost;}
void YESNO(ll a){if(!!a){pl("Yes");}else{pl("No");}}
void filesin(void){freopen("input.txt","r",stdin);}
void filesout(void){freopen("output.txt","w",stdout);}
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///AtCoder Beginner Contest 159
int main(void){
    fastio;
    ll n;
    c(n);
    ll arr[n];
    arrin(arr,n);
    map<ll,ll>mp;
    set<ll>s;
    f(i,0,n){
        mp[arr[i]]++;
        s.insert(arr[i]);
    }
    ll ans = 0;
    for(auto x:s){
        ans += (mp[x] * (mp[x]-1))/2;
    }
    f(i,0,n){
        ll ansi = ans;
        ansi -= (mp[arr[i]] * (mp[arr[i]]-1))/2;
        mp[arr[i]]--;
        ansi += (mp[arr[i]] * (mp[arr[i]]-1))/2;
        pl(ansi);
        mp[arr[i]]++;
    }
}


Measured memory_bytes: 17024
#include<stdio.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include <string.h>
#include<limits.h>
int main(void){
	int x, y, z, i;
	/////////////////////////
	int yy, yyy, yyyy;
	scanf("%d", &x);
	for (i = 1; i < x; i++) {
		y = i - (i / 10) * 10;
		yy = (i - (i / 100) * 100) / 10;
		yyy = (i - (i / 1000) * 1000) / 100;
		yyyy = (i - (i / 10000) * 10000) / 1000;
	//	printf("#%d#", yy);
		if (i % 3 == 0 || y == 3 || yy == 3 || yyy == 3 || yyyy == 3) {
			printf(" %d", i);
		}
	}
	y = i - (i / 10) * 10;
	yy = (i - (i / 100) * 100) / 10;
	yyy = (i - (i / 1000) * 1000) / 100;
	yyyy = (i - (i / 10000) * 10000) / 1000;
	if (i % 3 == 0 || y == 3 || yy == 3 || yyy == 3 || yyyy == 3) 
	{
		printf(" %d", i);
	}
	printf("\n");
	/////////////////////////
	return 0;
}


Measured memory_bytes: 2048
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};//RBLF
int main(){
	int n,m;
	while(cin>>n>>m,n){
		vs in(n+2,string(m+2,'#'));
		rep(i,n){
			string s;
			cin>>s;
			in[i+1]="#"+s+"#";
		}
		vvi used(n+2,vi(m+2));
		int x=1,y=1,to=1;
		int cnt=1;
		do{
			int nto=(to+1)%4;
			rep(i,4){
				int nx=x+dx[nto];
				int ny=y+dy[nto];
				if(in[nx][ny]!='#'){
					if(used[nx][ny]==0){
						x=nx;y=ny;to=nto;
						used[nx][ny]=cnt++;
						goto end;
					}else if(cnt==used[nx][ny]+2){
						used[x][y]=0;
						in[x][y]='#';
						x=nx;y=ny;to=nto;
						cnt--;
						goto end;
					}
				}
				nto=(nto+3)%4;
			}
//			cout<<x<<" "<<y<<endl;
			break;
			end:;
//			show2d(used);
		}while(!(x==1&&y==1));
		
		if(used[1][1]&&used[1][m]&&used[n][1]&&used[n][m])
			cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}












Measured memory_bytes: 3196
#include <bits/stdc++.h>  
#define rep(i, n) for(int i=0; i<(int)(n); ++i)
#define cout(val) cout << (val) << endl
using namespace std;
typedef long long ll;

int main(){
    int h, w;
    char t;
    cin >> h >> w;
    vector<vector<bool>> c(h, vector<bool>(w, false));
    queue<pair<int, int>> que1, que2;
    rep(i, h) rep(j, w){
        cin >> t;
        if(t == '#'){
            que2.push(make_pair(i, j));
            c[i][j] = true;
        }
    }
    pair<int, int> p;
    vector<int> dy ={1,0,-1,0}, dx={0,1,0,-1};
    int tx, ty, result = 0;
    while(!que2.empty()){
        ++result;
        que2.swap(que1);
        while(!que1.empty()){
            p = que1.front();
            que1.pop();
            rep(i, 4){
                ty = p.first + dy[i];
                tx = p.second + dx[i];
                if(ty==-1||tx==-1||ty==h||tx==w||c[ty][tx]) continue;
                que2.push(make_pair(ty, tx));
                c[ty][tx] = true;
            }
        }
    }
    cout(result-1);
}


Measured memory_bytes: 8592
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<memory>
using namespace std;

typedef struct Node {
    int key;
    Node *parent, *left, *right;
} Node;

Node *NIL, *root;

void inorder(Node *u) {
    if (u==NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if (u==NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = new Node;
    z->key = k;
    z->left = NIL;
    z->right = NIL;
    while (x!=NIL) {
        y=x;
        if (z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    z->parent = y;
    if (y==NIL) root = z;
    else {
        if (z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

bool Find(int k) {
    Node *x = root;
    while (x!=NIL) {
        if (x->key == k) return true;
        if (x->key > k) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    return false;
}

int main() {
    int i, n, x;
    string com;

    scanf("%d", &n);
    for (i=0; i<n; i++) {
        cin >> com;
        if (com=="insert") {
            scanf("%d", &x);
            insert(x);
        } else if (com=="find") {
            scanf("%d", &x);
            if (Find(x)) printf("yes\n");
            else printf("no\n");
        } else if (com=="print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 22068
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const double PI  = acos(-1.0);
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const LL INF  = 0x3f3f3f3f3f3f3f3f;
const int N=3e5+10;
const int M=1e6+10;
const int mod=1e9+7;
inline LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
inline LL lcm(LL a, LL b) { return a * b / gcd(a, b); }
inline LL read(){LL x=0,f=1;char c=getchar();while(c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}return x*f;}
inline LL qpow(LL x,LL k=mod-2,LL m=mod){LL res=1;while(k){if(k&1) res=res*x%m;x=x*x%m;k>>=1;}return res;}
/*=================================================================================================================*/
int a[N][2],n;

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d%d",&a[i][0],&a[i][1]);
    for(int i=3;i<=n;i++){
        if(a[i][0]==a[i][1]&&a[i-1][0]==a[i-1][1]&&a[i-2][0]==a[i-2][1]) return printf("Yes\n"),0;
    }
    printf("No\n");
    return 0;
}


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


int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a<=b && b<=c){
		cout<<a<<" "<<b<<" "<<c<<endl;
	}
else if(b<=c && c<=a){
		cout<<b<<" "<<c<<" "<<a<<endl;
	}
else if(b<=a && a<=c){
		cout<<b<<" "<<a<<" "<<c<<endl;
	}
else if(c<=b && b<=a){
		cout<<c<<" "<<b<<" "<<a<<endl;
	}
else if(a<=b && a>=c){
		cout<<c<<" "<<a<<" "<<b<<endl;
	}
else if(a<=c && c<=b){
		cout<<a<<" "<<c<<" "<<b<<endl;
	}	
	return 0;
}



Measured memory_bytes: 3100