akhauriyash/Code-Regression huggingface dataset:
#include<iostream> 
#include<cstdlib> 
#include<stdio.h> 
#include<memory.h> 
#include<vector> 
using namespace std; 
vector<int>v[100005]; 
int dfs(int x,int pre) 
{ 
    int ans=0; 
    for(int i=0;i<v[x].size();i++) 
    { 
        
        if(v[x][i]!=pre) 
        { 
            ans^=(1+dfs(v[x][i],x)); 
        } 
    } 
    return ans; 
} 
int main() 
{ 
    int a,b,n; 
    scanf("%d",&n); 
    for(int i=1;i<=n;i++) 
    v[i].clear(); 
    n--; 
    while(n--) 
    { 
        scanf("%d%d",&a,&b); 
        v[a].push_back(b); 
        v[b].push_back(a); 
    } 
        
        if(dfs(1,-1)) puts("Alice"); 
        else puts("Bob"); 
    
} 

Measured memory_bytes: 11904
N,M = map(int,input().split())

ans = [0]*N
ans[0] = 1
ball = [1]*N

for _ in range(M):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    if ans[x]:
        ans[y] = 1
    ball[x] -= 1
    ball[y] += 1

    if not ball[x]:
        ans[x] = 0

print(sum([i*(j>0) for i,j in zip(ans,ball)]))

Measured memory_bytes: 11284
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = [0] + list(map(int, input().split())) + [0]
    cost = 0
    pre = 0
    for a in A[1:]:
        cost += abs(a - pre)
        pre = a

    for i, a in enumerate(A):
        if i == 0 or i == N + 1: continue
        print(cost - abs(a - A[i - 1]) - abs(a - A[i + 1]) + abs(A[i + 1] - A[i - 1]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 87636
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define mp(x, y) make_pair(x, y)
#define pb(x) emplace_back(x)
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

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

const int N = 1e5;
int a[N];
int main()
{
    int a,b;cin>>a>>b;
    int ans=0;
    while(a)a/=b,ans++;
    cout<<ans;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
public static void main(String[]args){

Scanner sc= new Scanner(System.in);
int X =sc.nextInt();
int Y =sc.nextInt();
int Z =sc.nextInt();


int num=Y;
Y = X;
int ans =Z;
Z = num;

System.out.println(ans);
System.out.println(Y);
System.out.println(Z);

}
}

Measured memory_bytes: 23892
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <iomanip>

using namespace std;

using ll = long long;
const ll INF = 1e18L + 5;
const int mod = 1e9 + 7;

int n;

void add(int&a, int b){
    a += b;
    if(a >= mod){
        a -= mod;
    }
}
int mul(int a, int b){
    return (ll) a * b % mod;
}

struct M{
    vector<vector<int>> t;
    M(){
        t.resize(n, vector<int>(n));
    }
    M operator* (const M& b) const{
        M c = M();
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                for(int k = 0; k < n; k++){
                    add(c.t[i][k], mul(t[i][j], b.t[j][k]));
                }
            }
        }
        return c;
    }
};

int main(){
    
    ll k;
    
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    
    cin >> n >> k;
    
    vector<vector<int>> can(n, vector<int>(n));
    
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            cin >> can[i][j];
        }
    }
    
    M answer = M();
    for(int i = 0; i < n; i++){
        answer.t[i][i] = 1;
    }
    M m = M();
    
    m.t = can;
    while (k) {
        if(k % 2){
            answer = answer * m;
        }
        m = m * m;
        k /= 2;
    }
    
    int total = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            add(total, answer.t[i][j]);
        }
    }
    cout << total;
    
}



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

char s1[233333],s2[233333],s3[233333];


int main()
{
	int flag = 0;
	scanf("%s%s",s1,s2);
	int len = strlen(s1);
	int l = strlen(s2);
	if(len != l)
	{
		puts("NO");
		return 0;
	}
	for(int i = 0;i < len;i ++)
	{
		char tmp = s1[len - 1];
		for(int j = len - 1;j > 0;j --) s1[j] = s1[j - 1];
		s1[0] = tmp;
//		cout << s1 << endl;
		if(strcmp(s1,s2) == 0)
		{
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,k,ara[100002],visit[100002];

ll dp(ll pos)
{
    ll p,l,r,m;
    if(visit[pos]!=-1)return visit[pos];
    p=999999999;
    for(ll i=1; i<=k; i++)
    {
        if(pos+i<n)p=min(p,abs(ara[pos]-ara[pos+i])+dp(pos+i));
    }
    if(p==999999999)p=0;
    return visit[pos]=p;
}

int main()
{
    ll i;
    scanf("%lld %lld",&n,&k);
    for(i=0; i<n; i++)scanf("%lld",&ara[i]);
    memset(visit,-1,sizeof(visit));
    printf("%lld\n",dp(0));
    return 0;
}


Measured memory_bytes: 6528
import math
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
cd = []
for i in range(n):
    cd.append(iil())

dist = 0
for i in range(n):
    for j in range(i,n):
        dist += math.factorial(n-1)*2*((cd[i][0]-cd[j][0])**2+(cd[i][1]-cd[j][1])**2)**0.5
print(dist/math.factorial(n))

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
	return powmod(a, MOD-2);
}
ll f[1000001], invf[1000001];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
ll comb(int x, int y){
    if(x<y || y<0) return 0;
    return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b, a%b);
}
int main()
{
    int n; cin>>n;
    ll a[100010];
    for(int i=1; i<=n; i++){
        cin>>a[i];
    }
    ll g1[100010];
    g1[0]=0;
    for(int i=1; i<=n; i++) g1[i]=gcd(g1[i-1], a[i]);
    ll g2[100010];
    g2[n+1]=0;
    for(int i=n; i>=1; i--){
        g2[i]=gcd(g2[i+1], a[i]);
    }
    ll ans=0;
    for(int i=1; i<=n; i++){
        ans=max(ans, gcd(g1[i-1], g2[i+1]));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define P pair<int,int>
using namespace std;

int dx[6]={0,1,-1,1,-1,0},dy[6]{1,1,0,0,-1,-1};
bool a[500][500];
int mincost[500][500];
signed main(){
    int b,c;
    while(cin>>b>>c,b|c){
	memset(a,true,sizeof(a));
	memset(mincost,-1,sizeof(mincost));
	for(int d=0;d<c;d++){
	    int e,f;scanf("%d%d",&e,&f);
	    e+=250;f+=250;
	    a[e][f]=false;
	    }
	int sum=1;
	int n,m;scanf("%d%d",&n,&m);n+=250;m+=250;
	mincost[n][m]=0;
	queue<P>Q;
	Q.push(P(n,m));
	while(Q.size()){
	    P t=Q.front();Q.pop();
	    if(mincost[t.first][t.second]==b)continue;
	    for(int i=0;i<6;i++){
		int x=t.first+dx[i],y=t.second+dy[i];
		if(mincost[x][y]==-1&&a[x][y]){
		    mincost[x][y]=mincost[t.first][t.second]+1;
		    Q.push(P(x,y));
		    sum++;
		    }
		}
	    }
	    cout<<sum<<endl;
	}
    }

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

int main() {
  string S;
  cin >> S;
  int ans = 0;
  if(S.at(0) == '1') ans++;
  if(S.at(1) == '1') ans++;
  if(S.at(2) == '1') ans++;
  cout << ans << endl;
}


Measured memory_bytes: 256
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///最大公約数を返す
func gcd(_ array: [Int]) -> Int {
    var value = array[0]
    if array.count > 1 {
        for i in 1..<array.count {
            value = gcd(value, array[i])
        }
    }
    return value
}

///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

// https://melheaven.hatenadiary.jp/entry/atcoder144
///約数の配列を返す
func makeDivisors(_ n:Int) -> [Int] {
    var divisors = [Int]()
    for i in 1..<Int(pow(Double(n), 0.5)) + 1 {
        if n % i == 0{
            divisors.append(i + n / i)
        }
    }
    
    return divisors
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}

func main() {
    let hw = readInts()
    let (h, w) = (hw[0], hw[1])
    var table = [[String]]()
    for i in 0..<h {
        table.append(readLine()!.map { String($0)} )
    }
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    
    for i in 1..<h - 2{
        for j in 1..<w - 2{
            
            if table[i][j] == "#" {
                if table[i + 1][j] == "." && table[i - 1][j] == "." && table[i][j + 1] == "." && table[i][j - 1] == "." {
                    print("No")
                    return
                }
            }
            
        }
        
    }
    print("Yes")
}
    main()


Measured memory_bytes: 13560
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    int a, b, c,cnt=0;
    int aa, bb, cc;
    cin >> a >> b >> c;
    while (1) {
        if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1)break;
        aa = a / 2, bb = b / 2, cc = c/2;
        a = bb + cc, b = aa + cc, c = aa + bb;
        cnt++;
        if (cnt > 10000) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
class Solution
{
    static void Main(String[] args)
    {
      var s=Console.ReadLine();
       if((s.Contains('B')&&!s.Contains('A'))||(s.Contains('A')&&!s.Contains('B'))){
           Console.WriteLine("No");
       }else{
           Console.WriteLine("Yes");

       }
        

           
            
             
 
    }
 
}

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

int main() {
	long a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k <= a) cout<<k<<endl;
	else if(k <= (a + b)) cout<<a<<endl;
	else{
		k -= (a + b);
		cout<<a-k<<endl;
	}
	return 0;
}


Measured memory_bytes: 3636
w,h,n=gets.split.map(&:to_i)
ws=[0,w]
hs=[0,h]
n.times do
  xi,yi,ai=gets.split.map(&:to_i)
  if ai==1
    ws[0]=[ws[0],xi].max
  elsif ai==2
    ws[1]=[ws[1],xi].min
  elsif ai==3
    hs[0]=[hs[0],yi].max
  else
    hs[1]=[hs[1],yi].min
  end
end
puts [ws[1]-ws[0],0].max*[hs[1]-hs[0],0].max


Measured memory_bytes: 1788
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

#define C(I) cout<<(I)<<endl

ll n,m,a,b,c,x,y,z,aa[100010],ba[100010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc,cd[1000][1000];
vector<ll> va,vb,vc;


int main(){
    cin>>s;
    for(int i=0;i<s.size();i+=2){
        cout<<s[i];
    }
    cout<<endl;
    
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using str = string;
using ll = long long;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define RREP(i,n) for(int i=int(n)-1; i>=0; i--)
#define FOR(i,f,t) for(int i=int(f); i<=int(t); i++)
#define RFOR(i,f,t) for(int i=int(f); i>=int(t); i--)
#define ALL(vec) (vec).begin(),(vec).end()
#define ASORT(vec) sort(ALL(vec))
#define DSORT(vec) sort(ALL(vec), greater<int>());
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define YES(ans) if(ans) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define Yes(ans) if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define yes(ans) if(ans) cout<<"yes"<<endl; else cout<<"no"<<endl;

int main() {
    int l, r, d;
    cin >> l >> r >> d;
    cout << (r/d) - ((l-1)/d) << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define pii pair <int, int>
#define ll long long
#define ld long double
#pragma 03
using namespace std;
int main(){
    int n, t;
    cin >> n >> t;
    vector <pii> a(n);
    for (int i = 0; i<n; i++) cin >> a[i].first >> a[i].second;
    sort(a.begin(), a.end());
    vector <int> dp(t);
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans = max(ans, *max_element(dp.begin(), dp.end()) + a[i].second);
        for (int j = t-1; j>=a[i].first; j--) dp[j] = max(dp[j], dp[j - a[i].first] + a[i].second);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//   PIGMEISTER™   //

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

#define ll long long
#define sidha(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i)
#define ulta(i,x,n) for(ll i=(ll)(x);i>=(ll)(n);--i)
#define sab(a) a.begin(),a.end()
#define bas(a) a.rbegin(),a.rend()
#define test ll _;cin>>_;while(_--)
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD (ll)1000000007
//#define MOD (ll)998244353
#define MAX 100005

int main()
{
    jaldi;
    
    ll x;
    cin >> x;

    bool flag = false;
    sidha (i, -120, 121) {
        sidha (j, -120, 121)
            if (i*i*i*i*i-j*j*j*j*j == x) {
                cout << i << ' ' << j;
                flag = true;
                break;
            }
        if (flag) break;
    }
    
    return 0;
}


Measured memory_bytes: 3620
void main() {
	auto ip = readAs!(int[]), A = ip[0], B = ip[1];
	max(A+B, A-B, A*B).writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
	//freopen("in.txt","r",stdin);
	ll n,a,b;
	scanf("%lld%lld%lld",&n,&a,&b);
	printf("%lld\n",n/(a+b)*a+min(n%(a+b),a));
	return 0;
}

Measured memory_bytes: 256
import itertools

def main():
    A = int(input())
    B = int(input())
    C = int(input())
    X = int(input())
    a = [x for x in range(A+1)]
    b = [x for x in range(B+1)]
    c = [x for x in range(C+1)]
    ans = 0
    for i,j,k in itertools.product(a,b,c):
        if X == 500*i + 100*j + 50*k:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38768
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  int cnt = 0;
  FOR(i, 1, n + 1) {
    if (i & 1) ++cnt;
  }
  printf("%.8f\n", (double)cnt / n);
  return 0;
}


Measured memory_bytes: 256
list1=[list(map(int,input().split())) for i in range(3)]
n=int(input())
bl=[int(input()) for i in range(n)]

a=[[0]*3 for _ in range(3)] 
for bi in bl:
    for i in range(3):
        for j in range(3):
            if list1[i][j]==bi:
                a[i][j]=1
ans=0
for i in range(3): # 縦横の判別
    if a[0][i]==1 and a[1][i]==1 and a[2][i]==1:
        ans=1
    if a[i][0]==1 and a[i][1]==1 and a[i][2]==1:
        ans=1
if a[0][0]==1 and a[1][1]==1 and a[2][2]==1:
    ans=1
if a[0][2]==1 and a[1][1]==1 and a[2][0]==1:
    ans=1
if ans==0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 38384
/* C - XYZ Triplets */

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

int Triplets(int n){
  int ans = 0;
  if(n >= 6){
    for(int i = 1; i <= sqrt(n - 2) - 1; i++){
      for(int j = i; j <= sqrt(n - 2) - 1; j++){
        for(int k = j; k <= sqrt(n - 2) - 1; k++){
          if((i + j) * (i + j) + (j + k) * (j + k) + (k + i) * (k + i) == 2 * n){
            if(i == j && j == k && k == i){
              ans++;
            }else if(i == j || j == k || k == i){
              ans += 3;
            }else{
              ans += 6;
            }
          }
        }
      }
    }
  }
  return ans;
}

int main(){
  int N;
  cin >> N;
  for(int i = 1; i <= N; i++){
    cout << Triplets(i) << endl;
  }
}


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

main(){
int a,b;
cin >> a >> b;
if(a + b == 3){
  cout << 3 << endl;}
else if(a + b == 4){
  cout << 2 << endl;}
else{cout << 1 << endl;}
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int N;

	public static void main(String[] args) {
		int N = sc.nextInt();
		ArrayList<Integer> stack = new ArrayList<Integer>();
		int ans = 1;
		stack.add(sc.nextInt());
		for (int i = 1; i < N; ++i) {
			int a = Integer.parseInt(sc.next());
			while (!stack.isEmpty()) {
				int top = stack.get(stack.size() - 1);
				if (top > a) {
					stack.remove(stack.size() - 1);
				} else {
					break;
				}
			}
			if (stack.isEmpty() || stack.get(stack.size() - 1) < a) {
				stack.add(a);
				++ans;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 75052
using System;
using System.Collections.Generic;
using System.Linq;

namespace AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Read();
            var sim = false;
            if (S[2] == S[3] && S[4] == S[5]) sim = true;

            Console.WriteLine(sim ? "Yes" : "No");
            Console.ReadKey();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static string[] ReadArrayString() { return Read().Split(' '); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <cstring>

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

using namespace std;
typedef long long ll;

constexpr int inf=100000000;


struct Point{
    Point (){};
    Point (int h_,int w_):h(h_),w(w_){}
    int h;
    int w;
    
    void print(){
        cout<<"h: "<<h<<" w: "<<w<<endl;
    }
};


int main(){
    int H,W;
    cin>>H>>W;
    Point c,d;
    cin>>c.h>>c.w;
    --(c.h);--(c.w);
    cin>>d.h>>d.w;
    --(d.h);--(d.w);
    
    vector<string> mp;
    mp.resize(H);
    
    
    
    vector<vector<int> > seen(H,vector<int>(W,inf));
    
    for(int i=0;i<H;++i){
        cin>>mp[i];
    }
    
    
    queue<Point> q1;     //q1
    q1.push(c);
    seen[c.h][c.w]=0;
    
    
    while(!q1.empty()){
        Point p1=q1.front();
        q1.pop();
        
       // p1.print();
        
        queue<Point> q2;
        q2.push(p1);
        while(!q2.empty()){
           //cout<<"--------"<<endl;
            
            Point p2=q2.front();
            q2.pop();
           // p2.print();
            for(int i=-2;i<=2;++i){
                for(int j=-2;j<=2;++j){
                    Point p3(p2.h+i,p2.w+j);
                    //cout<<"p3 ";
                    //p3.print();
                    if(p3.h<0||p3.h>=H||p3.w<0||p3.w>=W)continue;
                    if(mp[p3.h][p3.w]=='#')continue;
                    if(seen[p3.h][p3.w]<=seen[p2.h][p2.w])continue;
                    
                    if((i==1&&j==0)||(i==0&&j==1)||(i==-1&&j==0)||(i==0&&j==-1)){
                        if(seen[p3.h][p3.w]>seen[p2.h][p2.w]){
                            q2.push(p3);
                            seen[p3.h][p3.w]=seen[p2.h][p2.w];
                           //  cout<<"q2 "<<p3.h<<" ; "<<p3.w<<" seen: "<<seen[p3.h][p3.w]<<endl;
                        }
                       
                       
                        
                    }else{
                        
                        if(seen[p3.h][p3.w]>seen[p2.h][p2.w]+1){
                            q1.push(p3);
                            seen[p3.h][p3.w]=seen[p2.h][p2.w]+1;
                           //  cout<<"q1  "<<p3.h<<" ; "<<p3.w<<" seen: "<<seen[p3.h][p3.w]<<endl;
                        }
                         
                    }
                }
            }
        }
        /*
        for(int i=0;i!=H;++i){
             for(int j=0;j!=W;++j){
                 cout<<seen[i][j]<<" ";
             }
             cout<<endl;
         }
         */
        
      
    }
    /*
    
    for(int i=0;i!=H;++i){
        for(int j=0;j!=W;++j){
            cout<<seen[i][j]<<" ";
        }
        cout<<endl;
    }
     
    */
    
    
    if(seen[d.h][d.w]==inf){
        cout<<-1<<endl;
    }else{
        cout<<seen[d.h][d.w]<<endl;
    }

    
    
}

Measured memory_bytes: 9484
#include <map>
#include <set>
#include <cmath>
#include <ctime> 
#include <queue>
#include <stack>
#include <bitset> 
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>
#include <iostream>
#include <algorithm>

#define fi first
#define se second
#define pb push_back
#define MP std::make_pair
#define PII std::pair<int, int>
#define all(x) (x).begin(), (x).end()
#define CL(a, b) memset(a, b, sizeof a)
#define rep(i, l, r) for (int i = (l); i <= (r); ++ i)
#define per(i, r, l) for (int i = (r); i >= (l); -- i)
#define PE(x, a) for (int x = head[a]; x;x = edge[x].next)

typedef long long ll;

int t[20];

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    t[a]++, t[b]++, t[c]++;
    int flag = 0;
    rep(i, 1, 9) {
        flag |= t[i] == 2;
    }
    printf(flag ? "Yes" : "No");
    return 0;
}

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

namespace _0018
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] temp = Console.ReadLine().Split(' ');
            int[] abcde = new int[temp.Length];

            for (int i = 0; i < temp.Length; i++)
            {
                abcde[i] = int.Parse(temp[i]);
            }
            Array.Sort(abcde);

            Console.WriteLine("{0} {1} {2} {3} {4}",abcde[4],abcde[3],abcde[2],abcde[1],abcde[0]);
        }
    }
}



Measured memory_bytes: 17956
#include <iostream>
using namespace std;
int main(void)
{
    int n;
    cin >> n;
    long long int min = 10000000;
    long long int max = -10000000;
    long long int x, sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> x;
        if (min > x) {
            min = x;
        }
        if (max < x) {
            max = x;
        }
        sum = sum + x;
    }
    cout << min << " ";
    cout << max << " ";
    cout << sum << endl;
    
}



Measured memory_bytes: 3100
/*
AizuOnline A1105v1
Unable Count
(TimeLimitExceeded)
*/
#include <stdio.h>

int prime[10]={2,3,5,7,11,13,17,19,23,29};
int gcd(int x,int y)
{ int w,r;
  int i,pr;
  
  for(i=0;i<10;i++)
    {
      pr=prime[i];
      if(x % pr == 0 && y % pr == 0)
	return(pr*gcd(x/pr,y/pr));
    }
  
  if(x < y)
    {
      w = x;
      x = y;
      y=  w;
    }
  if((r = x % y) ==0)
    return(y);
  return(gcd (y, r));
}

/*
int lcm(int x, int y)
{
  return(x/gcd(x,y)*y);
}
*/
/*valid n <= lcm(a,b)*/
int unable_count_simple2(int n,int a,int b)
{
  int i,j,c,ret;

  c=0;
  for(i=0;(float)i<(float)n/a;i++)
    {
      c += ((n - a*i)/b+((i)?1:0));
#ifdef DEBUG
    printf("c=%d\n",c);
#endif
    }
  ret = n-c;   
  return(ret);
}
int unable_count_single(int n,int a)
{
  return(n/a*(a-1) + (n % a)); 
}
int unable_count(int n,int a,int b)
{
  int ret;
  int gcd_ab = gcd(a,b);
  int lcm_ab = a/gcd_ab*b;

  if(lcm_ab >= n)
    return(unable_count_simple2(n,a,b));

  ret = unable_count_simple2(lcm_ab,a,b);
  ret += unable_count_single(n-lcm_ab,gcd_ab);
  return(ret);
    
}
main()
{
  int n,a,b,ret;


  while(EOF !=scanf(" %d %d %d",&n,&a,&b) && (n||a||b))
    {
      printf("%d\n",unable_count(n,a,b));
    }
return(0);
}

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

const int NUM = 100000;

typedef pair<char, int> card;
card L[NUM/2+2], R[NUM/2+2];

void merge(card A[], int l, int m, int r) {
  int n1 = m - l, n2 = r - m;

  for (int i = 0; i < n1; i++)
    L[i] = A[l+i];
  for (int i = 0; i < n2; i++)
    R[i] = A[m+i];

  L[n1] = R[n2] = card('X', numeric_limits<int>::max());

  int i = 0, j = 0;

  for (int k = l; k < r; k++) {
    if (L[i].second <= R[j].second) A[k] = L[i++];
    else A[k] = R[j++];
  }
}

void mergeSort(card A[], int l, int r) {
  if (l+1 < r) {
    int m = (l+r)/2;
    mergeSort(A, l, m);
    mergeSort(A, m, r);
    merge(A, l, m, r);
  }
}

int partition(card A[], int p, int r) {
  int x = A[r-1].second;
  int i = p - 1;
  for (int j = p; j < r-1; j++) {
    if (A[j].second <= x)
      swap(A[++i], A[j]);
  }
  swap(A[i+1], A[r-1]);
  return i+1;
}

void quickSort(card A[], int p, int r) {
  if (p < r) {
    int q = partition(A, p, r);
    quickSort(A, p, q);
    quickSort(A, q+1, r);
  }
}

int main() {
  int n;
  card quick[NUM], merge[NUM];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> quick[i].first >> quick[i].second;
    merge[i].first = quick[i].first;
    merge[i].second = quick[i].second;
  }

  quickSort(quick, 0, n);
  mergeSort(merge, 0, n);

  bool stable = true;
  for (int i = 0; i < n; i++) {
    if (quick[i] != merge[i]) {
      stable = false;
      break;
    }
  }

  cout << (stable ? "Stable" : "Not stable") << endl;

  for (int i = 0; i < n; i++)
    cout << quick[i].first << ' ' << quick[i].second << endl;

  return 0;
}

Measured memory_bytes: 3512
from fractions import gcd
A,B,C,D=map(int,input().split())
A-=1
S=B-B//C-B//D+B//((C*D)//gcd(C,D))
T=A-A//C-A//D+A//((C*D)//gcd(C,D))
print(S-T)

Measured memory_bytes: 5048
n, m = map(int, input().split())
h = list(map(int, input().split()))
edge = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
ans = n
for i in range(n):
    for j in edge[i]:
        if h[i] <= h[j]:
            ans -= 1
            break
print(ans)

Measured memory_bytes: 29424
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int s = scan.nextInt();
		int w = scan.nextInt();
		
		if(s <= w) {
			System.out.println("unsafe");
		}else {
			System.out.println("safe");
		}

	}

}


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

int n;
int a[110000];
signed main(){
    int n;cin >>n;
    rep(i,n)cin >> a[i+1];
    int sum = 0;
    rep(i,n+1){
        sum += abs(a[i+1] - a[i]);
    }
    vector<int> ans(n,sum);
    rep(i,n){
        
        if((a[i] < a[i+1]&& a[i+1]< a[i+2] )|| (a[i+2] < a[i+1]&& a[i+1]< a[i]))continue;
        int tmp = min(abs(a[i] - a[i+1]),abs(a[i+2] - a[i+1]));
        
        ans[i]-= tmp*2;

    }
    rep(i,n)cout << ans[i] << endl;


    return 0;
}

Measured memory_bytes: 2816
import java.util.*;

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

        int a = sc.nextInt();
        int b = sc.nextInt();

        if(b == 1){
            System.out.println(0);
            return;
        }
        int ans = 1;
        int plugs = a;
        while(plugs < b){
            plugs += a - 1;
            ans++;
        }

        System.out.println(ans);
        return;
    }
}

Measured memory_bytes: 23124
import string
atoz = string.ascii_lowercase
N = int(input())
azcount = {}
for i in range(N):
  s = input()
  for alph in atoz:
    if alph in azcount:
      azcount[alph] = min(s.count(alph), azcount[alph])
    else:
      azcount[alph] = s.count(alph)
res = ''

for alph in atoz:
  res += alph * azcount[alph]

print(res)

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

namespace abc107_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            Console.WriteLine(a - b + 1);
        }
    }
}


Measured memory_bytes: 27532
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define umap unordered_map
#define all(v) v.begin(),v.end()
#define st first
#define nd second
#define ln '\n'
#define MAX 1000000009
#define MOD 1000000007
#define N 500005
using namespace std;
typedef long long ll;
typedef pair<ll ,ll> pii;
typedef vector<int> vi;
ll n, x, ct[N + 1];
vi v;
unsigned long long int ans[N], sans;
int main(){
    #ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    #endif 
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);cout.tie(NULL);
	    cin >> n;
	    while(n--){
	    	cin >> x;
	    	ct[x]++;
	    	v.pb(x);
	    }
	    for(int i = 1; i <= N - 10; i++){
	    	//cout <<  ct[i] << ln;
	    	ans[i] = (unsigned long long int)(ct[i] * (ct[i] - 1) / 2 )- (unsigned long long int)((unsigned long long int)(ct[i] - 2)*(unsigned long long int) (ct[i] - 1)) / 2;
	    	sans = (unsigned long long int)sans + (unsigned long long int)((unsigned long long int)ct[i] * (ct[i] - 1)) / 2;
	    	//Bcerr << sans << " ";
	    }
	    cerr << sans << ln;
	    for(auto a : v){
	    	cout << (unsigned long long int)sans - ans[a] << ln;
	    }
}

Measured memory_bytes: 9588
object Main extends App {
  val scanner = new java.util.Scanner(System.in)

  val data = Iterator.continually {
    val H  = scanner.nextInt()
    val W  = scanner.nextInt()

    (H, W)
  }

  val outputs = data.takeWhile(_ != (0, 0)).map {
    case (h, w) =>
      s"${"#" * w}\n" +
        s"#${"." * (w-2)}#\n" * (h-2) +
        s"${"#" * w}\n"
  }

  outputs.foreach(println)
}

Measured memory_bytes: 45752
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  int H[N];
  for (int i = 0;i < N;i++) {
    cin >> H[i];
  }

  long num_of_attack = 0;
  std::sort(H, H + sizeof(H)/sizeof(H[0]));
  for (int i = 0;i < N - K;i++) {
    num_of_attack += H[i];
  }
  cout << num_of_attack << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
int main()
{   int chk[27]={0};
    char s[100001];
    scanf("%s",s);
    for(int i=0;i<strlen(s);i++){
        chk[s[i]-'a']++;
    }
    for(int i=0;i<26;i++){
        if(chk[i]==0){
            printf("%c",'a'+i);
            return 0;
        }
    }
    printf("None");
    return 0;
}


Measured memory_bytes: 256
import Control.Applicative ((<$>))

main :: IO ()
main = do
    d1 <- readDice <$> getLine
    d2 <- readDice <$> getLine
    putStrLn $ if solve d1 d2 then "Yes" else "No"

solve :: Dice -> Dice -> Bool
solve d1 d2 =  d1' == d2'
            || d1' == fmap rot d2'
            || d1' == fmap (rot.rot) d2'
            || d1' == fmap (rot.rot.rot) d2'
    where
        d1' = Just d1
        d2' = matchTB (top d1, bottom d1) d2

matchTB :: (String,String) -> Dice -> Maybe Dice
matchTB p d@(Dice t s e w n b)
    | p == (t,b) = Just d
    | p == (b,t) = Just $ goN $ goN d
    | p == (s,n) = Just $ goN d
    | p == (n,s) = Just $ goS d
    | p == (e,w) = Just $ goW d
    | p == (w,e) = Just $ goE d
    | otherwise = Nothing

goE :: Dice -> Dice
goE (Dice t s e w n b) = Dice w s t b n e
goN :: Dice -> Dice
goN (Dice t s e w n b) = Dice s b e w t n
goS :: Dice -> Dice
goS (Dice t s e w n b) = Dice n t e w b s
goW :: Dice -> Dice
goW (Dice t s e w n b) = Dice e s b t n w

rot :: Dice -> Dice
rot (Dice t s e w n b) = Dice t w s n e b

data Dice = Dice
    { top :: String
    , south :: String
    , east :: String
    , west :: String
    , north :: String
    , bottom :: String
    } deriving (Eq)

readDice :: String -> Dice
readDice str = Dice t s e w n b
    where (t:s:e:w:n:b:_) = words str

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

int main() {
  /*
  int i =12345;
  int s = i %10 ,t = i /10000 % 10;
  int u = i /10 % 10, v = i/1000 % 10;
  cout << s<< endl; //s=5 iti
  cout << t<< endl; //t=1 man
  cout << u<< endl; //u=4 jyu
  cout << v<< endl; //v=2 sen 
  */
  int a,b;
  int c = 0;
  cin >> a>> b;
  for(int i = a; i <= b; i++){
    int s = i %10 ,t = i /10000 % 10;
    int u = i /10 % 10, v = i/1000 % 10;
    if((s == t)&&(u == v)){
     c++; 
    }
    else{
    
   }
  }
  cout<<c;
}


Measured memory_bytes: 256
n = int(input())
ws = [1]
ws += [6**i for i in range(1, 8)]
ws += [9**i for i in range(1, 6)]
ws = sorted(set(ws))

INF = 10**5
dp = [INF] * (n+1)
dp[0] = 0
for i in range(n+1):
    for w in ws:
        if i + w <= n:
            dp[i+w] = min(dp[i]+1, dp[i+w])
print(dp[-1])


Measured memory_bytes: 3956
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A,B;
    cin >> A >> B;
    
    int C,D,E;
    
    C = A+B;
    
    D = A-B;
    
    E = A*B;
    
    int ans;
    if(C>D&&C>E)ans = C;
    else if(D > C && D > E) ans = D;
    else if(E > C && E > D)ans = E;
    
    cout << ans << endl;
    
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<string>
#include<string.h>
#include<map>
#include<math.h>

#define int long long
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define all(a) begin(a),end(a)
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define sz(x) ((int)x.size())
#define ins insert
#define rep(i,l,u) for(int i=l;i<=u;++i)
#define reb(i,l,u) for(int i=l;i>=u;--i)
using namespace std;
const int maxn=1e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
int gcd(int a,int b){
    return b==0?a:gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin>>n>>k;
    int ans=-inf;
    int p[5100],c[5100];
    int rd[5100],num[5100];
    for(int i=1;i<=n;++i)cin>>p[i];
    for(int i=1;i<=n;++i){
        cin>>c[i];
        ans=max(ans,c[i]);
    }
    map<int,int>vis;
    for(int i=1;i<=n;++i){
        if(vis[i])continue;
        int round_mx=0;
        vector<int>need;
        int numb=0;
        int pos=i;
        while(!vis[pos]){
            round_mx+=c[pos];
            vis[pos]=1;
            need.pb(pos);
            pos=p[pos];
            numb++;
        }
        for(auto j:need){
            rd[j]=round_mx;
            num[j]=numb;
        }
    }
    for(int i=1;i<=n;++i){
        int pos=i;
        int single_mx=c[i];
        int tmp;
        int more;
        if(k<=num[i]){
            more=0;
            tmp=k;
        }else{
            tmp=k%num[i]+num[i];
            more=(k-tmp)/num[i];
        }
        int round=0;
        int flag=0;
        while(tmp--){
            round+=c[pos];
            pos=p[pos];
            if(round>=single_mx){
                flag=1;
                single_mx=round;
            }
        }
        int cmp=more*rd[i]+single_mx;
        ans=max({ans,cmp,single_mx});
    }
    cout<<ans<<endl;
}
/**
2 3
2 1
1000000000 -999999999
**/


Measured memory_bytes: 4196
#include<math.h>
#include<stdio.h>

int main(){
  double v;

  while(scanf("%lf",&v)!=EOF){
    int n=0;
    int f=0;
    while(f==0){
      n++;
      double vv=7*sqrt(2.0*(double)(n-1));
      if(vv>v){
	f=1;
      }
    }
    printf("%d\n",n);
  }

  return 0;
}

Measured memory_bytes: 628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
typedef vector<int,vector<int>> vec;
typedef pair<int,int> P;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n,j) for (int i = n; j<i;i--)
#define print(out) cout<< out  << "\n";
#define all(vec) vec.begin(),vec.end()
#define mod 1000000007
const int INF = 1e9;

int main(){
  int N,M;cin>>N>>M;
  vector<int> S(M), C(M);
  REP(i,0,M){cin>>S[i]>>C[i];--S[i];}
  REP(n1,0,1000){
    string n=to_string(n1);
    bool flg=true;
    if(n.size()!=N){
      continue;
    }
    //print(n<<(n.at(0)))
    REP(m,0,M){
      if(n.at(S[m])!=(char)(C[m]+'0')){
        flg=false;
        break;
      }
    }
    if(flg){
      print(n)
      return 0;
    }
  }
  print("-1")

}


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

const double p = 1.0 / 6.0;
double dp[105][105][2] = {0};
int n, t, l, b;
bool isl[105] = {0}, isb[105] = {0};

double solve();

int main() {
  cout << fixed << setprecision(12);
  while(1) {
    cin >> n >> t >> l >> b;
    if(n + t + l + b == 0) break;
    for(int i = 0; i < l; ++i) {
      int x;
      cin >> x;
      isl[x] = 1;
    }
    for(int i = 0; i < b; ++i) {
      int x;
      cin >> x;
      isb[x] = 1;
    }
    cout << solve() << endl;
    for(int i = 0; i <= n; ++i) isb[i] = isl[i] = 0;
    for(int i = 0; i <= t; ++i)
      for(int j = 0; j <= n; ++j)
        for(int k = 0; k < 2; ++k) dp[i][j][k] = 0;
  }
  return 0;
}

double solve() {
  double ans = 0;
  dp[0][0][0] = 1;
  for(int i = 1; i <= t; ++i) {
    for(int j = 0; j < n; ++j) {
      for(int k = 1; k <= 6; ++k) {
        int nextx = j + k;
        // if over, return
        if(j + k > n) nextx = 2 * n - nextx;
        // if nextx = l
        if(isl[nextx])
          dp[i][nextx][1] += dp[i - 1][j][0] * p;
        // if nextx = b
        else if(isb[nextx])
          dp[i][0][0] += dp[i - 1][j][0] * p;
        else
          dp[i][nextx][0] += dp[i - 1][j][0] * p;
      }
      dp[i][j][0] += dp[i - 1][j][1];
    }
    ans += dp[i][n][0];
    dp[i][n][0] = 0;
  }
  return ans;
}



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

int main() {
	int N;
	string S;
	cin>>N>>S;
	int cnt=0,ans=0;
	rep(i,N){
		if(S[i]=='I')cnt++;
		else cnt--;
		ans=max(ans,cnt);
	}
	cout<<ans<<endl;
}

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

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

    int N = scanner.nextInt();
    long M = scanner.nextInt();
    long V = scanner.nextInt();
    int P = scanner.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) A[i] = scanner.nextInt();
    Arrays.sort(A);
    reverse(A);
    long[] cum = new long[N];
    for (int i = 1; i < N; i++) cum[i] = cum[i - 1] + A[i - 1];

    int count = P;
    for (int i = P; i < N && A[i] + M >= A[P - 1]; i++) {
      long cap = M * (P - 1 + N - i) + (i - P + 1) * (A[i] + M) - (cum[i] - cum[P - 1]);
      if (cap >= M * V) count++;
    }
    System.out.println(count);
  }

  private static void reverse(int[] a) {
    int i = 0;
    int j = a.length - 1;
    while (i < j) {
      int tmp = a[i];
      a[i] = a[j];
      a[j] = tmp;
      i++;
      j--;
    }
  }
}


Measured memory_bytes: 52020
na = lambda: list(map(int, input().split()))

h, w = na()
t = []
cnt = 0
for i in range(h):
    I = list(input())
    if not("#" in I):
        cnt += 1
        continue
    t.append(I)
output = []
for j in range(w):
    flag = False
    for i in range(h-cnt):
        if t[i][j] == "#":
            flag = True
    if flag:
        output.append(j)
for T in t:
    for num, i in enumerate(T):
        if num in output:
            print(i, end="")
    print()

Measured memory_bytes: 4596
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

int n, r, b;
int main() {
	string h;
	cin >> n;
	cin >> h;
	for (int i = 0; i < h.length(); ++i) {
		if (h[i] == 'R') { ++r; }
		else { ++b; }
	}
	if (r > b) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
}


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

string s;
std::vector<int> Make_MP_table(const std::string& key) {
	const int length = key.size();
	std::vector<int> ret(length + 1);

	ret[0] = -1;
	int matched = -1;
	for (int i = 0; i < length; ++i) {
		while (matched >= 0 && key[matched] != key[i]) {
			matched = ret[matched];
		}
		++matched;
		ret[i + 1] = matched;
	}
	return ret;
}

bool periodic(const vector<int>& arr, int i) {
  return arr[i] > 0 && i % (i - arr[i]) == 0;
}

int main() {
  cin >> s;
  const int n = s.size();
  if (count(s.begin(), s.end(), s[0]) == n) {
    cout << n << endl << 1 << endl;
  } else {
    auto arr = Make_MP_table(s);
    if (periodic(arr, n)) {
      reverse(s.begin(), s.end());
      auto rev = Make_MP_table(s);

      int cnt = n - 1;
      for (int i = 1; i < n; ++i) {
        if (periodic(arr, i) || periodic(rev, n - i)) {
          --cnt;
        }
      }
      cout << 2 << endl << cnt << endl;
    } else {
      cout << 1 << endl << 1 << endl;
    }
  }
}

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

#define MOD (1000000000+7)
#define MAX 200000

int N;
int C[MAX];

int num[MAX][2];
long long dp[MAX];

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

	dp[0] = 1;
	for( int i = 0; i < N; i++ ) {
		if( i ) {
			dp[i] = dp[i - 1];
		}
		if( i == 0 || C[i - 1] != C[i] ) {
			int c = C[i] - 1;
			num[c][0]++;
			if( num[c][0] > 1 ) {
				dp[i] = ( dp[i] + dp[ num[c][1] ] ) % MOD;
			}
			num[c][1] = i;
		}
	}
	long long ans = dp[N - 1];

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4096
#include<stdio.h>
#include<math.h>

int main(void){
  int n,k;
  double sum1,sum2;
  double ave1,ave2,S1,S2;
  while(1){
    sum1=0,sum2=0;
    scanf("%d",&n);
    if(n==0) break;
    double s[n+1];
    for(k=1;k<=n;k++){
      scanf("%lf",&s[k]);
      sum1+=s[k];
      sum2+=s[k]*s[k];
    }
    ave1 = sum1 / n;
    ave2 = sum2 / n;

    S1 = ave1*ave1 - ave2;
    S2 = sqrt(fabs(S1));
    //  printf("ave1???%lf??§ave2???%lf???S1???%lf\n",ave1,ave2,S1);
    printf("%lf\n",S2);
  }
  return 0;
}

Measured memory_bytes: 664
#include <iostream>
using namespace std;
int C[10001]={0};
int n=0, a;
int main() 
{
	int maxa=0;
	int mina=10000;
	cin>>n;
	for(int i=0;i<n;i++) {
		cin>>a; 
		++C[a]; 
		if (a>maxa)maxa=a;
		if (a<mina)mina =a;
	}
	
	for(int j=0;j<C[mina];j++){
		if (j) cout<<' ';
		cout<<mina;
	}
	for(int i=mina+1;i<=maxa;i++){
		for(int j=0;j<C[i];j++){
			cout<<' '<<i;
		}
	}
	cout<<endl;
}

Measured memory_bytes: 1200
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
s = input()
for S in ["SS","SW","WS","WW"]:
  st = S
  for i in range(1,n):
    if s[i] == "o":
      if st[i] == "S":
        st += st[i-1]
      else:
        st += ("W" if st[i-1] == "S" else "S")
    else:
      if st[i] == "S":
        st += ("W" if st[i-1] == "S" else "S")
      else:
        st += st[i-1]
  # print(st,"debug")
  if st[0] == st[-1]:
    ok = False
    if s[0] == "o":
      if st[0] == "S":
        if st[1] == st[-2]:
          ok = True
      else:
        if st[1] != st[-2]:
          ok = True
    else:
      if st[0] == "W":
        if st[1] == st[-2]:
          ok = True
      else:
        if st[1] != st[-2]:
          ok = True
    if ok:
      print(*st[:n],sep = "")
      exit()
print(-1)


Measured memory_bytes: 226260
#include <bits/stdc++.h>
using namespace std;
int main(){
  string h;
  int n,count=0;
  cin>>h>>n;
  for(int i=0;i<h.length();i+=n){
    cout<<h[i];
    count+=n;
    if(n>=h.length()) break;
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
using namespace std;
int main(){
  int n,k ; cin >>n>>k;
  int ans=1;
  for(int i=0;i<n;i++){
    if(k>ans) ans*=2;
    else ans+=k;
  }
  cout <<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 998244353
#define ll long long
using namespace std;
int n,a,b,q[300005],x[300005],ans;
ll k;
int pow(int c,int p){
	int tot=1;
	while(p){
		if(p&1) tot=1ll*c*tot%mod;
		c=1ll*c*c%mod;
		p>>=1;
	}
	return tot;
}
int C(int A,int B){
	if(A==0) return 1; if(A>B||B-A>n) return 0; if(A==B) return 1;
	return 1ll*q[B]*x[A]%mod*x[B-A]%mod;
}
int main(){
	scanf("%d%d%d%lld",&n,&a,&b,&k);
	q[1]=1;for(int i=2;i<=n;++i) q[i]=1ll*q[i-1]*i%mod;
	x[n]=pow(q[n],mod-2);
	for(int i=n-1;i>=0;--i) x[i]=x[i+1]*1ll*(i+1)%mod;
	if(k==0){puts("1");return 0;}
	for(int i=1;i<=n;++i){
		ll j=k-1ll*i*a;
		if(j%b) continue;
		j/=b;
		ans=(ans+1ll*C(i,n)*C(j,n)%mod)%mod;
	}
	printf("%d",ans);
}

Measured memory_bytes: 2560