akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional> // std::function<void(int)>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;

int u[2000][2000],d[2000][2000],l[2000][2000],r[2000][2000];
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h,w;
    cin>>h>>w;
    string s[2000];
    for(int i=0;i<h;i++)cin>>s[i];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#')u[i][j]=0;
            else if(i!=0)u[i][j]=u[i-1][j]+1;
            else u[i][j]=1;
        }
    }
    for(int i=h-1;i>=0;i--){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#')d[i][j]=0;
            else if(i!=h-1)d[i][j]=d[i+1][j]+1;
            else d[i][j]=1;
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#')l[i][j]=0;
            else if(j!=0)l[i][j]=l[i][j-1]+1;
            else l[i][j]=1;
        }
    }
    for(int i=0;i<h;i++){
        for(int j=w-1;j>=0;j--){
            if(s[i][j]=='#')r[i][j]=0;
            else if(j!=w-1)r[i][j]=r[i][j+1]+1;
            else r[i][j]=1;
        }
    }
    int res=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            res=max(res,u[i][j]+d[i][j]+l[i][j]+r[i][j]-3);
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 129536
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef int LL;
typedef unsigned int uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);
 
const LL mod=1e9+7;
struct matrix
{
	int a[3][3];
	void clear(int x=0)
	{
		for(int i=0;i<3;i++)for(int j=0;j<3;j++)a[i][j]=(i==j)*x;
	}
	matrix(){clear();}
	int *operator [](int x)
	{
		return a[x];
	}
}sum,tran;
matrix operator *(matrix a,matrix b)
{
	matrix ret;
	ret.clear(0);
	for(int i=0;i<3;i++)for(int j=0;j<3;j++)for(int k=0;k<3;k++)
		ret[i][j]=(ret[i][j]+1ll*a[i][k]*b[k][j])%mod;
	return ret;
}
matrix power(matrix x,int y)
{
	matrix ret;ret.clear(1);
	while(y)
	{
		if(y&1)ret=ret*x;
		x=x*x;
		y>>=1;
	}
	return ret;
}
 
int calc(int x)
{
	matrix t;t.clear();t[0][0]=0;t[1][0]=1;t[2][0]=5;
	t=power(tran,x)*t;
	return t[0][0];
}
int f[100111],n,x[100111],m;
int main()
{
	sum.clear();tran.clear();tran[0][1]=1;tran[1][2]=1;tran[2][0]=1;tran[2][1]=mod-2;tran[2][2]=4;
	get2(n,m);
	for(int i=1;i<=m;i++)get1(x[i]);
	x[++m]=n;
	for(int i=1;i<=m;i++)
	{
		sum=power(tran,x[i]-x[i-1])*sum;
		f[i]=calc(x[i])-sum[0][0];
		if(f[i]<0)f[i]+=mod;
		
		sum[1][0]=(sum[1][0]+f[i])%mod;
		sum[2][0]=(sum[2][0]+5ll*f[i])%mod;
	}
	printendl(f[m]);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,c;
ll x[100005],v[100005];
ll a[100005];
ll b[100005];
int main()
{
    while(cin>>n>>c)
    {
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       for(int i=0;i<n;i++)
       {
           cin>>x[i]>>v[i];
       }
       x[n]=c;
       ll ans=0;
       a[0]=v[0]-x[0];
       for(int i=1;i<n;i++)
       {
           a[i]=a[i-1]+v[i]-(x[i]-x[i-1]);
       }
       for(int i=n-1;i>=0;i--)
       {
           b[i]=b[i+1]+v[i]-(x[i+1]-x[i]);
       }
       for(int i=1;i<n;i++)
       {
           a[i]=max(a[i],a[i-1]);
       }
       for(int i=n-2;i>=0;i--)
       {
           b[i]=max(b[i],b[i+1]);
       }
       for(int i=0;i<n;i++)
       {
           ans=max(ans,a[i]);
           ans=max(ans,b[i]);
           ans=max(ans,a[i]-x[i]+b[i+1]);
           ans=max(ans,b[i]-(c-x[i])+a[i-1]);
       }
       cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    for (int i=0;i<17;++i){
        for(int j=0;j<15;++j){
            if(4*i+7*j==n)
            {
                cout << "Yes"<<endl;
                return 0;
            }

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] A, B;
		int min,max;
		A = new int[2];
		B = new int[2];
		for(int i = 0; i < 2; i++) {
			A[i] = sc.nextInt();
		}
		for(int i = 0; i < 2; i++) {
			B[i] = sc.nextInt();
		}

		if(A[1] <= B[0] || B[1] <= A[0]) {
			System.out.println(0);
			System.exit(0);
		}

		if(A[0] < B[0]) {
			min = B[0];
		}else {
			min = A[0];
		}

		if(A[1] < B[1]) {
			max = A[1];
		}else {
			max = B[1];
		}

		System.out.println(max - min);
		sc.close();
	}
}


Measured memory_bytes: 23764
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
answer = 0
for i in range(len(B)):
    if(B[i] == A[i]):
        answer += A[i]
    elif(B[i] < A[i]):
        answer += B[i]
    else:
        value = B[i] - A[i] - A[i+1]
        if(value >= 0):
            answer += A[i] + A[i+1]
            A[i+1] = 0
        else:
            check = B[i] - A[i]
            answer += A[i] + check
            A[i+1] -= check
print(answer)


Measured memory_bytes: 19776
def abc084_d():

  def primes_list(n):
    # n以下の素数列挙
    primes = set(range(2, n+1))
    for i in range(2, int(n**0.5+1)):
      primes.difference_update(range(i*2, n+1, i))
    return list(primes)

  # 素数リストを用意する
  primes = sorted(primes_list(10**5))

  # (n+1)//2 を素数判定するための準備
  is_prime = [False] * (10**5 + 10)
  for p in primes:
    is_prime[p] = True

  # 2017に似た数の累積個数 (1-index)
  acc_like = [0]
  for p in primes:
    this_like = 1 if is_prime[(p+1) // 2] else 0
    acc_like.append(acc_like[-1] + this_like)

  # 入力を受け取る
  q = int(input())
  query = [tuple(map(int, input().split())) for _ in range(q)]

  # クエリを処理する
  from bisect import bisect_left
  for l, r in query:
    # 2は素数だが奇数ではない、rは3以上でないと解が無い
    if r < 3:
      print(0)
      continue
    # 左側は3以下はカット
    l = max(l, 3)
    # 二分探索で範囲決める
    idx_l = bisect_left(primes, l)
    idx_r = bisect_left(primes, r+1)
    # 累積和から個数求める
    ans = acc_like[idx_r] - acc_like[idx_l]
    print(ans)

abc084_d()

Measured memory_bytes: 18792
# -*- coding:utf-8 -*-
"""
https://atcoder.jp/contests/abc106/tasks/abc106_b
"""

def solve():
    N = int(input())

    def count_divisor(n):
        """nの約数を数える"""
        cnt = 0
        i = 1
        while i*i <= n:
            if n%i == 0:
                cnt += 1
                if i != n//i:
                    cnt += 1
            i += 1
        return cnt

    ans = 0
    for i in range(1, N+1, 2):
        if count_divisor(i) == 8:
            ans += 1
    print(ans)


if __name__ == "__main__":
    solve()


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

using namespace std;

int main() {
	long long x;
	cin >> x;
	long long sq = 5000;
	for (long long a = -sq; a <= sq; a++) {
		for (long long b = -sq; b <= sq; b++) {
			if (a * a * a * a * a - b * b * b * b * b == x) {
				cout << a << " " << b << "\n";
				return 0;
			}
		}
	}
	return 0;
}




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

int main(){

  int N,X,Y=0;
  cin>>N>>X>>Y;
  
  map<int,int> mp;
	
  for(int i=1;i<N+1;i++){
	for(int j=i+1;j<N+1;j++){

      if(i<=X && j<=X){
        mp[j-i]++;
      	//cout<<i<<" "<<j<<" "<<j-i<<endl;                
      }
	  else if(i>=Y && j>=Y){
        mp[j-i]++;
      	//cout<<i<<" "<<j<<" "<<j-i<<endl;
      }
      else if(i<=X && X<j && j<=Y){
        int mini=min(j-X,Y-j+1);
        mp[mini+(X-i)]++;
        //cout<<i<<" "<<j<<" "<<mini+(X-i)<<endl;
      }
      else if(i<=X && Y<j){
        int dis=j-Y+1+(X-i);
        mp[dis]++;
        //cout<<i<<" "<<j<<" "<<dis<<endl;
      }
      else if(X<i && i<=Y && Y<j){

        int mini=min(Y-i,(i-X)+1);
        mp[j-Y+mini]++;
        //cout<<i<<" "<<j<<" mini = "<<mini<<", "<<j-Y+mini<<endl;
        
      }
      else if(X<i && i<=Y && X<j && j<=Y){
        
        int mini=min(j-i,(Y-j)+1+(i-X));
        mp[mini]++;
        //cout<<i<<" "<<j<<" "<<mini<<endl;
        
      }
      
      
      
    }
  }
  
  for(int k=1;k<N;k++){cout<<mp[k]<<endl;}

}


Measured memory_bytes: 384
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;//例: VVI dp(10, vector<int>(10, INF);
typedef priority_queue<int, vector<int>, less<int> > QUE_int;
const int INF = 2 * pow(10, 9) + 1;//+1しないとREになるかも(out of rangeになるんかな?? )

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

ll max(ll a, ll b) { return (a > b) ? a : b; }
ll min(ll a, ll b) { return (a < b) ? a : b; }

////////////////////////////////////////////////////////////////

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = pow(10, 9) + 7;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
};


////////////////////////////////////////////////////////////////

/*l way(ll x, ll K){
	ll res = x - K;
	if( res < 0 ) return -res;
	return way(res, K);
}*/

int main(void) {
	
	ll N, K;
	cin >> N >> K;

	ll ans, tmp;
	if(N >= K){
		ans = N%K;
		tmp = ans - K ;
		if(tmp < 0 ) tmp = -tmp;
		if( ans > tmp ) ans = tmp;

		cout << ans << endl;
	} 

	else if( N < K ){
		ans = N;
		tmp = -(N-K);
		if(ans > tmp) ans = tmp;
		cout << ans << endl;
	}



}




Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
using namespace std;

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


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




    return 0;
}

Measured memory_bytes: 3616
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

template <class T = usize> class rep {
	const T f, l;

public:
	class itr {
		friend rep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr rep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(f); }
	constexpr itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
	const T f, l;

public:
	class itr {
		friend revrep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr revrep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(l - 1); }
	constexpr itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool amax(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool amin(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool asmax(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool asmin(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }
template <class T> constexpr T difference(const T &a, const T &b) {
	return a <= b ? b - a : a - b;
}

#include <algorithm>
#include <iostream>
#include <utility>
#include <numeric>

int main() {
	usize n;
	::std::cin >> n;
	::std::vector<u32> l(n);
	for (auto &e : l) {
		::std::cin >> e;
	}
	::std::cout
		<< (::std::accumulate(l.cbegin(), l.cend(), 0)
		> *::std::max_element(l.cbegin(), l.cend()) * 2 ? "Yes" : "No")
		<< ::std::endl;
	return 0;
}


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

using namespace std;

using ll = long long;
#define long long long

int main(void) {
    vector<ll> s(1e7+1);
    ll t;
    cin >> t;
    for(ll i=1; ; i++) {
        if(!s[t]) s[t] = i, t = t&1 ? 3*t+1 : t/2;
        else {
            cout << i << endl;
            return 0;
        }
    }
}


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

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

int main() {
    int n,k; cin>>n>>k;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    
    rep(j,k){
        vector<int>b(n+1);
    rep(i,n){
        int l,r;
        l = max(0,i-a[i]);
        r = min(n,i+ a[i]);
        ++b[l]; --b[r+1];
    }
    rep(i,n+1)b[i+1]+=b[i];
    b.pop_back();
    if(a == b)break;
    else a = b;
    }
    
    rep(i, n){
        cout<<a[i];
        if(i != n-1)cout<<" ";
        else cout<<endl;
    }

	return 0;
}

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

int main() {
  cin.tie(nullptr);
  //ios_base::sync_with_stdio(false);
  
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> p(n, k-q);
  rep(i, q) {
    int a;
    cin >> a;
    --a;
    ++p[a];
  }
  rep(i, n) {
    if(p[i] <= 0) puts("No");
    else puts("Yes");
  }
  return 0;
}

Measured memory_bytes: 3708
<?php
$n=trim(fgets(STDIN));
$a=explode(" ",trim(fgets(STDIN)));
$m=0;
$i=$n-1;
while($i>=0){
  if($a[$i]%2==1){
    ++$m;
    $ans[]=$i+1;
    $p=floor(sqrt($i+1));
    $j=1;
    while($j<=$p){
      if(($i+1)%$j==0){
        ++$a[$j-1];
        ++$a[(($i+1)/$j)-1];
      }
      ++$j;
    }
    if($p*$p==$i+1){
      ++$a[$p-1];
    }
  }
  --$i;
}
echo $m. PHP_EOL;
if($m!=0){
  echo join(" ",$ans);
}

Measured memory_bytes: 25072
/*
Author: TianyuZhou
Accepted / Wrong Answer / Time Limit Error / Memory Limit Error / Compile Error
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	for(int i=0;i<s.size();++i)
		cout<<(s[i]+n<='Z'?char(s[i]+n):char(s[i]+n-26));
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  if(a[0]!=0){
    cout<<-1<<endl;
    return 0;
  }
  for(int i=0;i<n-1;i++){
    if(a[i+1]-a[i]>1){
      cout<<-1<<endl;
      return 0;
    }
  }
  int ans=a[n-1];
  int np=a[n-1];
  for(int i=n-2;i>=0;i--){
    np--;
    if(a[i]!=np){
      ans+=a[i];
      np=a[i];
    }

  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
const B=5000
function f(X,Y,x,y)
	z=x[:]
	w=y[:]
	for i=1:B
		tx=X+x[i]
		ty=Y+y[i]
		theta=atan2(ty,tx)
		if ty<0
			theta+=2*pi
		end
		id=floor(Int,theta*B/(2*pi))+1
		if hypot(z[id],w[id])<hypot(tx,ty)
			z[id]=tx
			w[id]=ty
		end
	end
	z,w
end
function main()
	x=zeros(Int,B)
	y=zeros(Int,B)
	N=parse(Int,readline())
	for i=1:N
		X,Y=map(x->parse(Int,x),split(readline()))
		if X!=0||Y!=0
			x,y=f(X,Y,x,y)
		end
	end
	ans=0
	for i=1:B
		ans=max(ans,hypot(x[i],y[i]))
	end
	println(ans)
end
main()

Measured memory_bytes: 171268
#include <iostream>
#include <algorithm>
#include <vector>
#define ll long long
#define ld long double
#define pb push_back
#define mk make_pair
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
using namespace std;

int main(){
    string s;
    cin >> s;
    ll f = 0;
    for(ll i = 0;i<s.length()-1;i++){
        if(s[i] == s[i+1]){
            f = 1;
            cout << "Bad";
            break;
        }
    }
    if(f == 0)
        cout << "Good";
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = System.Console.ReadLine().Trim();
            int iN = int.Parse(sS);
            sS = System.Console.ReadLine().Trim();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            List<char> lstChr = new List<char>();
            for (int i = 0; i < sS.Length; i++)
            {
                int iAsc = (int)sS[i] + iN;
                if (iAsc > 90) { iAsc = iAsc - 90 + 64; }
                lstChr.Add((char)iAsc);
            }
            sS = new String(lstChr.ToArray());

            // 出力
            System.Console.WriteLine("{0}", sS.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main(void)
{
	int n;
	cin >> n;
	vector<int> a(n); 
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	int ans = *max_element(a.begin(), a.end()) - *min_element(a.begin(), a.end());

	if (ans < 0) {
		cout << -ans << endl;
	} else {
		cout << ans << endl;
	}

	return 0;
}

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

#define f first
#define s second
#define p pair<int,int>
#define P pair<ll,ll>
#define pb push_back
#define ll long long
#define db double
#define zero(a) memset(a,0,sizeof(a))
#define inff(a,n) fill(a,a+n+1,inf)
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define read(x) scanf("%lld",&x)
#define read2(x,y) scanf("%lld%lld",&x,&y)
#define write(x) printf("%lld\n",x)

const int maxn=2e5+5;
const ll inf=1e9;
const db pi=acos(-1);

ll x1,x2,Y1,y2,n,x[maxn],flag,dp[maxn],a,b,num,sum,ans;
vector<P>v;

int main()
{
    read2(x1,Y1),read2(x2,y2);
    if(x1>x2)swap(x1,x2),swap(Y1,y2);
    if(Y1>y2)Y1*=-1,y2*=-1,flag=1;
    read(n);
    if(x1==x2&&Y1==y2)printf("0");
    else if(x1==x2)
    {
        for(int i=0; i<n; i++)
        {
            read2(a,b);
            if(flag)b*=-1;
            if(a==x1&&b>=Y1&&b<=y2)
            {
                sum++;
            }
        }
        db xy=(y2-Y1)*100,res=0;
        if(sum>0)res=20-5*pi;
        printf("%.12f",min(xy+(10*pi-20)*sum,xy+200-res));
    }
    else if(Y1==y2)
    {
        for(int i=0; i<n; i++)
        {
            read2(a,b);
            if(flag)b*=-1;
            if(a>x1&&a<x2&&b==y2)
            {
                sum++;
            }
        }
        db xy=(x2-x1)*100,res=0;
        if(sum>0)res=20-5*pi;
        printf("%.12f",min(xy+(10*pi-20)*sum,xy+200-res));
    }
    else
    {
        for(int i=0; i<n; i++)
        {
            read2(a,b);
            if(flag)b*=-1;
            if(a>=x1&&a<=x2&&b>=Y1&&b<=y2)
            {
                v.pb({a,b});
            }
        }
        sort(all(v));
        fill(dp,dp+n+1,inf);
        for(int i=0; i<v.size(); i++)
        {
            *lower_bound(dp,dp+n,v[i].s)=v[i].s;
        }
        if(v.size()==0)num=0;
        else num=lower_bound(dp,dp+n,inf)-dp;
        db xy=(y2-Y1+x2-x1)*100;
        if(num==min(x2-x1,y2-Y1)+1)xy=xy-(20-5*pi)*(num-1)+10*pi-20;
        else xy-=(20-5*pi)*num;
        printf("%.12f",xy);
    }
    return 0;
}



Measured memory_bytes: 6384
#include <bits/stdc++.h>
using namespace std;
using edge = struct{int to; int cost;};
typedef pair<long long,int> pp;
vector<edge> G[100000];
#define INF 1001001001001001

int main() {
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> r(R);
    for(int i=0; i<R; ++i) {
        cin >> r[i];
        --r[i];
    }
    for(int i=0; i<M; ++i) {
        int a,b,c;
        cin >> a >> b >> c;
        G[a-1].push_back({b-1, c});
        G[b-1].push_back({a-1, c});
    }

    vector<vector<long long>> dist(N, vector<long long>(N, INF));
    for(int i=0; i<N; ++i) {
        priority_queue<pp, vector<pp>, greater<pp>> que;
        dist[i][i] = 0;
        que.push(pp(0, i));
        while(!que.empty()) {
            pp p = que.top(); que.pop();
            int v = p.second;
            if(dist[i][v] < p.first) continue;
            for(edge &e : G[v]) {
                if(dist[i][e.to] > dist[i][v] + e.cost) {
                    dist[i][e.to] = dist[i][v] + e.cost;
                    que.push(pp(dist[i][e.to], e.to));
                }
            }
        }
    }

    long long ans = INF;
    sort(r.begin(), r.end());
    do{
        long long tmp = 0;
        for(int i=0; i+1<R; ++i) tmp += dist[r[i]][r[i+1]];
        ans = min(ans, tmp);
    } while(next_permutation(r.begin(), r.end()));
    cout << ans << endl;

    return 0;
}

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

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

  int st = 0;
  int left = 0;
  for(int i = 0;i < n;i++){
    if(s[i] == '('){
      st++;
    }else{
      if(st > 0){
        st--;
      }else{
        left++;
      }
    }
  }

  for(int i = 0;i < left;i++){
    cout << '(';
  }
  cout << s;
  for(int i = 0;i < st;i++){
    cout << ')';
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
string s;
map<string,int> M;
vector<string> S,ans;
int num[200010];
int main(){	
	n=read();
	int tot=0,anss=0;
	for(register int i=1;i<=n;i++){
		cin>>s;
		if(M[s])num[M[s]]++;
		else {
			M[s]=++tot;
			num[tot]=1;
			S.push_back(s);
		}
		if(num[M[s]]>anss){anss=num[M[s]];ans.clear();}
		if(num[M[s]]==anss)ans.push_back(s);
	}
	sort(ans.begin(),ans.end());
	for(register int i=0;i<ans.size();i++)cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 29152
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = 100000;
const int INF = int(1E9);
int arr[MAXN + 5], sum[MAXN + 5], temp[MAXN + 5];
long long tot1 = 0, tot2 = 0;
int N;
void MergeSort(int le, int ri) {
    if( le == ri ) return ;
    int mid = (le + ri) >> 1;
    MergeSort(le, mid);
    MergeSort(mid+1, ri);
    int p = le, q = mid+1, r = le;
    while( p <= mid && q <= ri ) {
        if( sum[p] < sum[q] ) {
            temp[r++] = sum[p++];
        }
        else {
            tot1 += (p-le);
            temp[r++] = sum[q++];
        }
    }
    while( p <= mid ) {
        temp[r++] = sum[p++];
    }
    while( q <= ri ) {
        tot1 += (p-le);
        temp[r++] = sum[q++];
    }
    for(int i=le;i<=ri;i++)
        sum[i] = temp[i];
}
bool Check(int x) {
    tot1 = 0;
    for(int i=1;i<=N;i++)
        sum[i] = (arr[i] <= x ? 1 : -1);
    for(int i=1;i<=N;i++)
        sum[i] += sum[i-1];
    MergeSort(0, N);
    return tot1 >= (tot2/2 + 1);
}
int main() {
    int le = INF, ri = -INF;
    scanf("%d", &N);
    for(int i=1;i<=N;i++) { 
        scanf("%d", &arr[i]);
        le = min(le, arr[i]);
        ri = max(ri, arr[i]);
        tot2 += i;
    }
    while( le < ri ) {
        int mid = (le + ri) >> 1;
        if( Check(mid) ) ri = mid;
        else le = mid + 1;
    }
    printf("%d\n", ri);
}

Measured memory_bytes: 1280
import itertools


def hand_in_answer(v):
    base = [".", ".", ".", ".", ".", ".", ".", "."]
    for i in range(8):
        tmp = base.copy()
        tmp[v[i]] = "Q"
        print("".join(tmp))


def ifGoodPosition(position, v):
    yo = position[0]
    xo = position[1]

    x = xo
    y = yo
    x += 1
    y += 1
    while x < 8 and x >= 0 and y >= 0 and y < 8:
        if v[y] == x:
            return False
        x += 1
        y += 1

    x = xo
    y = yo
    x += 1
    y -= 1
    while x < 8 and x >= 0 and y >= 0 and y < 8:
        if v[y] == x:
            return False
        x += 1
        y -= 1

    x = xo
    y = yo
    x -= 1
    y += 1
    while x < 8 and x >= 0 and y >= 0 and y < 8:
        if v[y] == x:
            return False
        x -= 1
        y += 1

    x = xo
    y = yo
    x -= 1
    y -= 1
    while x < 8 and x >= 0 and y >= 0 and y < 8:
        if v[y] == x:
            return False
        x -= 1
        y -= 1

    return True


fixed_q_count = int(input())
x_choices = set([_ for _ in range(8)])
fixed_qs = []
for _ in range(fixed_q_count):
    y, x = map(int, input().split(" "))
    fixed_qs.append([y, x])

for v in itertools.permutations(x_choices, 8):
    flag2 = True
    for fixed_q in fixed_qs:
        if not v[fixed_q[0]] == fixed_q[1]:
            flag2 = False
            break

    if not flag2:
        continue

    flag = True
    for y in range(8):
        if not ifGoodPosition([y, v[y]], v):
            flag = False
            break

    if flag:
        hand_in_answer(v)
        break



Measured memory_bytes: 5660
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n,ans=1,cnt[30];
char A[100005];
int main() {
	scanf("%d",&n);
	scanf("%s",A+1);
	for(int i=1; i<=n; i++)cnt[A[i]-'a'+1]++;
	for(int i=1; i<=26; i++)ans=1LL*ans*(cnt[i]+1)%mod;
	printf("%d",(ans-1+mod)%mod);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int N,M;
	int pi,ti;
	vector<int> fp;
	vector<vector<int>> ordt;
	vector<int> t;
	cin >> N >> M;

	for (int i=0; i<N; i++) {
		vector<int> tmp(0);
		ordt.push_back(tmp);
	}
	for (int i=0; i<M; i++) {
		cin >> pi >> ti;
		fp.push_back(pi);
		ordt[pi-1].push_back(ti);
		t.push_back(ti);
	}
	for (auto itr=ordt.begin(); itr!=ordt.end(); ++itr) {
		sort(itr->begin(), itr->end());
	}
	for (int i=0; i<M; i++) {
		cout << setfill('0') << right << setw(6) << fp[i];
		auto itr = lower_bound(ordt[fp[i]-1].begin(), ordt[fp[i]-1].end(), t[i]);
		cout << setfill('0') << right << setw(6) << itr-ordt[fp[i]-1].begin()+1 << endl;
	}
	return 0;
}


Measured memory_bytes: 7792
# ABC１１6　C

n = int(input())
flowers = list(map(int,input().split()))


counter = 0

def zero_count(L):
    ans = []
    for i in range(len(L)):
        if L[i] == 0:
            ans.append(i) 
    return ans

def change_number(i,j):
    for iii in range(i,j+1):
        flowers[iii] -= 1
    global counter
    counter += 1
    # print('flowers;',flowers)
    


zeros=zero_count(flowers)

while len(zeros) != n:
    if len(zeros) == 0:
#         print('Step1')
        
        change_number(0,n-1)
        
        
    else:
        for i in range(len(zeros)):
            if i==0 and zeros[i] !=0:
                
#                 print('Step2')
                change_number(0,zeros[i]-1)
                
            elif i==len(zeros)-1:
                if zeros[i] == n-1:
#                     print('Step3')
                    break
                else:
#                     print('Step4')
                    change_number(zeros[i]+1,n-1)

            else:
                if zeros[i+1]-zeros[i] != 1:
#                     print('Step5')
                    change_number(zeros[i]+1,zeros[i+1]-1)

    
    zeros = zero_count(flowers)
    


print(counter)




Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cctype>
#include <stdio.h>

using namespace std;

int main(){
	char a;
	for(int i=0;;i++){
		scanf("%c",&a);
		if(a=='\n')break;
		if( isupper(a)){
			printf("%c",tolower(a));
		}else if(islower(a)){
			printf("%c",toupper(a));
		}else{
			printf("%c",a);
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3216
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextInt()){
		int n = sc.nextInt();
		long a = 1;
		if(n==0)a=0;
		for(;0<n;n--){
			a*=n;
		}
		System.out.println(a);
		}
	}
}

Measured memory_bytes: 17160
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeSynonymInstances #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.IArray           as IA
import qualified Data.Array.IO               as AI
import qualified Data.Array.MArray           as MA
import qualified Data.Array.ST               as STA
import qualified Data.Array.Unboxed          as AU
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import qualified Data.Graph                  as G
import           Data.Int
import qualified Data.IntMap                 as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence               as SQ
import qualified Data.Set                    as S
import           Data.Time
import qualified Data.Tree                   as T
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putLn :: Show a => a -> IO ()
putLn = print

putList :: Show a => [a] -> IO ()
putList [n] = put n
putList (n:ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n] = putStr n
putStrList (n:ns) = do
  putStr n
  putStr " "
  putStrList ns

main = do
  [n] <- readInt
  if n >= 1000
    then putStrLn "ABD"
    else putStrLn "ABC"


Measured memory_bytes: 380
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    int N;
    ll D,A;
    cin>>N>>D>>A;
    vector<pair<ll,ll>> XI(N);
    vector<ll> X(N);
    vector<ll> H_tmp(N),H(N);
    REP(i,N){
        cin>>XI[i].first>>H_tmp[i];
        XI[i].second=i;
        H_tmp[i]=(H_tmp[i]+A-1)/A;
    }
    sort(ALL(XI));
    REP(i,N){
        int idx=XI[i].second;
        X[i]=XI[i].first;
        H[i]=H_tmp[idx];
    }

    vector<ll> S(N+1,0);
    ll ans=0;
    REP(i,N){
        ll x=X[i];
        ll h=H[i]-S[i];
        if(S[i] < H[i]){
            int id=upper_bound(ALL(X),x+2*D)-X.begin();
            S[i]+=h;
            if(id!=N) S[id]-=h;
            ans+=h;
        }
        S[i+1]+=S[i];
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 12772
import java.util.Scanner;

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

		int q = sc.nextInt();
		for (int i = 0; i < q; i++) {
			int xp0 = sc.nextInt();
			int yp0 = sc.nextInt();
			int xp1 = sc.nextInt();
			int yp1 = sc.nextInt();
			int xp2 = sc.nextInt();
			int yp2 = sc.nextInt();
			int xp3 = sc.nextInt();
			int yp3 = sc.nextInt();

			int ax = xp1 - xp0;
			int ay = yp1 - yp0;
			int bx = xp3 - xp2;
			int by = yp3 - yp2;
			int dot = Geom.dot(ax, ay, bx, by);
			int cross = Geom.cross(ax, ay, bx, by);

			if (cross == 0) {
				System.out.println("2");
			} else if (dot == 0) {
				System.out.println("1");
			} else {
				System.out.println("0");
			}
		}

		sc.close();
	}
	
	@SuppressWarnings("unused")
	private static class Geom {
		static int dot(int xa, int ya, int xb, int yb) {
			return xa * xb + ya * yb;
		}

		static int cross(int xa, int ya, int xb, int yb) {
			return xa * yb - xb * ya;
		}
		
		static int sumofsquare(int xa, int ya) {
			return xa * xa + ya * ya;
		}
	}
}

Measured memory_bytes: 29532
# -*- coding: utf-8 -*-
# E - Red and Green Apples
# 標準入力の取得
X,Y,A,B,C = list(map(int, input().split()))
p_list = list(map(int, input().split()))
q_list = list(map(int, input().split()))
r_list = list(map(int, input().split()))

# 最大値を求める
# p_list, q_listから最大値を求め、それをr_listで置きかえていく
sorted_p_list = list(reversed(sorted(p_list)))
sorted_q_list = list(reversed(sorted(q_list)))
sorted_r_list = list(reversed(sorted(r_list)))

selected = sorted_p_list[:X]
selected.extend(sorted_q_list[:Y])
selected = list(sorted(selected))

for c in range(C):
    if selected[c] < sorted_r_list[c]:
        selected[c] = sorted_r_list[c]
    else:
        break

print(sum(selected))

Measured memory_bytes: 24180
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
			int a = in.nextInt();
			int b = in.nextInt();
			System.out.println(a*a-b>0?a*a-b:0);
		in.close();
	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int ,int> P;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	int H, N;
	cin >> H >>N;
	int sum = 0;
	rep(i,0,N){
		int input;
		cin >> input;
		sum+= input;
	}
	if (sum >= H)
		cout << "Yes\n";
	else
		cout << "No\n";
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
    int n,i;
    long long int sum=0;
    cin >> n;
    for(i=1; i<=n; i++)
    {
        if(i%3!=0 && i%5!=0)
        {
            sum+=i;
        }

    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
/*
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/
using namespace std;
using namespace __gnu_pbds;
using ll = long long;

#define     _test int _TC; cin >> _TC; while(_TC--)
#define     CS(x) cout << "Case " << x << ": ";
#define     precision(n) cout << fixed << setprecision(n);
#define     Clear(a, b) memset(a, b, sizeof(a))
#define     sq(x) ((x) * 1LL * (x))
#define     eb emplace_back
#define     all(_n) _n.begin(), _n.end()
#define     rall(_n) _n.rbegin(), _n.rend()
#define     endl "\n"
#define     show(x) cout << x << endl
#define     nl cout << endl
#define     sz(x) int(x.size())
#define     gcd(a, b) __gcd(a, b)
#define     lcm(a, b) (abs((a) * (b)) / gcd(a, b))
#define     parity(a, b) ((a&1) ^ (b&1))
#define     make_unique(x) sort(all((x))); (x).erase(unique(all((x))), (x).end())
#define     IN(a) for(auto &it : a) cin >> it

template <typename T> void print (T t){ for(const auto &it : t) cout << it << ' '; nl; }
template <typename T> using OS = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // order_of_key find_by_order

const    double Pi = acos(-1.0);
const    int Mod = 1e9 + 7;
const    int Inf = 1 << 30; // INT_MAX = (1LL << 31) -1 // Inf -> 1e9
const    int Maxx = 1e6 + 10;

/************************************[Code Starts Here]************************************/


void _case()
{
    string s, l, r; cin >> s;
    int q; cin >> q;
    int t, f; char c; bool rev = 0;
     
    while (q--) {
        cin >> t;
        if (t == 1) {
            rev ^= 1;
        } else {
            if (rev) {
                cin >> f >> c;
                if (f == 1) r += c;
                else l = c + l;
            } else {
                cin >> f >> c;
                if (f == 2) r += c;
                else l = c + l;
            }
        }
    }
    string ans = l + s + r;
    if (rev) reverse(all(ans));
    show(ans);
}

int32_t main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    _case();
    return 0;
}




Measured memory_bytes: 1416
import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B

import           Control.Monad.ST
import           Data.Array.IArray
import           Data.Array.MArray
import           Data.Array.ST
import           Data.Array.Unboxed
import           Data.STRef

readi :: B.ByteString -> Int
readi b | Just (n, _) <- B.readInt b = n

solve :: Array Int [Int] -> ST s [Int]
solve grp = do
    clr <- newArray (s, t) False :: ST s (STUArray s Int Bool)
    out <- newSTRef []
    forM_ [s .. t] $ \i -> do
        cv <- readArray clr i
        when (cv == False) $ dfs clr out i
    return =<< readSTRef out
  where
    (s, t) = bounds grp

    dfs :: STUArray s Int Bool -> STRef s [Int] -> Int -> ST s ()
    dfs clr out i = do
        writeArray clr i True
        forM_ (grp ! i) $ \v -> do
            c <- readArray clr v
            when (c == False) $ dfs clr out v
        modifySTRef' out (i :)

main :: IO ()
main = do
    [v, e] <- fmap readi . B.words <$> B.getLine
    xss <- replicateM e $ do
        [a, b] <- fmap readi . B.words <$> B.getLine
        return (a, b)
    let g = accumArray (flip (:)) [] (0, v-1) xss :: Array Int [Int]
    let ans = runST $ solve g
    mapM_ print ans



Measured memory_bytes: 24892
#include <stdio.h>
int main(void)
{
  long long A, B, V, W, X, T, L, M, N;
  scanf("%lld%lld%lld%lld%lld", &A, &V, &B, &W, &T);
  L = A - B;

  if (L < 0)
  {
    M = (-1 * (A - B));
  }
  else
  {
    M = A - B;
  }

  X = (V - W) * T;
  N = M - X;
  if (N <= 0)
  {
    printf("YES\n");
  }
  else
  {
    printf("NO\n");
  }
  return 0;
}


Measured memory_bytes: 1660
#include<bits/stdc++.h>
#define ll long long
#define N 310
using namespace std;
ll C[N][N],f[N][N],s[N][N];
int n,K,mod;
int main(){
    scanf("%d%d%d",&n,&K,&mod); 
    C[0][0]=1;for(int i=1;i<=n;C[i][0]=1,i++)for(int j=1;j<=i;j++)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
    for(int j=0;j<=K;j++)f[1][j]=1,s[1][j]=K-j+1;
    for(int i=2;i<=n+1;i++){
        for(int j=0;j<=K;j++)for(int k=1;k<i;k++)f[i][j]=(f[i][j]+f[i-k][j]*s[k][j+1]%mod*C[i-2][k-1])%mod;  
        for(int j=K;j>=0;j--)s[i][j]=(f[i][j]+s[i][j+1])%mod;
    }
    printf("%lld",f[n+1][0]);           
    return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
	int a[3], k, b = 0;
	for (int i = 0 ; i < 3 ; i++) cin >> a[i];
	cin >> k;
	sort(a, a + 3);
	b = a[2];
	for (int i = 0 ; i < k ; i++) b *= 2;
	cout << a[0] + a[1] + b;  
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in); 
        while(true){
            int x = sc.nextInt();
            int y = sc.nextInt();
            
            if(x == 0 && y == 0){
                break;
            }
            
            if(x > y){
                int temp = x;
                x = y;
                y = temp;
            }
            System.out.println(x + " " + y);
        }
    }
}


Measured memory_bytes: 36284
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
typedef long long ll;
typedef long double ld;
#define rep(i,s,t) for(ll i=s ; i<t ; i++)
//typedef pair<int,int> P;
//typedef pair<int,P> pp;
const int INF = 1e5;
string s[20];
int h,w;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
const ll mod = 1e9+7;
vector<vector<pair<int,int> > > G;
vector<int> color;
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll modinv(ll a, ll mod) {
    return modpow(a, mod - 2, mod);
}
const int MAX = 3000000;
const int MOD = 1000000007;
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(){
  ll x,y; cin >> x >> y;
  if((2*x-y)%3 !=0 || (2*y-x)%3!=0){
    cout << 0 ;
    return 0;
  }
  ll a = (2*x-y)/3, b = (2*y-x)/3;
  COMinit();
  cout << COM(a+b, a) << endl;
  return 0;
}


Measured memory_bytes: 70528
import java.util.*

fun main(args: Array<String>) {

    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    val M = sc.nextInt()
    val list = BooleanArray(M){true}

    for (n in 0 until N) {
        val K = sc.nextInt()
        val l = BooleanArray(M){false}
        for (k in 0 until K) {
            val A = sc.nextInt()
            l[A-1] = true
        }
        for (m in 0 until M) list[m] = list[m]&&l[m]
    }

    println(list.count{it})
}


Measured memory_bytes: 31524
def solve(string):
    # 1-origin
    length = len(string)
    east, west = [0] * (length + 1), [0] * (length + 2)

    for i in range(1, length + 1):
        if string[i - 1] == "W":
            east[i] = east[i - 1] + 1
        else:
            east[i] = east[i - 1]
    for j in range(length, 0, -1):
        if string[j - 1] == "E":
            west[j] = west[j + 1] + 1
        else:
            west[j] = west[j + 1]

    ans = length
    for k in range(1, length + 1):
        ans = min(ans, east[k - 1] + west[k + 1])
    return ans


def main():
    n = int(input())
    string = input()
    ans = solve(string)
    print(ans)


main()


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

int main(void){
  int n, val;
  string com;
  list<int> lst;
  
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> com;
    if (com == "insert") {
      cin >> val;
      lst.push_front(val);
    } else if (com == "delete") {
      cin >> val;
      for (auto itr = lst.begin(); itr != lst.end(); itr++) {
        if (*itr == val) {
          lst.erase(itr);
          break;
        }
      }
    } else if (com == "deleteFirst") {
      lst.pop_front();
    } else if (com == "deleteLast") {
      lst.pop_back();
    }
  }
  
  for (auto itr = lst.begin(); itr != lst.end(); itr++) {
    if (itr != lst.begin()) cout << " ";
    cout << *itr;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 34380
s = 0
comb = 0

def main():
    global s, comb

    while True:
        n, s = map(int, input().split())
        if n == 0 and s == 0:
            break

        comb = 0
        dfs(0, n, 0)
        print(comb)


def dfs(i, num_count, current_sum):
    global comb
    if num_count == 0 and current_sum == s:
        comb += 1
        return
    if i > 9:
        return

    dfs(i + 1, num_count, current_sum)
    dfs(i + 1, num_count - 1, current_sum + i)


if __name__ == '__main__':
    main()

Measured memory_bytes: 7624
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    S=input()
    D=[None,"SAT","FRI","THU","WED","TUE","MON","SUN"]
    print(D.index(S))
resolve()

Measured memory_bytes: 38384