akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
        static Scanner sc = new Scanner(System.in);
        static void myout(Object t){System.out.println(t);}//standard output
        static void myerr(Object t){System.err.println(t);}//standard error
        static String getStr(){return sc.next();}
        static int getInt(){return Integer.parseInt(getStr());}
        static long getLong(){return Long.parseLong(getStr());}
        static boolean isNext(){return sc.hasNext();}
        static String[] mySplit(String str){return str.split("");}
        public static void main(String[] args){
          int N = getInt();
          int X = getInt();
          ArrayList<Integer> list = new ArrayList<Integer>(N+1);
          list.add(X);
          for(int i = 0; i < N; i++){
            list.add(getInt());
          }
          Collections.sort(list,Comparator.naturalOrder());
          long output = 0;
          boolean odd = false;
          boolean even = false;
          for(int i = 1; i < N+1; i++){
            if(i == 1){
              output = list.get(i)-list.get(i-1);
            }else{
              output = gcd(output, list.get(i)-list.get(i-1));
            }
          }
          myout(output);
        }
        //便利メソッド追加枠ここから
  public static long gcd(long m, long n) {return n != 0 ? gcd(n, m % n) : m;}
        //便利メソッド追加枠ここまで
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

int w,h,s[30][30],c[4],d[900][4],ans; //d[pos][dir]:=位置posに向きdirで入るための最小コスト

int encode(int y,int x){
    return w*y+x;
}

pii decode(int pos){
    return pii(pos/w,pos%w);
}

void dijkstra(){
    ans=inf;
    fill_n((int*)d,900*4,inf);
    d[0][0]=0;
    priority_queue<pair<int,pii>,vector<pair<int,pii>>,greater<pair<int,pii>>> que;
    que.push(make_pair(0,pii(0,0)));
    while(!que.empty()){
        pair<int,pii> p=que.top(); que.pop();
        int dist=p.first,pos=p.second.first;
        int y=decode(pos).first,x=decode(pos).second,dir=p.second.second;

        if(y==h-1 and x==w-1){
            ans=min(ans,dist);
            continue;
        }
        if(dist>d[encode(y,x)][dir]) continue;

        rep(i,0,4){
            int cost=c[i],ndir=(dir+i)%4;
            if(i==s[y][x]) cost=0;
            
            int ny=y+dy[ndir],nx=x+dx[ndir];
            int npos=encode(ny,nx);
            if(ny<0 or h<=ny or nx<0 or w<=nx) continue;
            if(dist+cost<d[npos][ndir]){
                d[npos][ndir]=dist+cost;
                que.push(make_pair(d[npos][ndir],pii(npos,ndir)));
            }
        }
    }
}

void solve(){
    while(true){
        cin >> w >> h;
        if(w==0 and h==0) break;

        rep(y,0,h) rep(x,0,w) cin >> s[y][x];
        rep(i,0,4) cin >> c[i];

        dijkstra();

        cout << ans << endl;
    }
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	solve();
	return 0;
}

Measured memory_bytes: 1308
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

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

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

int T, D, L;
int cnt;
int x;
int ans;
bool debug = true;

int main() {
	
	while( cin>>T>>D>>L, (T||D||L) ){
		cnt = 112345;
		ans = 0;
		REP( i, T ){
			cin>>x;
			if( x >= L ) cnt = 0;
			cnt++;
			if( cnt <= D && ( i != (T-1) ) ) ans++;
		}
		//if( debug ) cout<<"@ "; 
		cout<<ans<<endl;
	}
	
	return 0;
}



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

long long int N, M, x, y, z, d[5] = {1, -1, -1, -1, -1}, A = 0;
vector<long long int> v[8];

int main(){
    scanf("%lld%lld", &N, &M);
    if(M == 0)return 0 & puts("0");
    for(int i = 0; i < N; ++i){
        scanf("%lld%lld%lld", &x, &y, &z);
        for(int j = 0; j < 8; ++j){
            v[j].push_back(d[j & 1] * x + d[j & 2] * y + d[j & 4] * z);
        }
    }
    for(int j = 0; j < 8; ++j) {
        sort(v[j].rbegin(), v[j].rend());
        partial_sum(v[j].begin(), v[j].end(), v[j].begin());
        A = max(A, v[j][M - 1]);
    }
    cout << A << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<map>
#define PRE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;
const int Mod = 1e9 + 7;
char lst[4], sec[2] = { '+','-' };

int main()
{
	PRE;
	string str;cin >> str;

	int a=str[0]-'0', b=str[1]-'0', c=str[2]-'0', d=str[3]-'0';
	char c1, c2, c3;
	int ans = a;
	for (int i = 0;i <= 1;i++)
	{
		if (sec[i] == '+') ans += b;
		else ans -= b;
		for (int j = 0;j <= 1;j++)
		{
			if (sec[j] == '+')ans += c;
			else ans -= c;
			for (int k = 0;k <= 1;k++)
			{
				if (sec[k] == '+')ans += d;
				else ans -= d;
				if (ans == 7)
				{
					c1 = sec[i];c2 = sec[j];c3 = sec[k];
					cout << a << c1 << b << c2 << c << c3 << d << "=" << 7;
					return 0;
				}
				if (sec[k] == '+')ans -= d;
				else ans += d;
			}
			if (sec[j] == '+')ans -= c;
			else ans += c;
		}
		if (sec[i] == '+')ans -= b;
		else ans += b;
	}
}

Measured memory_bytes: 3196
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>

using namespace std;

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

int main() {
    string s;
    cin >> s;
    cout << s[0] << s.size()-2 << s[s.size()-1] << endl;
}


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

typedef long long ll;

#define F first 
#define S second 
#define PB push_back
#define MP make_pair 
#define rep(i,a,b) for (ll i=a;i<b;i++)

typedef vector<int> vi;
typedef pair<int,int> pi;


int isSorted(vi a)
{
    rep(i,1,a.size()+1)
    {
        if(a[i-1]!=i) 
        {
            return -1; 
        }
    }
    return 0; 
}
int main()
{
    int n;
    cin>>n;

    vi a(n); 
    vi b; 
    rep(i,0,n)
        cin>> a[i]; 

    ll count=0; 
    int i=1; 
    for(int j=0;j<n;j++)
    {
        if(a[j]==i) 
        {
            b.PB(i); 
            i++; 
        }
        else {
            count++; 
        }
    }
//    rep(i,0,b.size()) cout<<b[i]<<" "; 
    //cout<<"sorted" <<isSorted(b)<<endl; 
    if(!b.empty())
        cout<<count<<endl; 
    else cout<<-1<<endl; 

    return 0; 
}



Measured memory_bytes: 2168
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}


int i_gcd(int a, int b);
int i_gcd(int a, int b) {
	if (!b)return a;
	return i_gcd(b, a % b);
}
int i_lcm(int a, int b);
int i_lcm(int a, int b) {
	return (a * b) / i_gcd(a, b);
}
int ll_gcd(ll a, ll b);
int ll_gcd(ll a, ll b) {
	if (!b)return a;
	return ll_gcd(b, a % b);
}
int ll_lcm(ll a, ll b);
int ll_lcm(ll a, ll b) {
	return (a * b) / ll_gcd(a, b);
}

// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
//ll _pfact(ll a);
//static ll pf[100000000];
//static ll pc;
//
//ll _pfact(ll a) {
//	long i, r;
//	if (a % 2 == 0) {
//		pf[pc] = 2; pc++;
//		return(_pfact(a / 2));
//	}
//	r = sqrt(a);
//	for (i = 3; i <= r; i += 2) {
//		if (a % i == 0) {
//			pf[pc] = i; pc++;
//			return(_pfact(a / i));
//		}
//	}
//	if (a != 1) {
//		pf[pc] = a; pc++;
//	}
//	return 0;
//
//}

//同じものの最初の文字をNULLにして降順
int _sort(const void* a, const void* b);
int _sort(const void* a, const void* b) {
	char rc;

	rc = strcmp((char*)b, (char*)a);
	if (rc == 0) {
		*(char*)a = 0x00;
		return(1);
	}
	return(rc);
}
// 立っている ビットの数
int bitcount(unsigned int uc);
int bitcount(unsigned int uc)
{
	int bit;

	for (bit = 0; 0 != uc; uc = (unsigned int)(uc >> 1))
		if (0 != (uc & 1))++bit;

	return bit;
}//bitco

#define _rnd(a,b)    ((a+b-1)/b) //　A/Bの余りを繰り上げる
#define _abs(x) ((x)<0 ? -(x) : (x))
#define _MAX 200000
#pragma endregion

// ABC105 B - Cakes and Donuts

int main(void) {
	int n, mi, mj;

	scanf("%d", &n);
	mi = n / 4;
	mj = n / 7;

	for (int i = 0; i <= mi; i++)
		for (int j = 0; j <= mj; j++)
			if (i * 4 + j * 7 == n)
			{printf("Yes\n"); return 0;}			

	printf("No\n");
	return 0;
}



Measured memory_bytes: 1636
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <ctype.h>
#include <utility>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <list>
#include <sstream>
#include <iomanip>

using namespace std;

#define FORST(X,S,T) for(int X=(S); X<=(T); X++)  
#define RFORST(X,S,T) for(int X=(S); X>=(T); X--)  
#define FOR(X,XB) for(int X=0; X<(XB); X++)
#define RFOR(X,XB) for(int X=(XB)-1; X>=0; X--)
#define FORSTL(X,C) for(X=C.begin();X!=C.end();X++)
#define RFORSTL(X,C) for(X=C.rbegin();X!=C.rend();X++)
#define SQR(X) ((X)*(X))
#define MID(X,Y) (((X)+(Y))/2)
#define MIN(X,Y) (X=min((X),(Y)))
#define MAX(X,Y) (X=max((X),(Y)))
#define FILL(X,V) memset(X,V,sizeof(X))
#define FILE_R(X) freopen(X, "r", stdin)
#define FILE_W(X) freopen(X, "w", stdout)  
#define ERREQ(X,Y) (fabs((X)-(Y))<EPS)
#define DBGL cout << "here" << endl;
#define INITLISTS {L=0; FILL(adj,-1);}
#define SZ(X) (int)sizeof(X)
const double PI = acos(-1.0);
const double EPS = 1E-9;
const int INF = (int)1E9;
typedef long long LL;
typedef vector<int> VI;
typedef unsigned int uint;

#define MAXN 100005

int main(){
	int a[15];
	FOR(i,10) cin>>a[i];
	sort(a, a+10);
	FOR(i,3) cout << a[9-i] << endl;
	return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
using namespace std;

//#define RDEBUG 1
#ifdef RDEBUG
#define D(x) x
#else
#define D(x)
#endif
#define inf 0x7fffffff
#define MOD 1000000007

int sh[100010];
int N, K;
int dp[100010];

int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> K;
    for (int i = 0; i<N; i++) {
        cin >> sh[i];
    }
    for (int i = 1; i<N; i++) {
        dp[i] = numeric_limits<int>::max();
    }
    for (int i = 1; i<N; i++) {
        for (int j = max(i-K, 0); j<i; j++) {
            dp[i] = min(dp[i], abs(sh[i]-sh[j])+dp[j]);
        }
    }
    cout << dp[N-1] << endl;
    return 0;
}






Measured memory_bytes: 1024
program main;
var
    K, A, B, i : integer;
    found : boolean;
begin
    readln(K);
    readln(A, B);

    found:= false;
    for i := A to B do begin
        if  i mod K = 0 then
            found := true;
end;

if found then 
    writeln('OK')
else
    writeln('NG');
end.

Measured memory_bytes: 1380
#include<stdio.h>
#include<string.h>
#define min(a,b) (a)<(b)?(a):(b)
int main (void)
{
  int cnt1=0,cnt0=0,n,ans;
  char s[100010];
  scanf("%s",s);
  n=strlen(s);
  for(int i=0;i<n;i++){
    if(s[i]=='1'){
      //printf("%c\n",s[i]);
      cnt1++;
    }else{
      cnt0++;
      //printf("%c\n",s[i]);
    }
  }
  //printf("cnt0=%d cnt1=%d\n",cnt0,cnt1);
  ans=min(cnt0,cnt1);
  printf("%d",2*ans);
  return 0;
}


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

using namespace std;

int main()
{
    long long x;
    cin >> x;
    long long cur = 100;
    long long year = 0;
    while(cur < x){
        year++;
        cur = cur + (cur) / 100;
    }
    cout << year << endl;
    return 0;
}

Measured memory_bytes: 3672
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
const int64_t mod = 1e9 + 7;

int main(void) {
  ios::sync_with_stdio(false);
  string L;
  cin >> L;
  int N = L.size();

  vector<int64_t> DP1(N + 1, 0);  // == L
  vector<int64_t> DP2(N + 1, 0);  //  < L
  DP1[0] = 1;
  rep(i, N) {
    if (L[i] == '0') {
      DP1[i + 1] = DP1[i];
      DP2[i + 1] = (DP2[i] * 3) % mod;
    } else {
      DP1[i + 1] = (DP1[i] * 2) % mod;
      DP2[i + 1] = (DP1[i] * 1 + (DP2[i] * 3 % mod)) % mod;
    }
  }
  int64_t answer = (DP1[N] + DP2[N]) % mod;
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 5104
n,x,y = map(int,input().split())

ans = [0 for i in range(n)]

for i in range(1,n+1):
    for j in range(i+1,n+1):
        p1 = j-i
        p2 = abs(i-x)+abs(j-y)+1
        ans[min(p1,p2)] += 1
for i in range(1,n):
    print(ans[i])


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

int main()
{
    int a, b;
    cin >> a >> b;
    
    if((a*b)%2 == 0)
    {
        cout << "Even" << endl;
        return 0;
    }
    cout << "Odd" << endl;
    return 0;
}


Measured memory_bytes: 768
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split()) #高橋君
B1,B2 = map(int,input().split()) #青木君
D1,D2 = (A1-B1)*T1, (A1-B1)*T1+(A2-B2)*T2
if D1*D2 > 0:     print(0)
elif D2 == 0:     print("infinity")
elif -D1%D2 == 0: print(-D1//D2*2)
else:             print(-D1//D2*2+1)

Measured memory_bytes: 3064
chomp($n = <>);

if($n <= 99){
	print "0\n";
	exit;
}

($a, $b) = ($1, $2) if($n =~ /^(\d+)(\d{2})$/);

$t = 0;
for $i (split(//, "54321")){
	$h = int($b / $i);
	$t += $h;
	last if($b % $i == 0);
	$b -= ($h * $i);
}

if($a >= $t){
	print "1\n";
}else{
	print "0\n";
}


Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <climits>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <deque>
#include <map>
using namespace std;

typedef long long ll;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define forn(i,n) for(int i=0; i<int(n); i++)
#define for1(i,n) for(int i=1; i<=int(n); i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

void no(int ex = -1) {
	cout << ex << endl;
	//cout << "NO" << endl;
	//exit(0);
}
void bl(bool win) {
	if (win) cout << "YES"; else cout << "NO";
	cout << endl;
}

const int N = 1020;
const ll INF = LLONG_MAX;
const int mod = 998244353;

/*vector<bool> pr;
void prime() {
	int EDGE = 1000;
	pr.assign(EDGE, true);
	pr[0] = false; pr[1] = false;
	for (int i = 2; i < EDGE; i++) {
		if (pr[i])
			if (1LL * i * i < EDGE)
				for (int j = i * i; j < EDGE; j += i)
					pr[j] = false;
	}
}*/
//prime


ll T;

int main() {
	IOS;
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ll n, m, cnt = 0;
	cin >> n;
	vector<int> L(n), R(n);
	forn(i, n) {
		cin >> m;
		L[i] = i + m;
		R[i] = i - m;
	}
	sort(L.begin(), L.end());
	sort(R.begin(), R.end());
	vector<pair<int, int>> cntL,cntR;
	cntL.pb(mp(L[0], 1));
	cntR.pb(mp(R[0], 1));
	for (int i = 1; i < n; i++) {
		if (cntL.back().first == L[i]) cntL.back().second++;
		else cntL.pb(mp(L[i], 1));
		if (cntR.back().first == R[i]) cntR.back().second++;
		else cntR.pb(mp(R[i], 1));
	}
	ll ans = 0;
	int q = cntL.size(), w = cntR.size();
	int i = 0, j = 0;
	while (i < q && j < w) {
		if (cntL[i].first == cntR[j].first) {
			ans += cntL[i].second * cntR[j].second; i++; j++;
		}
		else if (cntL[i].first > cntR[j].first) j++; else i++;
	}
	cout << ans;
}

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

int main(void) {
  ll N;
  string S;
  cin >> N >> S;

  vector<ll> sumE(N + 1), sumW(N + 1);
  REP(i, 0, N) sumE[i + 1] = sumE[i] + (S[i] == 'E');
  REP(i, 0, N) sumW[i + 1] = sumW[i] + (S[i] == 'W');

  ll ans = (1LL << 60);
  REP(i, 0, N) {
    ans = min(ans, (sumW[i] - sumW[0]) + (sumE[N] - sumE[i + 1]));
  }
  cout << ans << endl;
}


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

using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");

ll pows(int a , int b)
{
	ll res=1;
	for(int i=0; i<b; ++i)
	{
		res*=a;
	}
	return res;
}

vi vis(100001,0);
vi dp(100001,-1);
vi price;

int dpx(int n)
{
	if(n==1)
		return dp[1];
	if(n==2)
		return dp[2];
	if(dp[n]==-1)
	{
		if(dp[n-1]==-1)
			dp[n-1]=dpx(n-1);
		if(dp[n-2]==-1)
			dp[n-2]=dpx(n-2);

		dp[n]=min((dp[n-1]+abs(price[n]-price[n-1])),(dp[n-2]+abs(price[n]-price[n-2])));
		return dp[n];
	}
	else
		return dp[n];
}

int main()
{	
    std::ios::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    int n;
    cin>>n;
    price.pb(0);
    for(int i=0; i<n; ++i)
    {
    	int x;cin>>x;price.pb(x);
    }
    dp[1]=0;
    dp[2]=abs(price[1]-price[2]);
    dpx(n);
    cout<<dp[n]<<"\n";

}

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

#define REP(i, n) for(int i=0; i<n;i++)
#define REPR(i, n) for(int i=n-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    int n;
    cin>>n;
    int i;
    int a[n];
    int b[n];
    for(i=0; i<n; i++){
        cin>>a[i];
        b[i] = a[i];
    }
    sort(b, b+n);
    int max_a = b[n-1];
    int nextmax_a = b[n-2];

    for(i=0; i<n; i++){
        if(a[i]==max_a){
            cout<<nextmax_a<<endl;
        }
        else{
            cout<<max_a<<endl;
        }
    }


        return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>
#include <boost/multiprecision/cpp_int.hpp>

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    inline input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }

    template <class T>
    inline T read()
    {
        T var;
        cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            cin >> *head;
            ++head;
        }
    }

    template <class T>
    inline std::vector<T> read(std::size_t n)
    {
        std::vector<T> res;
        res.reserve(n);

        for (std::size_t i = 0; i < n; ++i) {
            T tmp;
            cin >> tmp;
            res.emplace_back(tmp);
        }
        return res;
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

public:
    template <bool nl>
    class proxy
    {
        std::ostream& cout;

    public:
        proxy() : cout(std::cout) {}
        ~proxy() { final(); }
        template <class T>
        proxy& operator,(T&& val)
        {
            cout << ' ' << val;
            return *this;
        }
        template <bool f = nl>
        auto final() -> std::enable_if_t<f> { cout << '\n'; }
        template <bool f = nl>
        auto final() -> std::enable_if_t<!f> {}
    };

public:
    output() : cout(std::cout)
    {
        cout << std::fixed << std::setprecision(15);
    }

    template <class T>
    proxy<true> operator,(T&& val)
    {
        cout << val;
        return {};
    }
    proxy<false> noreturn() { return {}; }

    template <class T>
    void print(const T& container)
    {
        bool first = true;
        for (auto&& x : container) {
            if (!first) {
                cout << ' ';
                first = false;
            }
            cout << x;
        }
    }
};

void prog() {
    input in;
    output out;

    auto S = in.read<std::string>();
    std::sort(S.begin(), S.end());
    out, S[0] == S[1] && S[1] != S[2] && S[2] == S[3] ? "Yes" : "No";
}

int main()
{
    prog();
    return 0;
}


Measured memory_bytes: 256
from collections import deque

N = int(input())
S = list(input())

res = deque()
pcnt = 0
for s in S:
    if s == '(':
        pcnt += 1
    else:
        if pcnt:
            pcnt -= 1
        else:
            res.appendleft('(')
    res.append(s)
if pcnt:
    res.append(')' * pcnt)
print(*res, sep='')


Measured memory_bytes: 3316
#include "iostream"
using namespace std;

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


	long min = 1000000;
	long max = -1000000;
	long sum = 0;
	long nam;

	for (int i = 0; i < n; i++){
		cin >> nam;
		if (nam>max){
			max = nam;
		}
		if (nam<min){
			min = nam;
		}
		sum += nam;
	}

	cout << min << " " << max << " " << sum << endl;

	return 0;
}



Measured memory_bytes: 3112
#include <iostream>
#define MAX_N 1000000
using namespace std;
int main(){
	bool num[MAX_N];
	for(int i = 1; i < MAX_N; i++){
		num[i] = true;
	}
	num[0] = false;
	for(int i = 1; i < MAX_N; i++){
		if(num[i] == true){
			for(int j = 2*i+1; j < MAX_N; j += (i+1)){
				if((j+1) % (i+1) == 0){
					num[j] = false;
				}
			}
		}
	}
	int n;
	while(cin >> n){
		int prime = 0;
		for(int i = 1; i < n; i++){
			if(num[i] == true){prime++;}
		}
		cout << prime << endl;
	}
	return 0;
}

Measured memory_bytes: 2136
#include<cstdio>
#include<algorithm>
#include<vector>
#define ll long long
#define N 200005
#define inf 1000000000
using namespace std;
int n;
int a[N], c[N];
int q;
int main(){
    scanf("%d", &n);
    int sum=0;
    for(int i=1; i<=n; ++i) scanf("%d", &a[i]), sum^=a[i];
    for(int i=1; i<=n; ++i) printf("%d ",a[i]^sum);
	return 0;
} 

Measured memory_bytes: 3240
sx,sy,tx,ty = map(int, input().split())

v1 = tx - sx
if v1 >= 0:
	sv0 = "R"
	sv1 = "L"
	s1 = "R" * v1
	s3 = "L" * v1
else:
	sv0 = "L"
	sv1 = "R"
	s1 = "L" * v1
	s3 = "R" * v1

v2 = ty - sy

if v2 >= 0:
	sh0 = "U"
	sh1 = "D"
	s2 = "U" * v2
	s4 = "D" * v2
else:
	sh0 = "D"
	sh1 = "U"
	s2 = "D" * v2
	s4 = "U" * v2


print(s1 + s2 + s3 + s4 + sh1 + sv0 + s1 + s2 + sh0 + sv1 + sh0 + sv1 + s3 + s4 + sh1 + sv0)

Measured memory_bytes: 3064
#python 2.7
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab=sorted(ab,key=lambda x:x[0])
res=ans=0
for i in range(n):
  if res+ab[i][1]>=m:
    ans+=(ab[i][0])*(m-res)
    break
  else:
    ans+=(ab[i][0])*ab[i][1]
    res+=ab[i][1]
print(ans)

Measured memory_bytes: 29164
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

int K;
int A[100000];

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

    ll nmin = 2;
    ll nmax = 2;
    bool ok = true;

    for (int i = K - 1; i >= 0; --i) {
        int ai = A[i];
        nmin = (nmin + ai - 1) / ai * ai;
        nmax = (nmax / ai + 1) * ai - 1;
        if (nmin > nmax) {
            ok = false;
            break;
        }
    }
    if (ok) cout << nmin << " " << nmax << endl;
    else cout << -1 << endl;
}

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

const ll MAX = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;
const double PI=3.1415926535897932;

ll N, ans1=0, ans2=0, tmp=0;
vector<ll> A;

signed main(){
    for(int i=0;i<7;i++) {
        ll a;
        cin >> a;
        A.push_back(a);
    }
    ans1 += A[1];
    ans2 += A[1];
    if(A[0]>0&&A[3]>0&&A[4]>0) {
        A[0]--;
        A[3]--;
        A[4]--;
        ans1 += 3;
        ans1 += A[0]/2*2;
        ans1 += A[3]/2*2;
        ans1 += A[4]/2*2;
        A[0]++;
        A[3]++;
        A[4]++;
    }
    ans2 += A[0]/2*2;
    ans2 += A[3]/2*2;
    ans2 += A[4]/2*2;
    cout << max(ans1, ans2) << endl;
    return 0;
}

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

const int INF = 1e9;

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

  long ans=0;
  for(int i=0;i<n;i++) {
    int ai;
    cin>>ai;
    while(ai%2==0){
      ++ans;
      ai=ai/2;
    }
  }
  cout<<ans<<endl;

}

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

using namespace std;

static const int MAX = 50;

int N, A;
int x[MAX];
long long ans;

long long dp[MAX + 1][MAX + 1][(MAX + 1) * (MAX + 1)];

void selectCard(int sum, int key, int num) {
  if (num != 0 && (float)sum / (float)num == A) {
    ans += 1;
  }

  for (int i = key + 1; i < N; i++) {
    selectCard(sum + x[i], i, num + 1);
  }
}

long long calcSum() {

  for (int j = 0; j <= N; j++) {
    for (int k = 0; k <= j; k++) {
      for (int s = 0; s <= MAX * MAX; s++) {
        if (j == 0 && k == 0 && s == 0) dp[j][k][s] = 1;
        else if (j > 0 && s < x[j - 1]) dp[j][k][s] = dp[j - 1][k][s];
        else if (j > 0 && k > 0 && s >= x[j - 1]) dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j - 1]];
        else dp[j][k][s] = 0;
      }
    }
  }

  ans = 0;

  int s = 0;
  for (int k = 1; k <= N; k++) {
    s = k * A;
    ans += dp[N][k][s];
  }

  return ans;
}

int main() {
  
  ans = 0;

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

  for (int i = 0; i < N; i++) {
    scanf("%d", &x[i]);
  }

  //selectCard(0, -1, 0);

  calcSum();

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


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int A, B, C;
  cin >> A >> B >> C;

  for (int i = 1; A * i <= A * B; ++i) {
    if ((i * A) % B == C) {
      cout << "YES" << endl;
      return 0;
    }
  }

  cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'
const int INF = 1000000001;

using namespace std;

vector<vector<int>> d;
vector<bool> s;

int DFS(int vertex){
    s[vertex] = false;
    int ans = 1;
    for (int q: d[vertex]){
        if (s[q]){
            ans += DFS(q);
        }
    }
    return ans;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, m;
    cin >> n >> m;
    d.assign(n, {}), s.assign(n, true);
    for (int q = 0; q < m; q++){
        int x, y;
        cin >> x >> y;
        d[x-1].push_back(y-1);
        d[y-1].push_back(x-1);
    }
    int ans = 0;
    for (int q = 0; q < n; q++){
        if (s[q]){
            ans = max(ans, DFS(q));
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int n;
    int k;
    string s;
    cin >> n >> k;
    cin >> s;
    if(s[k-1]=='A'){
        s[k-1]='a';
    }else if(s[k-1]=='B'){
        s[k-1]='b';
    }else if(s[k-1]=='C'){
        s[k-1]='c';
    }
    
    cout << s << endl;
}


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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

// // Declaring ordered_set
// typedef tree<ll, null_type, less<ll>, rb_tree_tag,
//             tree_order_statistics_node_update>
//    ordered_set;

#define _start_ auto __start__ = high_resolution_clock::now();
#define _stop_ cerr << "\n" \
                    << duration_cast<microseconds>(high_resolution_clock::now() - __start__).count() / (double)1000000 << " sec\n";
#define mod 998244353
#define _                             \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define ideb \
    int _p_; \
    cin >> _p_;
typedef long long int ll;
typedef unsigned long long int ull;
long long power(long long x, long long n)
{
    long long result = 1;
    while (n > 0)
    {
        if (n % 2 == 1)
            result = (result % mod * x % mod) % mod;
        x = (x % mod * x % mod) % mod;
        n = n / 2;
    }
    return result % mod;
}

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

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

    int dp[n + 1];
    memset(dp, 0, sizeof(dp));

    dp[2] = abs(a[2] - a[1]);

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

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	int ans = 1;
	if(!a) ans = 0;
	if(a == 1) ans = 100;
	if(a == 2) ans = 10000;
	if(ans) cout << b * ans + (b / 100) * ans;
	else cout << ans + (b + b / 100);
}

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

void solve() {
	int k;
	cin >> k;
	string s;
	cin >> s;

	if (k >= s.length()) {
		cout << s;
	}
	else {
		for (int i = 0; i < k; i++) {
			cout << s[i];
		}
		cout << "...";
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
# ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
# endif
	solve();
	return 0;
}

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

//問題文より、英文と英単語のそれぞれの最大の文字数
#define TEXT_MAXLENGTH 1000
#define WORD_MAXLENGTH 10

//単語が一致しているか判別する関数
int word_match(char *word1, char *word2, int word1_length, int word2_length);

int main(void)
{
	//word_countは文章Tに含まれる単語の数を格納
	int i, word_count, match_count, word_length;
	char word[WORD_MAXLENGTH];
	char text[TEXT_MAXLENGTH][TEXT_MAXLENGTH];

	//英単語を入力し、その文字数を求める
	scanf("%s", word);
	word_length = strlen(word);

	word_count = 0;
	while(scanf("%s", text[word_count])){
		//文章の終わりまで入力を続ける
		if(!(strcmp(text[word_count], "END_OF_TEXT"))){
			break;
		}
		//単語の数を一つ増やす
		else{
			word_count++;
		}
	}

	match_count = 0;
	//文章Tに含まれる単語の数だけ判定する
	for(i = 0; i < word_count; i++){
		if(word_match(word, text[i], word_length, strlen(text[i]))){
			match_count++;
		}
	}

	//結果を出力
	printf("%d\n", match_count);

	return 0;
}

//2つの単語が一致していれば1を、そうでなければ0を返す
int word_match(char *word1, char *word2, int word1_length, int word2_length)
{
	int i;

	//2つの単語の文字数が等しければ判定を続ける
	if(word1_length == word2_length){
		//1文字ずつ確かめる
		for(i = 0; i < word1_length; i++){
			//'a' - 'A'は32
			if((*word1 != *word2) && ((*word1 - 32) != *word2)){
				break;
			}
			else{
				word1++;
				word2++;
			}
		}

		//最後まで繰り返しが完了した場合は2つの単語が一致している
		if(i >= word1_length){
			return 1;
		}
		else{
			return 0;
		}
	}
	else{
		return 0;
	}
}


Measured memory_bytes: 2044
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type Row []string

type Data []Row

func main() {
	nextReader = newScanner()
	S := nextString()
	if S == "ABC" {
		fmt.Printf("ARC")
		return
	}
	fmt.Printf("ABC")
}

var nextReader func() string

func newScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	// r.Split(bufio.ScanLines)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func CustomScan(data []byte, atEOF bool) (advance int, token []byte, err error) {
	for i := 0; i < len(data); i++ {
		if data[i] == ' ' {
			return i + 1, data[:i], nil
		}
	}
	fmt.Println(data)
	return 0, data, bufio.ErrFinalToken
}

func nextStrings() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	// r.Split(bufio.ScanWords)
	r.Split(CustomScan)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}


Measured memory_bytes: 1756
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e18;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;

char func(char prev, char ox, char beast) {
	bool flag = true;
	if (prev == 'W') flag = !flag;
	if (ox == 'x') flag = !flag;
	if (beast == 'W') flag = !flag;
	if (flag) return 'S';
	else return 'W';
}

char tmp[100000];
int main() {
	cin >> N;
	string s;
	cin >> s;
	tmp[0] = 'S';
	tmp[1] = 'S';
	rep(i, N - 2) {
		tmp[i + 2] = func(tmp[i], s[i + 1], tmp[i + 1]);
	}
	if (tmp[0] == func(tmp[N - 2], s[N - 1], tmp[N - 1]) && tmp[1] == func(tmp[N - 1], s[0], tmp[0])) {
		cout << tmp;
		return 0;
	}
	tmp[0] = 'W';
	tmp[1] = 'W';
	rep(i, N - 2) {
		tmp[i + 2] = func(tmp[i], s[i + 1], tmp[i + 1]);
	}
	if (tmp[0] == func(tmp[N - 2], s[N - 1], tmp[N - 1]) && tmp[1] == func(tmp[N - 1], s[0], tmp[0])) {
		cout << tmp;
		return 0;
	}
	tmp[0] = 'S';
	tmp[1] = 'W';
	rep(i, N - 2) {
		tmp[i + 2] = func(tmp[i], s[i + 1], tmp[i + 1]);
	}
	if (tmp[0] == func(tmp[N - 2], s[N - 1], tmp[N - 1]) && tmp[1] == func(tmp[N - 1], s[0], tmp[0])) {
		cout << tmp;
		return 0;
	}
	tmp[0] = 'W';
	tmp[1] = 'S';
	rep(i, N - 2) {
		tmp[i + 2] = func(tmp[i], s[i + 1], tmp[i + 1]);
	}
	if (tmp[0] == func(tmp[N - 2], s[N - 1], tmp[N - 1]) && tmp[1] == func(tmp[N - 1], s[0], tmp[0])) {
		cout << tmp;
		return 0;
	}
	cout << -1;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <map>
#include <utility>
using namespace std;
long long ans[10];
map<pair<int,int>,int> g;
int main()
{
	int h,w,n;
	scanf("%d%d%d",&h,&w,&n);
	ans[0]=(long long)(h-2)*(w-2);
	while (n--)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		for (int i=x;i<x+3;i++)
			for (int j=y;j<y+3;j++)
				if (3<=i&&i<=h&&3<=j&&j<=w)
				{
					ans[g[make_pair(i,j)]]--;
					ans[++g[make_pair(i,j)]]++;
				}
	}
	for (int i=0;i<10;i++)
		printf("%lld\n",ans[i]);
	return 0;
}

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

public class AtCoder_161_B
{
    public static void Main()
    {
        int[] line1 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int n = line1[0];
        int m = line1[1];

        int[] line2 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

        int count = 0;

        int sum = line2.Sum();

        for (int i = 0; i < n; i++)
        {
            if (4 * m * line2[i] >= sum)
            {
                count++;
            }
        }


        if (count >= m)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll m,n,i,j,k,l,p,q,a,b,ck=0;
//    ll ar[10005]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
//
//    cin>>n;
//    cout<<ar[n-1]<<endl;
    cin>>m>>n;
    if(m==1&&n!=1||n==1&&m!=1)
    {
      cout<<1<<endl;

    }
    else
    {
        p=m*n;
        if(p%2==1)
            ck=1;
        if(ck==0)
        {
            cout<<p/2<<endl;
        }
        else
        {
            cout<<(p/2)+1<<endl;
        }

    }
}


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

double ans[100010];

void MAIN(int n) {
    std::vector<double> prob;
    for(int i = 0; i < n; ++ i) {
        double p;
        scanf("%lf", &p);
        if(p < 0.995) {
            prob.push_back(p);
        } else if(prob.empty() || prob.back() < 0.995) {
            prob.push_back(p);
        } else {
            prob[prob.size() - 1] += 1;
        }
        ans[i] = 1e100;
    }
    n = prob.size();
    ans[n] = 0;
    for(int i = n - 1; i >= 0; -- i) {
        double now = 0;
        int upper = std::min(n, i + 50);
        for(int j = i + 1; j <= upper; ++ j) {
            if(prob[j - 1] >= 0.995) {
                now += prob[j - 1];
            } else {
                now = (now + 1) / prob[j - 1];
            }
            ans[i] = std::min(ans[i], now + ans[j] + 1);
        }
    }
    printf("%.11f\n", ans[0] - 1);
}

int main() {
    int n;
    while(scanf("%d", &n) == 1 && n > 0) {
        MAIN(n);
    }
    return 0;
}

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

string a(int d, int t, int s) {
  return s * t >= d ? "Yes" : "No";
}

int main() {
  int d, t, s;
  cin >> d >> t >> s;
  cout << a(d, t, s);
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 300010;
const int mod = 1e9+7;
int n;
LL a[N];
LL cnt[70][N];

LL g(int l,int r,int k,bool op){
	if(op){
		return (r-l+1)-(cnt[k][r]-cnt[k][l-1]);
	}
	return cnt[k][r]-cnt[k][l-1];
}

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	memset(cnt,0,sizeof(cnt));
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=61;i++){
		//cout<<i<<": ";
		for(int j=1;j<=n;j++){
			cnt[i][j]=cnt[i][j-1]+((a[j]&(1ll<<(i-1)))!=0);
			//cout<<cnt[i][j]<<' ';
		}
		//cout<<endl;	
	}
	LL ans=0;
	for(int i=1;i<=61;i++){
		LL sum=0,t=(1ll<<(i-1));
		//cout<<i<<": ";
		for(int j=1;j<n;j++){
			sum+=g(j+1,n,i,((a[j]&t)!=0));
			sum%=mod;
			//cout<<sum<<' ';
		}
		ans=(ans+(sum*(t%mod))%mod)%mod;
		//cout<<ans<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
vector<int> E[101010];
int mex[101010];


int dfs(int cur,int pre) {
	
	FORR(e,E[cur]) if(e!=pre) mex[cur]^=dfs(e,cur)+1;
	return mex[cur];
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
		E[y-1].push_back(x-1);
	}
	if(dfs(0,-1)) cout<<"Alice"<<endl;
	else cout<<"Bob"<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 10880
import fileinput
from collections import defaultdict

def longest_path(edges):
    if not edges:
        return 2

    modulo = 10**9 + 7
    graph = defaultdict(list)
    
    min_node = 10**9

    for v_a, v_b in edges:
        graph[v_a].append(v_b)
        graph[v_b].append(v_a)

        min_node = min(min_node, v_a, v_b)
    
    set_count_black = [0] * (len(graph) + 1)
    set_count_white = [0] * (len(graph) + 1)

    node_stack = []
    nodes_on_stack = [True] + [False] * node_count

    node_stack.append([min_node, 0])
    nodes_on_stack[min_node] = True

    while node_stack:
        top_node, last_child = node_stack[-1]
        if top_node in graph and last_child < len(graph[top_node]):
            node_stack[-1][1] += 1
            current_child = graph[top_node][last_child]
            if nodes_on_stack[current_child] == False:
                node_stack.append([current_child, 0])
                nodes_on_stack[current_child] = True
        else:
            node, children = node_stack.pop()
            nodes_on_stack[node] = False

            if (children == 1 and node != min_node) or children == 0:
                set_count_black[node] = 1
                set_count_white[node] = 1
            else:
                bc = 1
                wc = 1
                for child in graph[node]:
                    if nodes_on_stack[child]:
                        continue
                    bc *= set_count_white[child]
                    wc *= (set_count_white[child] + set_count_black[child])
                set_count_white[node] = wc % modulo
                set_count_black[node] = bc % modulo
    return (set_count_white[min_node] + set_count_black[min_node]) % modulo

inp = fileinput.FileInput()

node_count = int(inp.readline())
edges = []

for _ in range(node_count - 1):
    split = inp.readline().split(" ")
    edges.append(
        (int(split[0]), int(split[1]))
    )

print(longest_path(edges))

Measured memory_bytes: 86620
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] p = new int[N];
		for(int i=0;i<N;i++){
			p[i] = sc.nextInt();
		}
		int cnt = 0;
		for(int i=0;i<N-1;i++){
			if(p[i] == i+1){
				swap(p,i,i+1);
				cnt++;
			}
		}
		if(N>2){
			if(p[N-1] == N){
				swap(p,N-2,N-1);
				cnt++;
			}
		}
		System.out.println(cnt);
	}
	static void swap(int[] d,int i,int j){
		int swap = d[i];
		d[i] = d[j];
		d[j] = swap;
	}
}


Measured memory_bytes: 50580
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        List<Character> sli = new ArrayList<Character>(s.length());
        List<Character> tli = new ArrayList<Character>(t.length());
        for (int i = 0; i < s.length(); i++) {
            sli.add(s.charAt(i));
        }
        for (int i = 0; i < t.length(); i++) {
            tli.add(t.charAt(i));
        }
        sli.sort(Comparator.naturalOrder());
        tli.sort(Comparator.reverseOrder());
        int bre = 0;
        if (s.length() < t.length()) {
            for (int i = 0; i < s.length(); i++) {
                if (sli.get(i) < tli.get(i)) {
                    bre = 1;
                    break;
                } else if (sli.get(i) > tli.get(i)) {
                    bre = 2;
                    break;
                }
            }
            if (bre == 0) {
                bre = 1;
            }
        } else {
            for (int i = 0; i < t.length(); i++) {
                if (sli.get(i) < tli.get(i)) {
                    bre = 1;
                    break;
                } else if (sli.get(i) > tli.get(i)) {
                    bre = 2;
                    break;
                }
            }
            if (bre == 0) {
                bre = 2;
            }
        }
        if (bre == 1) {
            System.out.println("Yes");
        } else if (bre == 2) {
            System.out.println("No");
        }
    }
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
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;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}

//char->int
int ctoi(char c){
    return c-'0';
}



int main(){
    int n,k,d;
    cin >> n >> k ;

    int a[k][100];
    map<int,int> mp;

    for(int i=0;i<k;i++){
        cin >> d;
        for(int j=0;j<d;j++){
            cin >> a[i][j];
            mp[a[i][j]]++;
        }
    }

    cout << n-mp.size() << endl;

}


Measured memory_bytes: 3636