akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) (int i=a;i<n;i++)
#define per(i,a,n,s) (int i=n-1;i>=a;i--)
#define range(...) _overload3(__VA_ARGS__,per,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vecin(x) for(auto&youso_: (x) ) cin >>  youso_
#define vecout(x) for(auto&youso_: (x) ) cout << youso_ << " " ; cout << endl
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 (b<a) { a=b; return 1; } return 0; }
const int inf = 1e9+10;
const int mod = 1e9+7;
const long long llinf = 1e18;
#define _GLIBCXX_DEBUG
// head

struct UnionFind {
    vector<int> data;
    UnionFind(int sz) : data(sz, -1) { }
    bool unionSet(int x, int y) {
        if ((x = root(x)) == (y = root(y))) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y]; data[y] = x;
        return true;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
};

int main(){
    int ans=0;
    int n,m;
    cin >>n>>m;
    vector<pair<int,int>> E(m);
    for range(i,m){
        int a,b;
        cin >>a>>b;
        a--, b--;
        E[i].first = a;
        E[i].second = b;
    }
    for range(i,m){
        UnionFind uf(n);
        for range(j,m){
            if (j!=i) { uf.unionSet(E[j].first,E[j].second); }
        }bool flug=false;
        for range(k,n-1){
            for range(l,k+1,n){
                if (!uf.findSet(k,l)) { flug = true; }
            }
        }
        if (flug) { ans++ ;}  
    }
    cout << ans << endl;
}

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

int main() {
    string s; cin >> s;
    string s_a = s;
    reverse(s_a.begin(), s_a.end());
    if (s_a != s) {
        puts("No");
        return 0;
    }

    string s_b;
    s_a = s_b = s.substr(0, s.size()/2);

    reverse(s_a.begin(), s_a.end());
    if (s_a != s_b) {
        puts("No");
        return 0;
    }
    s_a = s_b = s.substr((s.size() + 1)/2);
    //cout << s_a <<endl;
    reverse(s_a.begin(), s_a.end());
    if (s_a != s_b) {
        puts("No");
        return 0;
    }
    puts("Yes");
}

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

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

long long MOD = 1000000000 + 7;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main(){
  cout << setprecision(10);
  int N,M; cin >> N >> M;
  vector<pair<int, pair<int,int>>> v(M);

  for(int i = 0; i < M; i++){
    int x,y,z; cin >> x >> y >> z;
    v[i] = make_pair(z, make_pair(x,y));
  }

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


  UnionFind tree(N);
  vector<pair<int,int>> ans;
  ll min_val = 0;
  for(int i = 0; i < M; i++){
    ll weight = (ll)v[i].first;
    int s = v[i].second.first;
    int t = v[i].second.second;

    if(tree.root(s) == tree.root(t)){
      continue;
    } else { 
      min_val += weight;
      tree.unionSet(s,t);
    }
  }
  cout << min_val << endl;
}



Measured memory_bytes: 4108
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int i=0;
String rtn="";
StringBuffer[] sb=new StringBuffer[3];
for(i=0;i<3;i++){sb[i]=new StringBuffer(sc.next());}
rtn=(sb[0].reverse().substring(0,1).equals(sb[1].substring(0,1))&&sb[1].reverse().substring(0,1).equals(sb[2].substring(0,1)))?"YES":"NO";
System.out.println(rtn);
}
}

Measured memory_bytes: 23764
#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 V = vector<ll>;
using P = pair<ll,ll>;

int main(){
   ll n;cin >>n;
   vector<ll>a(n);
   vector<ll > l(n+1,0);
   vector<ll > r(n+1,0);
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
        l[i+1]=__gcd(l[i],a[i]);
    }
    reverse(all(a));
    for (int i = 0; i < n; ++i) {
        r[i+1]=__gcd(r[i],a[i]);
    }
    ll mx=0;
    for (int j = 0; j < n; ++j) {
        mx=max(mx,__gcd(l[j],r[n-j-1]));
    }
    cout <<mx<<endl;
    return 0;
}

Measured memory_bytes: 2560
# -*- coding: utf-8 -*-

s = input().strip()

good_odds = list('RUD')
good_evens = list('LUD')

odd_s = s[::2]
even_s = s[1::2]

for c in odd_s:
    if c not in good_odds:
        print("No")
        exit()


for c in even_s:
    if c not in good_evens:
        print("No")
        exit()


print("Yes")


Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int h,w,wall[33][33][4],dist_broken[33][33][4];
int dy[]={-1,0,1,0},dx[]={0,-1,0,1};
// 0
//1 3
// 2

int bfs(int Y,int X){
	int d[33][33];
	rep(i,h+1)rep(j,w+1)d[i][j]=INF;
	d[Y][X]=0;
	queue<pi> Q;
	Q.push(pi(Y,X));
	while(Q.sz){
		pi p=Q.front();
		int y=p.fir,x=p.sec;
		if(y==h && x==w)return d[h][w];
		Q.pop();
		rep(i,4)if(!wall[y][x][i]){
			int ny=y+dy[i],nx=x+dx[i];
			if(d[y][x]+1 < d[ny][nx]){
				d[ny][nx]=d[y][x]+1;
				Q.push(pi(ny,nx));
			}
		}
	}
	return INF;
}

typedef pair<int,pi> tri;

int shortest(){
	int d[33][33];
	rep(i,h+1)rep(j,w+1)d[i][j]=INF;
	d[h][w]=0;
	priority_queue<tri,vector<tri>,greater<tri> > Q;
	Q.push(tri(0,pi(h,w)));
	while(Q.sz){
		tri t=Q.top();
		int dist=t.fir,y=t.sec.fir,x=t.sec.sec;
		if(y==1 && x==1)return dist;
		Q.pop();
		if(dist > d[y][x])continue;
		rep(i,4)if(!wall[y][x][i]){
			int ny=y+dy[i],nx=x+dx[i];
			int nc=max(dist+1,dist_broken[ny][nx][(i+2)%4]);
			if(nc < d[ny][nx]){
				d[ny][nx]=nc;
				Q.push(tri(nc,pi(ny,nx)));
			}
		}
	}
	return -1;
}

int main(){
	while(cin>>h>>w && h){
		rep(i,h+1)rep(j,w+1)rep(k,4)wall[i][j][k]=1;
		rep2(i,1,h+1){
			rep2(j,1,w)cin>>wall[i][j][3];
			if(i<h)rep2(j,1,w+1)cin>>wall[i][j][2];
		}
		rep2(i,1,h+1)rep2(j,1,w+1){
			wall[i][j][1]=wall[i][j-1][3];
			wall[i][j][0]=wall[i-1][j][2];
		}
		rep2(i,1,h+1)rep2(j,1,w+1)rep(k,4){
			if(wall[i][j][k])dist_broken[i][j][k]=INF;
			else{
				wall[i][j][k]=1;
				dist_broken[i][j][k]=bfs(i,j);
				wall[i][j][k]=0;
			}
		}
		cout<<shortest()<<endl;
	}
}

Measured memory_bytes: 944
#include<iostream>
using namespace std;
int main(){
  int n;
  int H[251];

  cin >> n;
  for(int i=1;i<n+1;++i){
    cin >> H[i];
  }
  for(int i=1;i<n+1;++i){
    if(i==1){
      cout << "node " << i << ": key = " << H[i] <<", left key = "<< H[i*2]<<", right key = "<< H[i*2+1]<<", "<<endl;
    }
    else if(i<n/2){
      cout<< "node " << i << ": key = " << H[i] <<", parent key = "<< H[i/2]<<", left key = "<< H[i*2]<<", right key = "<<H[i*2+1]<<", "<<endl;;
    }
    else if(n%i==0 && n/i ==2){
      cout<< "node " << i << ": key = " << H[i] <<", parent key = "<< H[i/2]<<", left key = "<< H[i*2]<<", "<<endl;;
    }
     else if(n%i==1&& n/i ==2){
      cout<< "node " << i << ": key = " << H[i] <<", parent key = "<< H[i/2]<<", left key = "<< H[i*2]<<", right key = "<<H[i*2+1]<<", "<<endl;;
    }
    else{cout<< "node " << i << ": key = " << H[i] <<", parent key = "<< H[i/2]<<", "<<endl;
  
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int num[110000];

int main(){
  bool flag=false;
  vector<ll> V;
  int N,count=0;
  ll A[110000],B[110000],ta=0;
  cin>>N;

  for(int i=0;i<N;i++) cin>>A[i];
  for(int i=0;i<N;i++){
    cin>>B[i];
    if(B[i]>A[i]){
      count++;
      ta+=B[i]-A[i];
    }else if(A[i]>B[i]){
      V.push_back(A[i]-B[i]);
    }
  }

  sort(V.begin(),V.end(),greater<ll>());
  
  if(ta==0) count--;

  for(int i=0;i<(int)V.size();i++){
    ta-=V[i];
    if(ta<=0){
      count+=i+1;
      flag=true;
      break;
    }
  }

  if(flag) cout<<count<<endl;
  else cout<<-1<<endl;

  
}


Measured memory_bytes: 2424
/*
 * a.cc:
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
#include<iomanip>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main(){
  int K,X;
  cin>>K>>X;

  for(int i=X-K+1;i<=X+K-1;i++){
    cout<<i<<endl;
    
  }
  return 0;
  
}

Measured memory_bytes: 3608
import sys
mod = 1000000007

def solve():
    input = sys.stdin.readline
    N = int(input())
    U = input().strip("\n")
    D = input().strip("\n")
    DP = [0] * N
    if U[0] == D[0]: DP[0] = 3
    else: DP[0] = 6

    for i in range(1, N):
        if U[i] == U[i-1]:
            DP[i] = DP[i-1]
        else:
            if U[i-1] == D[i-1]: DP[i] = (DP[i-1] * 2) % mod
            else:
                if U[i] == D[i]: DP[i] = DP[i-1]
                else: DP[i] = (DP[i-1] * 3) % mod
    print(DP[N-1]) 


    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double PI = 3.14159265358979;
const double E = 2.718281828459045;
const double root2 = sqrt(2);
typedef pair<int, int> P;
typedef unsigned int ui;
int main() {
	int isprime[1000001];
	fill(isprime, isprime + 1000001, 1);
  isprime[1]=0;
	for (int i = 2; i < 1000001; i++) {
		if (isprime[i] == 1) {
			for (int j = 2 * i; j < 1000001; j += i) {
				isprime[j] = 0;
			}
		}
	}
	int a, d, n;
	while (cin >> a >> d >> n) {
		if (n == 0)break;
		int count = 0; int i;
		for (i = a; count < n; i += d) {
			if (isprime[i] == 1)count++;
		}
		cout << i - d << endl;
	}
	return 0;
}



Measured memory_bytes: 6984
#include<bits/stdc++.h>
#define maxn 1e9+5
#define ll long long int
using namespace std;
int main()
{
 ll n,k;
 cin>>n>>k;
 vector<ll>h(n),dp(n+1,maxn);
 for(int i=0;i<n;i++) cin>>h[i];
 dp[0]=0;
 for(int i=1;i<n;i++){
     for(int j=i-1;j>=0&&j>=i-k;j--)
       {
           dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));   //this means we take min of current position and (position from past+distance/height to reach current position) and then check for different moves for min value
        }
    }

  
 cout<<dp[n-1]<<"\n";

 return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define N 200005
const int INF=0x3f3f3f3f;
struct edge{
	int t,next;
}e[N*4];int ecnt,head[N*2];//1~n blue n+1~n+n red
void addedge(int f,int t){
	e[++ecnt]=(edge){t,head[f]};head[f]=ecnt;
	e[++ecnt]=(edge){f,head[t]};head[t]=ecnt;
}
int fa[N],dis[N];
void DFS(int u,int fr){
	fa[u]=fr;dis[u]=dis[fr]+1;
	for(int i=head[u];i;i=e[i].next)
		if(e[i].t!=fr) DFS(e[i].t,u);
} 
bool judge(int f,int t){//is the distance between f and t is smaller or equal to 2
	if(dis[f]==dis[t]) return fa[f]==fa[t];
	if(dis[f]>dis[t]) swap(f,t);
	return fa[t]==f||fa[fa[t]]==f;
}
int n,x,y,ans;
void DFS2(int u,int fr,int d){
	if(dis[u-n]<=d) return;
	ans=max(ans,dis[u-n]);
	for(int i=head[u];i;i=e[i].next)
		if(e[i].t!=fr){
			DFS2(e[i].t,u,d+1);
			if(judge(u-n,e[i].t-n)==false)
				ans=INF;
		}
}
int main(){
	scanf("%d%d%d",&n,&x,&y);
	for(int i=1,f,t;i<n;i++)
		scanf("%d%d",&f,&t),addedge(f+n,t+n);
	for(int i=1,f,t;i<n;i++)
		scanf("%d%d",&f,&t),addedge(f,t);
	dis[0]=-1;DFS(y,0);
	DFS2(x+n,0,0);
	if(ans==INF) ans=-1;
	else ans*=2;
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;
typedef long long ll;


int main(){
    ll n,tot;
    cin>>n;
    for(ll i=n; ; i*=2){
        if(i%2==0 && i%n==0){
            tot=i;
            break;
        }
    }
    cout<<tot<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <tuple>

bool mycompare( const std::tuple<std::string,int,int> &lhs, const std::tuple<std::string,int,int> &rhs );
std::vector<std::tuple<std::string,int,int>> rests;

int main(void){
	int N;
	std::cin>>N;

	for(int i=0;i<N;i++){
		std::string S;
		int P;
		std::cin>>S>>P;
		std::tuple<std::string,int,int> temp = std::make_tuple(S,P,i+1);
		rests.push_back(temp);
	}
	sort(rests.begin(),rests.end(),mycompare);
	for(int i=0;i<N;i++){
		std::tuple<std::string,int,int> temp = rests.at(i);
		std::cout<<std::get<2>(temp)<<std::endl;
	}
	return 0;
}

bool mycompare( const std::tuple<std::string,int,int> &lhs, const std::tuple<std::string,int,int> &rhs )
{
    if (std::get<0>(lhs) != std::get<0>(rhs)) return std::get<0>(lhs) < std::get<0>(rhs);
    if (std::get<1>(lhs) != std::get<1>(rhs)) return std::get<1>(lhs) > std::get<1>(rhs);
    return std::get<2>(lhs) < std::get<2>(rhs);
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

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

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

// 約数の列挙 O(√n)
vector<ll> divisor(ll n) {
    vector<ll> res;

    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) res.push_back(n / i);
        }
    }

    return res;
}

int main() {
    INIT;
    ll N;
    cin >> N;

    vector<ll> divs = divisor(N);
    sort(ALL(divs));

    ll ans = 0;
    rep(i, SZ(divs)) {
        ll m = (N / divs[i]) - 1;
        if (m <= divs[i])
            continue;
        else
            ans += m;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define itn int

int main(void){
    int n;
    cin >> n;
    int x[n],num[n];
    
    for(int i = 0;i < n;i++)cin >> x[i];
    for(int i = 0;i < n;i++)num[i] = x[i];
    sort(num,num+n);
    
    for(int i = 0;i < n;i++){
        
        if(x[i] >= num[n/2]){
            cout << num[n/2-1];
        } else if(x[i] < num[n/2]){
            cout << num[n/2];
        }
        
        cout << endl;
        
    }
    
}

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

using namespace std;

int main(){
    int N;
    cin >> N;
    long long int ans = 1000,kabu=0;

    vector<long long int> A(N),mx(N,0),mn(N,10000);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }

    for(int i=1;i<N;i++){
        if(A[i-1]<A[i]){
            kabu = ans / A[i-1];
            ans -= kabu * A[i-1];
            ans += kabu * A[i];
            kabu = 0;
        }
    }

    cout << ans << endl;
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int n;
    string s;
    cin >> n >> s;
    int mx = 0;
    int m = 0;
    REP(i, n) {
        m += (s[i] == 'I' ? 1 : -1);
        mx = max(mx, m);
    }
    cout << mx << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
typedef long long ll;
struct node{
    ll i,j;
};
node fun(ll a){
    node ans;
    for (int i=(int)sqrt(a);i>=1;i--){
        if (a%i==0){
            ans.i=i,ans.j=a/i;
            return ans;
        }
    }
    return ans;
}
int main(){
    ll n;
    cin>>n;
    node ans;
    ans=fun(n);
    ll ans1=ans.i+ans.j-2;
    cout<<ans1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
main(){
    int N,D,X;
    cin>>N;
    cin>>D;
    D--;
    cin>>X;
    int a[N];
    for(int i;i<N;i++){
        cin>>a[i];
        X++;
        X+=(D/a[i]);
    }
    cout<<X<<endl;
    return 0;
    
}

Measured memory_bytes: 256
S = input()
if S[0] == 'A':
    i = S[2:-1].find("C")
    c = S[2:-1].count("C")
    if i != -1 and c == 1:
        i += 2
        for j in range(len(S)):
            if j > 0 and i != j:
                if not ord('a') <= ord(S[j]) <= ord('z'):
                    break
        else:
            print("AC")
            exit(0)
print("WA")


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

int main()
{
    int n;
    cin >> n;
    int a[n], b[n], c[n - 1];
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    for(int i = 0; i < n - 1; i++) cin >> c[i];

    int prev = -1;
    int sut = 0;
    for(int i = 0; i < n; i++)
    {
        sut += b[a[i] - 1];
        if(prev == a[i] - 1) sut += c[prev - 1];
        prev = a[i];
    }
    cout << sut << endl;
}

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

int main()
{
    int N;
    string S, T;
    cin >> N >> S >> T;
    string res = "";
    for (int i = 0; i < N; i++)
    {
        res += S.at(i);
        res += T.at(i);
    }
    cout << res << endl;
}

Measured memory_bytes: 256
fn main() {
    proconio::input! {
        h: usize,
        w: usize,
        a: [proconio::marker::Bytes; h],
    }
    const MOD: u32 = 1_000_000_007;
    let mut dp = vec![0u32; w + 1];
    dp[0] = 1;
    for a in a {
        let mut next = vec![0u32; w + 1];
        for (i, _) in a.into_iter().enumerate().filter(|c| c.1 == b'.') {
            dp[i + 1] = (dp[i + 1] + dp[i]) % MOD;
            next[i] = dp[i];
        }
        dp = next;
    }
    let ans = dp[w - 1];
    println!("{}", ans);
}

Measured memory_bytes: 3956
s = list(input())
X = []
hoge = 0
for i in range(len(s)):
    if s[i] == 'x':
        hoge += 1
    else:
        X.append(hoge)
        X.append(s[i])
        hoge = 0
X.append(hoge)
ans = 0

for i in range(len(X)//2):
    if i % 2 == 0:
        ans += abs(X[i]-X[-i-1])
    elif X[i] != X[-i-1]:
        print(-1)
        exit()
print(ans)

Measured memory_bytes: 5544
n, x = (int(i) for i in input().split())
l = [0] + [int(i) for i in input().split()]

d = 0
ans = 0
i = 1
while d <= x:
    ans += 1
    if ans == n+1:
        break
    d = d + l[i]
    i += 1

print(ans)

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

int main()
{
    int n, ac = 0, wa = 0, tle = 0, re = 0;
    string s;
    cin >> n;
    while(n--) {
        cin >> s;
        if(s == "AC") {
            ac++;
        }
        if(s == "WA") {
            wa ++;
        }
        if(s == "TLE") {
            tle++;
        }
        if(s == "RE") {
            re++;
        }
    }
    cout << "AC x " << ac << '\n';
    cout << "WA x " << wa << '\n';
    cout << "TLE x " << tle << '\n';
    cout << "RE x " << re << '\n';
    return 0;
}


Measured memory_bytes: 3632
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskD {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			long c = in.nextLong();
			long[] x = new long[n];
			long[] v = new long[n];
			for (int i = 0; i < n; i++) {
				x[i] = in.nextLong();
				v[i] = in.nextLong();
			}

			// Full circle.
			long ans = -c;
			for (int i = 0; i < n; i++) {
				ans += v[i];
			}

			long[] d0 = new long[n];
			{
				long sum = 0;
				for (int i = 0; i < n; i++) {
					sum += v[i];
					d0[i] = sum - 2 * x[i];
					if (i > 0) {
						d0[i] = Math.max(d0[i], d0[i - 1]);
					} else {
						d0[i] = Math.max(d0[i], 0);
					}
				}
			}

			long[] d1 = new long[n];
			{
				long sum = 0;
				for (int i = n - 1; i >= 0; i--) {
					sum += v[i];
					d1[i] = sum - 2 * (c - x[i]);
					if (i + 1 < n) {
						d1[i] = Math.max(d1[i], d1[i + 1]);
					} else {
						d1[i] = Math.max(d1[i], 0);
					}
				}
			}

			{
				long sum = 0;
				for (int i = 0; i < n; i++) {
					sum += v[i];
					long cur = Math.max(0, sum - x[i]);
					if (i + 1 < n) {
						cur += d1[i + 1];
					}
					ans = Math.max(ans, cur);
				}
			}

			{
				long sum = 0;
				for (int i = n - 1; i >= 0; i--) {
					sum += v[i];
					long cur = Math.max(0, sum - (c - x[i]));
					if (i - 1 >= 0) {
						cur += d0[i - 1];
					}
					ans = Math.max(ans, cur);
				}
			}

			out.println(ans);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

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

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

	}
}



Measured memory_bytes: 46980
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
#define INF  100000000000
//#define INF  100;
typedef long long ll;

ll dp[101][100001];

int main() {
  int N,W; cin >> N >> W;
  int v[101],w[101];
  for ( int i = 0; i < N; i++ ) cin >> w[i] >> v[i];
  for ( int i = 0; i <= N; i++ ) {
    for ( int j = 0; j <= 100000; j++ ) {
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;
  for ( int i = 0; i < N; i++ ) {
    for ( int j = 0; j <= 100000; j++ ) {
      if ( j-v[i] >= 0 ) {
      dp[i+1][j] = min(dp[i][j],dp[i][j-v[i]]+w[i]);
      } else {
	dp[i+1][j] = dp[i][j];
      }
    }
  }
  
  /* for ( int i = 0; i <= N; i++ ) {
    for ( int j = 0; j <=12; j++ ) {
      cout << dp[i][j] << " ";
    }
    cout << endl;
    }*/
  for ( int j = 100000; j >= 0; j-- ) {
    if ( dp[N][j] <= W ) {
      cout << j << endl;
      return 0;
    }
  }
				   
  return 0;
}


Measured memory_bytes: 79104
#pragma comment(linker,"/stack:16777216")
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define forr(a,n) for(int a=n;a>=1;a--)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define repr(a,n) for(int a=n-1;a>=0;a--)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0x3f,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

ll a[200010];
bool b[1000010];
template<typename _EuclideanRingElement>_EuclideanRingElement __lcm(_EuclideanRingElement __m, _EuclideanRingElement __n){
	_EuclideanRingElement __p=__gcd(__m,__n);
	_EuclideanRingElement __q=__m*__n/__p;
	return __q;
}
int main(int argc,char** argv){
	ll n;
	cin>>n;
	rep(i,n)cin>>a[i];
	if(n==1ll){
		cout<<1;
		return 0;
	}
	sort(a,a+n);
	ll did=0ll;
	rep(i,n){
		if(b[a[i]])continue;
		//cout<<a[i]<<endl;
		for(int j=a[i];j<=a[n-1];j+=a[i]){
			b[j]=1;
		}
		if(i<n-1){
			if(a[i]!=a[i+1]){
				//cout<<a[i]<<endl;
				did++;
			}
		}else did++;
	}
	cout<<did;
	return 0;
}

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

int main(){
    int n,x;
    int numcount=0;
    int num[100]={};
    while(1){
        cin>>n>>x;
        if(n==0&&x==0){
            break;
        }
        int count=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                for(int k=0;k<n;k++){
                    if((i!=j)&&(j!=k)&&(k!=i)&&(i+j+k+3==x)){
                        count++;
                    }
                }
            }
        }
        num[numcount]=count/6;
        numcount++;
    }
    for(int l=0;l<numcount;l++){
        cout<<num[l]<<endl;
    }
    
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++) 
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> pii;



int main() {

	string s, t,u;
	cin >> s >> t;
	int a,b;
	cin >> a>>b;
	cin >> u;

	if (s == u)a-- ;
	if (t == u)b--;
	cout << a << " " << b << endl;

}

Measured memory_bytes: 256
#abc091b

n=int(raw_input())
s=[]
t=[]
for i in xrange(n):
 s.append(raw_input())
m=int(raw_input())
for i in xrange(m):
 t.append(raw_input())
res=0
for i in xrange(n):
 res=max(res,s.count(s[i])-t.count(s[i]))
print res


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

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

        if (n == 0) break;

        vector<int> tmp(n);

        for (int i = 0; i < n; i++){
            string s;
            cin >> s;
            tmp[i] = (int)s.size();
        }

        for (int i = 0; i < n; i++){

            int cnt = i;

            int check = 0;
            while (check < 5){
                check += tmp[cnt];
                cnt++;
            }
            if (check != 5) continue;

            check = 0;
            while (check < 7){
                check += tmp[cnt];
                cnt++;
            }
            if (check != 7) continue;

            check = 0;
            while (check < 5){
                check += tmp[cnt];
                cnt++;
            }
            if (check != 5) continue;

            check = 0;
            while (check < 7){
                check += tmp[cnt];
                cnt++;
            }
            if (check != 7) continue;

            check = 0;
            while (check < 7){
                check += tmp[cnt];
                cnt++;
            }
            if (check != 7) continue;

            cout << i + 1 << endl;
            break;
        }
    }
}


Measured memory_bytes: 3168
while True:
    a=int(input())
    if a==0:
        break
    b=((1000-a)//500)
    c=(((1000-a)-500*b)//100)
    d=(((1000-a)-500*b-100*c)//50)
    e=(((1000-a)-500*b-100*c-50*d)//10)
    f=(((1000-a)-500*b-100*c-50*d-10*e)//5)
    g=((1000-a)-500*b-100*c-50*d-10*e-5*f)
    print(b+c+d+e+f+g)


Measured memory_bytes: 5592
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<string>
#include<map>

using namespace std;
const int INF = 1<<30;
typedef long long int ll;

int main(){
  int n;cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  int count=0;
  for(int i=0;i<n;i++){
  	if(a[a[i]-1]==i+1)count++;
  }
  cout<<count/2<<endl;
}


Measured memory_bytes: 640
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

int main(void) {

	char str;
	int ans = 700;
	for (int i = 0; i < 3; i++) {
		scanf("%c", &str);
		if (str == 'o')
			ans += 100;

	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
/**
* Think twice, code once.
* 1.integer overflow(maybe even long long overflow : (a+b >= c) -> (a >= c-b)
* 2.runtime error
* 3.boundary condition
* ---------------------------------------------------------------------------------------
* Author : zzy
* Date : 2020-03-19-19.11.19 Thursday
*/
#include <bits/stdc++.h>

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const i64 maxn = (i64)1e6+1000;
i64 n, W, w[110], v[110], dp[maxn];
const i64 INF = 0x3f3f3f3f;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    ms(dp, INF);
    dp[0] = 0;
    cin >> n >> W;
    for1(i, n) cin >> w[i] >> v[i];
    int sum = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = sum; j >= 0; --j) {
            if (dp[j] != INF) {
                dp[j+v[i]] = min(dp[j+v[i]], dp[j]+w[i]);
            }
        }
        sum += v[i];
    }
    int ans = 0;
    for (int i = sum; i >= 0; --i) {
        if (dp[i] <= W) {
            ans = i;
            break;
        }
    }
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 8064
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)

ll n,m,p[100000],a[100000],b[100000],c[100000];
ll imos[100000];

int main()
{
	cin>>n>>m;
	rep(i,m){
		cin>>p[i];
		p[i]--;
	}
	rep(i,n-1){
		cin>>a[i]>>b[i]>>c[i];
	}
	rep(i,m-1){
		if(p[i]<p[i+1]){
			imos[p[i]]++;
			imos[p[i+1]]--;
		}
		else{
			imos[p[i]]--;
			imos[p[i+1]]++;
		}
	}
	rep(i,n-2){
		imos[i+1]+=imos[i];
	}
	ll ans=0;
	rep(i,n-1){
		ans+=min(a[i]*imos[i],c[i]+b[i]*imos[i]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 7016
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int n,m,p,ans=0;
vector<int> e,b,c,d;
void dfs(vector<int>a){
  if(a.size()==n+1){
    int now=0;
    rep(i,p){
      if(a[b[i]]-a[e[i]]==c[i])now+=d[i];
    }
    ans=max(ans,now);
    return;
  }
  a.push_back(a.back());
  while(a.back()<=m){
    dfs(a);
    a.back()++;
  }
}
int main(){ 
  cin>>n>>m>>p;
  e=b=c=d=vector<int>(p);
  rep(i,p){
    cin>>e[i]>>b[i]>>c[i]>>d[i];
  }
  dfs(vector<int>(1,1));
  cout<<ans;
  }


Measured memory_bytes: 3604
S=input()
rec={"N":0,"W":0,"S":0,"E":0}
for i in S:
    rec[i]+=1

if rec["N"]>0 and rec["S"]==0:
    print("No")
elif rec["N"]==0 and rec["S"]>0:
    print("No")    
elif rec["W"]>0 and rec["E"]==0:
    print("No")
elif rec["W"]==0 and rec["E"]>0:
    print("No")    
else:
    print("Yes")

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

int64_t p = pow(10.0,9.0) + 7;

int64_t modPfactorial(int n) {
    if(n == 1)
        return 1;

    return ((modPfactorial(n-1) % p) * n) % p;
}
int main() {
    int trainingNum;
    cin >>trainingNum;

    cout << modPfactorial(trainingNum) << endl;
}   

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int a,b,c;
  cin>>a>>b>>c;
  if(a%2==1 && b%2==1 && c%2==1){
    cout<<min(a*b,min(b*c,a*c))<<endl;
  }else cout<<0<<endl;

  return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
a = [['#'] * (w + 2)] * 2
a[1: 1] = (list('#' + input() + '#') for _ in range(h))
p = [(i, j) for i in range(1, h + 1) for j in range(1, w + 1) if a[i][j] == '#']
d = (-1, 0), (1, 0), (0, -1), (0, 1)
r = -1
while p:
    r += 1
    s = []
    for i, j in p:
        for di, dj in d:
            di += i
            dj += j
            if a[di][dj] == '.':
                a[di][dj] = '#'
                s.append((di, dj))
    p = s
print(r)


Measured memory_bytes: 132688
import java.util.*;

/**
 * Main
 */
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int A = sc.nextInt();
		int B = sc.nextInt();
		if (A == B) {
			System.out.println(A + B);
		} else {
			System.out.println(2 * Math.max(A, B) - 1);
		}

		sc.close();
	}
};

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

using namespace std;

int n;
char s[1];
int a = 0, b = 0, c = 0, d = 0;

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		cin >> s[0];
		if (s[0] == 'P') {
			a = 1;
		} else if (s[0] == 'W') {
			b = 1;
		} else if (s[0] == 'G') {
			c = 1;
		} else if (s[0] == 'Y') {
			d = 1;
		}
	}
	if (a + b + c + d == 3) {
		puts("Three");
	} else {
		puts("Four");
	}
	return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    let M: usize = read();
    let X: usize = read();
    let mut vec = vec![];
    for _ in 0..N {
        let C: usize = read();
        let mut vec2: Vec<usize> = vec![];
        for _ in 0..M {
            vec2.push(read());
        }
        vec.push((C, vec2));
    }
    let ans = dfs(0, 0, vec![0; M], X, &vec);
    println!(
        "{}",
        match ans {
            None => -1,
            Some(a) => a as i32,
        }
    );
}

fn dfs(
    cost: usize,
    idx: usize,
    levels: Vec<usize>,
    target: usize,
    books: &[(usize, Vec<usize>)],
) -> Option<usize> {
    if levels.iter().all(|&v| v >= target) {
        return Some(cost);
    }
    if idx == books.len() {
        return None;
    }
    // skip next book
    let ans1 = dfs(cost, idx + 1, levels.clone(), target, books);
    // don't skip next book
    let next_cost = cost + books[idx].0;
    let mut next_levels = vec![];
    for i in 0..levels.len() {
        next_levels.push(levels[i] + books[idx].1[i]);
    }
    let ans2 = dfs(next_cost, idx + 1, next_levels, target, books);
    match (ans1, ans2) {
        (None, None) => None,
        (None, Some(a)) => Some(a),
        (Some(a), None) => Some(a),
        (Some(a), Some(b)) => Some(std::cmp::min(a, b)),
    }
}


Measured memory_bytes: 2156
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<iterator>
#include<stack>
#include<queue>
#include<utility>
#include<functional>
#include<bitset>
#include<numeric>
#include<cstring>
#include<tuple>
using namespace std;

int n;
long double ans = 0.0, dp[ 3003 ][ 3003 ];
vector< long double > p( 3003 ), pro( 3003, 1 );

long double solve( int i, int heads )
{
	if( i == 0 && heads == 0 )
	{
		return 1;
	}
	else if( i == 0 && heads >= 1 )
	{
		return 0;
	}
	else if( i >= 1 && heads == 0 )
	{
		return pro[ i ];
	}
	if( dp[ i ][ heads ] >= 0 )
	{
		return dp[ i ][ heads ];
	}
	dp[ i ][ heads ] = p[ i ] * solve( i - 1, heads - 1 ) + ( 1 - p[ i ] ) * solve( i - 1, heads );
	return dp[ i ][ heads ];
}

int main( void )
{
	ios :: sync_with_stdio( 0 );
	cin.tie( 0 );
	
	memset( dp, -1, sizeof( dp ) );
	cin >> n;
	for( int i = 1; i <= n; ++i )
	{
		cin >> p[ i ];		
	}
	for( int i = 1; i <= n; ++i )
	{
		pro[ i ] = pro[ i - 1 ] * ( 1 - p[ i ] );		
	}
	for( int i = n / 2 + 1; i <= n; ++i )
	{
		ans += solve( n, i );
	}
	cout << setprecision( 15 ) << fixed << ans << "\n";
	return 0;
}

Measured memory_bytes: 141440
package main

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

func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanInt64() int64 {
	sc.Scan()
	i, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return i
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func scanInts64(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		res[i] = scanInt64()
	}
	return res
}

func scanText() string {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Scan()
	return sc.Text()
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	var r float64
	fmt.Scan(&r)
	fmt.Println(r * 2 * math.Pi)

}


Measured memory_bytes: 1824
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
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; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

    int ans = 1 << 29;
    rep(start, 2)
    {
        int v = start;
        int cnt = 0;
        rep(i, s.size())
        {
            if (s[i] - '0' != v) cnt++;
            v = 1 - v;
        }
        chmin(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
def main():
    a, b, c, x, y = map(int, input().split())

    total_min = a * x + b * y

    for i in range(2, max(x, y)*2+1, 2):
        total = a * max(x - i//2, 0) + b * max(y - i//2, 0) + c * i
        total_min = min(total, total_min)
    print(total_min)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> P;

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

	cin >> n >> a >> b;

	ll x, y, ans;
	x = n / (a + b);
	y = n % (a + b);
	if (y > a) {
		ans = x * a + a;
	} else {
		ans = x * a + y;
	}
	cout << ans << endl;

	
	return 0;
}

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

using namespace std;

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

  vector<pair<int64_t, int64_t>> V;
  for (int i = 0; i < N; i++) {
    int64_t A, B;
    cin >> A >> B;

    V.push_back({B, A});
  }
  sort(V.begin(), V.end());

  int64_t t = 0;
  for (int i = 0; i < N; i++) {
    t += V[i].second;
    if (t > V[i].first) {
      printf("No\n");
      return 0;
    }
  }

  printf("Yes\n");

  return 0;
}


Measured memory_bytes: 6384
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
int x[20][20],y[20][20],a[20];
signed main(){
   int n;
   cin>>n;
   for (int i = 0; i < n; i++)
   {
       
       cin>>a[i];
    REP(j,a[i]) {
        cin>>x[i][j]>>y[i][j];
        x[i][j]--;
        y[i][j];
    }
   }
   int ans=0;
   for (int bit = 0; bit < (1<<n); bit++)
   {   bool ok=true,ok2=true;
       vector<bool>flag(n,false);
       for (int i = 0; i < n; i++)
       {    if(bit & (1LL<<i)) flag[i]=true;
           for (int j = 0; j < a[i]; j++)
           {
               if(flag[i]){
               if(y[i][j]){
                   if(!(bit & (1LL<<x[i][j]))){
                       ok=false;
                       break;
                   }
               }
               else{
                    if(bit & (1LL<<x[i][j])){
                       ok=false;
                       break;
                   }
               }
           }
          
           }
            if(!ok) {
                ok2=false;
                break;
            }
           
       }
       if(ok2){
           int cnt=0;
            for (int i = 0; i < n; ++i) {
            if (bit & (1LL<<i)) { // i が bit に入るかどうか
                cnt++;
            }
           // cout<<cnt<<endl;
        }
        chmax(ans,cnt);
       }
       
   }
   cout<<ans<<endl;
   
   
   
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){
  int n;
  cin >> n;
  mint ans = 1;
  rep(i, n){
    ans *= (i+1);
  }
  cout << ans.x << endl;
  return 0;
}

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

typedef long long int ll;
ll n;

string getAns(ll x) {
    string ans = "";

    while(x) {
        x--;
        ll cur = x%26;
        ans.push_back('a' + x%26);
        x /= 26;
    }
    reverse(ans.begin(), ans.end());
    return ans;
}

int main() {
    scanf("%lld", &n);

    cout << getAns(n) << endl;
}

Measured memory_bytes: 3644