akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 998244353;
const double eps = 1e-8;
const double pi = acos(-1);

ll n, a, b, k;

ll mod_pow(ll x, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = (res * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return res;
}

ll mod_inverse(ll x) {
    return mod_pow(x, mod-2);
}

const int max_n = 300100;
ll fact[max_n];
ll fact_inv[max_n];
void calc_fact() {
    fact[0] = 1;
    for (ll i = 1; i < max_n; i++)
        fact[i] = (fact[i-1] * i) % mod;
    fact_inv[max_n-1] = mod_inverse(fact[max_n-1]);
    for (ll i = max_n-2; i >= 0; i--)
        fact_inv[i] = (fact_inv[i+1] * (i+1)) % mod;
}
ll mod_comb(ll n, ll k) {
    if (n < 0 || k < 0 || n < k) return 0;
    return (fact[n] * fact_inv[k] % mod) * fact_inv[n-k] % mod;
}

ll solve() {
    calc_fact();
    ll res = 0;
    for (ll i = 0; i <= n; i++) {
        ll t = k - a * i;
        if (t >= 0 && t % b == 0) {
            ll j = t / b;
            res += mod_comb(n, i) * mod_comb(n, j);
            res %= mod;
        }
    }
    return res;
}

void input() {
    cin >> n >> a >> b >> k;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int x;
  cin>>x;
 long long int a,b,flag=0;
  for(long long int i=sqrt(x);i>=1;i--){
    if(x%i==0){
      a=i;
      b=x/i;break;}
  }
  long long int sum;
sum=a+b-2;

  cout<<sum;
  return 0;
}
    
  

Measured memory_bytes: 256
a = input()
m = ["01","02","03","04","05","06","07","08","09","10","11","12"]
if a[:2] in m and a[2:] in m:
  print("AMBIGUOUS")
elif a[:2] not in m and a[2:] in m:
  print("YYMM")
elif a[:2] in m and a[2:] not in m:
  print("MMYY")
else:
  print("NA")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()


int main(){
  ll N,ans=0;
  cin >> N;
  vec A(N);
  map<ll,ll> B;
  rep(i,N){
    cin >> A.at(i);
    B[A.at(i)]=i;
  }
  sort(all(A));
  rep(i,N){
    if(B.at(A.at(i))%2!=i%2){
      ans++;
    }
  }
  cout << ans/2 << endl;
}

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

int main(){
    string s;
    cin >> s;
    int count=0;
    rep(i,6){
        if(s[i]=='1'){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
int GCD(int a, int b) {
	return b ? GCD(b, a%b) : a;
}
//sort(a, a + N, greater<int>())   // descend
//sort(a, a+N)                    //  ascend

using ll = long long;
using namespace std;



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

Measured memory_bytes: 256
maisu=int(input())
taro_tokuten=0
hanako_tokuten=0

for i in range(maisu):
    huda=list(map(str,input().split()))
    taro=huda[0]
    hanako=huda[1]
    if taro>hanako:
        taro_tokuten+=3
    elif taro<hanako:
        hanako_tokuten+=3
    else:
        taro_tokuten+=1
        hanako_tokuten+=1

print(str(taro_tokuten)+" "+str(hanako_tokuten))



Measured memory_bytes: 5596
#include<stdio.h>
#include<string.h>
char taro[150];
char hanako[150];
int main(){
int n;
scanf("%d",&n);
int taro_point = 0;
int hanako_point = 0;
for(int i = 0;i<n;i++){
    int count = 0;

    scanf("%s",taro);
    scanf("%s",hanako);

    int len_taro = strlen(taro);
    int len_hanako = strlen(hanako);

   for(int j=0;taro[j] != '\0'  && hanako[j] != '\0'  ;j++){
        if(taro[j]>hanako[j]){
            taro_point += 3;
            break;
        }
        else if(taro[j]<hanako[j]){
            hanako_point += 3;
            break;
        }
        if(taro[j]==hanako[j]){
            count++;
        }
        if(count == len_taro && count==len_hanako){\
            taro_point += 1;
            hanako_point +=1;
        }

        else if(count == len_taro || count == len_hanako){
            if(len_taro>len_hanako){
                taro_point += 3;
            }
            else{
                hanako_point += 3;
            }
        }


    }

}
printf("%d %d\n",taro_point,hanako_point);

return 0;
}



Measured memory_bytes: 2044
#include <climits>
#include <cstring>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <unordered_set>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <fstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define f first
#define s second

#define MM INT_MAX/5
#define MIM INT_MIN/2

int di[] = { 1,-1,0,0 };
int dj[] = { 0,0,1,-1 };

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define v vector
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

#define MAX 1001
#define MOD (int)1000000007
char grid[MAX][MAX];
int DP[MAX][MAX];

int main()
{
	int R, C;
	cin >> R >> C;
	string hold;
	for (int i = 0; i < R; i++)
	{
		cin >> hold;
		for (int j = 0; j < C; j++)
			grid[i][j] = hold[j];
	}
	DP[0][0] = 1;
	for (int j = 0; j < C; j++)
		for (int i = 0; i < R; i++)
		{
			if (i == 0 && j == 0)
				continue;
			if (grid[i][j] == '.') {
				if (i > 0)
					DP[i][j] += (DP[i - 1][j]);
				if (j > 0)
					DP[i][j] += (DP[i][j - 1]);
				DP[i][j] %= MOD;
			}
		}
	cout << DP[R - 1][C - 1];
}


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

const int N = 3e5 + 10;
string s;
int n, m, v, u, degA[N], degB[N], mark[N];
vector<int> adj_matrix[N], que;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin >> n >> m;
	cin >> s;
	for (int i = 0; i < m; i++){
		cin >> v >> u;
		v--;u--;
		
		if(v == u){
			adj_matrix[v].push_back(v);
			degA[v] += (s[v] == 'A');
			degB[v] += (s[v] == 'B');
		}
		else{
			adj_matrix[v].push_back(u);
			adj_matrix[u].push_back(v);
			degA[v] += (s[u] == 'A');
			degB[v] += (s[u] == 'B');
			degA[u] += (s[v] == 'A');
			degB[u] += (s[v] == 'B');
		}
		
	}
	
	for (int i = 0; i < n; i++)
		if(degA[i] == 0 || degB[i] == 0)
			que.push_back(i), mark[i] = true;
	
	int i = 0;
	while(que.size() < n && i < que.size()){
		int v = que[i];
		for (int j : adj_matrix[v]){
			if(mark[j])
				continue;
			degA[j] -= (s[v] == 'A');
			degB[j] -= (s[v] == 'B');
			
			if(degA[j] == 0 || degB[j] == 0)
				que.push_back(j), mark[j] = true;
		}
		i++;
	}
	
	if(que.size() < n)
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 17100
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n = gi();
    ll s = 0;
    for (int i = 1; i <= n; i++)
        if (i%3 && i%5)
            s += i;
    cout << s << endl;

    return 0;
}


Measured memory_bytes: 3780
/*ex5_3
ryo_1129*/
#include<stdio.h>

int main(void){
    int h,w;//行数hと列数wの変数宣言
    scanf("%d %d",&h,&w);//hとwの入力
    char a[h][w];//2次元配列の宣言、マス目
    int i, j;//ループ変数宣言
    //行、列に黒が含まれるかどうかの情報を入れる配列宣言と準備
    int row[h],col[w];
    for(i=0;i < h;i++){
        row[i] = 0;
    }
    for(j=0;j < w;j++){
        col[j] = 0;
    }
    //マスの入力と黒を含む行、列を記録
    for(i=0;i < h;i++){
        for(j=0;j < w;j++){
            scanf(" %c",&a[i][j]);//入力
            //黒が入力された場合その行と列の配列に１を入れる
            if(a[i][j] == '#'){
                row[i] = 1;
                col[j] = 1;
            }
        }
    }
    //マスを圧縮して出力する
    for(i=0;i < h;i++){
        //行に黒が含まれる場合のみ表示する
        if(row[i] == 1){
            for(j=0;j < w;j++){
                //列に黒が含まれる場合のみ表示する
                if(col[j] == 1){
                    printf("%c",a[i][j]);
                }
            }
            printf("\n");//行を出力したら改行
        }
    }
    return 0;
}

Measured memory_bytes: 128
// In the name of God
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <assert.h>
#include <bitset>
#define sqr(a) (a)*(a)
#define all(a) (a).begin(), (a).end()
using namespace std;

template <typename T>
T next_int() {
    T x = 0, p = 1;
    char ch;
    do { ch = getchar(); } while(ch <= ' ');
    if(ch == '-') {
        p = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return p * x;
}

string next_token() {
    char ch;
    string ans = "";
    do { ch = getchar(); } while(ch <= ' ');
    while((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) {
        ans += ch;
        ch = getchar();
    }
    return ans;
}
    
const long long INF = (long long)1e18;
const int INFINT = (int)1e9 + 227 + 1;
const int MAXN = (int)1e5 + 227 + 1;    
const int MOD = (int)1e9 + 7;
const long double EPS = 1e-9;

long long Pow(long long a, long long b) {
    if(!b) return 1;

    long long ans = Pow(a, b / 2);

    ans = ans * ans % MOD;

    if(b % 2) ans = ans * a % MOD;

    return ans;
}

int main() {
    // freopen(".in", "r", stdin);

    int n; cin >> n;

    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++)
        cin >> a[i];

    int ans = 0;
    for(int i = 1; i <= n; i++) 
        if(a[a[i]] == i) ans++;

    cout << ans / 2 << "\n";
}

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

int main(){
    int N; cin >> N;
    vector<vector<int>> dp(N+1, vector<int>(3, 0));
    for(int i=0; i<N; i++){
        int a, b, c; cin >> a >> b >> c;
        if(i==0) {
            dp[i][0] = a;
            dp[i][1] = b;
            dp[i][2] = c;
        }
        else {
            dp[i][0] = max(dp[i-1][1]+a, dp[i-1][2]+a);
            dp[i][1] = max(dp[i-1][0]+b, dp[i-1][2]+b);
            dp[i][2] = max(dp[i-1][0]+c, dp[i-1][1]+c);
        }    
    }
    cout << *max_element(dp[N-1].begin(), dp[N-1].end()) << endl;    
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  int n,h,w;
  cin>>n>>h>>w;
  int l[10010]={};
  for(int i=0;i<w*n;i++){
    if(i%w)continue;
    l[i]++;
  }

  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    l[i*w]--;
    if(i%2)l[i*w-x]++;
    else l[i*w+x]++; 
  }

  int ans=0;
  int cnt=0;
  for(int i=0;i<w*n;i++){
    if(l[i]>0)cnt=w;
    if(cnt>0)cnt--,ans++;
  }

  cout<<(w*n-ans)*h<<endl;
  return 0;
}



Measured memory_bytes: 3152
#include<bits/stdc++.h>
#define  ll   long long int
#define  sz   200010

using namespace std;



int main()
{

    ll n,i,j,k,m,p,d,r;

    cin>>n;
    string s="";

    if(n==0)
    {
        cout<<0<<endl;
        return 0;
    }

    while(n!=0)
    {
        r=n%-2;
        n=n/-2;

        if(r<0)
        {
            r+=2;
            n+=1;
        }

        s+=(r+'0');
    }

    reverse(s.begin(),s.end());

    cout<<s<<endl;

    return 0;
}




Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a=0,b=0;
    cin>>a>>b;
    int upperl=min(int((a+1)*12.5),(b+1)*10);
    int lowerl=max(int(a*12.5),b*10);
    int p=lowerl,flag=0;
    while(p<upperl){
        if(int(p*0.08)==a && int(p*0.1)==b){
            flag=1;
            break;
        }
        p++;
    }
    if(flag==1)
        cout << p;
    else
        cout << "-1";
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

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

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

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return true;
    }
    return false;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return true;
    }
    return false;
}

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

struct edge{
    int cost, to;

    edge(int in_cost, int in_to){
        cost=in_cost;
        to=in_to;
    }
    bool operator<(const edge &a) const
    {
        return cost > a.cost;
    }
};

int K;
int A[100001];
ll judge(ll p){
    ll ret;
    ret=p;

    for(int i=0; i<K; i++){
        ret=ret/A[i]*A[i];
    }
    return ret;
}

int main() {
    cin >>K;
    
    rep(i,K){
        cin >> A[i];
    }

    ll ok=INF,ng=0LL;

    while(ok>ng+1){
        ll m=(ok+ng)/2;
        if(judge(m)>2){
            ok=m;
        }else{
            ng=m;
        }
    }

    ll ok2=INF,ng2=0LL;
    while(ok2>ng2+1){
        ll m=(ok2+ng2)/2;
        if(judge(m)>1){
            ok2=m;
        }else{
            ng2=m;
        }
    }

    if(ok==ok2){
        cout << -1 << endl;
    }else{
        cout << ok2 << " " << ok-1 << endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int a, b, k[100005];
	cin >> a >> b;
	for (int i = 0; i < b; ++i) {
		cin >> k[i];
	}
	if (b == 1) {
		cout << k[0] - 1 << endl;
		return 0;
	}
	sort(k, k + b);
	reverse(k, k + b);
	int mon = k[0];
	for (int i = 1; i < b; ++i) {
		mon -= k[i];
	}
	if (mon <= 0) cout << "0" << endl;
	else cout << mon - 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>

using ll = long long;

int main()
{
    std::string S, T;
    std::cin >> S >> T;
    std::map<char, int> s, t;
    for (int i = 0; i < S.length(); i++)
    {
        s[S[i]]++;
    }
    for (int i = 0; i < T.length(); i++)
    {
        t[T[i]]++;
    }

    for (auto& sp : s)
    {
        for (auto& tp : t)
        {
            if (sp.second == tp.second)
            {
                tp.second = 0;
                break;
            }
        }
    }

    for (auto& tp : t)
    {
        if (tp.second > 0)
        {
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    std::cout << "Yes" << std::endl;
    return 0;
}

Measured memory_bytes: 776
import math
import itertools

while 1:
    try:
        a, b, c, d, e, f = map(int, input().split())
        print('{0:.3f} {1:.3f}'.format((e*c-b*f)/(a*e-b*d)+0, (-d*c+a*f)/(a*e-b*d)+0))
    except:
        break

Measured memory_bytes: 6808
k,t=map(int,input().split())
l=[int(i) for i in input().split()]
if t==1:
    print(l[0]-1)
    exit()
while 1:
    l.sort(reverse=True)
    if l[1]==0: break
    l[0]-=l[1]
    l[1]=0

print(max(0,l[0]-1))

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

#define FIND(c, e) ((c).find(e) != (c).end())
#define NFIND(c, e) ((c).find(e) == (c).end())
#define ALL(t) (t).begin(), (t).end()
#define ALLR(t) (t).rbegin(), (t).rend()
#define MP make_pair

const int N = int( 2e5 ) + 10;
const int M = int( 1e6 ) + 1;
const int MOD = int( 1e9 ) + 7;
const double PI = acos(-1.0);
const double eps = 1e-6;
template<class T> T gcd(T a,T b){while(b){T r=a%b;a=b;b=r;}return a;}
template<class T> T lcm(T a,T b){return (a*b)/gcd(a,b);}
template<class T> T max(T a,T b,T c){return max(max(a,b),c);}
template<class T> T min(T a,T b,T c){return min(min(a,b),c);}

void __answer()
{
    int n, l, r, ans = 0;
    cin >> n;
    while(n--) {
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans;
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cout << setprecision(11) << fixed;
    #ifdef LOCAL
        freopen("TEST.txt", "r", stdin);
    #endif
    __answer();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int t[5] = {0,a,b,c};
	sort(t + 1,t + 3 + 1);
	a = t[1];
	b = t[2];
	c = t[3];
	int ans = 0;
	ans += abs(a - b);
	ans += abs(b - c);
	printf("%d\n",ans);
	return 0;
} 

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

template < unsigned mod >
class Modint
{
public:
        using uint = unsigned;
        using u64 = uint64_t;
        using i64 = int64_t;

        Modint (const i64 dat = 0) : dat(dat >= 0 ? dat % mod : (mod - (-dat) % mod) % mod) {}
        constexpr Modint operator + (const Modint &v) const { return ( Modint(dat + v.dat) ); }
        constexpr Modint operator - () const { return ( Modint(-((i64)dat)) ); }
        constexpr Modint operator - (const Modint &v) const { return ( (*this) + -v ); }
        constexpr Modint operator * (const Modint &v) const { return ( Modint((u64)dat * v.dat) ); }

        constexpr Modint operator ~ () const
        {
                i64 a = dat, b = mod, x1 = 1, x2 = 0, t;
                
                while ( b > 0 ) {
                        t = a / b;
                        swap(a -= t * b, b);
                        swap(x2 -= t * x1, x1);
                }
                
                return ( Modint(x1) );
        }
        
        constexpr Modint operator / (const Modint &v) const { return ( (*this) * ~v ); }

        Modint &operator = (const i64 &v) { return ( (*this) = Modint < mod > (v) ); }
        Modint &operator += (const Modint &v) { return ( (*this) = (*this) + v ); }
        Modint &operator -= (const Modint &v) { return ( (*this) = (*this) - v ); }
        Modint &operator *= (const Modint &v) { return ( (*this) = (*this) * v ); }
        Modint &operator /= (const Modint &v) { return ( (*this) = (*this) / v ); }

        constexpr Modint operator ^ (u64 n) const
        {
                Modint < mod > ret(1), mul(dat);
                while ( n > 0 ) {
                        if ( n & 1 ) ret *= mul;
                        mul *= mul;
                        n >>= 1;
                }
                return ( ret );
        }
        
        bool operator == (const Modint &v) { return ( dat == v.dat ); }
        bool operator != (const Modint &v) { return ( dat != v.dat ); }

        friend ostream& operator << (ostream &os, const Modint &p )
        {
                return ( os << p.dat );
        }
        
        friend istream& operator >> (istream &is, Modint &p )
        {
                i64 data;
                is >> data;
                p = Modint < mod >(data);
                return ( is );
        }

private:
        uint dat;
};

Modint < 1000000007 > dp[2005][2005];
int main()
{
        int N, M;
        int S[2005], T[2005];
        cin >> N >> M;
        
        dp[0][0] = 1;

        for ( int i = 1; i <= N; i++ ) cin >> S[i];
        for ( int i = 1; i <= M; i++ ) cin >> T[i];
        
        for ( int i = 0; i <= N; i++ ) {
                for ( int j = 0; j <= M; j++ ) {
                        if ( i > 0 ) dp[i][j] += dp[i - 1][j];
                        if ( j > 0 ) dp[i][j] += dp[i][j - 1];
                        if ( i > 0 && j > 0 && S[i] != T[j] ) dp[i][j] -= dp[i - 1][j - 1];
                }
        }
        
        cout << dp[N][M] << endl;

        return ( 0 );
}


Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9

int main() {
    int d, g;
    cin >> d >> g;
    vector<int> nums(d);
    vector<int> bonus(d);
    for (int i = 0; i < d; ++i) {
        cin >> nums[i] >> bonus[i];
    }
    int ans = INF;
    for (int mask = 0; mask < (1 << d); ++mask) {
        int tmpMask = mask;
        int last;
        int cnt = 0;
        int curSum = 0;
        for (int i = 0; i < d; ++i) {
            if (tmpMask & 1) {
                curSum += 100 * (i + 1) * nums[i] + bonus[i];
                cnt += nums[i];
            } else {
                last = i;
            }
            tmpMask >>= 1;
        }
        if (curSum >= g) ans = min(cnt, ans);
        else {
            for (int j = 1; j <= nums[last]; ++j) {
                if (curSum + j * 100 * (last + 1) >= g) {
                    cnt += j;
                    ans = min(cnt, ans);
                    break;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

static int speedUp = []() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();

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


int isprime(ll p)
{
	for (int i = 2; i <= sqrt(p); ++i)
	{
		if(p%i==0)
		{
			return 0;
		}
	}
	return 1;
}
int main()
{
   
  
   		int n;
   		cin>>n;

   		int a[n];

   		for (int i = 1; i <=n; ++i)
   		{
   			cin>>a[i];
   		}

   		int dp[n]={0};
   		dp[1]=0;
   		dp[2]=abs(a[2]-a[1]);

   		for (int i = 3; i <=n; ++i)
   		{
   			dp[i]=min(dp[i-1]+abs(a[i-1]-a[i]),dp[i-2]+abs(a[i-2]-a[i]));

   		}

   		cout<<dp[n];
   	
   	
   

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) rep2(i,0,n)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
int a,b,c;
int main()
{
	cin>>a>>b>>c;
	re((a/b+(a%b!=0))*c)
	return 0;}

Measured memory_bytes: 3532
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define all(v) v.begin(),v.end()
#define mem(v,x) memset(v,x,sizeof(v))
#define N 1000005

using namespace std;

ll mod = 1e9+7;
ll power(ll a,ll b){
    ll res = 1;
    while(b){
        if(b&1){
            res = (res*a)%mod;
        }
        a = (a*a)%mod;
        b >>= 1;
    }
    return res;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll ans = 0;
    for(ll i=k;i<n+2;i++){
        ll mn = i*(i-1)/2;
        ll mx = n*(n+1)/2 - (n-i)*(n-i+1)/2;
        ll val = mx-mn+1;
        val = val%mod;
        ans = (ans+val)%mod;
    }
    cout<<ans;
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int solve_time(int a)
{
    if (a % 10 != 0)
    {

        return a + 10 - a % 10;
    }
    else
    {
        return a;
    }
    return 0;
}
int main()
{
    vector<int> ans;
    int a[5];
    for (int i = 0; i < 5; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            if (j != i)
            {
                for (int k = 0; k < 5; k++)
                {
                    if (k != i and k != j)
                    {
                        for (int l = 0; l < 5; l++)
                        {
                            if (l != i and l != j and l != k)
                            {
                                for (int m = 0; m < 5; m++)
                                {
                                    if (m != i and m != j and m != k and m != l)
                                    {
                                        int t_sum = 0;
                                        t_sum += solve_time(a[i]);
                                        t_sum += solve_time(a[j]);
                                        t_sum += solve_time(a[k]);
                                        t_sum += solve_time(a[l]);
                                        t_sum += a[m];
                                        ans.push_back(t_sum);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    int min = *min_element(ans.begin(), ans.end());
    cout << min;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */


int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) b[i] = a[i];
    sort(ALL(a), greater<int>());
    rep(i, n) {
        if(a[0] == b[i]) cout << a[1] << endl;
        else cout << a[0] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3200
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC085
{
    class ProblemA
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine().ToString();
            char[] c = input.ToCharArray();
            if (c[3] == '7')
            {

                c[3] = '8';
                Console.WriteLine(new string(c));
            }
            else
            {
                Console.WriteLine(input);
            }
        }
    }
}


Measured memory_bytes: 11092
#include<stdio.h>
int main(void){
int h,n;
int i;
int a;
scanf("%d%d",&h,&n);
for(i=0;i<n;i++){
scanf("%d",&a);
h-=a;
}
if(h<=0){
    puts("Yes");
}else{
    puts("No\n");
}
}

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

int main(){

	int y, m, d;
	int v[4][3] = {{1868, 9, 8}, {1912, 7, 30}, {1926, 12, 25}, {1989, 1, 8}};
	string str[5] = {"pre-meiji", "meiji", "taisho", "showa", "heisei"};
	
	while(cin >> y >> m >> d){
		for(int i=0; i<4; i++){
			if(y < v[i][0]){
				if(i != 0) cout << str[i] << " " << y - v[i-1][0] + 1 << " " << m << " " << d << endl;
				else cout << str[0] << endl;
				break;
			}
			else if(y == v[i][0]){
				if(m < v[i][1]){
					if(i != 0) cout << str[i] << " " << y - v[i-1][0] + 1 << " " << m << " " << d << endl;
					else cout << str[0] << endl;
					break;
				}
				else if(m == v[i][1] && d < v[i][2]){
					if(i != 0) cout << str[i] << " " << y - v[i-1][0] + 1 << " " << m << " " << d << endl;
					else cout << str[0] << endl;
					break;
				}
			}
			
			if(i == 3) cout << str[4] << " " << y - v[3][0] + 1 << " " << m << " " << d << endl;
		}
	}

	return 0;

}

Measured memory_bytes: 1204
#include <iostream>

int main(int argc, char *argv[]) {
  int a, b, c, k;
  std::cin >> a >> b >> c >> k;
  int sum = 0;
  if (a > k) {
    std::cout << k << std::endl;
    return 0;
  }

  if (a <= k)
    sum += a;

  if (a + b >= k) {
    std::cout << sum << std::endl;
    return 0;
  }

  if (a + b < k)
    sum -= k - (a + b);

  std::cout << sum << std::endl;
}


Measured memory_bytes: 3192
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

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

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=405;
const int mod=1e9+7;

ll n,a[N],sum[N],dp[N][N];
ll rec(int i,int j){
    if(i>=j) return 0;
    ll &cache=dp[i][j];
    if(cache) return cache;
    cache=1e18;
    rep(k,i,j) cache=min(cache,rec(i,k)+rec(k+1,j)+sum[j]-sum[i-1]);
    return cache;
}
signed main(){
    FastIO;
    cin>>n;
    rep(i,1,n){
        cin>>a[i];
        sum[i]=sum[i-1]+a[i];
    }
    cout<<rec(1,n);
    return 0;
}


Measured memory_bytes: 4948
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		 Scanner scan = new Scanner(System.in);
	        int A  = scan.nextInt();
	        int B  = scan.nextInt();
	        int a=0;
	        int b = 0;
	        for(int i= (A<B)?A:B ;i < ((A<B)?B:A);i++) {
	           	if(Math.abs(A-i) == Math.abs(B-i)){

	           		System.out.println(String.valueOf(i));
	           		return ;
	        	}
	        }
	        System.out.println("IMPOSSIBLE");
	}

}


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

int main(){
  string S; cin >> S;
  int result=1000000;
  for(int i=0; i<=S.size()-3; i++){
    result=min(result,abs(stoi(S.substr(i,3))-753));
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  set<ll>::iterator it;
  set<ll>s;
  ll temp,tc,q,x,l,r;
  cin>>tc;
  while(tc--)
  {
    cin>>q;
    if(q==0)
    {
      cin>>temp;
      s.insert(temp);
      cout<<s.size()<<endl;
    }
    else if(q==1)
    {
      cin>>x;
      cout<<s.count(x)<<endl;
    }
    else if(q==2)
    {
      cin>>x;
      s.erase(x);
    }
    else
    {
      cin>>l>>r;
			for(it=s.lower_bound(l);it!=s.upper_bound(r);it++){
			cout<<(*it)<<endl;
    }
  }
}
}



Measured memory_bytes: 12384
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stdbool.h>

#define loop(i,st,en) for(int i=st;i<en;i++)
#define loop0n(i,n) for(int i=0;i<n;i++)


int main() {
  int M=0,N=0,Q=0;
  int abcd[60][4]={0};
  int A[11]={0};
  int max=0,point=0;
  scanf("%d %d %d",&N,&M,&Q);
  loop0n(i,Q){
    scanf("%d %d %d %d",&abcd[i][0],&abcd[i][1],&abcd[i][2],&abcd[i][3]);
  }

  loop(i,1,M+1){
    loop(j,i,M+1){
      loop(k,j,M+1){
        loop(l,k,M+1){
          loop(m,l,M+1){
            loop(n,m,M+1){
              loop(o,n,M+1){
                loop(p,o,M+1){
                  loop(q,p,M+1){
                    loop(r,q,M+1){
                      A[1]=i;
                      A[2]=j;
                      A[3]=k;
                      A[4]=l;
                      A[5]=m;
                      A[6]=n;
                      A[7]=o;
                      A[8]=p;
                      A[9]=q;
                      A[10]=r;
                      loop0n(i,Q){
                        if((A[abcd[i][1]]-A[abcd[i][0]])==abcd[i][2]){
                          point += abcd[i][3];
                        }
                      }
                      if(point>max){
                        max=point;
                      }
                      point=0;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }

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

Measured memory_bytes: 1728
#include<stdio.h>
int main ()
{
    int A,B,N;
    scanf ("%d %d %d",&N,&A,&B);
    if (N>=1&&N<=20&&A>=1&&N<=50&&B>=1&&B<=50)
    {
        if ((N*A)<B)
        {
            printf ("%d\n",N*A);
        }
        else
        {
            printf ("%d\n",B);
        }
    }
    return 0;
}


Measured memory_bytes: 1700
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x)
#define abs(x,y) (max(x,y)-min(x,y))
#define mp make_pair
#define fi first
#define se second
using namespace std;
int i[111111];
vector<int> ii;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=1,e=0,f=0,g=0,h,j;
  string s;
  cin >>a>>b;
  for(int n=0;n<a;n++){
    if(d*2<d+b) d=d*2;
    else d+=b;
  }
  cout <<d<<'\n';
  return (0);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 4000
typedef pair<int,int> P;

struct Edge{
	Edge(int arg_to,int arg_capacity,int arg_cost,int arg_rev_index){
		to = arg_to;
		capacity = arg_capacity;
		cost = arg_cost;
		rev_index = arg_rev_index;
	}

	int to,capacity,cost,rev_index;
};

struct Info{
	int A,B;
};

int V;
int value_index[2000],wood_index[1000];
vector<Edge> G[NUM];
int dist[NUM];
int pre_node[NUM],pre_edge[NUM];
Info info[1000];
int h[NUM];


void add_edge(int from,int to,int capacity,int cost){
	G[from].push_back(Edge(to,capacity,cost,G[to].size()));
	G[to].push_back(Edge(from,0,-cost,G[from].size()-1));
}

int min_cost_flow(int source,int sink,int flow){
	int ret = 0;
	for(int i = 0; i < V; i++)h[i] = 0;
	while(flow > 0){
		priority_queue<P,vector<P>,greater<P>> Q;
		for(int i = 0; i < V; i++)dist[i] = BIG_NUM;
		dist[source] = 0;
		Q.push(P(0,source));

		while(!Q.empty()){
			P p = Q.top();
			Q.pop();
			int node_id = p.second;
			if(dist[node_id] < p.first)continue;
			for(int i = 0; i < G[node_id].size(); i++){
				Edge &e = G[node_id][i];
				if(e.capacity > 0 && dist[e.to] > dist[node_id]+e.cost+h[node_id]-h[e.to]){
					dist[e.to] = dist[node_id]+e.cost+h[node_id]-h[e.to];
					pre_node[e.to] = node_id;
					pre_edge[e.to] = i;
					Q.push(P(dist[e.to],e.to));
				}
			}
		}

		if(dist[sink] == BIG_NUM){
			return -1;
		}

		for(int node_id = 0; node_id < V; node_id++)h[node_id] += dist[node_id];

		int tmp_flow = flow;
		for(int node_id = sink; node_id != source; node_id = pre_node[node_id]){
			tmp_flow = min(tmp_flow,G[pre_node[node_id]][pre_edge[node_id]].capacity);
		}
		flow -= tmp_flow;
		ret += tmp_flow*h[sink];
		for(int node_id = sink; node_id != source; node_id = pre_node[node_id]){
			Edge &e = G[pre_node[node_id]][pre_edge[node_id]];
			e.capacity -= tmp_flow;
			G[node_id][e.rev_index].capacity += tmp_flow;
		}
	}
	return ret;
}

int main(){

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

	vector<int> VALUE;

	int source = 0,sink = 1,index = 2;

	for(int i = 0; i < N; i++){
		scanf("%d %d",&info[i].A,&info[i].B);
		VALUE.push_back(info[i].A);
		VALUE.push_back(info[i].B);
	}

	sort(VALUE.begin(),VALUE.end());
	VALUE.erase(unique(VALUE.begin(),VALUE.end()),VALUE.end());

	for(int i = 0; i < VALUE.size(); i++){
		value_index[i] = index++;
		add_edge(source,value_index[i],1,0);
	}

	for(int i = 0; i < N; i++){
		wood_index[i] = index++;
		add_edge(wood_index[i],sink,1,0);
	}

	for(int i = 0; i < VALUE.size(); i++){
		for(int k = 0; k < N; k++){
			if(info[k].A == VALUE[i]){
				add_edge(value_index[i],wood_index[k],1,-info[k].B);
			}
			if(info[k].B == VALUE[i]){
				add_edge(value_index[i],wood_index[k],1,-info[k].A);
			}
		}
	}

	add_edge(source,sink,2010,0);

	V = index;

	printf("%d\n", -min_cost_flow(source,sink,2010));

	return 0;
}



Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
char s[111111];
int len;
int main(){
	cin>>s + 1;
	len = strlen(s + 1);
	if(len == 1){
		puts("0");
		return 0;
	}
	for(int i = 1;i <= len; i++)s[i] -= '0';
	int ans = len, sum = 0;
	for(int i = 1;i <= len; i++){
		int now = i & 1;
		if(now != s[i])sum++;
	}
	ans = sum;
	sum = 0;
	for(int i = 1;i <= len; i++){
		int now = i & 1;
		if(now == s[i])sum++;
	}
	ans = min(ans, sum);
	printf("%d\n", ans);
	return 0;
} 

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

int main(void){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    string  s = "Yes";
    if(min(abs(a-b), abs(a-c)) > d || min(abs(c-a), abs(c-b)) > d){
        s = "No";
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void solve()
{
   string s;
   cin>>s;
   bool a,b,c;
   //cehck reverse
   string rev=s;
   reverse(rev.begin(),rev.end());
   if(rev==s)
   {
   	 a=true;
   }
   else
   {
   	 a=false;
   }
  int n=s.size();
   string tb=s.substr(0,(n-1)/2);
   string bt=tb;
   reverse(bt.begin(),bt.end());
   if(bt==tb)
   	  b=true;
   else
   	  b=false;
   tb=s.substr(((n+3)/2)-1);
     bt=tb;
   reverse(bt.begin(),bt.end());
   if(bt==tb)
   	  c=true;
   else
   	  c=false;

   if(a&&b&&c)
   	 {
   	 	cout<<"Yes";

   	 }
   	 else
   	 {
   	 	 cout<<"No";
   	 }
   
}
main()
{
int t;
t=1;
while(t--)
{
solve();

}
}

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

namespace AtCoder
{
    class Program
    {
        private static int[][] Solve(int H, int W, int h, int w)
        {
            if (h * w == 1) { return null; }
            int[][] matrix = new int[H][];
            long sum = 0;
            int n = 999999999 / (h * w - 1);
            for (int i = 0; i < H; ++i)
            {
                matrix[i] = new int[W];
                for (int j = 0; j < W; ++j)
                {
                    int value = (i % h == h - 1 && j % w == w - 1) ? -1000000000 : n;
                    matrix[i][j] = value;
                    sum += value;
                }
            }
            return (sum > 0) ? matrix : null;
        }
        static void Main(string[] args)
        {
            int[] values = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            var matrix = Solve(values[0], values[1], values[2], values[3]);
            if (matrix != null)
            {
                Console.WriteLine("Yes");
                foreach (int[] row in matrix) { Console.WriteLine(string.Join(" ", row)); }
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 36948
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001




int main() {
    int N; cin >> N;
    vector<int> V(N);
    for(int &i:V){
        cin >> i;
    }
    
    sort(V.begin(), V.end());
    int s = V[N/2 - 1];
    int e = V[N/2];
    
    cout << e - s << endl;
    
    
    return 0;
}



Measured memory_bytes: 768
#include<stdio.h>
#include<string.h>
int main(){
	char s[1000];
	int flag=0;
	scanf("%s",&s);
	for(int i=0;i<strlen(s);i++){
		if(s[i]=='9'){
			flag=1;
			printf("Yes\n");
			break;
		}
	}
	if(!flag) printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define pb push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr double eps = 1e-14; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int N;
    cin >> N;
    int a=0;
    rep(i,N){
        string s;
        cin >> s;
        if(s=="A"){
            a++;
        }else{
            a--;
        }
        if(a<0){
            cout << "NO" << endl;
            return 0;
        }
    }
    if(a==0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3144
/**
 *    author:  FromDihPout
 *    created: 2020-07-31
**/

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    deque<int> a;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if ((i % 2) ^ (n % 2)) {
            a.push_front(x);
        }
        else {
            a.push_back(x);
        }
    }
    
    while (!a.empty()) {
        cout << a.front() << ' ';
        a.pop_front();
    }
    cout << '\n';
    
    
    return 0;
}

Measured memory_bytes: 4368
n = gets.chomp.to_i

a = []
sort = []

for i in 1..n do
    line = gets.chomp.to_i
    a.push(line)
    sort.push(line)
end

sort.sort!.reverse!
max1 = sort[0]
max2 = sort[1]

for i in 1..n do 
    if a[i-1] == max1
        puts max2
    else
        puts max1
    end
end

Measured memory_bytes: 8556
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <tuple>

using lint = long long;

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Edges = std::vector<Edge<Cost>>;

template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

struct UnionFind {
    std::vector<int> par, sz;
    int gnum;

    explicit UnionFind(int n)
        : par(n), sz(n, 1), gnum(n) {
        std::iota(par.begin(), par.end(), 0);
    }

    int find(int v) {
        return (par[v] == v) ? v : (par[v] = find(par[v]));
    }

    void unite(int u, int v) {
        u = find(u), v = find(v);
        if (u == v) return;

        if (sz[u] < sz[v]) std::swap(u, v);
        sz[u] += sz[v];
        par[v] = u;
        --gnum;
    }

    bool same(int u, int v) { return find(u) == find(v); }
    bool ispar(int v) { return v == find(v); }
    int size(int v) { return sz[find(v)]; }
};

void solve() {
    int n;
    lint d;
    std::cin >> n >> d;

    std::vector<lint> xs(n);
    for (auto& x : xs) std::cin >> x;

    MinHeap<Edge<lint>> heap;
    std::queue<std::pair<int, int>> que;
    que.emplace(0, n);

    while (!que.empty()) {
        int l, r;
        std::tie(l, r) = que.front();
        que.pop();
        if (r - l <= 1) continue;

        // 区間を分割
        int m = (l + r) / 2;
        que.emplace(l, m);
        que.emplace(m, r);

        // 左右で最もコストが小さい頂点を探す
        int li = l;
        for (int i = l + 1; i < m; ++i) {
            if (xs[i] - i * d < xs[li] - li * d) li = i;
        }
        int ri = m;
        for (int i = m + 1; i < r; ++i) {
            if (xs[i] + i * d < xs[ri] + ri * d) ri = i;
        }

        // 辺を追加
        for (int i = l; i < m; ++i) {
            heap.emplace(i, ri, xs[i] + xs[ri] + (ri - i) * d);
        }
        for (int i = m; i < r; ++i) {
            heap.emplace(li, i, xs[li] + xs[i] + (i - li) * d);
        }
    }

    // Kruskal
    lint ans = 0;
    UnionFind uf(n);
    while (!heap.empty()) {
        auto e = heap.top();
        heap.pop();

        if (uf.same(e.src, e.dst)) continue;
        ans += e.cost;
        uf.unite(e.src, e.dst);
    }

    std::cout << ans << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}


Measured memory_bytes: 69472
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        try (Scanner sc = new Scanner(System.in)) {
            int w = sc.nextInt();
            int n = sc.nextInt();
            int[] values = new int[w];
            for(int i = 0; i < values.length; i++){
                values[i]=i+1;
            }
            for(int i = 0; i < n; i++){
                String str = sc.next();
                String[] ab = str.split(",");
                int a = Integer.parseInt(ab[0])-1;
                int b = Integer.parseInt(ab[1])-1;
                int c = values[a];
                values[a]=values[b];
                values[b]=c;
            }
            for(int i = 0; i < values.length; i++){
                System.out.println(values[i]);
            }
        }
    }
}



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

using namespace std;

int n, score[3005];
long long dp[3005][3005];

long long solve(int l, int r) {
    if (dp[l][r] != -1) return dp[l][r];
    if (l > r) return 0;

    int turn = l + n - 1 - r;

    if ((turn & 1) == 0) {
        return dp[l][r] = max(solve(l + 1, r) + score[l], solve(l, r - 1) + score[r]);
    }
    else {
        return dp[l][r] = min(solve(l + 1, r) - score[l], solve(l, r - 1) - score[r]);
    }
}

int main() {
    scanf("%d", &n);

    for (int i = 0; i < n; i++) scanf("%d", &score[i]);

    memset(dp, -1, sizeof(dp));

    printf("%lld\n", solve(0, n - 1));
}


Measured memory_bytes: 70912