akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <sstream>
 
using namespace std;

vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while(!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss; ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
 
#define MOD 1000000007
#define A first
#define B second
#define all(x) (x).begin(), (x).end

typedef long long ll;
 
inline int mulmd(ll a, ll b){
  ll ret = (a * b) % MOD;
  return (int) ret;
}
 
inline int power(ll x, ll y, int m){
  ll res = 1;
  x = x % m;
  while(y > 0){
    if(y & 1){
      res = mulmd(res, x);
    }
    y = y >> 1;
    x = mulmd(x, x);
  }
  return (int) res;
}
 
inline int submd(ll a, ll b){
  ll ret = (a - b);
  if(ret < 0) ret += MOD;
  return (int) ret;
}
 
inline int addmd(ll a, ll b){
  ll ret = (a + b) % MOD;
  return (int) ret;
}
 
inline int invPow(ll a){
  return power(a, MOD - 2, MOD);
}
 
inline int divmd(ll a, ll b){
  ll ret = mulmd(a, invPow(b));
  return (int) ret;
}
 
const int N = 1e5 + 5;

int arr[N];

void solve(){
  int n;
  cin >> n;
  int i = 0;
  while(1000 * i < n) i++;
  int ans = 1000 * i - n;
  cout << ans;
}

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



Measured memory_bytes: 3640
#include <stdio.h>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>

using namespace std;



signed main(int argc, char *argv[]) {
  double a,b,c;
  cin >> a >> b >> c;
  if ((a+b)>=c)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;


  return 0;
}


Measured memory_bytes: 256
def digit_sum(x):
    sum = 0
    while x :
        sum += x % 10
        x = int(x / 10)
    return sum

N = int(input())
l = [ digit_sum(x) for x in range(1, N+1)]

sum_a_b = []
if N % 2 == 0:
    sum_a_b.append(l[int(N/2)-1]*2)

for i in range(1, int(N/2)):
    sum_a_b.append(l[i-1] + l[N-i-1])

print(min(sum_a_b))


Measured memory_bytes: 4248
let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (N, x) = (input[0], input[1])
var a = [0] + readLine()!.characters.split(" ").map{Int(String($0))!}
var ans = 0
for i in 1...N {
    let tmp = max(a[i-1] + a[i] - x, 0)
    a[i] -= tmp
    ans += tmp
}
print(ans)

Measured memory_bytes: 7736
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static int N, W;
	static int[] vn, wn;
	static Map<Long, Long> memo = new HashMap<>();

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			N = in.nextInt();
			W = in.nextInt();

			vn = new int[N];
			wn = new int[N];

			for (int i = 0; i < N; i++) {
				int v = in.nextInt(), w = in.nextInt();
				vn[i] = v;
				wn[i] = w;
			}

			out.println(rec(0, 0));

		}
		static long rec(int i, int totalW) {
			long key = (long)i << 32 | totalW;
			if (i == N) {
				memo.put(key, 0L);
				return 0;
			}
			if (memo.containsKey(key)) {
				return memo.get(key);
			}
			long ret = 0;
			if (totalW+wn[i] <= W) {
				ret = Math.max(rec(i+1, totalW), rec(i+1, totalW+wn[i])+vn[i]);
			} else {
				ret = rec(i+1, totalW);
			}

			memo.put(key, ret);
			return ret;

		}

	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

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

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

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}



Measured memory_bytes: 224184
#include<string>
#include<vector>
#include<iomanip>
#ifndef _WIN32
#include<iostream>
#endif
#include<algorithm>
using namespace std;
#define FOR(i,bg,ed) for(int i =(bg); i< (ed);i++)
#define REP(i,n) FOR(i,0,n) 

struct cww{
	cww(){
		ios::sync_with_stdio(false);
		cin.tie(0);
	}
}star;
typedef long long LL;
const int mod = 1e9 + 7;

typedef vector<int> V;
typedef vector<V> VV;

template<typename T>
istream& operator>>(istream& is, vector<T>& v){
	for (auto &it : v)is >> it;
	return is;
}

int main(){
	int N;
	cin >> N;
	vector<int> res(10,-1e7);
	res[0] = 0;
	REP(i, N){

		int s; cin >> s;
		auto nxt = res;
		REP(j, 10)nxt[(j + s) % 10] = max(nxt[(j + s) % 10], res[j] + s);
		swap(nxt, res);
	}
	int ans = 0;
	FOR(i,1, 10)ans = max(ans, res[i]);
	cout << ans << endl;
}

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

void i_to_b(int n){
	for(int i=0 ; i<7 ; ++i, n <<= 1){
		cout << ((n & 64)? 1 : 0);
	}
	cout << endl;
}

int main(){
	int n;
	int f[10] = {63,6,91,79,102,109,125,39,127,111};
	while( cin >> n , ~n ){
		int state = 0;
		for(int i=0 ; i<n ; ++i ){
			int d;
			cin >> d;
			i_to_b( state ^ f[d] );
			state = f[d];
		}
	}
}

Measured memory_bytes: 0
import Control.Monad
import Control.Monad.ST
import Data.Array.ST
import qualified Data.ByteString.Char8 as C
import Data.List
import qualified Data.Map.Strict as M

main = sub <$> get >>= put

get = fmap (unfoldr (C.readInt . C.dropWhile (==' '))) . C.lines <$> C.getContents

sub ([n,k,_]:es) = sol n (splitAt k es)

put = putStrLn . unwords . fmap show

sol n (es0,es1) = runST $ do
  uf0 <- newUF n
  forM_ es0 (unionUF uf0) 
  uf1 <- newUF n
  forM_ es1 (unionUF uf1)
  ps <- mapM (liftM2 (,) <$> findUF uf0 <*> findUF uf1) [1..n]
  return $ ((<$>) =<< cnts) ps

cnts = (M.!) . M.fromList . fmap (liftM2 (,) head length) . group . sort

-- | Union-Find
data UnionFind s = UnionFind {ids:: STUArray s Int Int, szs:: STUArray s Int Int}

newUF :: Int -> ST s (UnionFind s)
newUF n = liftM2 UnionFind (newListArray (1,n) [1..n]) (newArray (1,n) 1)

findUF :: UnionFind s -> Int -> ST s Int
findUF uf i = do
  ix <- readArray (ids uf) i
  if ix == i
    then return i
    else do
      writeArray (ids uf) i =<< readArray (ids uf) ix
      findUF uf ix

unionUF :: UnionFind s -> [Int] -> ST s ()
unionUF uf [p,q] = do
  i <- findUF uf p
  j <- findUF uf q
  szi <- readArray (szs uf) i
  szj <- readArray (szs uf) j
  if szi < szj
    then do
      writeArray (ids uf) i j
      writeArray (szs uf) j (szi+szj)
      writeArray (szs uf) i 0
    else do
      writeArray (ids uf) j i
      writeArray (szs uf) i (szj+szi)
      writeArray (szs uf) j 0


Measured memory_bytes: 82812
import Control.Applicative

main :: IO ()
main = do
  { [a,b,x] <- readLineInputs :: IO [Int]
  ; print $ solve a b x
  }
; 
solve :: Int -> Int -> Int -> Int
solve a b x = let
  { r = a `mod` x
  ; d = b - a + 1 - if r == 0 then 0 else x - r 
  } in if d < 0 then 0 else case divMod d x of
          { (q,0) -> q; (q,_) -> q+1 }

-- I/O

readLineInputs :: Read a => IO [a]
readLineInputs = map read . words <$> getLine


Measured memory_bytes: 508
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>

using namespace std;

int main() {
	int l;
	while (true) {
		cin >> l;
		if (!l) break;
		int flag = 13;
		for (int i = 1; i <= 12; i++) {
			int a, b;
			cin >> a >> b;
			l -= a;
			l += b;
			if (l <= 0 && flag == 13) {
				flag = i;
			}
		}
		if (flag == 13) {
			cout << "NA" << endl;
		} else {
			cout << flag << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
# AOJ ALDS1_4_B Binary Search
# Python3 2018.7.3 bal4u

import sys
from sys import stdin
input = stdin.readline

n = int(input())
s = set(map(int, input().split()))
q = int(input())
t = set(map(int, input().split()))
print(len(s & t))


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

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

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

template<class T, class... Args>
auto create(size_t n, Args&&... args) {
	if constexpr(sizeof...(args) == 1)
		return vector<T>(n, args...);
	else
		return vector(n, create<T>(args...));
}

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef OJ
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define all(x) (x).begin(), (x).end()
#define rsort(x) sort((x).rbegin(), (x).rend())
#define sz(x) ((int)x.size())
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return 0;}while(0)

const char en = '\n';
const int MOD = 0;
const int MAXN = 0;
const int INF = 1e9+1;

#include <atcoder/all>
using namespace atcoder;

int solve() {
    int n,q; cin >> n >> q;
    dsu d(n);
    fori(i,q) {
        int t, u,v; cin >> t >> u >> v;
        if(t == 0) {
            d.merge(u,v);
        } else {
            cout << (d.same(u,v) ? 1 : 0) << en;
        }
    }
    return 0;
} 

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int ntest = 1;
    //cin >> ntest;
    fori(test, ntest) {
        //cout << "Case #" << test+1 << ": ";
        solve();
    }

    return 0;
}


Measured memory_bytes: 4012
#include"bits/stdc++.h"
#define int long long
#define mod 1000000007
#define pf push_forward
#define pb push_back
#define mp make_pair
#define f(i,in,n) for(i=in; i<n; ++i)
#define scant int t; cin>>t;while(t--)
using namespace std;
main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	int n, i, k;
	cin >> n >> k;
	int h[n];
	for (i = 0; i < n; i++) {
		cin >> h[i];
	}
	int dp[n];
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for (i = 2; i < n; i++) {
		dp[i] = INT_MAX;
		for (int j = 1; j <= k; j++) {
			if (i - j >= 0)
				dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
		}
		//dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n - 1];

}

Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<int, int> pii;
     
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

const int N = (int)1e5 + 9;
vector<int> T[N];
int dp[N];

void dfs(int u){
    dp[u]=0;
    vector<int> dps;
    for(auto x : T[u]){
        dfs(x);
        dps.push_back(dp[x]);
    }
    int ad = 1;
    sort(dps.begin(), dps.end());
    reverse(dps.begin(), dps.end());
    for(auto x : dps){
        dp[u]=max(dp[u],x + ad);
        ad ++ ;
    }
}

int main(){
    fastIO;
    int n;
    cin >> n;
    int p;
    for(int i = 2; i <= n; i ++ ){
        cin >> p;
        T[p].push_back(i);
    }
    dfs(1);
    cout << dp[1];
    return 0;
}

Measured memory_bytes: 17024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    cin >> n;
    double ans;
    if (n%2==0) ans = 0.5;
    else ans = (1.0*int(n/2)+1)/n;
    cout << setprecision(7) << ans << endl;
}

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

using namespace std;

#define int long long

const int MAXN = 2e5 + 7;

int a[MAXN];

int getp(int n) {
    int ans = 1;
    while (ans <= n) {
        ans <<= 1;
    }   
    return ans;
}   

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    multiset <int> ms;
    for (int i = 0; i < n; ++i) {
        ms.insert(a[i]);
    }   

    int ans = 0;
    while (ms.size()) {
        auto u = *ms.rbegin();
        ms.erase(ms.find(*ms.rbegin()));
        int w = getp(u) - u;
        if (ms.find(w) != ms.end()) {
            ms.erase(ms.find(w));
            ++ans;
        }   
    }   

    cout << ans << '\n';
    return 0;
}   

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

long long oper(long long n, long long k) {
	return abs(n - k);
}

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

	long long n, k;
	cin >> n >> k;
	if (k == 1) cout << 0 << "\n";
	else {
		cout << min(n%k, k - (n%k)) << "\n";
	}
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
const ll MOD=1e9+7;
using namespace std;

int main(){
    ll N,AB=0,A=0,B=0,cnt=0;
    cin>>N;
    for(ll i=0;i<N;i++){
        string s;
        cin>>s;
        ll a=s.size();
        for(ll j=0;j+1<a;j++){
            if(s[j]=='A'&&s[j+1]=='B') cnt++;
        }
        if(s[0]=='B'&&s[a-1]=='A') AB++;
        else if(s[0]=='B') B++;
        else if(s[a-1]=='A') A++;
    }
    if(A!=0||B!=0) cnt+=min(A,B)+AB;
    else if(AB>0)cnt+=AB-1;
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

int main(void){
    int n,x;
    int counter = 0;
    int is_prime = 0;
    scanf("%d", &n);

    for(int i=0; i<n;i++){
        scanf("%d", &x);
        if(x == 2){
            counter ++;
            continue;
        }
        if(!(x%2) || x == 1) continue;
        is_prime = 1;
        for (int j=2; j<sqrt(x)+1; j++){
            if(x % j == 0){
                is_prime = 0;
                break;
            }
        }
        if(is_prime) counter ++;
    }
    printf("%d\n", counter);
    return 0;
}


Measured memory_bytes: 2648
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {

	static FastReaderR in = new FastReaderR(System.in) ;
	
	static LinkedList<pair> l = new LinkedList<>() ;
	
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		int N = in.nextInt() ;
		int i = 1 ;
		while(N-- > 0){
			pair p = new pair() ;
			p.s = in.next() ;
			p.p = in.nextInt() ;
			p.index = i++ ;
			l.add(p) ;
		}
		Collections.sort(l,new Comparator<pair>() {

			@Override
			public int compare(pair o1, pair o2) {
				// TODO Auto-generated method stub
//				int f = -1 ;
				int f = 0 ;
				if(o1.s.compareTo(o2.s)<0)
					f = -1 ;
				else{
					if(o1.s.compareTo(o2.s)==0){
						if(o1.p>o2.p)
							f = -1 ;
						else{
							if(o1.p==o2.p)
								f = 0 ;
							else
								f = 1 ;
						}
					}else{
						f = 1 ;
					}
				}
				return f ;
			}
		});
		for(pair p:l){
			System.out.println(p.index) ;
		}
	}

}

class pair{
	String s ; int p ; int index ;
}

class FastReaderR {
    byte[] buf = new byte[2048];
    int index, total;
    InputStream in;
 
    FastReaderR(InputStream is) {
        in = is;
    }
    int scan() throws IOException {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0) {
                return -1;
            }
        }
        return buf[index++];
    }
    int nextInt() throws IOException {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan());
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }
    String next() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan());
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }
}

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

const int MAX = 2*1e5;
const int mod = 1e9+7;

vector<pair<ll,ll> > factor(ll n){
    vector<pair<ll,ll> > res;
    for(ll p = 2; p*p<=n; p++){
        if(n%p!=0) continue;
        int num = 0;
        while(n%p == 0){num++;n/=p;}
        res.push_back(make_pair(p,num));
    }
    if(n != 1) res.push_back(make_pair(n,1));
    return res;
}


ll fac[MAX],finv[MAX],inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod/i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}
ll COM(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}


int main(){
    int n,m; cin >> n >> m;
    COMinit();
    auto vec = factor(m);
    ll res = 1;
    for(auto pa: vec){
        int num = pa.second;
        ll tmp = COM(num+n-1,n-1);
        res = (res*tmp)%mod;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#include <sstream>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define LB long double
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const double eps=1e-10;
const int INF=2e9;
const LL LINF=2e16;
const int magic=100;

inline int getint()
{
	char ch;
	while ((ch=getchar())<'0' || ch>'9') {}
	int res=ch-'0';
	while ((ch=getchar())>='0' && ch<='9') res=res*10+ch-'0';
	return res;
}

int n,e,T;
LL a[100048];
priority_queue<pair<LL,int> > q1,q2;
LL dp[100048];

int main ()
{
	int i;
	n=getint();e=getint();T=getint();
	for (i=1;i<=n;i++) a[i]=(LL)getint();
	dp[0]=0;
	a[0]=0;
	q2.push(mp(a[0]-dp[0],0));
	//dp[1]=a[1]+T;
	//q2.push(mp(a[1]-dp[1],1));
	int num1,num2;
	for (i=1;i<=n;i++)
	{
		
		bool f=true;
		while (!q2.empty() && f)
		{
			int num=q2.top().y;f=false;
			if (T-2*a[i]+2*a[num+1]<0)
			{
				q2.pop();f=true;
				q1.push(mp(a[num]+2*a[num+1]-dp[num],num));
			}
		}
		LL ans1=LINF,ans2=LINF;
		if (!q1.empty())
		{
			num1=q1.top().y;
			ans1=dp[num1]+3*a[i]-a[num1]-2*a[num1+1];
		}
		if (!q2.empty())
		{
			num2=q2.top().y;
			ans2=dp[num2]+a[i]-a[num2]+T;
		}
		dp[i]=min(ans1,ans2);
		q2.push(mp(a[i]-dp[i],i));
	}
	//for (i=1;i<=n;i++) cout<<dp[i]<<' ';
	//cout<<endl;
	cout<<dp[n]+(e-a[n])<<endl;
	return 0;
}

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

using namespace std;

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

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    set<int> s;
    rep(i, N) cin >> a[i];
    rep(i, N) s.insert(a[i]);
    vector<int> ans;
    int cnt = 0;
    rep(i, N) {
        if (a[i] == 2) ans.push_back(i + 1);
        if (a[i] == -2) cnt++;
    }
    // cout << cnt << ", " << s.count(-1) << endl;
    if (cnt > 0 && cnt % 2 == 1 && s.count(-1)) {
        rep(i, N) if (a[i] == -1) {
            ans.push_back(i + 1);
            break;
        }
    }
    if (!s.count(-1)) cnt -= cnt % 2;

    rep(i, N) {
        if (cnt == 0) break;
        if (a[i] == -2) {
            cnt--;
            ans.push_back(i + 1);
        }
    }

    sort(all(ans));
    cout << ans.size() << endl;
    for (auto x : ans) {
        cout << x << endl;
    }
    return 0;
}



Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A(N,0);
    for(ll i=0;i<N;++i)cin>>A[i];
    ll ans=1;
    for(ll i=0;i<N;++i){
        if(A[i]==0){prt(0)return 0;}
    }
    for(ll i=0;i<N;++i){
        if(A[i]>(ld)((ld)powl(10,18)/(ld)ans)){prt(-1)return 0;}
        ans*=A[i];
        if(ans>powl(10,18)){prt(-1)return 0;}
    }
    prt(ans)
    
    return 0;
}


Measured memory_bytes: 3992
import java.util.*;

class aoj0002
{
    public void solve()
    {
	Scanner sc = new Scanner(System.in);
	while(sc.hasNext())
	    {
		System.out.println(new Integer(sc.nextInt() + sc.nextInt()).toString().length());
	    }
    }
}

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

Measured memory_bytes: 20448
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int p = scan.nextInt();
		int q = scan.nextInt();
		int ans=0;
		for(int i=0;i<2;i++){
			if(p>q){
				ans+=p;
				p--;
			}else{
				ans+=q;
				q--;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
def main():

   N = int(input())
   hList = list(map(int,input().split()))
   diffList = [ y-x for x,y in zip(hList,hList[1:])]

   length = len(diffList)-1
   count = 0
   atmax = 0

   for i,j in enumerate(diffList):
      if i == length:
         if j<=0:
            count +=1
            atmax = max(atmax,count)  
         else:
            atmax = max(atmax,count)
      elif j <=0:
         count += 1      
      else :
         if atmax < count:
            atmax = count
         count = 0
   print(atmax)

if __name__== "__main__":
    main() 






Measured memory_bytes: 14252
#include<bits/stdc++.h>
#define mod 2019
using namespace std;
map<int,int> M;
int Ele[200200];
int main()
{
	string S;
	cin>>S;
	reverse(S.begin(),S.end());
	int N=S.length();
	int pow10=1;
	for(int i=0;i<N;i++)
	{
		Ele[i]=(S[i]-'0')*pow10%mod;
		pow10=pow10*10%mod;
	}
	int Sum=0;
	M[0]=1;
	long long Ans=0;
	for(int i=0;i<N;i++)
	{
		Sum=(Sum+Ele[i])%mod;
		Ans+=M[Sum];
		M[Sum]++;
	}
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 4500
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<30;
const ll LINF = 1LL<<58;
const ll mod = 1000000007;

int main(){
    int n, k;
    string s;
    cin >> n >> k >> s;
    vector<int> zero, one;
    s += '#';
    int cnt = 0;
    rep(i,n){
        while(s[i] == '1') {
            cnt++;
            i++;
        }
        one.pb(cnt);
        cnt = 0;
        while(s[i] == '0') {
            cnt++;
            i++;
        }
        if(cnt)zero.pb(cnt);
        cnt = 0;
        i--;
    }
    if(s[n-1] == '0') one.pb(0);
    int z = zero.size(), o = one.size();
    if(z <= k) {
        cout << n << endl;
        return 0;
    }
    int zerosum[z+1], onesum[o+1];
    zerosum[0] = 0;
    onesum[0] = 0;
    rep(i,z) zerosum[i+1] = zerosum[i] + zero[i];
    rep(i,o) onesum[i+1] = onesum[i] + one[i];
    int ans = 0;
    rep(i,z-k+1){
        chmax(ans, zerosum[i+k] - zerosum[i] + onesum[i+k+1] - onesum[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1404
# include <iostream>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if((a%2==1 && b%2==1) || (a%2==0 && b%2==0)){
    cout << (a+b)/2;
  }
  else if(a==b){
    cout << "IMPOSSIBLE";
  }
  else {
    cout << "IMPOSSIBLE";
  }
    return 0;
}
    

  

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

int main(){
  int n; cin >>n;
  vector<int> a(n);
  int cnt1 = 0, cnt2 = 0, cnt4 = 0;
  rep(i,n) {
    cin >>a[i];
    if(a[i]%4==0) cnt4++;
    else if(a[i]%2==0) cnt2++;
    else cnt1++;
  }
  if(cnt2) cnt1++;
  if(cnt1<=cnt4+1) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0; 
}

Measured memory_bytes: 3768
/* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mod 998244353
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 1000005
 
 
// Driver code to test above functions
int32_t main()
{
  
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int n, ans = 0;
    cin >> n;
    map<int, int> mp;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin >> x;
 
        ans += mp[i-x];
 
        mp[i+x]++;
    }
 
    cout << ans;
 
    return 0;
 
} 

Measured memory_bytes: 26212
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <string.h>
int main()
{
   char S[4];
   scanf("%s",S);
   char str[2]={'\0'};
  strncpy(str, S+2,2);
  int B =  (str[0] - '0') * 10 + (str[1] - '0');
  str[0]='\0';
  strncpy(str, S,2);
  int A = (str[0] - '0') * 10 + (str[1] - '0');
  int YYMM=0;
  int MMYY=0;
  if ( 1<=A && A<=12){
    MMYY++;
  }
  if (1<=B && B<=12){
    YYMM++;
  }
  if (YYMM==1 && MMYY==0)printf("YYMM");
  else if (YYMM==0 && MMYY==1)printf("MMYY");
  else if (YYMM==1 && MMYY==1)printf("AMBIGUOUS");
  else printf("NA");

    return 0;
}


Measured memory_bytes: 256
using System;
class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		int h = int.Parse(input[0]);
		int f = int.Parse(input[1]);
        if (h * 2 > f || h * 4 < f || f % 2 != 0)
        {
			Console.WriteLine("No");
        } else
        {
			Console.WriteLine("Yes");
        }
	}
}

Measured memory_bytes: 27532
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int rec[200010][26];
int dp[200010];
vector<int> pos[26];
signed main() {
    string s; cin >> s;
    int N = s.length();
    rep(i,0,N) {
        pos[ s[i] - 'a' ].push_back(i);
    }
    rep(i,0,26) pos[i].push_back(INF);

    rep(i,0,N) rep(j,0,26) {
        int idx = *lower_bound(pos[j].begin(), pos[j].end(), i);
        rec[i][j] = idx;
        // if(i < 4) printf("rec[%lld][%lld] = %lld\n", i, j, rec[i][j]);
    }

    rep(i,0,N) dp[i] = INF;
    dp[N] = 1;
    repr(i,N-1,0) {
        rep(k,0,26) {
            if(rec[i][k] == INF) chmin(dp[i], 1LL);
            else chmin(dp[i], dp[ rec[i][k] + 1 ] + 1);
        }
    }

    // rep(i,0,N) printf("dp[%lld] = %lld\n", i, dp[i]);

    int len = dp[0], idx = 0;
    string ans = "";
    while(len--) {
        rep(i,0,26) {
            if(rec[idx][i] == INF && len == 0) {
                // printf("idx = %lld, i = %lld, len = %lld\n", idx, i, len);
                ans += (char)('a' + i);
                break;
            }
            else if(dp[idx] == dp[ rec[idx][i] + 1 ] + 1) {
                // printf("idx = %lld, i = %lld, len = %lld\n", idx, i, len);
                ans += (char)('a' + i);
                idx = rec[idx][i] + 1;
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 44548
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   for(int i=0;i<(n);++i)
#define SORT(c)    sort((c).begin(),(c).end())
#define CLR(a)     memset((&a), 0 ,sizeof(a))//clear memory
#define dump(x)    cerr << #x << " = " << (x) << endl;//debug
#define debug(x)   cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define EPS        1e-10//sample:if((double)>=(double)+EPS)
//cin,cout release
//std::cin.tie(0);
//ios::sync_with_stdio(false);

using namespace std;

struct node {
  int key;
  node *parent,*right, *left;
};
typedef node* nodep;
nodep root,NIL;
void insert(int key){
  nodep y=NIL,x=root,z=(nodep)malloc(sizeof(node));
  z->key=key;
  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;
    }
}
void inorder(nodep u){
  if(u==NIL)return;
  inorder(u->left);
  cout<<" "<<u->key;
  inorder(u->right);
}
void preorder(nodep u){
  if(u==NIL)return;
  cout<<" "<<u->key;
  preorder(u->left);
  preorder(u->right);
}
int main(){
  string buf;
  int a,n;
  cin>>n;
  rep(i,n){
    cin>>buf;
    if(buf[0]=='i'){
      cin>>a;
      insert(a);
    }
    else{
      inorder(root);
      cout<<endl;
      preorder(root);
      cout<<endl;
    }
  }


  return 0;
}


Measured memory_bytes: 26500
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define BUF_SIZE 100

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

void swap(int *a, int *b) {
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

void reversed(int *a, int size) {
    int *b = (int*)malloc(sizeof(int)*size);
    memcpy(b, a, sizeof(int)*size);
    int i;
    for(i = 0; i < size; i++) {
        a[i] = b[size-1-i];
    }
}

// in-place(C++ like function)
// see also https://cpprefjp.github.io/reference/algorithm/next_permutation.html
int next_permutation(int *arr, int size) {
    int i, k;
    if(!size || size==1) return 0;
    // step1. 
    for(k = size-2; k >= 0; k--) {
        if(arr[k+1] > arr[k]) break;
    }
    if(k < 0) {
        // reversed
        reversed(arr, size);
        return 0;
    }
    for(i = size-1; i >= 0; i--) {
        if(arr[i] < arr[k]) continue;
        break;
    }
    swap(&arr[i], &arr[k]);
    reversed(&arr[k+1], size-1-k);
    return 1;
}

#define VERTEXES_MAX 8

int main(void) {
    int vs, es;
    static char graph[VERTEXES_MAX][VERTEXES_MAX];
    get_int2(&vs, &es);
    int i;
    for(i = 0; i < es; i++) {
        int v1, v2;
        get_int2(&v1, &v2);
        // 1-indexed -> 0-indexed
        v1--; v2--;
        // undirected
        graph[v1][v2] = graph[v2][v1] = 1;
    }
    int arr[VERTEXES_MAX];
    for(i = 0; i < vs; i++) arr[i] = i;

    int cnt = 0;
    do {
        // starting point must be 0
        if(arr[0] != 0) break;
#ifdef DEBUG
        for(i = 0; i < vs; i++) printf("%d ", arr[i]);
        putchar('\n');
#endif
        int flag = 1;
        for(i = 1; i < vs; i++) {
            if(graph[arr[i-1]][arr[i]]) continue;
            flag = 0;
            break;
        }
        if(flag) cnt++;
    } while(next_permutation(arr, vs));

    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>
#include <tuple>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1e18;

int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll mx = -INF;
    mx = max(mx, a*c);
    mx = max(mx, a*d);
    mx = max(mx, b*c);
    mx = max(mx, b*d);
    cout << mx << endl;
    return 0;
}


Measured memory_bytes: 3620
/*redwackyferret*/
#include<bits/stdc++.h>
#define pb push_back
#define all(v) v.begin(), v.end()
#define ff first
#define pii pair<int,int>
#define ss second
#define pp make_pair
#define endl "\n"
#define ll long long int

using namespace std;

const int MOD = 1e9 + 7;
const int inf = INT_MAX;



int main(){
     int n;
     string up, down;
     cin>>n>>up>>down;
     ll dp[n];
     memset(dp, 0, sizeof dp);
     // 0 for horizontal and 1 for vertical
     bool last = 0; //for horizontal and 1 for vertical
     int i;
     if(up[0]==down[0]){
          dp[0] = 3;
          last = 1;
          i=1;
     }
     else {
          
          dp[0] = 6;
          dp[1] = 6; 
          last=0;
          i=2;
     }
     for(; i<n; ){
          //vertical
          if(last){
               //abhi kya h tu
               if(up[i]==up[i+1]){
                    //tu horizontal hai
                    dp[i] = dp[i+1] = (2*dp[i-1])%MOD;
                    // cout<<i<<" ---> "<<dp[i]<<endl;
                    // cout<<i+1<<" ---> "<<dp[i+1]<<endl;
                    i = i+2;
                    last = 0;
                    continue;
               }
               else{
                    dp[i] = (2*dp[i-1])%MOD;
                    // cout<<i<<" ---> "<<dp[i]<<endl;
                    i++;
                    last = 1;
                    continue;
                    
                    
               }
          }
          if(last==0){
               //abhi kya h tu
               if(up[i]==up[i+1]){
                    //tu horizontal hai
                    dp[i] = dp[i+1] = (3*dp[i-1])%MOD;
                    // cout<<i<<" ---> "<<dp[i]<<endl;
                    // cout<<i+1<<" ---> "<<dp[i+1]<<endl;
                    i = i+2;
                    last = 0;
                    continue;
               }
               else{
                    dp[i] = dp[i-1]%MOD;
                   // cout<<i<<" ---> "<<dp[i]<<endl;
                    i++;
                    last = 1;
                    continue;
                    
                    
               }
               
               
               
               
          }
     }
     cout<<(dp[n-1])%MOD<<endl;
     
     
     
     
     
return 0;
}

Measured memory_bytes: 3600
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int x,a,b;
	cin>>x>>a>>b;
	int d1=x-a;
	int d2=x-b;
	if (d1<0){
		d1=-d1;
	}
	if (d2<0){
		d2=-d2;
	}
	if (d1<=d2){
		cout<<"A"<<endl;
	}else{
		cout<<"B"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
	auto NM = readln.split.to!(int[]);
	auto N = NM[0], M = NM[1];
	auto H = readln.split.to!(int[]);
	
	int[] AB_max;
	AB_max.length = N;
	foreach (i; 0 .. M) {
	    auto ab = readln.split.to!(int[]);
	    AB_max[ab[0]-1] = max(AB_max[ab[0]-1], H[ab[1]-1]);
	    AB_max[ab[1]-1] = max(AB_max[ab[1]-1], H[ab[0]-1]);
	}
	
	int ans;
	foreach (i; 0 .. N) {
	    if (AB_max[i] < H[i]) ans++;
	}
	
	writeln(ans);
}

Measured memory_bytes: 6996
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;


int main(){
    ll n;cin>>n;
    ll x[300],y[300],h[300];

    rep(i,0,n){
        cin>>x[i]>>y[i]>>h[i];
    }
    
    rep(c1,0,101){
        rep(c2,0,101){
            int ok=1;
            ll stan=-1;
            rep(i,0,n){
                if(h[i]!=0){
                ll tmp=h[i]+abs(c1-x[i])+abs(c2-y[i]);
                if(stan==-1){stan=tmp;}
                
                else if(stan!=tmp){ok=0;break;}
                }
            }
            rep(i,0,n){
                if(h[i]==0){
                    if(stan>abs(c1-x[i])+abs(c2-y[i]))ok=0;
                }
            }
            if(ok==1){
                cout<<c1<<" "<<c2<<" "<<stan<<endl;
            }
        }
    }
    
    
}







Measured memory_bytes: 256
s=input()
t=input()
ls=len(s)
lt=len(t)

min_change=lt
# print(min_change)

for i in range(0,ls-lt+1):
    if(True):
        d = 0
        for j in range(0,lt):
            if(s[i+j]!=t[j]):
                d+=1

        min_change=min(min_change,d)

print(min_change)


Measured memory_bytes: 72832
#include <iostream>
#include <vector>
#include <sstream>

using namespace std;
int main()
{
    int N;
    double x[10];
    std::string u[10];
    double sum=0;
    cin>>N;
    for(int i=0; i<N; i++){
        cin>>x[i]>>u[i];
        sum += (u[i]=="BTC") ? x[i] * 380000.0 : x[i];
    }
    cout<<sum<<endl;
    return 0;
}

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

using db = double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back

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

int main() {
	cout << fixed << setprecision(9);
	ios :: sync_with_stdio(0);

	for(int n, m; cin >> n >> m && n && m; ) {
		int x = 1, y = 1, d = 1;
		for(string s; cin >> s && s != "STOP"; ) {
			if(s == "LEFT") d = (d + 1) % 4;
			if(s == "RIGHT") d = (d + 3) % 4;
			if(s == "FORWARD" || s == "BACKWARD") {
				int sgn = (s == "FORWARD" ? 1 : -1);
				int t; cin >> t;
				while(t --) {
					int nx = x + dx[d] * sgn;
					int ny = y + dy[d] * sgn;
					if(nx >= 1 && nx <= n && ny >= 1 && ny <= m) {
						x = nx; y = ny;
					}
				}
			}
		}
		cout << x << ' ' << y << '\n';
	}

	return 0;
}

Measured memory_bytes: 3240
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef int Int;
typedef pair<Int, Int> pii;
typedef pair<Int, double> pid;
typedef pair<double, double> pdd;
typedef pair<Int, pii> pip;
typedef pair<pii, Int> ppi;
typedef pair<double, Int> pdp;
typedef vector<Int> veci;
typedef vector<double> vecd;
typedef vector<int> veci;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<pii> vecpii;
typedef vector<ppi> vecppi;
typedef vector<veci> mati;
typedef vector<vecll> matll;
typedef vector<vecd> matd;
#define PB(x) push_back(x)
#define EB(x) emplace_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (x).size()
#define CLR(x) memset(x,0,sizeof x)
#define pdebug() printf("%d\n",__LINE__)
#define REP(i, a, b) for(int i = (a);i <= (b);i++)
#define FORO(i, n) REP(i,0,(int)n-1)
#define FORI(i, n) REP(i,1,(int)n)
#define FORIT(i, t) for(auto i = t.begin();i != t.end();i++)
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define dist(_a, _b) sqrt(sqr(_a.A-_b.A)+sqr(_a.B-_b.B))
#define norm(_a) sqrt(sqr(_a.A)+sqr(_a.B))
#define DEBUG 1
#if DEBUG
#define DUMP(a) do { std::cout << #a " = " << (a) << ", "; } while(false)
#define DUMPLN(a) do { std::cout << #a " = " << (a) << std::endl; } while(false)
#else
#define DUMP(a)
#define DUMPLN(a)
#endif
template<typename T, typename U>
inline void getMin(T &a, U b) { if (a > b) a = b; }
template<typename T, typename U>
inline void getMax(T &a, U b) { if (a < b) a = b; }
template<typename T>
vector<T> getVector(const int n) { return vector<T>(n); }
template<typename T>
vector<T> getVector(const int n, const T a) { return vector<T>(n, a); }
template<typename T>
vector<T> getEmptyVector() { return vector<T>(); }
template<typename T>
void appendAll(vector<T> &a, vector<T> b) { a.insert(a.end(), b.begin(), b.end()); }
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
// #define X first
// #define Y second
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const ll MOD = 1000000007;
const int MAXN = 1 << 17;
const int inf = 1 << 27;
const ll llinf = 1LL << 50;
const int NIL = -inf;
int popcount(int x) { return __builtin_popcount(x); }


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int ans = 0;
    int cnt = 0;
    for(int i = 0;i < s.length();i++) {
        if(s[i] == 'R') {
            cnt++;
        } else {
            cnt = 0;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3648
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=1e9+7;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
int main(void){
	int i,n;cin>>n;
	vector<int>p(n);for(auto &it:p){cin>>it;}
	vector<int>sosa;
	while(-1){
		for(i=0;i<n;i++){
			sosa.pub(1);
			if(i==n-1){continue;}
			if(p[i]>p[i+1]){sosa.pub(n-1);swap(p[i+1],p[i]);}
		}
		int ok=1;
		for(i=0;i<n;i++){if(p[i]!=i){ok=0;break;}}
		if(ok==1){break;}
	}
	cout<<sosa.size()<<endl;
	for(auto it:sosa){cout<<it<<endl;}
	return 0;
}

Measured memory_bytes: 768
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

vector<int> to[100005];
int a[100005];
int b[100005];
int visited1[100005];
int visited2[100005];

void dfs1(int v){
    if(visited1[v]){
        return;
    }
    visited1[v]=1;
    for(int u:to[v]){
        if(visited1[u]==0){
            a[u]=a[v]+1;
            dfs1(u);
        }
    }
    return;
}

void dfs2(int v){
    if(visited2[v]){
        return;
    }
    visited2[v]=1;
    for(int u:to[v]){
        if(visited2[u]==0){
            b[u]=b[v]+1;
            dfs2(u);
        }
    }
    return;
}


int main(){
    int n;
    cin >> n;
    rep(i,n-1){
        int a,b;
        cin >> a>> b;
        a--;b--;
        //cerr<<i;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    int A=0,B=0;
    a[0]=0;
    //cerr<<"ch1";
    dfs1(0);
    
    
    b[n-1]=0;
    //cerr<<"ch2";

    dfs2(n-1);
    rep(i,n){
        if(a[i]<=b[i]){
            A++;
        }else{
            B++;
        }
    }
    
    if(A>B){
        cout<<"Fennec"<<endl;
    }else{
        cout<<"Snuke"<<endl;
    }
    return 0;
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
signed main(){
  string a[100],b;
  int c,d;
  cin>>c>>d;
  for(int i=0;i<=c;i++){
    cin>>a[i];
  }
  for(int i=0;i<c;i++){
    for(int j=i;j<c;j++){
      if(a[i]>a[j]) swap(a[i],a[j]);
    }
  }
  for(int i=0;i<c;i++){
    cout<<a[i];
  }
  cout<<"\n";
}

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

#define UPPER 100000

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

	int Q;
	scanf("%d", &Q);

	vector<bool> A(UPPER + 1, false);
	A[0] = true;
	A[1] = true;  // 0,1は素数ではない
	for (int i = 2; i <= (int)sqrt(UPPER); i++) {
		if (A[i] == true) {
			continue;
		}
		for (int j = 2; j * i <= UPPER; j++) {
			A[j * i] = true;
		}
	}
	// for (int i = 0; i <= UPPER; i++) {
	// 	printf("%d %d\n", i, (int)A[i]);
	// }
	vector<int> B(UPPER + 1, 0);
	for (int j = 1; j <= UPPER; j += 1) {
		if (!A[j] && !A[(j + 1) / 2]) {
			B[j] = B[j - 1] + 1;
		} else {
			B[j] = B[j - 1];
		}
	}

	// for (int i = 0; i <= UPPER; i++) {
	// 	printf("%d %d\n", i, B[i]);
	// }

	int l, r;

	for (int i = 0; i < Q; i++) {
		scanf("%d %d", &l, &r);
		printf("%d\n", B[r] - B[l - 1]);
	}
	return 0;
}

Measured memory_bytes: 1024