akhauriyash/Code-Regression huggingface dataset:
import heapq
num, day = map(int, input().split())

dic = dict()
for i in range(num):
    days, pay = map(int, input().split())
    dic.setdefault(days, []).append(pay)
#print(dic)
taku = []
ans = 0
today = day
while today >= 0:
    key = day - today
#    print("today is "+str(today)+", key is "+str(key))
    if key in dic:
        for s in dic[key]:
            heapq.heappush(taku, s*(-1))
#    print(taku)
    if len(taku) != 0:
        ans -= heapq.heappop(taku)
    today -= 1
#    print(taku)
print(ans)

Measured memory_bytes: 27344
main = interact $ unlines . itp1_9_d . lines

itp1_9_d (str:_:ps) = process (map words ps) str
 where
  process [] _ = []
  process (["print",a,b]:ps) str = print' (read a) (read b) str : process ps str
  process (["reverse",a,b]:ps) str = process ps (reverse' (read a) (read b) str)
  process (["replace",a,b,p]:ps) str = process ps (replace' (read a) (read b) p str)

print' a b str = (drop a . take (b+1)) str
reverse' a b str = take a str ++ reverse ((drop a . take (b+1)) str) ++ drop (b+1) str
replace' a b p str = take a str ++ p ++ drop (b+1) str

Measured memory_bytes: 5480
#include "bits/stdc++.h"
using namespace std;

#ifdef LOCAL
        #include "debug.h"
        #define input freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
        #else
        #define debug(...) 4
        #define input ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#endif

using ll = long long;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;

int main() {
    input;
        
    int n, k, s;
    cin >> n >> k >> s;
    int a[n];

    for(int i = 0; i < n; i++) {
        if(s != 1e9)
            a[i] = s + 1;
        else
            a[i] = 1;

    }
    for(int i = 0; i < n; i++)
        cout << (i < k ? s : a[i]) << " ";
    

}   

Measured memory_bytes: 1664
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Text;
using System.Diagnostics;
using static System.Math;
using static System.Array;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{

    class Solve
    {
        const int mod = 1000000007;
        const int INF = 2147483647;
        const long SINF = 9223372036854775807;

        static int N;
        static long[] Au, Ad;

        public static void Input()
        {
            var cin = new Scanner();
            N = int.Parse(Console.ReadLine());
            Au = cin.SplitReaderL();
            Ad = cin.SplitReaderL();
        }

        static void Main(string[] args)
        {
            Input();

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            long ans = 0;
            long[] usum = new long[N];
            long[] dsum = new long[N];

            for(var i = 0; i < N; i++)
            {
                if (i == 0)
                {
                    usum[i] = Au[i];
                    dsum[i] = Ad[i];
                }
                else
                {
                    usum[i] = usum[i - 1] + Au[i];
                    dsum[i] = dsum[i - 1] + Ad[i];
                }
            }

            for (var i = 0; i < N; i++)
            {
                if (i == 0) { ans = Max(ans, usum[i] + dsum[N - 1]); }
                else { ans = Max(ans, usum[i] + dsum[N - 1] - dsum[i - 1]); }
            }

            Console.WriteLine(ans);
            //Console.Out.Flush();

        }

       
    }

    public class Scanner
    {
        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }

    }

    public class Graph
    {
        
    }
}

    



Measured memory_bytes: 13396
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}

void solve()
{
	int n;
	cin >> n;
	int a[n], b[n];
	for(int i = 1; i < n; ++i){
		cin >> b[i];
	}
	b[n] = inf;
	b[0] = b[1];
	int res = 0;
	for(int i = 0; i < n; ++i){
		int cur = b[i];
		if(i) cur = min(cur, b[i + 1]);
		res += cur;
	}
	cout << res;

}


 
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1000000000
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

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

	ll N,aa,bb,cc;
	cin>>N;
	if(N==1){
		cin>>aa>>bb>>cc;
		cout<<max(aa-bb,max(bb-cc,aa-cc));
		return 0;
	}
	priority_queue<ll>X;
	priority_queue<ll>Xd;
	VI rk(N+1);
	VI bk(N+1);
	VI k(N);
	ll red=0,blue=0;
	REP(i,N){
		int a;
		cin>>a;
		red+=a;
		//X.push(a);
		Xd.push(INF-a);
	}
	//cout<<red<<endl;
	rk[0]=red;
	REP(i,N){
		int a;
		cin>>a;
		k[i]=a;
		Xd.push(INF-a);
		red+=a;
		red-=abs(Xd.top()-INF);
		Xd.pop();
		rk[i+1]=red;
	}
	//REP(i,N+1)cout<<rk[i]<<endl;
	REP(i,N){
		int a;
		cin>>a;
		blue+=a;
		X.push(a);
	}
	//cout<<blue<<endl;
	bk[N]=blue;
	for(int i=N-1;i>=0;i--){
		blue+=k[i];
		X.push(k[i]);
		blue-=X.top();
		X.pop();
		bk[i]=blue;
	}
	//REP(i,N+1)cout<<bk[i]<<endl;
	ll ans=-9223372036854775807;
	//cout<<ans<<endl;
	REP(i,N+1)
		ans=max(ans,rk[i]-bk[i]);
	
	cout<<ans<<endl;
		
	
	return 0;
}

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

struct UnionFind{
    vector<int> par; //親を示す
    vector<int> siz; //素集合のサイズ

    //コンストラクタ
    UnionFind(int n) : par(n),siz(n,1){
        for(int i=0; i<n; i++) par[i] = i;
    }
    
    void init(int n){
        par.resize(n);
        siz.resize(n);
        for(int i=0; i<n; i++) par[i] = i;
    }

    int root(int x){
        while(par[x] != x){
            x = par[x] = par[par[x]];
        }
        return x;
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        if(siz[rx] < siz[ry]) swap(rx, ry);
        //siz[ry]<siz[rx]のときpar[ry]をpar[rx]に結合
        siz[rx] += siz[ry];
        par[ry] = rx;
    }
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    int size(int x){
        return siz[root(x)];
    }
};
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> x(m),y(m),z(m);
    for(int i=0; i<m; i++){
        int a,b,c;
        cin>>a>>b>>c;
        x[i]=a-1;
        y[i]=b-1;
        z[i]=c-1;
    }
    vector<bool> a(n,false);
    UnionFind tree(n);
    for(int i=0; i<m; i++){
        tree.unite(x[i],y[i]);
    }
    ll ans=0;
    for(int i=0; i<m; i++){
        if(!a[tree.root(x[i])]){
            a[tree.root(x[i])]=true;
            ans++;
        }
    }
    for(int i=0; i<n; i++){
        if(!a[tree.root(i)]){
            a[tree.root(i)]=true;
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2176
#include<iostream>
#include<fstream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<typeinfo>
using namespace std;

struct Edge{
    int s;
    int t;
    int weight;
    bool operator<(const Edge& right) const {
        return (weight<right.weight);
    }
    Edge(int s, int t, int weight): s(s), t(t), weight(weight){};
};

int Kruscal(vector<Edge> &edges, int V){
    int res = 0;
    vector<int> connect(V);
    for (int i=0;i<V;i++){
        connect[i] = i;
    }
    sort(edges.begin(), edges.end());
    for(int i=0;i<edges.size();i++){
        Edge e = edges[i];
        if (connect[e.s] != connect[e.t]){
            res += e.weight;
            int tmp = connect[e.t];
            for (int j=0;j<V;j++){
                if (connect[j] == tmp){
                    connect[j] = connect[e.s];
                }
            }
        }
    }
    return res;
}

int main(){
    int V, E, s, t, w;
    cin >> V >> E;
    vector<Edge> edges;
    for (int i=0;i<E;i++){
        cin >> s >> t >> w;
        edges.push_back(Edge(s, t, w));
    }
    cout << Kruscal(edges, V) << endl;
    //cout << "Naive: " << Kruscal(edges, V) << endl;
    //cout << "UnionFind" << KruscalUnionFind(edges, V) << endl;
    return 0;
}

Measured memory_bytes: 4516
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  string x,y;
  cin>>x>>y;
  if(x<y){
    cout<<"<"<<"\n";
  }
  else if(x>y){
    cout<<">"<<"\n";
  }
  else{
    cout<<"="<<"\n";
  }
  return 0;
  }

Measured memory_bytes: 3636
def euclid(a,b):
    if b == 0:
        return a
    else:
        return euclid(b,a%b)


def gcd(a,b):
    if a == b:
        return a
    elif a > b:
        return euclid(a,b)
    elif a < b:
        return euclid(b,a)

    print "error"
    return 0

def lcm(a,b):
    return a*b/gcd(a,b)

def monsters_battle_royale(n,a):
    _a = sorted(a)
    tmp = _a[0]
    for i in range(n):
        tmp = gcd(tmp,_a[i])

    return tmp
if __name__ == '__main__':
    n = int(raw_input())
    a = map(int,raw_input().split())


    print monsters_battle_royale(n,a)

Measured memory_bytes: 11320
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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 n, k; cin >> n >> k;
    cout << (n > k ? 0 : 1) << endl;
}



Measured memory_bytes: 3120
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        int a = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        double[] tt = new double[n];
        for (int i = 0; i < n; i++) {
            tt[i] = t - h[i] * 0.006;
        }
        double min = 1000000;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            double sa = Math.abs(a - tt[i]);
            if (sa < min) {
                min = sa;
                ans = i;
            }
        }
        System.out.println(ans + 1);
    }
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll n;cin>>n;
    vector<bool>isprime(n+1,true);
    vector<ll>prime;
    for (int i = 2; i <=n; ++i) {
        if(isprime[i]){
            prime.push_back(i);
            for (ll j = i*2; j <=n;j+=i) {
                isprime[j]=false;
            }
        }
    }
    ll ans=1;
    for(auto p:prime){
        ll now=0;
        now+=n/p;
        ll c=n;
        while(c>0){
            c/=p;
            now+=c/p;
        }
        ans*=now+1;
//        cout <<p <<" "<<ans<<endl;
        ans%=mod;
    }
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from bisect import bisect_left

c = ["light fly", "fly", "bantam", "feather", "light", "light welter", "welter", "light middle", "middle", "light heavy", "heavy"]
w = [48, 51, 54, 57, 60, 64, 69, 75, 81, 91, float("inf")]

for _w in map(float, sys.stdin.readlines()):
    print(c[bisect_left(w, _w)])


Measured memory_bytes: 5612
#include<iostream>

using namespace std;

int main(){
	int n,m,p;
	while(cin>>n>>m>>p){
		if(n==m && m==p&&n==0)break;
		int sum=0;
		int suc=0;
		for(int i=1;i<=n;i++){
			int x;
			cin>>x;
			if(i==m)suc=x;
			sum+=x;
		}
		sum*=(100-p);
		if(suc!=0)cout<<sum/suc<<endl;
		else cout<<0<<endl;
	}
}

Measured memory_bytes: 1160
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N,H,W,f=1;
  bool visited[100][100];
  char a[100][100];
  cin >> H >> W;
  REP(i,H){
    cin >> a[i];
  }
  REP(i,100)REP(j,100)visited[i][j] = false;
  queue<P> que;
  int c = 0;
  que.push(P(0,0));
  while(!que.empty()){
    c = 0;
    P p = que.front();que.pop();
    
    if(visited[p.first][p.second])
      continue;
    visited[p.first][p.second] = true;
    
    REP(i,4){
      if(p.first+dx[i] < W && p.second+dy[i] < H && p.first+dx[i] >= 0 && p.second >= 0)
        if(a[p.second+dy[i]][p.first+dx[i]] == '#'){
          if(i < 2){
            que.push(P(p.first+dx[i],p.second+dy[i]));
          }else if(!(visited[p.first+dx[i]][p.second+dy[i]])){
            f = 0;
          }
          if(!(visited[p.first+dx[i]][p.second+dy[i]]))
            c++;
        }
      if(c >= 2)
        f=0;
    }
    
  }

  
  
  if(f && visited[W-1][H-1])
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;
}



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

int main(){
    int a,b,c,d,e,k;
    cin >> a >> b>>c>>d>> e >> k;
    if(e-a>k){
       cout<< ":(" << endl;
    }else{
         cout<< "Yay!" << endl;
    }
    return 0;
}


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

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

  vector<string> vec(n);

  rep(i, n){
    cin >> vec.at(i);
  }

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

  rep(i, n){
    cout << vec.at(i);
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  string s;
  while(cin>>s){
    int r1=0,r2=0;
    char op='n';
    bool f=0;
    int p=0;
    while(p<(int)s.size()){
      while(isdigit(s[p])) r2=r2*10+(s[p++]-'0');
      if(r2>9999){
    f=1;
    break;
      }
      if(op=='n') r1=r2;
      if(op=='+') r1+=r2;
      if(op=='-') r1-=r2;
      if(op=='*') r1*=r2;
      if(r1<0||r1>9999){
    f=1;
    break;
      }
      r2=0;
      op=s[p++];
    }
    if(f) cout<<"E"<<endl;
    else cout<<r1<<endl;
  }
  return 0;
}

Measured memory_bytes: 3084
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

final class Main {

    private Main() {
    }

    public static void main(final String[] argv) throws IOException {
        final BufferedReader inputReader =
                new BufferedReader(new InputStreamReader(System.in));
        int totalPrice = 0;
        int totalAmount = 0;
        int count = 0;
        while (true) {
            String input = inputReader.readLine();
            if (input == null) {
                break;
            }
            String[] temp = input.split(",");
            totalPrice += Integer.parseInt(temp[0]) * Integer.parseInt(temp[1]);
            totalAmount += Integer.parseInt(temp[1]);
            count++;
        }
        int average = (int) Math.round(totalAmount / (double) count);
        System.out.println(totalPrice);
        System.out.println(average);
    }
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define en '\n'
#define pb push_back
#define mp make_pair

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;

struct aaa {
	aaa() {
		cin.tie(0);
		ios::sync_with_stdio(0);
		cout << fixed << setprecision(20);
	};
}aaaaa;


int main() {
	string s;
	cin >> s;

	int w = 0;

	ll count = 0;
	for (int i = 0; i < sz(s); i++) {
		if (s[i] == 'W') {
			count += (i - w);
			w++;
		}
	}

	cout << count << en;
	return 0;
}

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

const int MAXN=200010;
int n;
int a[200010];
int m;
int x,y;
int f[400020];
int size[400020];
int ans;

int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for (int i=1;i<=n;i++) cin>>a[i];
	for (int i=1;i<=n;i++) f[i]=i;
	for (int i=1;i<=n;i++) 
	{
		f[a[i]]--;
		size[MAXN+f[a[i]]]++;
	}
	for (int i=0;i<n;i++) if (!size[MAXN+i]) ans++;
	for (int i=1;i<=m;i++)
	{
		cin>>x>>y;
		int now=f[y];
		if (!size[MAXN+now-1] && now-1>=0) ans--;
		size[MAXN+now-1]++;
		f[y]=now-1;
		
		now=f[a[x]];
		size[MAXN+now]--;
		f[a[x]]++;
		if (!size[MAXN+now] && now>=0) ans++;
		a[x]=y;
		cout<<ans<<endl;
	}
	
	
}

Measured memory_bytes: 4608
import scala.io.StdIn
import scala.annotation.tailrec
import scala.collection.mutable.ListBuffer

object Main{
  def main(args: Array[String]){
    StdIn.readLine()
    val line = StdIn.readLine().split(" ").toList.map(_.toInt)

    println(line.sorted.mkString(" "))
    println(sSort(List(), line, 0))
  }

  @tailrec
  def sSort(sorted: List[Int], unsorted: List[Int], n: Int): Int={
    if(unsorted.length == 0) n
    else if(unsorted.sorted == unsorted) n
    else {
      val pos = unsorted.indexWhere(_ == unsorted.min)
      val swapped = unsorted.updated(0, unsorted(pos)).updated(pos, unsorted.head)

      if(pos == 0) sSort(sorted :+ unsorted.min, unsorted.updated(0, unsorted(pos)).updated(pos, unsorted.head).tail, n)
      else sSort(sorted :+ unsorted.min, unsorted.updated(0, unsorted(pos)).updated(pos, unsorted.head).tail, n+1)
    }
  }
}

Measured memory_bytes: 45816
#define _CRT_SECURE_NO_WARNINGS
//#include <stdafx.h>
//#include "targetver.h"
#include <stdio.h>
//#include <tchar.h>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif>

#define LL long long
#define MOD 998244353
#define INF 1000000000
#define LINF 1000000000000000000

using namespace std;

const int N = 4e3 + 10;
double a[N],sum;
double b[N];
double dp[N][N];
vector<int>vec;
int n;

int main()
{
	cout << fixed << setprecision(10);

	double p1, p2;
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++)
		cin >> a[i];
		//scanf("%f", &a[i]);

	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			dp[i][j] = 1;

	dp[0][0] = 1.0 - a[0];
	dp[0][1] = a[0];

	for (int i = 1; i < n; i++)
		for (int j = 0; j <= i+1; j++) {
			p1 = dp[i - 1][j] != 1 ? dp[i - 1][j] * (1.0 - a[i]) : 0;
			p2 = j > 0 ? dp[i - 1][j - 1]*a[i] : 0;
			dp[i][j] = p1 + p2;
		}

	for (int i = n / 2 + 1; i <= n; i++)
		sum += dp[n - 1][i];

	cout << sum;
}



Measured memory_bytes: 94208
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

void dout() { cerr << '\n'; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << " " << H;
    dout(T...);
}

#ifdef LOCAL
    #define dbg(...) cerr << #__VA_ARGS__, dout(__VA_ARGS__)
#else
    #define dbg(...) ;
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;

const int N = 2e5 + 123, MOD = 1e9 + 7;
int n, f[N], up[N], fact[N], dp[N], sz[N];
vector <int> adj[N];

int binpow(int x, int y) {
    int res = 1;
    while (y > 0) {
        if (y & 1) {
            res = (ll)res * x % MOD;
        }
        x = (ll)x * x % MOD;
        y /= 2;
    }
    return res;
}

void dfs(int v, int p) {
    sz[v] = 1;
    f[v] = 1;
    for (int to : adj[v]) {
        if (to == p) {
            continue;
        }
        dfs(to, v);
        sz[v] += sz[to];
        f[v] = (ll)f[v] * f[to] % MOD;
        f[v] = (ll)f[v] * binpow(fact[sz[to]], MOD - 2) % MOD;
    }
    f[v] = (ll)f[v] * fact[sz[v] - 1] % MOD;
}

void go(int v, int p) {
    if (v != p) {
        int tmp = (ll)dp[p] * binpow(f[v], MOD - 2) % MOD;
        tmp = (ll)tmp * binpow(fact[n - 1], MOD - 2) % MOD;
        tmp = (ll)tmp * fact[n - sz[v] - 1] % MOD;
        tmp = (ll)tmp * fact[sz[v]] % MOD;
        dp[v] = (ll)f[v] * binpow(fact[sz[v] - 1], MOD - 2) % MOD;
        dp[v] = (ll)dp[v] * fact[n - 1] % MOD;
        dp[v] = (ll)dp[v] * binpow(fact[n - sz[v]], MOD - 2) % MOD;
        dp[v] = (ll)dp[v] * tmp % MOD;
    }   else {
        dp[v] = f[v];
    }
    for (int to : adj[v]) {
        if (to == p) {
            continue;
        }
        go(to, v);
    }
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(NULL);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif

    cin >> n;
    fact[0] = 1;
    for (int i = 1; i <= n; i++) {
        fact[i] = (ll)fact[i - 1] * i % MOD;
    }
    for (int i = 1; i < n; i++) {
        int x, y;
        cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    dfs(1, 1);
    go(1, 1);
    for (int i = 1; i <= n; i++) {
        cout << dp[i] << '\n';
    }
}


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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int n, k;
	cin >> n >> k;
	if (k == 1) cout << 0 << endl;
	else cout << (n - k + 1) - 1 << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define ll long long
using namespace std;
const ll N=1e9;
int main(){
    ll s;cin>>s;
    ll x3=(s%N==0 ? 0:N-s%N);
    ll y3=(s+x3)/N;
    cout<<"0 0 1000000000 1 "<<x3<< " " <<y3<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    lint a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;

    lint dist = abs(a - b);
    dist += w * t;
    dist -= v * t;

    if (dist <= 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3620
def main():
    S = input()
    N = len(S)

    full_even = (N + 1) // 2
    even = 0
    for i in range(0, N, 2):
        if S[i] == '0':
            even += 1

    full_odd = N // 2
    odd = 0
    for i in range(1, N, 2):
        if S[i] == '0':
            odd += 1

    # print(even, odd)
    case1 = even + full_odd - odd
    case2 = odd + full_even - even
    print(min(case1, case2))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
<?php
while(list($n, $x) = explode(" ", trim(fgets(STDIN)))){
    if($n == 0 && $x == 0){
        return 1;
    }
    $count = 0;
    for($i = 1; $i <= $n; $i++){
        for($j = $i+1 ; $j <= $n; $j++){
            for($k = $j+1; $k <= $n; $k++){
                if($i + $j + $k == $x){
                    $count += 1;
                }
            }
        }
    }
    echo $count.PHP_EOL;
}

Measured memory_bytes: 15168
using System;
class Program{
 static void Main(string[] args){
   string[] n = Console.ReadLine().Split(' ');
   int a = int.Parse(n[0]);
   int b = int.Parse(n[1]);
   
   if(a<=9&&1<=a&&b<=9&&1<=b){
     Console.WriteLine(a*b);
   }else{
     Console.WriteLine(-1); 
   }
 }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define IOS   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define mp    make_pair
#define pb    push_back
#define F     first
#define pi 	  3.14159265358979323846
#define S     second
#define ll    long long
#define ld    long double
#define sz(s) (ll)s.size() 
#define vl    vector < ll >
#define pll   pair < ll, ll >
#define ml    map < ll, ll >
#define mod   1000000007
#define qe	  998244353
#define MAXN  1e5+5
#define mx    10000005
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define inv(i,a,b)  for(i=a;i>=b;i--)
#define all(a)  (a).begin(),(a).end()
using namespace std;
ll set_bit(ll n){
	ll ans=0;
	while(n){
		if(n&1)ans++;
		n>>=1;
	}
	return ans;
}
ll dp[1<<21]={0};
int main(){
//	#ifndef ONLINE_JUDGE
//    if (fopen("input.txt", "r"))
//    {
//        freopen("input.txt", "r", stdin);
//        freopen("output.txt", "w", stdout);
//    }
//	#endif
	IOS;
	ll t,n,l,l1;
	ll i,j,m,mn,q,d,x,y,sum=0,r,p,k,c;
	string s,s1;
	cin>>n;
	ll a[n][n];
	rep(i,0,n)rep(j,0,n)cin>>a[i][j];
	
	rep(i,0,1<<n){
		k=set_bit(i);		
		rep(j,0,n){
			if(a[k][j] && !(i&(1<<j))){
				if(k==0)dp[i|1<<j]=1;
				else dp[i|1<<j]+=dp[i];
				dp[i|1<<j]=dp[i|1<<j]%mod;
			}
			
		}
	}
//	rep(i,0,1<<n)cout<<dp[i]<<" ";
	cout<<dp[(1<<n)-1];
}

Measured memory_bytes: 19972
a = input()
flag = 0
j = int(a)
k = 1
while(k!=0):
    flag = 0
    for i in range(2, j):
        if(j % i == 0):
            flag = 1
            break;
    if(flag == 1):
        j += 1;
        k = 1
    else:
        k = 0

print (j)
    
        


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

long long n;
long long tab[100010];
long long DP[100010];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (long long i = 1 ; i <= n ; i++)
		cin >> tab[i];
	DP[2] = abs(tab[2] - tab[1]);
	for (long long i = 3 ; i <= n ; i++)
	{
		DP[i] = min(DP[i - 1] + abs(tab[i] - tab[i - 1]),DP[i - 2] + abs(tab[i] - tab[i - 2]));
	}
	cout << DP[n] << endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  string s;

  cin >> s;
  int n = s.size();
  s = "$" + s;

  int dp[SIZE][2] = {};

  dp[0][0] = 0;

  for(int i=1; i<=n; i++) {
    if (i >= 2) dp[i][1] = max(dp[i][1], dp[i-2][0] + 1);
    dp[i][0] = max(dp[i][0], dp[i-1][1] + 1);

    if (s[i] != s[i-1]) {
      dp[i][0] = max(dp[i][0], dp[i-1][0] + 1);
    }
  }


  cout << max(dp[n][0], dp[n-1][1]) << endl;

  return 0;
}


Measured memory_bytes: 2112
while True:
    n=input()
    if n==0:break
    L=[map(int,raw_input().split()) for i in range(n)]
    S=set([min(i) for i in L])
    for t in [[i[j] for i in L] for j in range(n)]:
	maxInt=max(t)
        if maxInt in S:
            print maxInt
            break
    else:
	print 0

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

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

    int cnt = 0;
    for(int i = 0; i < n; i++){
        int minj = i;
        for(int j = i; j < n; j++)
            if(a[j] < a[minj]) minj = j;
        if(i == minj) continue;
        swap(a[i], a[minj]);
        cnt++;
    }

    for(int k = 0; k < n; k++)
        cout << a[k] << (k == n-1 ? '\n' : ' ');
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <map>

using namespace std;

typedef long long ll;

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

int main() {
    ll n; cin >> n;
    vector<ll> a(n);
    for(ll i = 0; i< n; i++){
        cin >> a[i];
    }
    ll ans = 0;
    for(ll i = 0; i< 60; i++) {
        ll count = 0;
        for(long long j = 0; j< n; j++) {
            count += (a[j] >> i) & 1;
        }
        ll add = ll(pow(2,i)) %MOD;
        add *= count;
        add %= MOD;
        add *= n-count;
        add %= MOD;
        ans += add;
        ans %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
//  RAKSHIT KADAM
//ALWAYS USE &IT FOR ITERATING USING AUTO ...
 #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
#warning !!!check the size of arrayss!!!

// NUMERIC DEFINITIONS :
    #define INF 2000000000000000005
    #define MOD  1000000007
    #define newMOD  998244353
    #define MAX 300006
    #define pi 3.1415926535897932384626433832795
 
 #define ll long long
 #define int long long
 #define P(gg) for(auto rax:gg){cout<<rax<<" ";}cout<<endl;
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define endl "\n"
 #define x first
 #define y second
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define vi vector<ll>
 #define Endl endl
 #define lb lower_bound
 #define ub upper_bound
#define pii pair<ll,ll>
 #define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
 #define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
//ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
//int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;                                                  return (y%2 == 0)? p : (x * p) % m;}
//ll modInverse(int a, int m){int g = gcd(a, m); { return power(a, m-2, m);}}
ll score;

ll n,m,q;
ll a[60],b[60],c[60],d[60];
void dfs(vi v)
{
    if(v.size()==n+1)
    {
        ll temp=0;
        for(ll i=0;i<q;i++)
        {
            if(v[b[i]]-v[a[i]]==c[i])
                temp+=d[i];
        }
        score = max(score,temp);return;
    }
    ll start = v.back();
    for(ll i=start;i<=m;i++)
    {
        v.pb(i);
        dfs(v);
        v.pop_back();
    }
}
void solve()
{
    cin>>n>>m>>q;
    for(ll i=0;i<q;i++)
    {
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        
    }
    vi ve;ve.pb(1);
    dfs(ve);
    cout<<score<<endl;
}
signed main()
{
 
   
    Need_for_speed(activated);
//satisfy
//    {
//   solve();
//    }

 solve();
    return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<math.h>
#include<vector>
#include <cstdlib>
using namespace std;

int int_check(double x){
  int count=0;
  if (ceil(x) != floor(x)){
  }
  else{
    count++;
  }    
   
  return count;
}

int main() {
  int n, d; cin >> n >> d;
  int ans = 0;
  vector < vector < int> > v(n, vector <int> (d));

  for(int i = 0; i < n; i++){
    for(int j = 0; j < d; j++){
      cin >> v[i][j];
    }
  }

  float x=0;
  int num=0;
  for(int i = 0; i < n; i++){
    int k = i + 1;
      while(k < n){
        for(int j = 0; j < d; j++){
         
          num = abs(v[k][j] - v[i][j]);
          num *= num;
          x += num;
       }
         x = sqrt(x);
        ans += int_check(x);
        x = 0;
        k++;
    }
  }  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
//#pragma GCC target ("tune=native")
#pragma GCC target ("avx2")
#include <bits/stdc++.h>

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}

struct chtime{
	chrono::system_clock::time_point stm;
	auto nget() { return chrono::system_clock::now();}
	chtime() { stm = nget();}
	uint64_t gtm(){
		return chrono::duration_cast<chrono::milliseconds>(nget()-stm).count();
	}
	void disp(){ cerr << gtm() <<"\n";}
};
chtime tmq;

ll CTM;
const ll TLMT = 2 *1000 - 50;
const ll ZGZ = 1000000;
mt19937 mran(202005282);
int D;
VI C(26), USD(26);
vector<VI> S(366, VI(26));

inline int xran(int su){ return mran() % su;}
inline int xran2(int su){ return mran() & su ;} //su = (2^n)-1
inline ll xran9(ll su){ return mran() & su ;}

vector<double> mkfq(int n = 100){
	vector<double> zzx(n+1);
	rep(i, n+1)  zzx[i] = 1 -(1 - i /(1.0*n)) * (1 - i/(1.0*n));
	return zzx;
}

inline ll clpt(const VI& t){
	VI usd(27, 0);
	//VL rtn(D);
	ll ans = 0;
	rep(i, D){
		ans += S[i][t[i]];
		usd[t[i]] = i+1;
		rep(j, 26){
			ans -= (ll)C[j] * (i+1 - usd[j]);
		}
		//dbg(i, ans);
	}
	return ans;
}

inline ll clpt2(const VI& t, int p1, int p2, int op1){
	ll ans = 0;
	ans +=S[p1][p2];
	ans -=S[p1][op1];
	
	//ll z1=0, z2=0;
	//rep(i, D){
	//	if(t[i]==p2) z1 += i;
	//	if(t[i]==op1) z2 += i;
	//}
	ans += C[op1] * p1;
	ans -= C[p2 ] * p1;
	
	return ans;
}





int main()
{
	typedef pair<ll, VI> LVI;
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >>D;
	rep(i, 26) cin >> C[i];
	rep(i, D) rep(j, 26) cin >>S[i][j];
	auto fqd = mkfq(100);
	for(auto& z: fqd) z /= 100;
	int tct =0, chcnt =0, upcnt =0;
	rep(i, 99) xran2(1023);
	
	
	
	VI idt(D);
	rep(i, D) idt[i] = i%26;
	auto rc = clpt(idt);
	dbg("Init",rc);
	LVI BST = LVI(rc, idt);
	auto ALBST = BST;
	for(; (tct &511) != 509 || (CTM = tmq.gtm()) < TLMT; tct++){
	
		int p1 = xran(D), p2 = (xran(25) + p1)%26;
		while(idt[p1]==p2) p2 = xran(26);
		int op1 = idt[p1];
		idt[p1] = p2;
		//auto npt = clpt2(idt, p1, p2, op1);
		auto npt = clpt(idt);
		if(BST.first < npt){
			BST = LVI(npt, idt); upcnt++;
		}else{
			double zan = 1.0 - 1.0 * CTM / TLMT; 
			int qw= zan*100;
			
			if(xran2(1023) < fqd[qw] * 1023  && 
				abs((BST.first - npt) / BST.first)  < fqd[qw]  ){
				BST = LVI(npt, idt); chcnt++;
				//idt[p1] = op1;
			}else{
			//if(tct%ZGZ==0) dbg(zan, qw, BST);
				idt[p1] = op1;
			}
		}
		ALBST =max(ALBST, BST);
		
	}
	dbg("res",ALBST.first, BST.first, tmq.gtm(), "cnt=", tct, upcnt, chcnt);
	rep(i, D) cout << ALBST.second[i] +1 <<"\n";
	return 0;
}
// gpp mar.cpp && a < tester\sample2.in.txt


Measured memory_bytes: 3736
#include "bits/stdc++.h"
#define hhh cerr<<"hhh"<<endl
#define see(x) cerr<<(#x)<<'='<<(x)<<endl
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;}

const int maxn = 5e5+7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;

int n, k;
ll f[maxn], inv[maxn];

ll comb(int n, int m) {
    if(m<0||m>n) return 0;
    return f[n]*inv[m]%mod*inv[n-m]%mod;
}

int main() {
    f[0]=f[1]=inv[0]=inv[1]=1;
    for(int i=2; i<maxn; ++i) f[i]=i*f[i-1]%mod;
    for(int i=2; i<maxn; ++i) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    for(int i=2; i<maxn; ++i) inv[i]=inv[i]*inv[i-1]%mod;
    n=read(), k=read();
    ll ans=comb(n+n-1,n-1);
    for(int i=1; k+i<n; ++i) {
        ans=(ans-comb(n,i)*comb(n-1,i-1)%mod+mod)%mod;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 8064
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
x=0
for i in range (N-1):
  if A[i]+1 == A[i+1]:
    x= x+B[i]+C[A[i]-1]
  else:
    x= x+B[i]
print(x+B[N-1])

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    string s; cin >> s;
    int n = s.size();
    if(s[n-1] == 's'){
        cout << s << "es" << endl;
    }else{
        cout << s << "s" << endl;
    }
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){int b=0;for(auto itr :a){if(b++!=0)cout << " "; cout << itr;} }
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
#define int ll
signed main(){
    int n; cin >> n;
    vector<int>v(n);
    vector<int>indexOf(n);
    set<int>S;
    rep(i,n) cin >> v[i];
    rep(i,n) indexOf[--v[i]] = i;
    int ans = 0;
    S.insert(-1);
    S.insert(n);
    rep(i,n){
        auto itr1 = S.lower_bound(indexOf[i]);
        auto itr2  = prev(itr1);
        int r_val = *itr1;
        int l_val = *itr2;
        int l,r;
        r = r_val - indexOf[i];
        l = indexOf[i] - l_val;
        S.insert(indexOf[i]);
        ans += r*l*(i+1);
    }
    cout << ans << endl;
}






Measured memory_bytes: 12800
#include <iostream>
#include <algorithm>
using namespace std;
string s, t;
int dp[3100][3100];

int main() {
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j < t.size(); j++) {
            if (s[i] == t[j]) dp[i+1][j+1] = max(dp[i][j], dp[i][j] + 1);
            dp[i+1][j+1] = max({dp[i+1][j+1], dp[i+1][j], dp[i][j+1]});
        }
    }
    string ans = "";
    int i = s.size(), j = t.size();
    while (i > 0 && j > 0) {
        if (dp[i-1][j] == dp[i][j]) i--;
        else if (dp[i][j-1] == dp[i][j]) j--;
        else {
            ans = s[i-1] + ans;
            i--, j--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 37120
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll=long long;
using vi=vector<int>;
using pii=pair<int, int>;

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
ll read(){ll a;scanf("%lld",&a);return a;}

const int inf = TEN(9) + 10;
const int mod = TEN(9) + 7;

struct SegTree { // 区間sum
	int n;
	vector<int> Sum;
	void init(int n_) {
		n = 1;
		while (n < n_) n *= 2;
		Sum.resize(2 * n);
		for (int i = 0; i < 2 * n - 1; ++i) {
			Sum[i] = 0;
		}
	}
	void add(int idx, int val) {
		idx += n - 1;
		Sum[idx] += val;
		while (idx > 0) {
			idx = (idx - 1) / 2;
			Sum[idx] = Sum[idx * 2 + 1] + Sum[idx * 2 + 2];
		}
	}
	int get_sum(int a, int b, int k = 0, int l = 0, int r = -1) { // [a, b)のsum
		if (r == -1) r = n;
		if (r <= a || b <= l) return 0;
		if (a <= l && r <= b) return Sum[k];
		int vl = get_sum(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = get_sum(a, b, k * 2 + 2, (l + r) / 2, r);
		return vl + vr;
	}
};

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

int N, X;

signed main()
{
	cin >> N >> X;

	int ans = 0;

	rep(i, N) {
		ans = gcd(ans, abs(X - read()));
	}

	cout << ans << endl;
}




Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	static void drawBox(int w, int h){
		for(int i = 0; i < h; i ++){
			for(int j = 0; j < w; j ++){
				System.out.print("#");
			}
			System.out.print("\n");
		}
		System.out.print("\n");
	}
	
    public static void main(String[] args){
    	Scanner in = new Scanner(System.in);
    	
    	while(in.hasNextLine()){
    		int h = in.nextInt(), w = in.nextInt();
    		int i = 0;
    		
    		if(w == 0 && h == 0){
    			break;
    		}else{
    			if(i != 0){
    				System.out.print("\n");
    			}
    			drawBox(w, h);
    			i ++;
    		}
       	}
    	
    	in.close();
	}
}

Measured memory_bytes: 35396
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <map>
#include <vector>

#define div 1000000000+7

typedef long long ll;

using namespace std;

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

    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'A'){
            a = i;
            break;
        }
    }
    for(int i = s.length(); i > 0; i--){
        if(s[i] == 'Z'){
            b = i;
            break;
        }
    }
    cout << b-a+1 << endl;


    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
ll inf = 1000000000;
typedef pair<ll, ll> P;
P q[200005];
P ans(int x) {
	int a = x % 10;
	int b = 0;
	while (x) {
		b = x % 10;
		x = x / 10;
	}
	return P{ a,b };
}
int main() {
	int n;
	cin >> n;
	map<P,int>mp;
	for (int i = 1; i <= n; i++) {
		P kai = ans(i);
		mp[kai]++;
	}
	ll count = 0;
	for (int i = 1; i <= n; i++) {
		P kai2 = ans(i);
		q[i] = make_pair(kai2.second, kai2.first);
		count += mp[q[i]];
	}
	cout << count << endl;
	return 0;
}


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

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
bool chmax(T &a, const T &b) {if (a < b){ a = b; return 1;} return 0;}
template <class T>
bool chmin(T &a, const T &b) {if (a > b){ a = b; return 1;}return 0;}
template <class T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main()
{
    int N, D;
    cin >> N >> D;

    if (N%(2*D+1) == 0) cout << N/(2*D+1) << endl;
    else cout << N/(2*D+1) +1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
using ll = long long;
 
 
int main() {
	
	int n;
	cin >> n;
    
	if ( n < 4 )
      	cout << "No\n";
  	else if (n == 5 or n == 6 or n == 9 or n == 10 or n == 13 or n == 17) 
      	cout << "No\n";
  	else
      	cout << "Yes\n";
	
}

Measured memory_bytes: 256
while line = gets
  a = line.split.map(&:to_i)
  b = gets.split.map(&:to_i)
  ht,bw = 0,0
  4.times do |i|
    if a[i] == b[i] then ht += 1
    elsif a.include? b[i] then bw += 1 end
  end
  puts "#{ht} #{bw}"
end

Measured memory_bytes: 8632
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

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

int main()
{
    int s=0,a,t=0,b;
    REP(4){cin >> a; s+=a;}
    REP(4){cin >> b; t+=b;}
    cout << max(s,t) << endl;
    return 0;
}

Measured memory_bytes: 0