akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

template <unsigned long long mod> class modint {
public:
	unsigned long long v;
	modint(const long long x = 0) : v(x % mod) {}
	modint operator+(const modint rhs) { return modint(*this) += rhs; }
	modint operator-(const modint rhs) { return modint(*this) -= rhs; }
	modint operator*(const modint rhs) { return modint(*this) *= rhs; }
	modint operator/(const modint rhs) { return modint(*this) /= rhs; }
	modint operator-() { return modint(mod - this->v); }
	modint& operator+=(const modint rhs) {
		v += rhs.v;
		if (v >= mod) v -= mod;
		return *this;
	}
	modint& operator-=(const modint rhs) {
		if (v < rhs.v) v += mod;
		v -= rhs.v;
		return *this;
	}
	modint& operator*=(const modint rhs) {
		v = v * rhs.v % mod;
		return *this;
	}
	modint inverse(modint a) {
		unsigned long long exp = mod - 2;
		modint ret(1ULL);
		while (exp) {
			if (exp % 2) { ret *= a; }
			a *= a;
			exp >>= 1;
		}
		return ret;
	}
	modint& operator/=(modint rhs) {
		(*this) *= inverse(rhs);
		return *this;
	}
	friend ostream& operator<<(ostream& os, modint& u) {
		os << u.v;
		return (os);
	}
	friend istream& operator>>(istream& is, modint& u) {
		is >> u.v;
		return (is);
	}
};

const int MOD = 1000000007;
using mint = modint<MOD>;

const int MAX = 1000005;
mint fact[MAX], invfact[MAX], inv[MAX];

void facinit() {
	fact[0] = fact[1] = 1;	
	invfact[0] = invfact[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++){
		fact[i] = fact[i - 1] * i;
		inv[i] = - inv[MOD%i] * (MOD / i);
		invfact[i] = invfact[i - 1] * inv[i];
	}
}

class Solution {
public:
	void solve() {
		int n;
		cin >> n;
		facinit();
		vector<int> a(n, 0);
		for(int i=0; i<n; i++)cin >> a[i];
		mint ans{0};
		mint x{0};
		for(int i = 0; i < n-1; i++){
			x += inv[i+1];
			ans += x * (a[i+1] - a[i]);
		}
		ans *= fact[n-1];
		cout << ans << "\n";
		
		
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

typedef long long ll;

int n, k, dp[205][2], f1[205][2], f2[205][2];
char str[205];

void DP(char *str, int n) {
  memset(dp, 0, sizeof dp);
  dp[1][0] = 0, dp[1][1] = 1;
  for (int i = 2; i <= n; i++) {
    if (str[i] == str[i - 1]) {
      dp[i][0] = min(dp[i - 1][1], dp[i - 1][0] + 1);
      dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]) + 1;
    } else {
      dp[i][1] = (dp[i][0] = min(dp[i - 1][0], dp[i - 1][1])) + 1;
    }
  }
}

int main() {
  scanf("%s %d", str + 1, &k);
  n = strlen(str + 1);
  if (n == 1) {
    printf("%lld", 1ll * k / 2);
    return 0;
  }
  int pl = 1;
  while (pl < n && str[pl + 1] == str[pl]) pl++;
  int pr = n;
  while (pr > 1 && str[pr - 1] == str[pr]) pr--;
  if (pl == n) {
    printf("%lld\n", 1ll * k * n / 2);
    return 0;
  }
  ll ans = 0;
  DP(str, n);
  memcpy(f1, dp, sizeof dp);
  for (int i = n + 1; i <= n + pl; i++) {
    str[i] = str[n - i];
  }
  DP(str + pl, n);
  memcpy(f2, dp, sizeof dp);
  ans = 1ll * min(f1[n][0], f1[n][1]) * k;
  if (k == 1) {
    printf("%lld\n", ans);
    return 0;
  }
  if (str[1] == str[n]) {
    if (f1[n][0] >= f1[n][1]) {
      
    } else {
      if ((pl + n - pr + 1) % 2 == 0) {
        ans += k - 1;
      } else {
        ans = min(f1[pr - 1][0], f1[pr - 1][1]);
        ans += (n - pr + 1) / 2;
        k--;
        ans += 1ll * k * min(f2[n][0], f2[n][1]);
      }
    }
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 256
v=[[2e9,s=1]]
`sort -nr`.lines{|e|x,d=e.split.map &:to_i
d&&(r=1
r*=v.pop[1]while v[-1][0]<x+d
v<<[x,r+1])}
v.map{|_,y|s*=y}
p s%998244353

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

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

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

template<typename T>
void cmpmax(T& reference, T value) {
	reference = max(reference, value);
}

template<typename T>
void cmpmin(T& reference, T value) {
	reference = min(reference, value);
}

const ll mod = 1000000007;

static const ll INF = 1e15;

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

	//dp[i][j]...iからjまでのデータに対するX-Yの値
	//dp[i][j]
	//奇数の番の場合...max(dp[i+1][j] + as[i], dp[i][j-1] + as[j])
	//偶数の番の場合...min(dp[i+1][j] - as[i], dp[i][j-1] - as[j])

	vector<vector<ll>> dp(n, vector<ll>(n, INF));
	ll sign = n % 2 ? 1 : -1;
	rep(i, n) {
		dp[i][i] = sign * as[i];
	}
	for (int length = 2; length <= n; length++) {
		for (int left = 0; left <= n - length; left++) {
			int right = left + length - 1;
			bool turn = (n - (right + 1 - left)) % 2;
			if (!turn) {
				ll c1 = dp[left + 1][right] + as[left];
				ll c2 = dp[left][right-1] + as[right];
				dp[left][right] = max(c1, c2);
			}
			else {
				ll c1 = dp[left + 1][right] - as[left];
				ll c2 = dp[left][right - 1] - as[right];
				dp[left][right] = min(c1, c2);
			}
		}
	}
	cout << dp[0][n - 1] << endl;
	return 0;
}
	


Measured memory_bytes: 70784
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf = 1e9;

int N;
pair<pair<int,int>,bool>  RB[220];
bool rr[110], bb[110];
int main(){
    cin>>N;
    REP(i,0,2*N){
        int a,b;
        cin>>a>>b;
        RB[i]={{a,b},i>=N};
    }
    sort(RB,RB+2*N);

    int ans=0;
    int r=0,b=0;
    vector<int> vt;
    REP(i,0,2*N) {
        if(!RB[i].S){
            vt.push_back(RB[i].F.S);
            sort(vt.begin(),vt.end());
        }
        if(RB[i].S){
            RREP(j,0,vt.size()){
                if(RB[i].F.S>vt[j]){
                    ans++;
                    vt.erase(vt.begin()+j);
                    break;
                }
            }

        }
    }
    p(ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define loop(i,N) for(int i=0; i<(N); i++)
template<typename T>
auto input(int N) {
    std::vector<T> v(N);
    loop(i,N) std::cin >> v[i];
    return std::move(v);
}

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

    cout << (N-2)/(K-1) + 1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
int main(void){
    int n,i=0;
    char s[101];
    scanf("%d %s",&n,s);
    while(i<n && i<strlen(s)){
        printf("%c",s[i]);
        i++;
    }
    if(n<strlen(s)) printf("...");
}

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


int main() {
    int n,m;
    cin >> n >> m;
    priority_queue<ll, vector<ll>, greater<ll>> a;
    for(int i=0; i<n; i++){
        int x;
        cin >> x;
        a.push(x);
    }
    vector<pair<ll,ll>> bc (m);
    for(int i=0; i<m; i++){
        int b,c;
        cin >> b >> c;
        bc.at(i) = make_pair(c,b);
    }
    sort(bc.begin(),bc.end());
    reverse(bc.begin(),bc.end());
    for(int i=0; i<m; i++){
        for(int j=0; j<bc.at(i).second; j++){
            int mi = a.top();
            if(mi >= bc.at(i).first) break;
            a.pop();
            a.push(bc.at(i).first);
        }
    }
    ll ans = 0;
    while(!a.empty()){
        ans += a.top();
        a.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 2676
/*
// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
*/
/*
*/
#include <bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> ii;
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    //let's fuck dp
    int n,k;
    cin>>n>>k;
    if(k>((n-1)*(n-2))/2)
    {
        cout<<-1<<endl;
    }
    else
    {
        set<pair<int,int>>st;
        for(int i=1;i<n;i++)
        {
            for(int j=i+1;j<=n;j++)
            {
                st.insert({i,j});
            }
        }
        int cnt=0;
        while(cnt<k)
        {
            auto itr=st.rbegin();
            st.erase({itr->ff,itr->ss});
            cnt++;
        }
        cout<<(int)st.size()<<endl;
        for(auto itr:st)
        {
            cout<<itr.ff<<" "<<itr.ss<<endl;
        }
    }
}



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

using namespace std;

#define INF 1e9
#define ll long long
#define vi vector<int>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

int N;

bool is_harshad(){
    int buff = N, digit_sum = 0;
    
    while(true){
        digit_sum += buff % 10;
        buff = buff / 10;
        if(buff==0) break;
    }

    if (N % digit_sum == 0) return true;
    else return false;
}

int main(){
    cin >> N;

    if(is_harshad()) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main(){
  string s;
  cin >> s;
  vector<string> hoge = { "SUN","MON","TUE","WED","THU","FRI","SAT"};
  auto itr = find(hoge.begin(), hoge.end(), s);
  cout << 7 - (itr - hoge.begin()) << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N + 1];
        long[] x = new long[N + 1];
        long[] y = new long[N + 1];
        // long xmax = 0;
        for (int i = 0; i < N; i++) {
            A[i + 1] = sc.nextInt();
            if (A[i + 1] + (i + 1) <= N) {
                x[A[i + 1] + (i + 1)]++;
            }
            // if (A[i + 1] + (i + 1) > xmax) {
            //     xmax = A[i + 1] + (i + 1);
            // }
            if ((i + 1) - A[i + 1] >= 0) {
                y[(i + 1) - A[i + 1]]++;
            }
        }
        long ans = 0;
        for (int i = 0; i < N; i++) {
            ans += x[i] * y[i];
        }

        System.out.println(ans);

        sc.close();

    }

}

Measured memory_bytes: 62956
N = int(input())
F = [list(map(int,input().split())) for _ in range(N)]
P = [list(map(int,input().split())) for _ in range(N)]
ans = -(10**9)
for i in range(1,2**10):
    a = [(i>>j)&1 for j in range(10)]
    tmp = 0
    for j in range(N):
        tmp += P[j][sum(a[k]*F[j][k] for k in range(10))]
    ans = max(ans,tmp)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
int fact[200001] = {0};

ll mpow(ll x, int n) {
    ll ans = 1;
    while (n > 0) {
        if (n & 1) ans = (ans * x) % MOD;
        x = (x * x) % MOD;
        n >>= 1;
    }
    return ans;
}

ll combi(int n, int r){
    ll ans = (fact[n] * mpow(fact[n-r], MOD-2)) % MOD;
    ans = ans * mpow(fact[r], MOD-2) % MOD;
    return ans;
}

int main() {
    int n, k;
    cin >> n >> k;
    fact[0] = 1;
    for (ll i = 1; i <= 200000;i++) {
        fact[i] = (fact[i-1] * i) % MOD;
    }
    ll l = min(k, n - 1);
    ll ans = 0;
    for(int i = 1; i <= l; ++i){
        ans += ((combi(n - 1, i) * combi(n, i))) % MOD;
    }
    cout << (ans+1) % MOD << endl;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
   int a,b,c;
   cin>>a>>b>>c;
   if(a==5 and b==5 and c==7)
  cout<<"YES";
  
   else if(a==5 and b==7 and c==5)
   cout<<"YES";
  
   else if(a==7 and b==5 and c==5)
 cout<<"YES";
   
   else
    cout<<"NO";
   
 
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    int N, a;
    cin >> N;
    vector<int> A;
    for (int i = 0; i < N; ++i)
    {
        cin >> a;
        A.push_back(a);
    }
    sort(A.begin(), A.end());
    int alice = 0;
    int bob = 0;
    
    for(int i = 0; i < N; i += 2){
        if(N % 2 == 0) {
            bob += A[i];
            alice += A[i+1];
        } else {
            alice += A[i];
            bob += A[i+1];
        }
    }

    cout << alice - bob << endl;

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

int main()
{
    int h, w;
    cin >> h >> w;

    vector<string> s(h+2, string(w+2, '.'));
    for(int i=1; i<=h; ++i){
        for(int j=1; j<=w; ++j){
            cin >> s[i][j];
        }
    }

    for(int y=1; y<=h; ++y){
        for(int x=1; x<=w; ++x){
            if(s[y][x] == '.')
                continue;
            
            int ok = false;
            for(int i=0; i<4; ++i){
                int y2 = y + dy[i];
                int x2 = x + dx[i];
                if(s[y2][x2] == '#'){
                    ok = true;
                    break;
                }
            }

            if(!ok){
                cout << "No" << endl;
                return 0;
            }
        }
    }

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


Measured memory_bytes: 384
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL =long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 9; //924844033 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans,dp[20000], a[20000], b[20000];
string str, ss;
bool f;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<Edge>vec[20000];
vector<edge>ed;
vector<LL>v;
map<string,LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main() {
	cin >> n;
	cin >> h >> w;
	rep(i, n) {}
	cout << (n-h+1)*(n-w+1) << endl;
	return 0;
}

Measured memory_bytes: 768
x,n = [int(x) for x in input().split()]
p = set([int(x) for x in input().split()])


l,r = x,x
while True:
  if l not in p:
    print(l)
    exit()
  elif r not in p:
    print(r)
    exit()

  l-=1
  r+=1

Measured memory_bytes: 9036
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main() {
	int k;
	string s;
	cin >> k;
	cin >> s;
	if (s.size() <= k) {
		cout << s << endl;
	}
	else {
		for (int i = 0; i < k; i++) {
			cout << s[i];
		}
		cout << "..." << endl;
	}
	return 0;
}

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

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

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARINGS
#include <iostream>
#include <iomanip>
#include <map>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <fstream>
#include <map>
#include <unordered_map>

using namespace std;
typedef int me;
typedef long long ll;
typedef unsigned long long ull;

#define andrew ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define sz(v) (int)(v.size())
#define all(v) v.begin(), v.end()
#define PI 3.1415926535
#define sin(i) (long double)sin(i *PI / 180.0)
#define cos(i) (long double)cos(i * PI/ 180.0)

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ull lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int dy8[] = { 0, 0, 1, -1, 1, -1, -1, 1 };
int dx8[] = { 1, -1, 0, 0, 1, -1, 1, -1 };
int id8[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
struct happ
{
    int a, b, c;
};
int n;
vector<happ>v;
ll mem[100005][4];
ll solve(int i, int last)
{
    if (i == n+1)
        return 0;

    ll& ret = mem[i][last];
    
    if (ret != -1)
        return ret;

    if (last != 1)
        ret = max(ret, solve(i + 1, 1) + v[i].a);
    if (last != 2)
        ret = max(ret, solve(i + 1, 2) + v[i].b);
    if (last != 3)
        ret = max(ret, solve(i + 1, 3) + v[i].c);

    return ret;
}
int main()
{
    andrew;
    cin >> n;
    v.resize(n + 1);

    for (int i = 1; i <= n; i++)
        cin >> v[i].a >> v[i].b >> v[i].c;

    for (int i = 0; i < 100005; i++)
        for (int j = 0; j < 4; j++)
            mem[i][j] = -1;

    cout << solve(0, 0) << endl;



}


Measured memory_bytes: 15308
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD

H,N = imn()
AB = [iln() for _ in range(N)]
MAX_H = 10**4+1
dp = [10**10 for _ in range(MAX_H)]
dp[0] = 0

for i in range(N):
    for j in range(MAX_H):
        if j - AB[i][0] >= 0:
            dp[j] = min(dp[j], dp[j-AB[i][0]]+AB[i][1])
ans = 10 ** 10
for i in range(H, MAX_H):
    ans = min(ans, dp[i])
print(ans)



Measured memory_bytes: 72024
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <map>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}

int n;

int main(){
    int a,b;
    char op;
    
    cin >> a >> op >> b;
    
    if(op == '+') cout << a+b << endl;
    else cout << a-b << endl;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n, d;
    cin >> n >> d;
    cout << (n + 2 * d) / (2 * d + 1) << endl;
}

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

int dp[1001][1001];
string str1, str2;
int n;

int solve(string str1, string str2) {
  memset(dp, 0, sizeof(dp));
  for(int r = 0; r < str2.size(); r++) {
    for(int c = 0; c < str1.size(); c++) {
      if(str2[r] == str1[c]) {
        dp[r + 1][c + 1] = dp[r][c] + 1;
      }
      else {
        dp[r + 1][c + 1] = max(dp[r + 1][c], dp[r][c + 1]);
      }
    }
  }
  return dp[str2.size()][str1.size()];
}

int main() {
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> str1 >> str2;
    cout << solve(str1, str2) << endl;
  }
}



Measured memory_bytes: 7108
#include <stdio.h>

int main()
{
  int i,n;
  int a[20], b[20], c[20];
  int pts=0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  for (i = 0; i < n; i++) scanf("%d", &b[i]);
  for (i = 0; i < n-1; i++) scanf("%d", &c[i]);
  pts=b[a[0]-1];
  for (i = 1; i < n; i++){
    pts+=b[a[i]-1];
    if(a[i]-a[i-1]==1) pts+=c[a[i-1]-1];
  }
  printf("%d\n",pts);  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#define int long long
#define MOD 1000000007
using namespace std;

int n,k,dp[110][110][2010],sum[110][2010];

signed main()
{
    cin>>n>>k;
    int p=1;
    for(int i=1;i<=n;i++){
    	for(int j=0;j<=k;j++){
    		for(int l=0;l<=2000;l++){
    			if(j>i){
    				dp[i][j][l]=sum[i-1][l]+(((l+j)*p)%MOD);
    				dp[i][j][l]%=MOD;
				}
				else{
					int val=j+l;
					int num=val/i,rem=val%i;
					if(l+num<=2000){
    					dp[i][j][l]=sum[i-1][l+num]+((rem*p)%MOD);
    					dp[i][j][l]%=MOD;
    				}
				}
    		}
    		for(int l=0;l<=2000;l++){
    			sum[i][l]+=dp[i][j][l];
    			sum[i][l]%=MOD;
    		}
    	}
    	p*=(k+1);
    	p%=MOD;
    }
    cout<<sum[n][0]<<endl;
	return 0;
}

Measured memory_bytes: 177792
// {{{ include
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
// }}}

using namespace std;

typedef long long ll;
inline int in(){int x;scanf("%d",&x);return x;}

int key[128];

char getPrev(char C, int p) {
  const string table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  return table[(table.find(C) + table.size() - p) % table.size()];
}

int main()
{
  int N;
  while (N = in()){
    for (int i = 0; i < N; i++) key[i] = in();
    string S;
    cin >> S;
    for (int i = 0, i_len = S.size(); i < i_len; i++){
      putchar(getPrev(S[i], key[i % N]));
    }
    puts("");
  }

  return 0;
}

Measured memory_bytes: 1208
n = int(input())
s = list(input())

r = s.count('R')
g = s.count('G')
b = s.count('B')

# 1つ目の条件を満たす組の数
ans = r * g * b

# 2つ目の条件を満たす組の数
c = 0
for i in range(n):
    for j in range(i+1,n):
        k = 2 * j -i
        if k > n-1:
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            c += 1

print(ans - c)

Measured memory_bytes: 68200
#include <iostream>
#include <math.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = (ll)1 << 62;

ll a[500][500] = {};
struct pos {
	ll y1;
	ll x1;
	ll y2;
	ll x2;
};
vector<pos> v;

int main() {
	ll h, w; cin >> h >> w;
	rep(i, 0, h)rep(j, 0, w) cin >> a[i][j];

	rep(i, 0, h) {
		rep(j, 0, w - 1) {
			if (a[i][j] & 1) {
				a[i][j + 1]++;
				pos p;
				p.y1 = i + 1;
				p.x1 = j + 1;
				p.y2 = i + 1;
				p.x2 = j + 2;
				v.push_back(p);
			}
		}
	}
	rep(i, 0, h - 1) {
		if (a[i][w - 1] & 1) {
			a[i + 1][w - 1]++;
			pos p;
			p.y1 = i + 1;
			p.x1 = w;
			p.y2 = i + 2;
			p.x2 = w;
			v.push_back(p);
		}
	}

	cout << v.size() << endl;
	for (vector<pos>::iterator it = v.begin(); it != v.end(); it++) {
		cout << it->y1 << " " << it->x1 << " " << it->y2 << " " << it->x2 << endl;
	}

	return 0;
}

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

int N;
int A[210];         // 最大 200 個なので余裕を持って 210 に --- 200 以上ならなんでもよいです

int main() {
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> A[i];

    int res = 0;

    // 操作が行える限り操作を繰り返す
    while (true) {
        bool exist_odd = false;  // A[i] がすべて偶数かどうかを判定するフラグ
        for (int i = 0; i < N; ++i) {
            if (A[i] % 2 != 0) {
                exist_odd = true;  // 奇数があったらフラグを立てる
                break;
            }
            A[i] /= 2;
        }

        if (exist_odd) break;  // 奇数があったら break

        // // 操作を行えるなら操作を実際に行う
        // for (int i = 0; i < N; ++i) {
        //     A[i] /= 2;
        // }
        ++res;  // 操作回数をインクリメント
    }

    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

ll solve(const vector<ll>& v, int flg){
  ll ret = 0;

  ll a = 0, b = v.size()-1;

  ll l, r;
  if(flg == 0){
    l = v[a];
    r = v[a];
    a++;
    flg = 1;
  }else{
    l = v[b];
    r = v[b];
    b--;
    flg = 0;
  }

  while(a <= b){
    if(flg == 0){
      bool which = false;
      if(a<=b) {
        if(abs(l-v[a]) > abs(r-v[a])){
          ret += abs(l-v[a]);
          l = v[a];
          which = false;
        }else{
          ret += abs(r-v[a]);
          r = v[a];
          which = true;
        }
        a++;
      }
      if(a<=b) {
        if(which){
          ret += abs(l-v[a]);
          l = v[a];
        }else{
          ret += abs(r-v[a]);
          r = v[a];
        }
        a++;
      }
      flg = 1;
    }else{
      bool which = false;
      if(a<=b) {
        if(abs(l-v[b]) > abs(r-v[b])){
          ret += abs(l-v[b]);
          l = v[b];
          which = false;
        }else{
          ret += abs(r-v[b]);
          r = v[b];
          which = true;
        }
        b--;
      }
      if(a<=b) {
        if(which){
          ret += abs(l-v[b]);
          l = v[b];
        }else{
          ret += abs(r-v[b]);
          r = v[b];
        }
        b--;
      }
      flg = 0;
    }
  }

  return ret;
}


int main(){
  int N;
  cin >> N;
  vector<ll> v;
  rep(i,N){
    ll a;
    cin >> a;
    v.push_back(a);
  }
  sort(ALLOF(v));

  ll ret1 = solve(v, 0);
  ll ret2 = solve(v, 1);

  cout << max(ret1, ret2) << endl;
  
  return 0;
}



Measured memory_bytes: 1400
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())), reverse=True)
l = []
# print(x)
if n >= m:
    print(0)
else:
    for i in range(m-1):
        l.append(x[i] - x[i+1])
    l.sort(reverse=True)
    # print(l)
    print(sum(l[n-1:]))

Measured memory_bytes: 13968
def main():
    boxes, operation_num = map(int, input().split())
    operation = []
    for _ in range(operation_num):
        operation.append(list(map(int, input().split())))
    can_exist_red = [False for _ in range(boxes)]
    ball = [1 for _ in range(boxes)]
    can_exist_red[0] = True
    for op_from, op_to in operation:
        ball[op_to - 1] += 1
        ball[op_from - 1] -= 1
        if can_exist_red[op_from - 1]:
            can_exist_red[op_to - 1] = True
            if ball[op_from - 1] == 0:
                can_exist_red[op_from - 1] = False
    answer = 0
    for c in can_exist_red:
        if c:
            answer += 1
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 29024
import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    val inputs = Iterator.continually(StdIn.readLine()).takeWhile(_ != null)
    for{
      in <- inputs
      val Array(h, w, _*) = in.split(" ").map(_.toInt)
      }{
        if(h != 0 && w != 0){
          println((List.tabulate(h, w){(i, j) =>
            val isSharp = (i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0)
            val isDot = !isSharp
            val EOL = j == w-1

            if(isSharp && EOL) "#\n"
            else if(isDot && EOL) ".\n"
            else if(isSharp) "#"
            else "."
          }).flatten.mkString)
        }
      }
  }
}

Measured memory_bytes: 48532
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
  int N;
  cin >> N;
  char S[N][N];
  rep(i,N) cin >> S[i];
  int ans=0;
  rep(i,N){
    bool check=true;
    rep(j,N) rep(k,N) if(S[j][(k+i)%N]!=S[k][(j+i)%N]) check=false;
    if(check) ans+=N;
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    char a;
    cin>>a;
    cout<<char(a+1)<<endl;
    
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n , x = 0 , t = 0;
    string s;
    cin >> n >> s;
    for (int i = 0 ; i < n ; i++){
        if (s[i]=='I')
            x++;
        else if (s[i]=='D')
            x--;
        if (x>t)
            t = x;
    }
    cout << t;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int n,k;
    cin >> n >> k;
    vector a(n,0);
    for (int i=0; i<n; i++) cin >> a[i];

    for (int i=k; i<n; i++) {
        bool ans = a[i-k] < a[i];
        cout << (ans? "Yes" : "No") << endl;
    }
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	string S;
	cin >> S;
	int len = S.length(), fav = 753, ans = INT_MAX;
	for (int i = 0; i <= len - 3; ++i) {
		string b = S.substr(i, 3);
		int best = stoi(b);
		ans = min(ans, abs(best - fav));
	}
	cout << ans << '\n';	
	
	return 0;
}


Measured memory_bytes: 256
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll a[Max];
ll n,A,B,ans;
void solve(){
	cin>>n;
	rep(i,0,n)cin>>a[i];
	rep(i,0,n){
		rep(j,i+1,n){
			ans+=a[i]*a[j];
		}
	}
	cout<<ans;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

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

const int INF = 1000000007;
const ll MOD = 1000000007;

void solve_test()
{
    string s;
    cin >> s;
    int n = (int)s.size();
    if(s[n-1] == 's')
    {
        s = s + "es";
    }
    else
    {
        s += "s";
    }
    cout << s;
}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int tests;
    tests = 1;
    //cin >> tests;
    while(tests--)
    {
        solve_test();
    }
    return 0;
}


Measured memory_bytes: 3624
# encoding: utf-8
n = int(input())
v = list(map(int, input().split()))

odd = [0] * (10 ** 5)
even = [0] * (10 ** 5)
for i, vi in enumerate(v):
    if i % 2: even[vi - 1] += 1
    else: odd[vi - 1] += 1

max_o = max_e = 0
imax_o = imax_e = 0
sub_o = sub_e = 0
for i, (valo, vale) in enumerate(zip(odd, even)):
    # odd
    if valo > max_o:
        sub_o = max_o
        max_o = valo
        imax_o = i + 1
    elif valo > sub_o: sub_o = valo
    # even
    if vale > max_e:
        max_e = vale
        imax_e = i + 1
    elif vale > sub_e: sub_e = vale

if imax_o == imax_e: print(min(n - max_o - sub_e, n - sub_o - max_e))
else: print(n - max_o - max_e)

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vector<double> x(n),y(n);
    rep(i,n) cin>>x[i]>>y[i];
    auto g = [&](double _x, double _y){
        double ret=0.0;
        rep(i,n){
            double dx = x[i]-_x;
            double dy = y[i]-_y;
            chmax(ret, sqrt(dx*dx+dy*dy));
        }
        return ret;
    };
    auto f = [&](double x){
        double l = 0.0, r = 1000.0;
        rep(i,80){
            double c1 = (l*2+r)/3;
            double c2 = (l+r*2)/3;
            if (g(x,c1)>g(x,c2)) l = c1;
            else r = c2;
        }
        return g(x,(l+r)/2);
    };
    double lo = 0.0, hi = 1000.0;
    rep(i,80){
        double c1 = (lo*2+hi)/3;
        double c2 = (lo+hi*2)/3;
        if (f(c1)>f(c2)) lo = c1;
        else hi = c2;
    }
    cout<<setp(12)<<f((lo+hi)/2)<<endl;
    return 0;
}


Measured memory_bytes: 256
X, N = map(int, input().split())
P = map(int, input().split())

Ps = set(P)
import sys

if X not in Ps:
    print(X)

else:
    dec = X - 1
    inc = X + 1

    while True:
        if dec not in Ps:
            print(dec)
            break
        else:
            dec -= 1
        
        if inc not in Ps:
            print(inc)
            break
        else:
            inc += 1


Measured memory_bytes: 9188
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <climits>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <bitset>
using namespace std;

int main() {
    int n;
    cin>>n;
    int x=n*800;
    int q=n/15;
    cout<<(x-q*200)<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;
using System.Timers;

static class MainClass
{
    public static void Main(string[] args)
    {
        var HW = Console.ReadLine().SplittedStringToInt32List();
        var H = HW[0];
        var W = HW[1];
        var N = Console.ReadLine().ToInt32();
        var an = Console.ReadLine().SplittedStringToInt32List();
        var ls = new List<int>();
        var j = 1;
        foreach (var item in an)
        {
            for (int i = 0; i < item; i++)
            {
                ls.Add(j);
            }
            j++;
        }
        var grid = new List<List<int>>();
        for (int i = 0; i < H; i++)
        {
            var lss = new List<int>();
            lss.AddRange(ls.Take(W * (i + 1)).Skip(W * i));
            if (i % 2 == 0)
            {
                lss.Reverse();
            }
            grid.Add(lss);
        }
        foreach (var item in grid)
        {
            var sb = new StringBuilder();
            foreach (var item2 in item)
            {
                sb.Append(item2.ToString() + " ");

            }
            var str = sb.ToString();
            Console.WriteLine(str.Remove(str.Length - 1,1));
        }
    }


    #region ライブラリ
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    #endregion
}


Measured memory_bytes: 13792
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define SIZE 300010
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define mp make_pair
#define ll long long
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
ll n, w, k;
string s;

int main() {
	io(); cin >> n >> s;
	rep(i, 0, (n - 1)) if (s[i] == 'R') w++;
	k = n - w;
	if (w > k) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n,q,a,b;
    cin>>n>>q;
    vector<vector<ll>> adj(n);
    rep(i,n-1){
        cin>>a>>b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    vector<ll> cnt(n,0),vis(n,0);
    vis[0]=1;
    rep(i,q){
        cin>>a>>b;
        a--;
        cnt[a]+=b;
    }
    queue<ll> que;
    que.push(0);
    while(!que.empty()){
        ll f=que.front(); que.pop();
        rep(i,adj[f].size()){
            if(!vis[adj[f][i]]){
                que.push(adj[f][i]);
                vis[adj[f][i]]=1;
                cnt[adj[f][i]]+=cnt[f];
            }
        }
    }
    rep(i,n) cout<<cnt[i]<<' ';
    cout<<endl;
    return 0;
}

Measured memory_bytes: 19440
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define inf 1000000007;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}



signed main() {
	int n, x, y;
	cin >> n >> x >> y;
	cout << min(x, y) << " " ;
	if ((x + y) - n >= 0)cout << (x + y) - n << endl;
	else cout << 0 << endl;
	getchar(); getchar();
	return 0;
}

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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << '\n';
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

using Graph = vector<vector<int>>;
Graph g;

int chase[100005];
int run[100005];

void rec_run(int p, int v) {
    if (p == -1) run[v] = 0;
    else run[v] = run[p] + 1;

    for (auto e : g[v]) {
        if (e == p) continue;
        rec_run(v, e);
    }
}

void rec_chase(int p, int v) {
    if (p == -1) chase[v] = 0;
    else chase[v] = chase[p] + 1;

    for (auto e : g[v]) {
        if (e == p) continue;
        rec_chase(v, e);
    }
}

void solve() {
    int N, u, v; cin >> N >> u >> v;
    u--; v--;

    g.resize(N);
    for (int i = 0; i < N-1; i++) {
        int A, B; cin >> A >> B;
        A--; B--;
        g[A].push_back(B);
        g[B].push_back(A);
    }

    rec_run(-1, u);
    rec_chase(-1, v);

    int ans = 0;
    for (int i = 0; i < N; i++) {
        //print("chase:", chase[i], " run:", run[i]);
        if (chase[i] > run[i]) ans = max(ans, chase[i]);
    }
    ans--;

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

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

    solve();

    return 0;
}

Measured memory_bytes: 13092
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    string s, t, u;
    int a, b;

    cin >> s >> t >> a >> b >> u;
    if (s == u) {
        a--;
    } else {
        b--;
    }

    cout << a << " " << b << endl;

    return 0;
}

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

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  LL a, b, x; cin >> a >> b >> x;
  cout << (b / x) - (a>0? ((a-1) / x): -1) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main()
{
  int n;
  scanf("%d",&n);
  static char s[300000];
  scanf("%s",s);
  int c=0;
  long long ans=1ll;
  const long long mod=1000000007ll;
  for(int i=0;i<2*n;i++){
    if((c%2==0)==(s[i]=='W')){
      ans=(ans*c)%mod;
      c--;
    }
    else{
      c++;
    }
  }
  if(c!=0){
    ans=0;
  }
  for(int i=1;i<=n;i++){
    ans=(ans*i)%mod;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 384