akhauriyash/Code-Regression huggingface dataset:
import sys
import numpy as np
import heapq as hp

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def compute(A, B, X):
    """左からn番の人まで。AからX人とる。ときの最大スコアを返す。"""
    result = np.zeros(len(A), np.int64)
    result[X - 1] = A[:X].sum()
    q = []
    for i in range(X):
        q.append(A[i] - B[i])
    hp.heapify(q)
    for i in range(X, len(A)):
        x = result[i - 1] + A[i]  # とりあえず A をとる
        loss = hp.heappushpop(q, A[i] - B[i])  # ひとつ B に取り換えたときのロス
        result[i] = x - loss
    return result

if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    i8 = numba.from_dtype(np.int64)
    sig = (i8[:], i8[:], i8)

    cc = CC('my_module')
    cc.export('compute', sig)(compute)
    cc.compile()

from my_module import compute

def main(ABC, X, Y, Z):
    A = ABC[::3]
    B = ABC[1::3]
    C = ABC[2::3]
    ind = np.argsort(C - A)
    A, B, C = A[ind], B[ind], C[ind]
    dp1 = compute(A, B, X)
    dp2 = compute(C[::-1], B[::-1], Z)[::-1]
    x = dp1[X - 1:X + Y] + dp2[X:X + Y + 1]
    return x.max()

X, Y, Z = map(int, readline().split())
ABC = np.array(read().split(), np.int64)

print(main(ABC, X, Y, Z))

Measured memory_bytes: 47760
#include <stdio.h>

int main(void){
 int a,b,c;
   scanf("%d %d %d", &a,&b,&c);
  if(a == b){
    if( a == c)
      printf("No");
    else if(b != c)
      printf("Yes");
  }
  else{
   if(a == c)
     printf("Yes");
   else if(b == c)
     printf("Yes");
   else
     printf("No");
  }
    
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  string ans = "Good";
  if ( s[0] == s[1] || s[1] == s[2] || s[2] == s[3] ) { ans = "Bad"; }
  cout << ans << endl;
  return 0;
}

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll x; cin >> x;
  cout << 1 - x << endl;

  return 0;
}



Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("kmp.in","r",stdin);freopen ("kmp.out","w",stdout);
#define mod 1000000009
#define fs(x,y) for(int i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(int i=x;i<=y;i++)
#define INF 1000000000005
using namespace std;

ll n,m,ar[N],sum;

int main()
{
	fast;
	cin>>n;
	n--;
	cout<<n*(n+1)/2;


}



/*     cd onedrive\desktop\kod
cls


*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
long long int mod = 1000000007;
long long fast_exp(long long a,long long n,long long mod1)
    {
     
      if (n==0)return 1;
      else if (n==1)return a;
      if (n%2==0)return fast_exp((a*a)%mod1,n/2,mod1);
      else return (a*fast_exp((a*a)%mod1,n/2,mod1))%mod1;
    }
static bool is_power[1000001]={false};
void sieve()
{
    for (long long int c=2;c<=1000000;c++)
        if (is_power[c]==true)
            continue;
        else 
            for (long long int c1=c*c;c1<=1000000;c1=c1*c)
                is_power[c1]=true;
    return ;
}
int main()
{
    sieve();
    fast_io;
    int t;
    t=1;//cin >> t;
    for (;t>0;t--)
    {
        string a;
        cin >> a;
        if (a.find("7")!=-1)
            cout << "Yes" << endl;
            else cout << "No" << endl;
    }
    return 0;
}




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

int main() {
  int N; cin >> N;
  int v[] = {3, 13, 23, 43, 53, 73, 83, 103, 113, 163, 173, 193, 223, 233, 263, 283, 293, 313, 353, 373, 383, 433, 443, 463, 503, 523, 563, 593, 613, 643, 653, 673, 683, 733, 743, 773, 823, 853, 863, 883, 953, 983, 1013, 1033, 1063, 1093, 1103, 1123, 1153, 1163, 1193, 1213, 1223, 1283, 1303};

  for(int i=0;i<N;++i) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);	
		int h = sc.nextInt();
		int w = sc.nextInt();
		//String data[][] = new String[h][w];
		//String cc[] = new String[w];
		char [][] cdata = new char[h][w];
		int [][] resultdata = new int[h][w];
		int cnt=0,ccnt=0;
		for(int k = 0;k<h;k++){
			cdata[k] = sc.next().toCharArray();	
		//	System.out.println(cdata[k]);
		}
		for(int i = 0;i < h;i++){
			
			for(int j = 0;j < w;j++){	
				if(cdata[i][j]==('.')){
					if(ccnt != 1){
						resultdata[i][j] = -1;
					}else{
						cnt++;
						resultdata[i][j] = cnt;
					}
				}
				else if(cdata[i][j]==('c')){
					 cnt = 0;
	    			 ccnt = 1;
	    			 resultdata[i][j] = 0;
				}
			}
			ccnt = 0;
			 
		}
		for(int i = 0;i < h;i++){
			for(int j = 0;j < w;j++){
				if((j+1)==w){
					System.out.println(resultdata[i][j]);
				}else{
					System.out.print(resultdata[i][j]+" ");
				}
			}
		}
			
	}
}

Measured memory_bytes: 34956
/* ***************************************
Author        :Scau.ion
Created Time  :2016/10/01 20:09:48 UTC+8
File Name     :ion.cpp
*************************************** */

#include <bits/stdc++.h>

#define LL long long
#define ULL unsigned long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<PII>
#define X first
#define Y second
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define IN freopen("in", "r", stdin);
#define OUT freopen("out", "w", stdout);

using namespace std;

const int maxn=200010;

char s[maxn];

int main()
{
	scanf("%s",s);
    int n=strlen(s);
    int ts=0;
    int ss=0;
    for (int j=0;j<n;++j)
    {
        if (s[j]=='T')
        {
            if (ss) --ss;
            else ++ts;
        }
        else ++ss;
    }
    printf("%d\n",ss+ts);
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}

	void solve() {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		sc.close();
		int res = n/3;
		System.out.println(res);
	}
}


Measured memory_bytes: 22996
import sys

MOD = 10 ** 9 + 7
U = 10 ** 6
def make_fac_ifac(n=U, p=MOD):
  fac = [None] * (n + 1)
  fac[0] = 1
  for i in range(n): fac[i+1] = fac[i] * (i + 1) % p
  ifac = [None] * (n + 1)
  ifac[n] = pow(fac[n], p - 2, p)
  for i in range(n, 0, -1): ifac[i-1] = ifac[i] * i % p
  return fac, ifac

fac, ifac = make_fac_ifac()

def mod_choose(n, r, p=MOD):
  if r > n or r < 0: return 0
  return fac[n] * ifac[r] % p * ifac[n-r] % p

def make_choose_n_table(n=10 ** 9, r=U, p=MOD):
  table = [None] * (r + 1)
  table[0] = 1
  j = 1
  for i in range(n, n - r, -1): 
    table[j] = table[j-1] * i % p
    j += 1
  for i in range(1, r + 1): table[i] = table[i] * ifac[i] % p
  return table
    
mod_choose_n = make_choose_n_table()

n, m = map(int, sys.stdin.readline().split())

def main():
  d = abs(n - m)
  if d >= 2: res = 0
  elif d == 1: res = fac[n] * fac[m] % MOD
  else: res = fac[n] * fac[m] % MOD * 2 % MOD
  print(res)
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 121844
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    unsigned x{};
    vector<unsigned> a(n);
    for(auto&i:a) cin>>i,x^=i;
    for(auto&i:a) cout<<(x^i)<<" ";
    cout<<'\n';
}

Measured memory_bytes: 3972
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}
	
	// RRRRRRRWWWWWWWWW
	
	void run() {
		FastScanner sc=new FastScanner();
		int N=sc.nextInt();
		char[] cs=sc.next().toCharArray();
		int s=0,t=N;
		int ans=0;
		while (s<t) {
			if (cs[s]=='R') {
				++s;
				continue;
			}
			if (cs[t-1]=='W') {
				--t;
				continue;
			}
			++ans;
			++s;--t;
		}
		System.out.println(ans);
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
	
	
	class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        if (!hasNext()) throw new NoSuchElementException();
	        long n = 0;
	        boolean minus = false;
	        int b = readByte();
	        if (b == '-') {
	            minus = true;
	            b = readByte();
	        }
	        if (b < '0' || '9' < b) {
	            throw new NumberFormatException();
	        }
	        while(true){
	            if ('0' <= b && b <= '9') {
	                n *= 10;
	                n += b - '0';
	            }else if(b == -1 || !isPrintableChar(b)){
	                return minus ? -n : n;
	            }else{
	                throw new NumberFormatException();
	            }
	            b = readByte();
	        }
	    }
	    public int nextInt() {
	    	return (int)nextLong();
	    }
	}
}



Measured memory_bytes: 34204
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 200010
using namespace std;
ll n,a[N],ans=0;
int main(){
	ll i,mx=0;
	scanf("%lld",&n);
	for(i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(i=0;i<n;i++)
	{
		mx=max(mx,a[i]);
		ans+=mx-a[i];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 5384
a,b=[int(i) for i in input().split(" ")]

lA=[]
lB=[]

minV,minID=0,0
for i in range(1300):
    k=int(i*0.08)
    if minV<k:
        lA.append((minID,i-1))
        minV=k
        minID=i

minV,minID=0,0
for i in range(1300):
    k=int(i*0.1)
    if minV<k:
        lB.append((minID,i-1))
        minV=k
        minID=i

a1,a2=lA[a]
b1,b2=lB[b]

for i in range(min(a1,a2,b1,b2),max(a1,a2,b1,b2)+1):
    if a1<=i and b1<=i and a2>=i and b2>=i:
        print(i)
        exit(0)

print(-1)


Measured memory_bytes: 3188
n = int(input())
A = list(map(int, input().split()))
A.append(0)
A.insert(0, 0)
ans = 0
for i in range(1, n+2):
    ans+=abs(A[i]-A[i-1])
for i in range(1, n+1):
    d = abs(A[i]-A[i-1])+abs(A[i+1]-A[i])
    print(ans-d+abs(A[i-1]-A[i+1]))


Measured memory_bytes: 14048
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];

            var lst = new List<Tuple<string, long, long>>();
            for (var i = 0; i < N; ++i)
            {
                var sp = ReadLine().Split();
                var s = sp[0];
                var p = long.Parse(sp[1]);
                lst.Add(new Tuple<string, long, long>(s, p, i + 1));
            }
            var ans = lst.OrderBy(sp => sp.Item1).ThenByDescending(sp => sp.Item2).ToList();
            foreach (var a in ans)
            {
                WriteLine(a.Item3);
            }
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const ll MOD = 1000000007;
const ll INF = 100000000000000000;
/* END OF TEMPLATE */

// https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
// mod. m での a の逆元 a^{-1} を計算する
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 割り算MOD
ll divmod(ll a, ll b){
    a %= MOD;
    return a * modinv(b, MOD) % MOD;
}

const int MAX = 200100;
// fac: n! %mod, finv: (1/n!) %mod, inv: 1/n %mod
ll fac[MAX], finv[MAX], inv[MAX];

ll powa[MAX], powb[MAX], powab[MAX];

// テーブルを作る前処理
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

void powinit(ll a, ll b){
    a %= MOD;
    b %= MOD;
    powa[0] = powb[0] = powab[0] = 1;
    rea(i, 1, MAX){
        powa[i] = powa[i-1] * a % MOD;
        powb[i] = powb[i-1] * b % MOD;
        powab[i] = powab[i-1] * (a+b) % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    COMinit();
    ll n, a, b, c;
    cin >> n >> a >> b >> c;
    powinit(a, b);
    ll ans = 0;
    rep(i, n){
        ll anstemp = 1;
        anstemp *= (powa[n]*powb[i]%MOD+powa[i]*powb[n]%MOD)%MOD;
        //dump(anstemp);
        anstemp *= COM(i+n-1, n-1);
        //dump(anstemp);
        anstemp %= MOD;
        //dump(anstemp);
        anstemp *= i+n;
        //dump(anstemp);
        anstemp %= MOD;
        //dump(anstemp);
        anstemp = divmod(anstemp, powab[i+n]);
        //dump(anstemp);
        ans += anstemp;
        ans %= MOD;
    }
    ans *= 100;
    ans %= MOD;
    ans = divmod(ans, 100-c);
    cout << ans << endl;
}

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

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/


  long long N;

  cin>>N;

  if(N<=10){
    if(N%6!=0){
      cout<<N/6+1<<endl;
    }else{
      cout<<1<<endl;
    }
  }
  else if(N%11==0){
    cout<<N/11*2<<endl;
  }else{
    
    if(N%11<=6){
      cout<<N/11*2+1<<endl;
    }else{
      cout<<N/11*2+2<<endl;
    }
  }
    
  return 0;

}




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

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

#define INF 100000000

int main() {
  int N;
  cin >> N;
  map<string,int> S;
  rep(i,N){
    string name;
    cin >> name;
    if (S.count(name)){
      S[name]++;
    }
    else{
      S[name] = 1;
    }
  }
  
  int mx = 0;
  for(pair<string,int> p : S){
    mx = max(mx, p.second);
  }

  vector<string> S1;
  for(pair<string,int> p : S){
    if(mx == p.second){
      S1.push_back(p.first);
    }
  }

  sort(S1.begin(), S1.end());

  for(int i = 0; i < S1.size(); ++i){
    cout << S1.at(i) << endl;
  }

  return 0;
}

Measured memory_bytes: 26868
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long k = sc.nextLong();
		long d = sc.nextLong();
		long absx = Math.abs(x);
		if (absx / d >= k) {
			System.out.println(absx - k * d);
		} else {
			long r = k - absx / d;
			long start = absx % d;
			if (r % 2 == 0) {
				System.out.println(start);
			} else {
				long ans = Math.min(Math.abs(start + d), Math.abs(start - d));
				System.out.println(ans);
			}
		}
	}
}
 
 
 
 
 
 
 
 
 
 


Measured memory_bytes: 35568
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
int n;
cin>>n;
string s;
ol("0\n");
cin>>s;
if(s=="Vacant")return 0;
int lo=0,hi=n-1,mid;
while(lo<=hi)
{
	mid=(lo+hi)/2;
	string s1;
	ol(mid);on;
	cin>>s1;
	if(s1=="Vacant")return 0;
	if(mid%2==0)
	{
		if(s==s1)lo=mid+1;
		else hi=mid-1;
	}
	else
	{
		if(s==s1)hi=mid-1;
		else lo=mid+1;
	}
}
return 0;
}



Measured memory_bytes: 852
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
const int INF = 1e9;
 
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
 
  int n, W;
  cin >> n >> W;
 
  vector<ll> dp(W+1);
 
  for(int i=0; i<n; i++) {
    int w, v;
    cin >> w >> v;
    for(int j=W-w; j>=0; j--) {
      dp[j+w] = max(dp[j+w], dp[j] + v);
    }
  }

  cout << dp[W];
  
  return 0;
}

Measured memory_bytes: 3908
# coding: utf-8
# Your code here!
"""
Bellman_Ford
単一始点最短経路を求める
g: グラフの隣接リスト
start: 始点
返り値: dist, is_OK (負回路なしならTrue)
"""
def Bellman_Ford(g,start):
    n = len(g)    
    dist = [float("inf")]*n
    dist[start] = 0
    
    for i in [0]*(n):
        updated = False
        for v in range(n):
            for to, cost in g[v]:
                if dist[to] <= dist[v] + cost: continue
                dist[to] = dist[v] + cost
                updated = True
        if not updated: break
    else: return None, False #n周更新された場合
    return dist, True        
    

"""
###############################################################
AOJ: GRL_1_B http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_B

##############################################################
"""

v,e,r = [int(i) for i in input().split()]
std = [[int(i) for i in input().split()] for _ in range(e)]

g = [[] for _ in range(v)]
for s,t,d in std:
    g[s].append((t,d))


dist, tf = Bellman_Ford(g,r)
if tf:
    for i in dist:
        print(i if i != float("inf") else "INF")
else: print("NEGATIVE CYCLE")

    



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

int main() {
    string s;
    cin >> s;
    for (int i = 0; i < s.size() - 1; i++)
    {
        if (s[i] == 'A' && s[i + 1] == 'C')
        {
            cout << "Yes" << endl;
            return 0;
        }
        
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <vector>

#define rep(i,a,b) for(long long i=a;i<b;i++)

using namespace std;


int main(void) {

	long long N = 0, K = 0, H = 0, W = 0, C = 0;
	char a[100][100] = {};
	int b[100] = {};
	long long c[300] = { 0 };
	long long d[300] = { 0 };
	//long long y[20] = {};
	string s;
	
	long long min = 0, min2 = 0;
	long long dif = 0;
	long long hoge = 0;
	long long sum = 0;
	long long up = 0;

	cin >> H >> W;

	rep(j, 0, H) {
		rep(i, 0, W) {
			cin >> a[i][j];
		}
	}

	rep(j, 0, H) {
		rep(i, 0, W) {

			if (a[i][j] == '#' || a[i][j] == '\0') {
				break;
			}
			else {
				sum++;
			}


		}

		if (sum == W) {
			b[j] = 1;
		}
		sum = 0;
	}


	

	rep(i, 0, W) {
		rep(j, 0,H) {

			if (a[i][j] == '#' || a[i][j] == '\0') {
				break;
			}
			else {
				sum++;
			}


		}

		if (sum == H) {
			c[i] = 1;
		}
		sum = 0;
	}

	/*rep(i, 0, W) {

		cout << c[i];
	}
*/

	rep(j, 0, H) {

		if (b[j] == 0) {
			rep(i, 0, W) {
				if (c[i] == 0)
					cout << a[i][j];
			}
			cout << endl;
		}
	}
	
	return 0;

}



Measured memory_bytes: 256
w,h,n=map(int,input().split())
l=list(list(map(int,input().split()))for _ in range(n))
xl=0
xh=w
yl=0
yh=h
for i in range(n):
    if l[i][2]==1:xl=max(xl,l[i][0])
    if l[i][2]==2:xh=min(xh,l[i][0])
    if l[i][2]==3:yl=max(yl,l[i][1])
    if l[i][2]==4:yh=min(yh,l[i][1])
print(max((xh-xl),0)*max((yh-yl),0))

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

using namespace std;

int a,b;
int i;

int main()
{
    scanf("%d%d",&a,&b);
    if(a>b)
    {
        int t;
        t=a;
        a=b;
        b=t;
    }
    for(i=a;i<b+1;i++)
    {
        if(a*b*i%2!=0)
        {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))

kaisuulist=[]
nowmax=0

for i in range(1,n):
  if h[i-1]<h[i]:
    kaisuulist.append(i-nowmax-1)
    nowmax=i

#print(kaisuulist)
if not kaisuulist:
  print(n-1-nowmax)
else:
  print(max(max(kaisuulist),n-1-nowmax))

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define s second
#define int long long
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<ll, ll> pii;
typedef vector<vector<ll>> mat;
const ll mod = 1e9+7;
const int MAXN = 1e4+5;

int32_t main() {
	int n;
	cin >> n;
	vector<int> v(n);
	for(int &i : v)
		cin >> i;
	int smaller = INF;
	int ans = 0;
	for(auto i : v) {
		smaller = min(smaller, i);
		if(i == smaller) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, M;
ll x[1010], y[1010], z[1010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> z[i];
  }
  ll ans = 0;
  for (int i = 0; i < 1 << 3; i++) {
    vector<ll> v;
    for (int j = 0; j < N; j++) {
      ll sum = 0;
      sum += (i >> 0 & 1 ? 1 : -1) * x[j];
      sum += (i >> 1 & 1 ? 1 : -1) * y[j];
      sum += (i >> 2 & 1 ? 1 : -1) * z[j];
      v.emplace_back(sum);
    }
    sort(v.rbegin(), v.rend());
    ans = max(ans, accumulate(v.begin(), v.begin() + M, 0LL));
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __mr__
    #include "prettyprint.hpp"
#else
    #define endl                    '\n'
#endif
#define len(x)                      (uint)(x).size()
#define int                         int32_t
#define uint                        uint32_t
#define ulong                       uint64_t
#define long                        int64_t
#define maxof(x)                    numeric_limits<x>::max()
#define minof(x)                    numeric_limits<x>::min()
using namespace std;
const ulong mod = 1000000007ul;

int main(int argc, char const *argv[]) {
    #ifndef __mr__
        ios::sync_with_stdio(0);cin.tie(0);
    #endif
    string s;
    cin >> s;
    for (int i = (int)s.size() - 1; i >= 0; ) {
        if (s[i] == 'm') {
            if (i - 4 < 0 || s.substr(i - 4, 5).compare("dream") != 0) {
                cout << "NO" << endl;
                return 0;
            }
            i -= 5;
        } else if (s[i] == 'e') {
            if (i - 4 < 0 || s.substr(i - 4, 5).compare("erase") != 0) {
                cout << "NO" << endl;
                return 0;
            }
            i -= 5;
        } else {
            if (i - 5 < 0) {
                cout << "NO" << endl;
                return 0;
            }
            if (s.substr(i - 5, 6).compare("eraser") == 0) {
                i -= 6;
                continue;
            }
            if (i - 6 < 0 || (s.substr(i - 6, 7).compare("dreamer") != 0)) {
                cout << "NO" << endl;
                return 0;
            }
            i -= 7;
        }
//        cout << i << endl;
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	int h,w;
	cin >> h >> w;
	vector<vector<int>> a(h,vector<int>(w));
	REP(i,h) REP(j,w) cin >> a[i][j];
	
	vector<vector<int>> ans;
	REP(i,h){
		if(i%2==0){
			for(int j=0; j<w; j++){
				vector<int> change(4);
				int nexti, nextj;
				if(a[i][j]%2==1){
					change[0]=i+1;
					change[1]=j+1;
					
					if(j < w-1){
						nexti=i;
						nextj=j+1;
					}else if(i < h-1){
						nexti=i+1;
						nextj=j;
					}else{
						continue;
					}
					change[2]=nexti+1;
					change[3]=nextj+1;
					
					a[nexti][nextj]++;
					ans.push_back(change);
				} 
			}
		}else{
			for(int j=w-1; j>=0; j--){
				vector<int> change(4);
				int nexti, nextj;
				if(a[i][j]%2==1){
					change[0]=i+1;
					change[1]=j+1;
					
					if(j > 0){
						nexti=i;
						nextj=j-1;
					}else if(i < h-1){
						nexti=i+1;
						nextj=j;
					}else{
						continue;
					}
					change[2]=nexti+1;
					change[3]=nextj+1;
					
					a[nexti][nextj]++;
					ans.push_back(change);
				} 
			}
		}
	}
	
	cout << ans.size() << endl;
	for(auto x:ans){
		REP(i,4){
			if(i!=0) cout << " ";
			cout << x[i];
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 11156
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

class Processees {
	private String name;
	private int time;

	public String getName() {
		return name;
	}

	public int getTime() {
		return time;
	};

	public void setTime(int time) {
		this.time = time;
	}

	public Processees(String name, int time) {
		this.name = name;
		this.time = time;
	}

}


public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int p = scanner.nextInt();

		Deque<Processees> Processeeses = new ArrayDeque<Processees>(n);
		for (int i = 0; i < n; i++) {
			Processeeses.add(new Processees(scanner.next(), scanner.nextInt()));
		}
		int totalTime =0;
		int tempTime;
		while(Processeeses.size()!=0){
			if(Processeeses.element().getTime()<=p){
				totalTime+=Processeeses.element().getTime();
				System.out.println(Processeeses.element().getName()
						+ " "+totalTime);
				Processeeses.poll();
			}
			else{
				tempTime = Processeeses.element().getTime()-p;
				Processeeses.element().setTime(tempTime);
				Processeeses.add(Processeeses.element());
				Processeeses.poll();
				totalTime+=p;
			}
		}

	}
}

Measured memory_bytes: 65664
/**
 * auther: moririn_cocoa
 */

#include <iostream>
#include <math.h>
using namespace std;

int main(void) {
  
  int A;
  int B;
  
  cin >> A;
  cin >> B;

  if ( B * 2 < A ) {
    
    cout << A - ( B * 2 ) << endl;
  }
  
  else if ( B * 2 >= A ) {
    
    cout << 0 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3608
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    static FastReader s = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    private static int[] rai(int n) {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextInt();
        }
        return arr;
    }

    private static int[][] rai(int n, int m) {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextInt();
            }
        }
        return arr;
    }

    private static long[] ral(int n) {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextLong();
        }
        return arr;
    }

    private static long[][] ral(int n, int m) {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextLong();
            }
        }
        return arr;
    }

    private static int ri() {
        return s.nextInt();
    }

    private static long rl() {
        return s.nextLong();
    }

    private static String rs() {
        return s.next();
    }
    public static void main(String[] args) throws IOException {
        StringBuilder ans = new StringBuilder();
//        int t=ri();
        int t=1;
        while (t-- > 0)
        {
            int n=ri();int k=ri();int[] arr=rai(n);
            Arrays.sort(arr);
            int sum=0;
            for(int i=0;i<k;i++)
            {
                sum+=arr[i];
            }
            ans.append(sum).append("\n");
        }
        out.print(ans.toString());
        out.flush();

    }
}


Measured memory_bytes: 26028
using System;
    using System.Collections.Generic;
    using System.Text;
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();

            int count = 0;
            int repeat = input.Length / 2;

            for (int i = 0; i < repeat; i++)
            {
                if (input.Substring(i, 1) != input.Substring(input.Length - 1 - i,1))
                {
                    count++;
                }
            }

            Console.WriteLine(count.ToString());
        }
    }

Measured memory_bytes: 13140
N, K = map(int, input().split())
D = list(map(int, input().split()))

can_use = []
for i in range(10):
    if i not in D:
        can_use.append(i)

ans = []
t = 0
for i, dig in enumerate(list(str(N))):
    m = 10
    for cu in can_use:
        sa = cu - int(dig)
        if sa <= m and sa >= 0:
            m = sa
            ans.append(cu)
            if abs(len(list(str(N)))-1-i) == 0:
                break
            t += cu*10**abs(len(list(str(N)))-1-i)
            tmp = t + int(str(can_use[0])*abs(len(list(str(N)))-1-i))
            if tmp >= N:
                print(tmp)
                exit()



# for dig in list(str(N))[::-1]:
#     m = 10
#     for cu in can_use:
#         sa = cu - int(dig)
#         if sa <= m and sa >= 0:
#             m = sa
#             ans.append(cu)

if len(ans) < len(list(str(N))):
    min_not0 = can_use[1] if can_use[0] == 0 else can_use[0]
    print(str(min_not0)+str(can_use[0])*len(list(str(N))))
    exit()

print(''.join(map(str, ans[::-1])))
# print(''.join(map(str, ans[::-1])))


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
  int n;
  int h[100] = {0};
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> h[i];

  int round = 0;
  while (true) {
    int l = 0;
    for (; l < n; ++l) {
      if (h[l] > 0)
        break;
    }
    int r = l;
    for (; r < n; ++r) {
      if (h[r] == 0)
        break;
    }
    if (l == r && h[l] == 0) {
      break;
    }
    for (int i = l; i < r; ++i) {
      h[i]--;
    }
    round++;
  }
  cout << round << endl;
  return 0;
}


Measured memory_bytes: 256
//A - Don't be late
//Hiia
#include <stdio.h>
#include <stdlib.h>//rannsuu, zettaichi(absolute)
#include <time.h>
//srand((unsigned int) time(0));
#include <math.h>//koudona keisann
#include <string.h>//hairetsu
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
typedef long long ll;
//#define N 998244353
#define pi 3.1415926535897932384626433832

int gcd(int m,int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
int lcm(int m,int n){if((0==m)||(0==n))return 0;return(m*n/gcd(m, n));}
int fact(int x){if(x==1) return(x);else return(x*fact(x-1));}//Kaijou x!
int ruijou(int base,int exponent){int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

long long int llgcd(long long int m,long long int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
long long int lllcm(long long int m,long long int n){if((0==m)||(0==n))return 0;return(m*n/llgcd(m, n));}
long long int llfact(long long int x){if(x==1) return(x);else return(x*llfact(x-1));}//Kaijou
int llruijou(long long int base,long long int exponent){long long int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

int main()
{
  int d,t,s;
  scanf("%d %d %d", &d, &t, &s);
  int t1=d/s, t2=d%s;
  //printf("%d %d\n", t1,t2);
  if(t2==0){
    if(t1<=t){
      printf("Yes\n");
    }
    else{
      printf("No\n");
    }
  }
  else{
    if(t1<=t-1){
      printf("Yes\n");
    }
    else{
      printf("No\n");
    }
  }

  return 0;
}


Measured memory_bytes: 1660
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;const int N=1e5+10;typedef long long ll;
int n;long long a[200010];ll res=0;
int main()
{
	scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%lld",&a[i]);ll x=0;ll s=0;
	for(int i=1,j=1;i<=n;i++)
		{x^=a[i];s+=a[i];while(x!=s){x^=a[j];s-=a[j];j++;}res+=i-j+1;}
	printf("%lld",res);return 0;
}

Measured memory_bytes: 1792
s = input()
slist = list(s)

if len(slist) ==2:
    if len(set(slist)) ==1:
        print(1,2)
        exit()
    else:
        print("-1 -1")
        exit()

else:
    for i in range(1,len(slist)-1):
        if len(set(slist[i-1:i+2])) !=3:
            print(i,i+2)
            exit()
            
    print("-1 -1")

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

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

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> left(n+1), right(n+1);
  for(int i = 0; i < n; i++) left[i+1] = gcd(left[i], a[i]);
  for(int i = n-1; i >= 0; i--) right[i] = gcd(right[i+1], a[i]);
  int ans = 0;
  for(int i = 0; i < n; i++){
    int now = gcd(left[i], right[i+1]);
    ans = max(ans, now);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4200
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define mp make_pair


int main() {
    lli a,b,c,d;
    cin>>a>>b>>c>>d;
    lli prod=max({a*c,b*d,a*d,b*c});
    cout<<prod;
	return 0;
}

Measured memory_bytes: 3668
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<iomanip>
#include<set>
#include<unordered_map>
using namespace std ;

#define MAXN 1007

struct tuhla {
    double x , y ;
    double r ;
};
int n ;
tuhla a[ MAXN ] ;

double dist[ MAXN ][ MAXN ] ;

double ans[ MAXN ] ;


void dijkstra ( int st ) {
    for ( int i = 1 ; i <= n + 2 ; ++ i ) {
        ans[ i ] = -1 ;
    }
    ans[ st ] = 0 ;
    priority_queue < pair < double , int > > pq ;
    pq.push ( { 0 , st } ) ;
    while ( pq.empty ( ) == false ) {
        pair < double , int > aux = pq.top ( ) ;
        pq.pop ( ) ;
        aux.first = -aux.first ;
        if ( aux.first > ans[ aux.second ] || aux.first < ans[ aux.second ] ) { continue ; }
        for ( int i = 1 ; i <= n + 2 ; ++ i ) {
            double c = aux.first + dist[ aux.second ][ i ] ;
            if ( ans[ i ] < 0 || ans[ i ] > c ) {
                ans[ i ] = c ;
                pq.push ( { - c , i } ) ;
            }
        }
    }
}

double calc ( tuhla p1 , tuhla p2 ) {
    double act = sqrt ( ( p1.x - p2.x ) * ( p1.x - p2.x ) + ( p1.y - p2.y ) * ( p1.y - p2.y ) ) ;
    act -= p1.r + p2.r ;
    if ( act < 0 ) { act = 0 ; }
    return act ;
}

void input ( ) {
    pair < double , double > foo1 , foo2 ;
    cin >> foo1.first >> foo1.second >> foo2.first >> foo2.second ;
    cin >> n ;
    a[ n + 1 ].x = foo1.first ;
    a[ n + 1 ].y = foo1.second ;

    a[ n + 2 ].x = foo2.first ;
    a[ n + 2 ].y = foo2.second ;

    a[ n + 1 ].r = a[ n + 2 ].r = 0.0 ;
    
    for ( int i = 1 ; i <= n ; ++ i ) {
        cin >> a[ i ].x >> a[ i ].y >> a[ i ].r ;
    }
}

void solve ( ) {
    for ( int i = 1 ; i <= n + 2 ; ++ i ) {
        for ( int j = 1 ; j <= n + 2 ; ++ j ) {
            if ( i == j ) { continue ; }
            dist[ i ][ j ] = calc ( a[ i ] , a[ j ] ) ;
        }
    }
    dijkstra ( n + 1 ) ;
    printf ( "%.15lf\n" , ans[ n + 2 ] ) ;
}


int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


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

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using ull = unsigned long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vvc = vector<vc>;
using ii = pair<int,int>;
using vii = vector<ii>;
using vvii = vector<vii>;
using dd = pair<double, double>;
using vdd = vector<dd>;
using vvdd = vector<vdd>;
using Mii = map<int,int>;
using vMii = vector<Mii>;

#define fi first
#define se second
#define INF INT_MAX
#define mod(a,m) (a%m+m)%m
#define PB push_back
#define MP make_pair

vvd memo;
vd prob;
int n;

// score := n + (#heads - #tails)
double dp(int pos, int score) {
	if(pos == -1) return (score == n? 1.0 : 0.0);
	double& ans = memo[pos][score];
	if(fabs(ans + 1) > 1e-9) return ans; // ans != -1
	ans = prob[pos] * dp(pos-1, score-1) + (1 - prob[pos]) * dp(pos-1, score+1);
	return ans;
}

int main(){
	while (cin >> n) {
		prob = vd(n);
		for (int i = 0; i < n; ++i) cin >> prob[i];
		memo = vvd(n, vd(2*n + 1, -1.0));
		double ans = 0;
		for(int i = 1; i <= n; ++i) {
			ans += dp(n-1, n + i);
		}
		cout << fixed;
		cout << setprecision(15);
		cout << ans << '\n';
	}
}



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

int COUNT(int N, string S){
    int count = 0;
    rep(i, N - 1) {
        if(S[i] == '1') {
            if(S[i + 1] == '1') {
                S[i + 1] = '0';
                count++;
            }
        } else {
            if(S[i + 1] == '0') {
                S[i + 1] = '1';
                count++;
            }
        }
    }
    return count;
}

int main() {
    int N, count, count2, answer;
    string S;
    cin >> S;
    N = S.size();
    count = COUNT(N, S);

    if(S[0] == '1') {
        S[0] = '0';
    } else {
        S[0] = '1';
    }
    count2++;
    count2 += COUNT(N, S);
    answer = min(count, count2);
    cout << answer << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;

int main(){
  int n;cin >> n;
  map<string,int> mp;
  vector<string> s(n);
  bool flag = true;
  rep(i,n){
    string k;cin >> k;
    mp[k]++;
    s[i] = k;
  }
  for(auto &i:mp) if(i.second!=1) flag = false;
  if(!flag){
    cout << "No" << endl;
    return 0;
  }
  char t=s[0].back();
  REP(i,1,n){
    if(s[i].front()!=t) flag = false;
    t=s[i].back();
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
  int S;

  cin >> S;
  
  int hour, min, sec;
  
  hour = S/(60*60);
  min = (S%(60*60))/60;
  sec = (S%(60*60))%60;

  cout << hour << ":" << min << ":" << sec << endl;

  return 0;		 
}
	


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

const ll INF=1001001001001001;

int main() {
  ll d,g;
  cin>>d>>g;
  vector<P> v(d);
  rep(i,d){
    cin>>v[i].first;
    cin>>v[i].second;
  }


  ll ans=INF;
  for(ll i=1;i<(1<<d);i++){
    ll s=0;
    ll cnt=0;
    rep(j,d){
      if (i&(1<<j)){
        if (g<v[j].first*100*(j+1)){
          cnt+=(g+100*(j+1)-1)/(100*(j+1));
        //  cout<<599/200;
      //    cout<<(g+100*(j+1)-1)<<' '<<100*(j+1)<<' '<<cnt<<' '<<j<<'j'<<endl;
          s=g;
        }
        //cout<<cnt<<endl;

        else{
          s+=(v[j].first*100*(j+1));
    //      cout<<s<<'s'<<j<<'j'<<endl;
          s+=v[j].second;
          cnt+=v[j].first;
        }
      }
    }
  //  cout<<s<<' '<<i<<'I'<<endl;

    if(s<g){
    //  cout<<s<<' '<<i<<'I'<<endl;
      ll temp=INF;
      rep(j,d){
      if (!(i&(1<<j))){
      //sav  cout<<j<<'j'<<endl;
        ll now=(g-s+(100*(j+1))-1)/(100*(j+1));
    //    cout<<now<<' '<<j<<'n'<<endl;
        if (now<=v[j].first){
          temp=min(temp,now);
      //    cout<<temp<<' '<<j<<'J'<<endl;
        }
      }
      }
      cnt+=temp;

    }
  //  cout<<cnt<<' '<<i<<"nct"<<endl;
      ans=min(cnt,ans);
  }
  cout<<ans;

}


Measured memory_bytes: 256
n,m = map(int,input().split())
ac_list = [0]+[0]*n
wa_list = [0]+[0]*n

for _ in range(m):
    p,s = input().split()
    p = int(p)
    if s == 'AC':
        ac_list[p] = 1
    elif s == 'WA' and ac_list[p] == 0:
        wa_list[p] += 1

for i in range(1,n+1):
    if ac_list[i] == 0:
        wa_list[i] = 0

print(sum(ac_list),sum(wa_list))

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

#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define setbitsll(x) __builtin_popcountll(x)
#define zerobitsll(x) __builtin_ctzll(x)
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef map<int,int> mii;

const int MOD = 1e9+7;

void solve () {
	string str;
	cin >> str;
	bool rev = false;	
	int q,type;
	cin >> q;
	deque<char>dq;
	for (int i = 0;i < str.length();++i) {
		dq.pb(str[i]);
	}
 	while (q--) {
		cin >> type;
		if (type == 1) {
			rev = !rev;
		} else {
			int f;char c;
			cin >> f >> c;
			if (f == 1) {
				if (rev) {
					dq.push_back(c);
				} else {
					dq.push_front(c);
				}
			} else {
				if (rev) {
					dq.push_front(c);
				} else {
					dq.push_back(c);
				}
			}
		}
	}
	string res = "";
	while (!dq.empty()) {
		res += dq.front();
		dq.pop_front();
	}
	if (rev) {
		reverse(all(res));
	}
	cout << res << '\n';
}

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



Measured memory_bytes: 4280
import java.util.Scanner;


class Main {
    static int gcd (int x, int y) {
        int temp;
        while((temp = x%y)!=0) {
            x = y;
            y = temp;
        }
        return y;
    }

    public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    
    int x = stdIn.nextInt();
    int y = stdIn.nextInt();
    int z;
    if(x<y){
        z = x;
        x = y;
        y = z;
    }

    System.out.println(gcd(x,y));

    stdIn.close();
    }


}


Measured memory_bytes: 26316
import collections

n = int(input())
s = [input() for i in range(n)]
s_list = []

max_s = collections.Counter(s).most_common()[0][1]
for i, j in collections.Counter(s).most_common():
    if j == max_s:
        s_list.append(i)
print(*sorted(s_list), sep = "\n")

Measured memory_bytes: 54248