akhauriyash/Code-Regression huggingface dataset:
# 2020/04/12
# AtCoder Beginner Contest 162 - D

# Input
n = int(input())
s = input()

# Calc
acmsum = [[0] * (n+1) for i in range(3)]

for i in range(n):
    if s[i] == 'R':
        acmsum[0][i+1] = acmsum[0][i] + 1
        acmsum[1][i+1] = acmsum[1][i]
        acmsum[2][i+1] = acmsum[2][i]
    elif s[i] == 'G':
        acmsum[0][i+1] = acmsum[0][i]
        acmsum[1][i+1] = acmsum[1][i] + 1
        acmsum[2][i+1] = acmsum[2][i]
    else:
        acmsum[0][i+1] = acmsum[0][i]
        acmsum[1][i+1] = acmsum[1][i]
        acmsum[2][i+1] = acmsum[2][i] + 1

ans = 0
for i in range(1, n-1):
    j = 1
    x = 0
    while(i+j < n and i-j >= 0):
        if s[i-j] != s[i] and s[i-j] != s[i+j] and s[i] != s[i+j]:
            x = x + 1
        j = j + 1
    
    if s[i] == 'R':
        ans = ans + (acmsum[1][i]) * (acmsum[2][n] - acmsum[2][i]) - x
        ans = ans + (acmsum[2][i]) * (acmsum[1][n] - acmsum[1][i])
        
    elif s[i] == 'G':
        ans = ans + (acmsum[0][i]) * (acmsum[2][n] - acmsum[2][i]) - x
        ans = ans + (acmsum[2][i]) * (acmsum[0][n] - acmsum[0][i])
        
    else:
        ans = ans + (acmsum[1][i]) * (acmsum[0][n] - acmsum[0][i]) - x
        ans = ans + (acmsum[0][i]) * (acmsum[1][n] - acmsum[1][i])

# Output
print(ans)


Measured memory_bytes: 9348
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        int ans = 0;
        for (int i = 0 ; i < n ; i++) {
            x -= a[i];
            if (x >= 0) {
                ans++;
            } else {
                System.out.println(ans);
                return;
            }
        }
        if (x > 0) {
            System.out.println(ans - 1);
        } else {
            System.out.println(ans);
        }


    }

}

Measured memory_bytes: 23764
N = int(input())
A = list(map(int, input().split()))

fu = 0
for i in range(N):
    if A[i] < 0:
        fu += 1
        A[i] = -A[i]

if fu % 2 == 0:
    ans = sum(A)
else:
    ans = sum(A) - min(A) * 2

print(ans)


Measured memory_bytes: 14224
#include<iostream>
#include<algorithm>
#include<cmath>
#include<deque>
#include<vector>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
int main() {
  int n;
  cin >> n;
  deque<int> dq;
  while(n--) {
    int x;
    cin >> x;
    if(x==0) {
      int y,z;
      cin >> y >> z;
      if(y==0) {
        dq.push_front(z);
      }
      else {
        dq.push_back(z);
      }
    }
    else if(x==1) {
      int y;
      cin >> y;
      cout << dq[y] << endl;
    }
    else {
      int y;
      cin >> y;
      if(y==0) {
        dq.pop_front();
      }
      else {
        dq.pop_back();
      }
    }
  }
}


Measured memory_bytes: 4640
#include<stdio.h>
int main()
{
	int m,f,b;
	scanf("%d%d%d",&m,&f,&b);
	if(m>=b){
		printf("0\n");
	}else if(m+f<b){
		printf("NA\n");
	}else{
		printf("%d\n",b-m);
	}
    return 0;
}

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

int main()
{
    int i, n, tp=0, hp=0, j;
    char tc[128], hc[128];
    scanf("%d", &n);
    for(i=0; i<n; i++) {
        scanf(" %s %s", tc, hc);
        j=strcmp(tc, hc);
        if(j==0) tp++, hp++;
        else if(j>0) tp+=3;
        else hp+=3;
    }
    printf("%d %d\n", tp, hp);
    return 0;
}

Measured memory_bytes: 604
# あなたは、X 円を持ってケーキとドーナツを買いに出かけました。
# あなたはまずケーキ屋で 1個 A円のケーキを 1個買いました。
# 次に、ドーナツ屋で 1個 B 円のドーナツをできるだけたくさん買いました。
#
# これらの買い物のあと手元に残っている金額は何円ですか。

# 制約
# 1 ≦ A, B ≦ 1,000
# A + B ≦ X ≦ 10,000
# X, A, B は整数である

# 標準入力から、X, A, B の値を取得する
x = int(input())
a = int(input())
b = int(input())

# 残金を計算して出力する
result = 0

result = (x - a) % b
print(result)


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

int main(){
	int n;
	cin>>n;
	int v[n+1],c[n+1],d[n+1]; int val=0;
	for(int i=1;i<=n;i++)	cin>>v[i];
	for(int i=1;i<=n;i++)	cin>>c[i];
	for(int i=1;i<=n;i++)	d[i]=v[i]-c[i];
	for(int i=1;i<=n;i++){
		if(d[i]>0)	val+=d[i];
	}
	cout<<val<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp make_pair
#define F first
#define S second
#define pf pop_front
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
typedef long long ll;
const ll mod=1e9+7;
const ll maxn=1005;
const ll inf=1e9+7;
ll dp[maxn][maxn];
vector<ll> g[maxn];
ll in[maxn];
ll h,w;
int main()
{
    while(cin>>h>>w)
    {
       rep1(i,h)
       {
           rep1(j,w)
           {
               char c;
               cin>>c;
               if(c=='#') dp[i][j]=-1;
           }
       }
       dp[1][1]=1;
       rep1(i,h)
       {
           rep1(j,w)
           {
               if(dp[i][j]==-1) continue;
               if(dp[i-1][j]!=-1) dp[i][j]+=dp[i-1][j];
               if(dp[i][j-1]!=-1) dp[i][j]+=dp[i][j-1];
               dp[i][j]%=mod;
           }
       }
       cout<<dp[h][w]<<"\n";
    }
}


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

int main() {
    ll k, a, b;
    cin >> k >> a >> b;

    ll ans = 0;
    if (a >= b - 1 || a >= k)
        ans = k + 1;
    else {
        k -= a + 1;
        ans = b + k / 2 * (b - a) + k % 2;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_B&lang=jp
//https://www.slideshare.net/iwiwi/ss-3578511


#include <iostream>
#include <vector>
#include <algorithm>

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

using namespace std;

const int MAX_N=100;
const int MAX_W=10000;
bool done[MAX_N+10][MAX_W+10];
int memo[MAX_N+10][MAX_W+10];
int N,W;
int v[MAX_N];
int w[MAX_N]; 

int search(int i,int u)
{
    if (done[i][u]) return memo[i][u];
    int res;
    if(i==N) res=0;
    else if(u<w[i])
    {
        res=search(i+1,u);
    }
    else{
        int res1=search(i+1,u);
        int res2=search(i+1,u-w[i])+v[i];
        res=max(res1,res2);
    }
    done[i][u]=true;
    memo[i][u]=res;
    return res;
}

int main()
{

    cin>>N>>W;
    for (int i=0;i<N;i++)
    {
        cin>>v[i]>>w[i];
    }
    int res=search(0,W);
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 7820
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef pair<int, int> P;

ll gcd(ll a, ll b){ return b? gcd(b, a%b):a;}
ll lcm(ll a, ll b){ return a/gcd(a,b)*b;}

int main(){
    int a, b;
    cin >> a >> b;

    string A, B;
    for(int i = 0; i < b; i++) A += to_string(a);
    for(int i = 0; i < a; i++) B += to_string(b);
    cout << min(A, B) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

int main(int argc, char *argv[])
{
    int n;
    std::string s;

    std::cin >> n;
    std::cin >> s;

    const int len = s.length();

    for (int i = 0; i < len; i++) {
        s[i] += n;
        if (s[i] > 'Z') {s[i] -= 26;}
    }

    std::cout << s << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 860;
const int INF = 19191919;
int dp[N][N], nx[N][N];

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

    rep(i,N)rep(j,N) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i,n){
        rep(j,N)rep(k,N) nx[j][k] = INF;
        rep(j,N)rep(k,N)if(dp[j][k]<INF){
            if(j+t[i]<N) nx[j+t[i]][k] = min(nx[j+t[i]][k], dp[j][k]);
            if(k+t[i]<N) nx[j][k+t[i]] = min(nx[j][k+t[i]], dp[j][k]);
            nx[j][k] = min(nx[j][k], dp[j][k]+t[i]);
        }
        rep(j,N)rep(k,N) dp[j][k] = nx[j][k];
    }

    int ans = INF;
    rep(i,N)rep(j,N) ans = min(ans, max({i,j,dp[i][j]}));
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 8880
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

from itertools import accumulate

def main():
    N = II()
    A = LI()
    A.sort()
    S = list(accumulate(A))
    ans = 1
    for s, a in zip(S[-2::-1], A[-1::-1]):
        if s * 2 < a:
            break
        ans += 1

    return ans

print(main())

Measured memory_bytes: 14476
ROOM_NUM = 10
FLOOR_NUM = 3
BUILDING_NUM = 4
building_info = Array.new(BUILDING_NUM).map{Array.new(FLOOR_NUM).map{Array.new(ROOM_NUM,0)}}

n = gets.chop.to_i

1.step n do
  b, f, r, v = gets.chop.split(' ').map(&:to_i)
  building_info[b-1][f-1][r-1] += v
end

building_info.each_with_index do |building, index|
  building.each do |floor|
    floor.each do |room|
      printf " %d", room
    end
    puts ""
  end
  puts "#"*ROOM_NUM*2 if index != 3
end



Measured memory_bytes: 6912
def solve(): # 071C - Make a Rectangle
    n = int(input())
    sides = list(map(int, input().split(" ")))
    check_dual = {}
    possible_sides = []

    for i in sides:
        if i in check_dual:
            check_dual[i] += 1
        else:
            check_dual[i] = 1

    for k, v in check_dual.items():
        if v >=4:
            possible_sides.append(k)
            possible_sides.append(k)
        elif v == 2 or v == 3:
            possible_sides.append(k)

    possible_sides.sort(reverse=True)
    if len(possible_sides) < 2:
        print(0)
    else:
        print(possible_sides[0] * possible_sides[1])


solve()

Measured memory_bytes: 18060
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     9e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define sll                     set<ll>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define umcl                    um<char,ll>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll Testcases;cin>>Testcases;while(Testcases--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,val)               lower_bound(all(v),val)-v.begin()
#define ub(v,val)               upper_bound(all(v),val)-v.begin()
#define SS                      stringstream
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

ll poww(ll b,ll e){if(e==0)return 1;else if(e%2==0){ll a=pow(b,e/2);return a*a;}else {ll a=pow(b,e/2);return b*a*a;}}
ll powm(ll x,ll y,ll m=MOD){x=x%m;ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll modInverse(ll a, ll m=MOD) { return powm(a, m-2, m);}

ll nCr(ll n,ll r)
{
	ll res=1;
	if((n-r)<r)
		r=n-r;
	rep(i,0,r-1,1)
	{
		res*=(n-i);
		res%=MOD;
		res*=modInverse(i+1);
		res%=MOD;
	}
	
	return res;
}

int main()
{
	fastIO
	ll n,a,b;
	cin>>n>>a>>b;
	ll ans=(powm(2,n)-1+MOD)%MOD;
	ans-=nCr(n,a);
	ans+=MOD;
	ans%=MOD;
	ans-=nCr(n,b);
	ans+=MOD;
	ans%=MOD;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 384
function main(lines) {
  const N = n();
  
  const nSqrt =  Math.sqrt(N);
  let divisor;
  for (let i = 1; i <= nSqrt; i++) {
    divisor = N % i == 0 ? i : divisor;
  }
  const ans = Math.max(divisor, N/divisor).toString(10).length;
  
  return ans;
}



const lines = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");

let lineCount = 0;
const s = () => lines[lineCount++];
const n = () => Number(s());
const b = () => BigInt(s());
const sa = () => s().split(' ');
const na = () => sa().map(Number);
const ba = () => sa().map(BigInt);

const ans = main(lines);
console.log( ans );

Measured memory_bytes: 32544
s=input()
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])
if a+b+c+d==7:
    print(str(a)+"+"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
elif a+b+c-d==7:
    print(str(a)+"+"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
elif a+b-c+d==7:
    print(str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
elif a+b-c-d==7:
    print(str(a)+"+"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
elif a-b+c+d==7:
    print(str(a)+"-"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
elif a-b+c-d==7:
    print(str(a)+"-"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
elif a-b-c+d==7:
    print(str(a)+"-"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
elif a-b-c-d==7:
    print(str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 998244353
#define eps 1e-13
// #define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pll a, pll b)//true for a before b
{
	if(a.F*b.S < b.F*a.S)
		return 1;
	if(a.F*b.S > b.F*a.S)
		return 0;
	if(a.F <= b.F)
		return 1;
	return 0;
}

const int N = (1e5) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 900;
const int SQRT = BUCK+9;



void solve()
{
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	if(k % 2LL == 0LL)
		cout << (a-b) << '\n';
	else
		cout << (b-a) << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(9);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace dwacon5th_prelims_a
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
			double ave = x.Sum(); ave /= n;
			int ret = 0; double diff = double.MaxValue;
			for (int i = 0; i < n; i++)
			{
				if (Math.Abs(ave - x[i]) < diff)
				{
					ret = i; diff = Math.Abs(ave - x[i]);
				}
			}
			Console.WriteLine(ret);
		}
	}
}

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

int main() {
  int H, W, a, b, c, d;
  cin >> H >> W;
  string str = "";
  for (int i = 0; i < H; i++){
    string line;
    cin >> line;
    str += line;
  }
  for (int i = 0; i < H; i++){
    if (i == 0){
      b = 1;
      if (H == 1){
        a = 1;
      }
      else
        a = 2;
    }
    else if (i == H - 1){
      a = 2;
      b = 0;
    }
    else{
      a = 3;
      b = 0;
    }
    for (int j = 0; j < W; j++){
      if (j == 0){
        d = 0;
        if (W == 1)
          c = 1;
        else
          c = 2;
      }
      else{
        d = 1;
        if (j == W - 1)
          c = 2;
        else
          c = 3;
      }
      if (j == W - 1){
        if (str.at(i * W + j) == '#')
          cout << "#" << endl;
        else{
          int count = 0;
          for (int k = 0; k < a; k++){
            for (int l = 0; l < c; l++){
              if (str.at((i - 1 + k + b) * W + j - d + l) == '#')
                count++;
            }
          }
          cout << count << endl;
        }
      }
      else if (str.at(i * W + j) == '#')
        cout << "#";
      else{
        int count = 0;
        for (int k = 0; k < a; k++){
          for (int l = 0; l < c; l++){
            if (str.at((i + k - 1 + b) * W + j + l - c + 2) == '#')
              count++;
          }
        }
        cout << count;
      }
    }
  }
}

Measured memory_bytes: 3616
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for(int i = a ; i < (int)n ; i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define eps 1e-14
#define INF 1e9
#define m0(x) memset(x, 0, sizeof(x))

using namespace std;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){
  int a, b;
  int n;

  cin >> n;

  vector<int> v1, v2;

  REP(i, 1, n+1){
    cin >> a;
    if(i % 2 == 0){ // even
      v1.pb(a);
    }else{  // odd
      v2.pb(a);
    }
  }

  vector<int>::iterator even, odd;
  int cnt = 0;
  
  if(n % 2 == 0){
    reverse(ALL(v1));
    even = v1.begin();
    odd = v2.begin();
    while(even != v1.end()){
      cout << *even << " ";
      even++;
      cnt++;
    }
    
    while(odd != v2.end()){
      cout << *odd << " "; 
      odd++;
    }
  }else{    
    reverse(ALL(v2));
    even = v1.begin();
    odd = v2.begin();
    while(odd != v2.end()){
      cout << *odd << " "; 
      odd++;
    }
    while(even != v1.end()){
      cout << *even << " ";
      even++;
      cnt++;
    }
  }

  //if(cnt > 0) cout << " ";
  


  
  cout << "\n";
}


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

using namespace std;
typedef long long ll;

int n, ans;
char s[100005];

void input()
{
	scanf("%s", s);
	n = strlen(s);
}

void solve()
{
	for(int i = 1; i < n; i++)
		if(s[i] != s[i - 1])
			ans++;
}

void output()
{
	printf("%d\n", ans);
}

int main()
{
	input();
	solve();
	output();

	return 0;
}


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

int main() {
    string s;
    cin >> s;
    if(s == "Sunny") cout << "Cloudy" << '\n';
    if(s == "Cloudy") cout << "Rainy" << '\n';
    if(s == "Rainy") cout << "Sunny" << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

map<string, int> kindToKindIdx = {
    {"S", 0},
    {"H", 1},
    {"C", 2},
    {"D", 3},
};

map<int, string> kindIdxToKind = {
    {0, "S"},
    {1, "H"},
    {2, "C"},
    {3, "D"},
};

int main(void) {
    int cardCount;
    cin >> cardCount;
    
    bool hasCards[4][13] = {};
    for (int loop = 0; loop < cardCount; loop++) {
        string kind;
        int lank;
        cin >> kind >> lank;
        hasCards[kindToKindIdx[kind]][lank - 1] = true;
    }
    
    for (int kindIdx = 0; kindIdx < (sizeof(hasCards) / sizeof(hasCards[0])); kindIdx++) {
        for (int lank = 1; lank <= (sizeof(hasCards[0]) / sizeof(hasCards[0][0])); lank++) {
            if (hasCards[kindIdx][lank - 1] == false) {
                cout << kindIdxToKind[kindIdx] << " " << lank << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define M ((ll)(1e9)+7)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
int n;
vector<pair<int,int>> v;
map<int,int> dp;
int ans(int h)
{
    if(h<=0)
    return 0;
    int mi=(int)1e9;
    if(dp[h]!=0)
    return dp[h];
    for(int i=0;i<n;i++)
    mi=min(mi,v[i].S+ans(h-v[i].F));
    dp[h]=mi;
    return dp[h];
}
void solve()
{
    int h;
  cin>>h>>n; int a,b;
  for(int i=0;i<n;i++)
  {
      cin>>a>>b;
      v.pb(mp(a,b));
  }
  cout<<ans(h)<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep2(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
const ll INF = 100100100100;
const int MOD = 1000000007;
const ld EPS = 1e-10;

int main(){
  int K, X; cin >> K >> X;
  if (K * 500 >= X) cout << "Yes";
  else cout << "No";
  cout << endl;
  return 0;
}

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

int main(){
  int n; cin >>n; vector<int>v(n+1);
  for(int i=1; i<n+1; i++)
  {int a; cin >>a; v[a]=i;}
  for(int i=1; i<n+1; i++) cout <<v[i]<<" ";
return 0;}

Measured memory_bytes: 1152
h,w=map(int, input().split())
# 余白付け足し
s=['.'*(w+2)]
for _ in range(h):
    s.append('.'+input()+'.')
s.append('.'*(w+2))
    
# 全ての#マスにおいて、縦横のいずれかが#であればOK
for i in range(h+1):
    for j in range(w+1):
        if s[i][j]=="#":
            if s[i-1][j] == s[i+1][j] == s[i][j-1] == s[i][j+1] == ".":
                print("No")
                exit()
print("Yes")
    
    

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

int n, m, ans[55];
pair<int, int> s[55], c[55];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> s[i].first >> s[i].second;
    }

    for (int i = 0; i < m; i++) {
        cin >> c[i].first >> c[i].second;
    }

    for (int i = 0; i < n; i++) {
        int id = -1, cur = 1e9;
        for (int j = 0; j < m; j++) {
            if (abs(s[i].first - c[j].first) + abs(s[i].second - c[j].second) < cur) {
                id = j;
                cur = abs(s[i].first - c[j].first) + abs(s[i].second - c[j].second);
            }
        }

        ans[i] = id;
    }

    for (int i = 0; i < n; i++) {
        cout << ans[i] + 1 << '\n';
    }

    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.Random;

public class Main {
    private static FastScanner sc = new FastScanner();
    private static boolean DEBUG_FLG = false;

    public static void main(String[] args) {
    	int n = sc.nextInt();
    	int[] p = new int[n];
    	for(int i=0; i<n; i++) {
    		p[i] = sc.nextInt();
    	}
    	int ans = 0;
    	for(int i=0; i<n-2; i++) {
    		if(Math.max(Math.max(p[i], p[i+1]), p[i+2]) != p[i+1] && Math.min(Math.min(p[i], p[i+1]), p[i+2]) != p[i+1]) {
    			ans++;
    		}
    	}
    	System.out.println(ans);
    }

    static void debug(long... args) {
    	if(!DEBUG_FLG) return;
    	boolean flg = false;
    	for(long s : args) {
    		if(flg) System.out.print(" ");
    		flg = true;
    		System.out.print(s);
    	}
    	System.out.println();
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }

    static void shuffleArray(long[] arr){
        int n = arr.length;
        Random rnd = new Random();
        for(int i=0; i<n; ++i){
            long tmp = arr[i];
            int randomPos = i + rnd.nextInt(n-i);
            arr[i] = arr[randomPos];
            arr[randomPos] = tmp;
        }
    }
}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
#include <iostream> 
#include <algorithm> 
using namespace std;
int main()
{
    long int n,k,i,m=0;
    cin >> n;
	cin >> k;
    long int a[n];
    for(i=0;i<n;i++)
        cin >> a[i];
    sort(a, a+n);
    for(i=0;i<(n-k);i++)
    	m+=a[i];
    cout << m;
    
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int n,m,ans;
void work(){
    int ed = (int)(sqrt(m));
    ed = min(ed, m / n);
    ans = 1;
    for (int i=ed;i>0;i--) if (m % i == 0){
        if (m / i >= n) ans = max(ans, i);
        if (i >= n) ans = max(ans, m/i);
    }
    cout<<ans<<endl;
}

int main(){
    while (cin>>n>>m) work();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int sum=0;
	int H,W;
	int h,w;
	cin>>H>>W;
	cin>>h>>w;
	int a[H][W];
	for(int i=0;i<H;i++)
	{
		for(int j=0;j<W;j++)
		{
			a[i][j]=0;
		}
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<W;j++)
		{
			a[i][j]=1;
		}
	}
	for(int i=0;i<H;i++)
	{
		for(int j=0;j<w;j++)
		{
			a[i][j]=1;
		}
	}
	for(int i=0;i<H;i++)
	{
		for(int j=0;j<W;j++)
		{
			if(a[i][j]==0)
			{
				sum++;
			}
		}
	}
	cout<<sum<<endl;
}

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

using namespace std;

#define fcout(d) cout << fixed << setprecision(d)
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rep1(i,n) for(int (i) = 1; (i) <= (n); ++(i))
#define repU(i,s,t) for(int (i) = (s); (i) <= (t); ++(i))
#define repD(i,t,s) for(int (i) = (t); (i) >= (s); --(i))
#define all(v)  begin(v),end(v)
#define clr(v) fill(all(v),0)
#define l_bnd lower_bound
#define u_bnd upper_bound
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second
#define q_ceil(n,d) ((n - 1)/(d) + 1)
#define parity(a,b) ((a)^(b) & 1LL ^ 1LL)

typedef long long ll;
typedef unsigned long long ull;
typedef double db;

const pair<int,int> DIR[] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int INF_32 = -1 + (1 << 30);
const ll INF_64 = -1 + (1LL << 62);
const int MOD = 1e9 + 7;

ull next_subset(ull subset){
	ull tem = subset + (subset & -subset);
	ull btm = (~tem & subset) / (subset & -subset) >> 1;
	return btm | tem;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,a;
	cin>>n;
	int k = 0,l = 0;
	rep(i,n){
		cin>>a;
		if(a % 4){
			if(!(a & 1)) ++k;
		}
		else ++l;
	}
	if(2 * l + 1 >= n) cout<<"Yes\n";
	else if(2 * l + k >= n) cout<<"Yes\n";
	else cout<<"No\n";
	
	return 0;
}





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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define repr(i, n) for(int i = n;i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define MOD 1000000007

typedef long long ll;

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

    int n,a,b,ans = 0;
    cin >> n >> a >> b;

    for(int i = 1; i <= n; ++i){
        int c = 0, t = i;
        
        for(int j = 0; j < 5; ++j){
            c = c + t % 10;
            t = t / 10;
        }
        
        if(a <= c && c <= b) ans += i;
    }

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

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

using namespace std;

int main(){
  int N ;cin >> N;
  string S; cin >> S;
  int cnt = 0;
  for(int i = 0; i < N; i++){
    if(S[i] == '('){ cnt++;}
    else{cnt--;}
    
    while(cnt < 0){ cout << '('; cnt++;}}
  
  cout << S;
  
  if(cnt > 0){
  for(int i = 0; i < cnt; i++){
    cout << ')' ;}}
  
  return 0;}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 7;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
ll a[maxn],b[maxn];

int main(){
	ll n,k;
	cin>>n>>k;
	ll sum = 0;
	a[0] = n;
	for(int i = 1; i <= n; i++){
		a[i] = a[i-1] + n - i;
	}
	b[0] = 0;
	for(int i = 1; i <= n; i++){
		b[i] = b[i-1] + i;
	}
	for(int i = k-1; i <= n; i++){
		ll tmp = a[i] - b[i] + 1;
		tmp %= mod;
		sum += tmp;
		sum %= mod;
		
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 6692
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
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<pair<pair<string, int>, int>> V(N);
    for(int i=0; i<N; i++){
        string S; cin >> S;
        int P; cin >> P;
        V[i] = pair<pair<string, int>, int>(pair<string, int>(S, P), i+1);
    }
    
    sort(V.begin(), V.end());
    for(int i=0; i<N; i++){
        string C = V[i].fs.fs;
        int j = i+1;
        if(j>=N) break;
        int p = i;
        while(V[j].fs.fs==C){
            j++;
            i++;
            if(j>=N || i>=N) break;
        }
        reverse(V.begin()+p, V.begin()+j);
    }
    
    
    
    for(int i=0; i<N; i++){
        cout << V[i].sc << endl;
    }
    
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=100005;
int n,x,y;
vector<int> G[max_n];
void dfs(int u,int fa,int d[]){
    for(auto v:G[u]){
        if(v==fa)continue;
        d[v]=d[u]+1;
        dfs(v,u,d);
    }
}
int dx[max_n],dy[max_n];
void work(int x,int d[]){
    d[x]=0;
    dfs(x,0,d);
}
int main(){
    scanf("%d%d%d",&n,&x,&y);
    for(int i=1;i<n;i++){
        int u,v;scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(x,0,dx);
    dfs(y,0,dy);
    int ans=0;
    for(int i=1;i<=n;i++){
        if(dx[i]<=dy[i])ans=max(ans,dy[i]-1);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 11648
#include <bits/stdc++.h>
#define L long long
#define LL long long
#define SS string
#define PB push_back
#define pp pair<L,L>
#define f(x, n , i) for (i = x ; i <= n ; i++)
#define setaE0 memset(a,0,sizeof(L));
#define N 100005
using namespace std;
    L a[101][N];
int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    L n,w;
    cin >> n >> w;
    L g[n+1][2];
    setaE0;
    L i;
    L j;
    f(1,n , i)
    {
        cin >> g[i][0] >> g[i][1];
    }
    f(0,n,i)
    {
        f(0,w,j)
        {
            if (i == 0 or j == 0)
            {
                a[i][j] = 0;
                continue;
            }
            if (j < g[i][0])
            {
                a[i][j] = a[i-1][j];
            }
            else 
            {
                a[i][j] = max(a[i-1][j] , a[i-1][j-g[i][0]] + g[i][1]);
            }
        }
    }
    cout << a[n][w];
    return 0; 
}

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2097162
#define inf 1e9
#define MOD 1000000007

ll m, sw[15], n, st[15];
vector< ll > lt[15];

bool on()
{

    for(ll i = 1; i <= m; i++)
    {

        ll cnt = 0;
        for(ll j = 0; j < lt[i].size(); j++)
        {

            if(sw[lt[i][j]] == 1) cnt++;
        }
        if(cnt%2 != st[i]) return false;
    }
    return true;
}

ll ans = 0;

void solve(ll x)
{

    if(x > n)
    {

        if(on()) ans++;
        return;
    }
    sw[x] = 0;
    solve(x+1);
    sw[x] = 1;
    solve(x+1);
}

int main()
{

    cin >> n >> m;
    for(ll i = 1; i <= m; i++)
    {

        ll k;
        cin >> k;
        for(ll j = 0; j < k; j++)
        {

            ll x;
            cin >> x;
            lt[i].pb(x);
        }
    }
    for(ll i = 1; i <= m; i++) cin >> st[i];
    solve(1);
    cout << ans;
}

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

using namespace std;
typedef long long ll;

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

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

	int ans = 0, tmp = 0;
	rep(i, n)
	{
		ans++;
		tmp = a[tmp];
		if (tmp == 1)
		{
			cout << ans << '\n';
			return 0;
		}
	}
	cout << -1 << '\n';
	return 0;
}


Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
#define fo(i,a,n) for(i=a;i<n;i++)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define sortrev(x) sort(all(x),greater<int>())
#define pi 3.1415926535897932384626

typedef pair<int,int> pii;
typedef pair<ll, ll> pl;
typedef vector<int>	vi;
typedef vector<bool> vb;
typedef vector<ll>	vl;
typedef vector<pii>	vpii;
typedef vector<pl>	vpl;
typedef vector<vi>	vvi;
typedef vector<vl>	vvl;
typedef vector<double> vd;


const int mod = 1000000007;
const int inf = 1000000000;
const int N = 200007, M = N;
ll i,j,cnt,par;
vi vec[N];

ll dfs(ll u , vi& vis) {
    vis[u] = 1;
    ll cnt = 1;
    for(ll v : vec[u]) {
        if(!vis[v]) {
            cnt+=dfs(v , vis);
        }
    }
    return cnt;
}

void solve() {
   ll n,m;
   cin>>n>>m;

   ll x,y;

   for(int i=0;i<m;i++) {
    cin>>x>>y;
    vec[x].pb(y);
    vec[y].pb(x);
   }

   ll ans = 0;
   vi vis(n+1,0);
   for(int i=1;i<=n;i++) {
    if(!vis[i]) ans = max(ans , dfs(i,vis));
   }

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


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

    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }

    return 0;
}




Measured memory_bytes: 24236
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x)  ((int)x.size ())
#define all(x) (x).begin(), (x).end()
#define re return
#define mp make_pair
#define sqrt(x) sqrt (abs(x))
#define y0 y3451
#define y1 y4562
#define j0 j25624
#define j1 j45624
#define makeunique(x) sort(all(x)), (x).resize (unique(all(x)) - (x).begin())

typedef pair <int, int> ii;
typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef long double ld;
typedef unsigned int uint;
typedef vector <string> vs;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <vi> vvi;

template <class T> using _tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> T abs (T x) { re x > 0 ? x : -x; }
template <class T> T sqr (T x) { re x * x; }
template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }
template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }

#define filename ""

const D pi = acos(-1.);
const int N = 2e5 + 20;
const int inf = 1e9 + 7;

int mod = inf;
ii a[N];
ll dp[3010];

inline ll power(ll x, ll y = mod - 2) {
	ll ans = 1;
	while (y) {
		if (y & 1) ans = ans * x % mod;
		y /= 2;
		x = x * x % mod;
	}
	re ans;
}
ll f[N], rev[N];
int w, h;

inline ll cnk(int n, int k) {
    ll ans = f[n] * rev[k] % mod;
    re ans * rev[n - k] % mod;
}
int n, m;

int main() {
	cin >> w >> h >> n;
	for (int i = 0; i < n; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		a[i] = {x - 1, y - 1};
	}
	a[n] = {w - 1, h - 1};
	n++;
	sort(a, a + n);
	f[0] = rev[0] = 1;
	for (int i = 1; i <= w + h; i++) {
		f[i] = f[i - 1] * i % mod;
		rev[i] = power(f[i]);
	}
	for (int i = 0; i < n; i++) {
		dp[i] = cnk(a[i].fi + a[i].se, a[i].fi);
		for (int j = 0; j < i; j++)
			if (a[i].fi >= a[j].fi && a[i].se >= a[j].se)
				dp[i] = (mod + dp[i] - cnk(a[i].fi - a[j].fi + a[i].se - a[j].se, a[i].fi - a[j].fi) * dp[j] % mod) % mod;
	}
	cout << dp[n - 1];
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  string s;
  cin >> s;
  ll n=s.size();
  if(s.size()==1) {
    cout << 1 << endl;
    return 0;
  }
  ll ans=(n+1)/2;
  ll r=n/2;
  ll l=n/2-1;
  if(n%2==0) {
    if(s[l]!=s[l+1]) {
      cout << ans << endl;
      return 0;
    }
    else {
      ans++;
      l--;
    }
  }
  for(ll i=0;ans<n;i++) {
    if((s[l-i]!=s[l+i+1])||(s[r+i]!=s[r+i+1])) {
      cout << ans << endl;
      return 0;
    }
    else {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
n,m = map(int, input().split())
s = input()
s = s[::-1]
ans = list()
goal = False
now = 0
while not goal:
    for adv in reversed(range(1,m+1)):
        if now + adv >= n:
            ans.append(n-now)
            goal = True
            break
        elif s[now+adv] == '0':
            ans.append(adv)
            now += adv
            break
    else:
        print(-1)
        break

if goal:
    print(*ans[::-1])




Measured memory_bytes: 50544
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

n, m = map(int, input().split(" "))
max = 1
#print(make_divisors(m))
for i in make_divisors(m):
  if i > m/n:
    break
  else:
    max = i
print(max)

Measured memory_bytes: 3188
import scala.io.StdIn

object Main extends App {
  val inputs = StdIn.readLine().split(" ")
  val N = inputs(0).toInt
  val L = inputs(1).toInt

  val min = L + 1 - 1
  val max = L + N - 1

  val eat = (min to max).minBy(i => i.abs)



  println((min to max).sum - eat)
}

Measured memory_bytes: 25544
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())

C = Counter(a)
ans = sum(a)

for i in range(q):
    b, c = map(int, input().split())
    ans += (c-b)*C[b]
    C[c] += C[b]
    C[b] = 0
    print(ans)

Measured memory_bytes: 24008
#include<stdio.h>
int main(){
  int N;
  int D;
  scanf("%d%d",&N,&D);
  int x;
  x=2*D+1;
  if(N%x==0){
    printf("%d",N/x);
  }
  else{
    printf("%d",N/x+1);
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << ": " << x << '\n';

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    mp[a] = i + 1;
  }
  for (int i = 1; i < n + 1; i++) {
    cout << mp[i] << " ";
  }
  cout << '\n';
}


Measured memory_bytes: 5504
import java.util.Scanner;


//A問題
public class Main {
	public static void main(String[] args) {

		//スキャナーを宣言する
	    Scanner sc = new Scanner(System.in);

	    //入力を受け取る
	    int A = sc.nextInt();
	    int B = sc.nextInt();

	    //スキャナーを閉じる
	    sc.close();

	    if((A % 3 == 0)||(B % 3 == 0)||((A + B) % 3 == 0)) {
	    	System.out.println("Possible");
	    }
	    else {
	    	System.out.println("Impossible");
	    }
	}
}

Measured memory_bytes: 21716
# 配列の要素入れ替え
class Array
  def swap!(a, b)
    self[a], self[b] = self[b], self[a]
  end
end

INF = 10 ** 6
n = gets.to_i
nums = gets.split.map(&:to_i)
nums << INF
ans = 0
n.times do |i|
  if nums[i] == i + 1
    nums.swap!(i, i + 1)
    ans += 1
  end
end
puts ans


Measured memory_bytes: 10116
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end());
#define MIN(vec) *std::min_element(vec.begin(), vec.end());
#define MAXI(vec)                                                              \
  std::distance(vec.begin(), *std::max_element(vec.begin(), vec.end()));
#define MINI(vec)                                                              \
  std::distance(vec.begin(), *std::min_element(vec.begin(), vec.end()));
#define ARY2D(a, b) vector<vector<ll>>((a), vector<ll>((b), 0));

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

template <typename T, typename U> U read(ll V, T a, U b) {
  REP(i, V) {
    cin >> a;
    b.push_back(a);
  }
  return b;
}

int main() {
  string T = "";
  cin >> T;
  ll N = T.size();
  vector<ll> a(5, 0);
  vector<ll> b(5, 0);
  b[0] = 1;
  REP(i, N) {
    if (T[i] == 'A') {
      a[0] = b[0] % MOD;
      a[1] = (b[0] + b[1]) % MOD;
      a[2] = b[2] % MOD;
      a[3] = b[3] % MOD;
    } else if (T[i] == 'B') {
      a[0] = b[0] % MOD;
      a[2] = (b[1] + b[2]) % MOD;
      a[1] = b[1] % MOD;
      a[3] = b[3] % MOD;
    } else if (T[i] == 'C') {
      a[0] = b[0] % MOD;
      a[3] = (b[2] + b[3]) % MOD;
      a[1] = b[1] % MOD;
      a[2] = b[2] % MOD;
    } else if (T[i] == '?') {
      a[0] = (b[0] * 3) % MOD;
      a[1] = (b[0] + (b[1] * 3) % MOD) % MOD;
      a[2] = (b[1] + (b[2] * 3) % MOD) % MOD;
      a[3] = (b[2] + (b[3] * 3) % MOD) % MOD;
    }
    b = a;
  }
  cout << a[3] << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
typedef long long ll;
ll n,s[100000],tot,N;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
        tot+=s[i];
    }
    N=n*(n+1)/2;
    if(tot%N!=0){
        cout<<"NO"<<endl;
        return 0;
    }
    N=tot/N;
    tot=0;
    for(int i=1;i<n;i++){
        s[i-1]=s[i]-s[i-1]-N;
        if(-s[i-1]%n!=0||s[i-1]>0){
            cout<<"NO"<<endl;
            return 0;
        }
        tot+=-s[i-1]/n;
    }
    if(tot<=N){
        cout<<"YES"<<endl;
    }
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 1024
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
from numba import njit
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

X = I()
if X >= 30:
    ans = True
else:
    ans = False

if ans:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 91760
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n) for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
	int a,b,h;
	cin >> a >> b >> h;
	cout << (a+b)*h/2 << endl;
	return 0;
}



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

int pri[maxn + 10];
int f[maxn + 10];

int main() {
	long long n, p; cin >> n >> p;
	memset(f, 0, sizeof(f)); pri[0] = 0;
	for (int i = 2; i <= maxn; i ++)
		if (!f[i]) {
			pri[++pri[0]] = i;
			for (int j = 2*i; j <= maxn; j += i) f[j] = 1; 
		}
	long long ans = 1; 
	for (int i = 1; i <= pri[0]; i ++)
		if (pri[i] <= p) {
			int t = 0;
			while (p % pri[i] == 0 && p >= pri[i]) { p /= pri[i]; t ++; }
			ans *= pow(pri[i], t / n);
		} else break;
	if (p > 1) ans *= pow(p, 1/n);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6528